tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdan...@apache.org
Subject svn commit: r1041915 - in /tuscany/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml: ReadWriteAnyAttributeTestCase.java ReadWriteAnyElementTestCase.java ReadWriteLocalCompositeTestCase.java
Date Fri, 03 Dec 2010 17:10:50 GMT
Author: bdaniel
Date: Fri Dec  3 17:10:49 2010
New Revision: 1041915

URL: http://svn.apache.org/viewvc?rev=1041915&view=rev
Log:
Modify test cases so that they aren't checking for an exact string. Different parser implementations
can return strings that are equivalent but different in some trivial way

Modified:
    tuscany/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java
    tuscany/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java
    tuscany/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteLocalCompositeTestCase.java

Modified: tuscany/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java?rev=1041915&r1=1041914&r2=1041915&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java
Fri Dec  3 17:10:49 2010
@@ -22,6 +22,7 @@ package org.apache.tuscany.sca.assembly.
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.StringReader;
 
@@ -29,7 +30,9 @@ import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLOutputFactory;
 import javax.xml.stream.XMLStreamReader;
 
+import org.apache.tuscany.sca.assembly.Component;
 import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.Extension;
 import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
 import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
 import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
@@ -47,7 +50,7 @@ import org.junit.Test;
 public class ReadWriteAnyAttributeTestCase {
 
     private static final String XML = "<?xml version='1.0' encoding='UTF-8'?>"+
-		 	 "<composite xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200912\" " +
+		 	 "<composite xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200912\" " +		 	
 		 	            "targetNamespace=\"http://calc\" " +
 		 	            "name=\"Calculator\">"+
  	 	 	    "<component name=\"AddServiceComponent\" xmlns:test=\"http://test\" test:customAttribute=\"customValue\">"+
@@ -94,6 +97,8 @@ public class ReadWriteAnyAttributeTestCa
     	assertNotNull(composite);
     	reader.close();
 
+    	verifyComposite(composite);
+    	
     	ByteArrayOutputStream bos = new ByteArrayOutputStream();
     	staxProcessor.write(composite, bos, context);
 
@@ -101,7 +106,11 @@ public class ReadWriteAnyAttributeTestCa
     	// System.out.println(XML);
     	// System.out.println(bos.toString());
 
-    	assertEquals(XML, bos.toString());    	
+    	//assertEquals(XML, bos.toString());    	
+    	
+    	ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+    	composite = staxProcessor.read(bis, Composite.class, context);
+    	verifyComposite(composite);
     }
 
     /**
@@ -118,6 +127,8 @@ public class ReadWriteAnyAttributeTestCa
     	assertNotNull(composite);
     	reader.close();
 
+    	verifyComposite(composite);
+    	
     	ByteArrayOutputStream bos = new ByteArrayOutputStream();
     	staxProcessor.write(composite, bos, context);
 
@@ -125,6 +136,22 @@ public class ReadWriteAnyAttributeTestCa
     	// System.out.println(XML);
     	// System.out.println(bos.toString());
 
-    	assertEquals(XML, bos.toString());
+    //	assertEquals(XML, bos.toString());
+    	
+    	ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+    	composite = staxProcessor.read(bis, Composite.class, context);
+    	verifyComposite(composite);
+    }
+    
+    private void verifyComposite(Composite c) {
+    	assertEquals("Calculator", c.getName().getLocalPart());
+    	assertEquals(1, c.getComponents().size());
+    	Component component = c.getComponents().get(0);
+    	assertEquals("AddServiceComponent", component.getName());
+    	assertEquals(1, component.getAttributeExtensions().size());
+    	Extension extension = component.getAttributeExtensions().get(0);
+    	assertEquals("customAttribute", extension.getQName().getLocalPart());
+    	assertEquals("http://test", extension.getQName().getNamespaceURI());
+    	assertEquals("customValue", extension.getValue());
     }
 }
\ No newline at end of file

Modified: tuscany/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java?rev=1041915&r1=1041914&r2=1041915&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java
Fri Dec  3 17:10:49 2010
@@ -21,13 +21,17 @@ package org.apache.tuscany.sca.assembly.
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.StringReader;
 
 import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 
+import org.apache.tuscany.sca.assembly.Component;
 import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.Extension;
 import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
 import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
 import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
@@ -101,24 +105,54 @@ public class ReadWriteAnyElementTestCase
         assertNotNull(composite);
         reader.close();
 
+        verifyExtendedElementComposite(composite);
+        
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         staxProcessor.write(composite, bos, context);
 
         // used for debug comparison
-        // System.out.println(XML_RECURSIVE_EXTENDED_ELEMENT);
-        // System.out.println(bos.toString());
+//         System.out.println(XML_RECURSIVE_EXTENDED_ELEMENT);
+//         System.out.println(bos.toString());
 
-        assertEquals(XML_RECURSIVE_EXTENDED_ELEMENT, bos.toString());
+      //  assertEquals(XML_RECURSIVE_EXTENDED_ELEMENT, bos.toString());
         bos.close();
+        
+        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+    	composite = staxProcessor.read(bis, Composite.class, context);
+    	verifyExtendedElementComposite(composite);
     }
 
-    @Test
+    private void verifyExtendedElementComposite(Composite composite) throws XMLStreamException
{
+
+		assertEquals("RecursiveExtendedElement", composite.getName().getLocalPart());
+		assertEquals(1, composite.getExtensions().size());
+		Extension ext1 = (Extension) composite.getExtensions().get(0);
+		assertEquals("unknownElement", ext1.getQName().getLocalPart());
+		assertEquals("http://docs.oasis-open.org/ns/opencsa/sca/200912", ext1.getQName().getNamespaceURI());
+	
+		XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader((String)ext1.getValue()));
			
+		reader.next();
+		assertEquals("unknownElement", reader.getLocalName());
+		reader.next();
+		assertEquals("subUnknownElement1", reader.getLocalName());
+		assertEquals(1, reader.getAttributeCount());
+		assertEquals("attribute", reader.getAttributeLocalName(0));
+		assertEquals("anyAttribute", reader.getAttributeValue(0));
+
+		reader.close();
+					
+	}
+
+	@Test
     public void testReadWriteUnknwonImpl() throws Exception {
+
         XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML_UNKNOWN_IMPL));
         Composite composite = (Composite)staxProcessor.read(reader, context);
         assertNotNull(composite);
         reader.close();
 
+        verifyUnknownImplComposite(composite);
+        
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         staxProcessor.write(composite, bos, context);
 
@@ -126,13 +160,33 @@ public class ReadWriteAnyElementTestCase
         // System.out.println(XML_UNKNOWN_IMPL);
         // System.out.println(bos.toString());
 
-        assertEquals(XML_UNKNOWN_IMPL, bos.toString());
+      //  assertEquals(XML_UNKNOWN_IMPL, bos.toString());
         bos.close();
+        
+        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+    	composite = staxProcessor.read(bis, Composite.class, context);
+    	verifyUnknownImplComposite(composite);
     }
 
-    // @Test
+    private void verifyUnknownImplComposite(Composite composite) {
+
+    	assertEquals("aaaa", composite.getName().getLocalPart());
+    	assertEquals(1, composite.getComponents().size());
+    	Component component = composite.getComponents().get(0);
+    	assertEquals("unknownImpl", component.getName());
+    	assertEquals(1, component.getServices().size());
+    	assertEquals("service", component.getServices().get(0).getName());
+    	assertEquals(1, component.getExtensions().size());
+    	Extension ext = (Extension) component.getExtensions().get(0);
+    	assertEquals("http://docs.oasis-open.org/ns/opencsa/sca/200912", ext.getQName().getNamespaceURI());
+    	assertEquals("implementation.unknown", ext.getQName().getLocalPart());
+		
+	}
+
+	// @Test
     @Ignore()
     public void testReadWriteInvalidAttribute() throws Exception {
+    	
         XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML_UNKNOWN_IMPL_WITH_INVALID_ATTRIBUTE));
         Composite composite = (Composite)staxProcessor.read(reader, context);
         assertNotNull(composite);

Modified: tuscany/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteLocalCompositeTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteLocalCompositeTestCase.java?rev=1041915&r1=1041914&r2=1041915&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteLocalCompositeTestCase.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteLocalCompositeTestCase.java
Fri Dec  3 17:10:49 2010
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 
@@ -98,6 +99,11 @@ public class ReadWriteLocalCompositeTest
         staxProcessor.write(composite, bos, context);
         System.out.println(bos.toString());
         
-        assertEquals(LOCAL_COMPOSITE_XML, bos.toString());
+      //  assertEquals(LOCAL_COMPOSITE_XML, bos.toString());
+        
+        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+    	composite = staxProcessor.read(bis, Composite.class, context);
+    	assertNotNull(composite);
+    	assertTrue(composite.isLocal());
     }
 }



Mime
View raw message