You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ke...@apache.org on 2007/04/19 12:15:31 UTC

svn commit: r530359 - in /incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests: CTSGeneralSuite.java general/XSDHelperTest.java general/XSDSerializationTest.java

Author: kelvingoodson
Date: Thu Apr 19 03:15:24 2007
New Revision: 530359

URL: http://svn.apache.org/viewvc?view=rev&rev=530359
Log:
TUSCANY-1181 applied Dan's patch,  but took the liberty of reversing the logic in the checkTypes method as per the comment in the method.
This revealed another test failure which was fixed up by adding a setup/teardown method to handle refreshing the scope between tests.  Doing this also allowed me to remove the @Ignore comment from the test of doing a duplicate define

Added:
    incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/general/XSDHelperTest.java
      - copied, changed from r530330, incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/general/XSDSerializationTest.java
Removed:
    incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/general/XSDSerializationTest.java
Modified:
    incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/CTSGeneralSuite.java

Modified: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/CTSGeneralSuite.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/CTSGeneralSuite.java?view=diff&rev=530359&r1=530358&r2=530359
==============================================================================
--- incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/CTSGeneralSuite.java (original)
+++ incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/CTSGeneralSuite.java Thu Apr 19 03:15:24 2007
@@ -25,7 +25,7 @@
 
 import test.sdo21.tests.api.DataObjectTest;
 import test.sdo21.tests.conversion.DateConversionTest;
-import test.sdo21.tests.general.XSDSerializationTest;
+import test.sdo21.tests.general.XSDHelperTest;
 import test.sdo21.tests.api.DynamicTypesFromSchemaTestCase;
 
 /**
@@ -34,14 +34,14 @@
  * <ul>
  * <li>{@link test.sdo21.tests.api.DataObjectTest}</li>
  * <li>{@link test.sdo21.tests.conversion.DateConversionTest}</li>
- * <li>{@link test.sdo21.tests.general.XSDSerializationTest}</li>
+ * <li>{@link test.sdo21.tests.general.XSDHelperTest}</li>
  * <li>{@link test.sdo21.tests.api.DynamicTypesFromSchemaTestCase}</li>
  * </ul>
  * New test cases, or test cases that do not have consencus by the community
  * should be placed in the {@link test.sdo21.UnderReviewSuite} suite.
  */
 @RunWith(Suite.class)
-@Suite.SuiteClasses( {DateConversionTest.class, XSDSerializationTest.class, DataObjectTest.class,
+@Suite.SuiteClasses( {DateConversionTest.class, XSDHelperTest.class, DataObjectTest.class,
                       DynamicTypesFromSchemaTestCase.class})
 public class CTSGeneralSuite {
 

Copied: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/general/XSDHelperTest.java (from r530330, incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/general/XSDSerializationTest.java)
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/general/XSDHelperTest.java?view=diff&rev=530359&p1=incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/general/XSDSerializationTest.java&r1=530330&p2=incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/general/XSDHelperTest.java&r2=530359
==============================================================================
--- incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/general/XSDSerializationTest.java (original)
+++ incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/general/XSDHelperTest.java Thu Apr 19 03:15:24 2007
@@ -26,13 +26,26 @@
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-
+import java.io.IOException;
+import java.io.Reader;
 import java.net.URL;
 import java.util.Hashtable;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Vector;
 
 //import org.junit.Before;
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchemaComplexType;
+import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.apache.ws.commons.schema.XmlSchemaObjectTable;
+import org.apache.ws.commons.schema.XmlSchemaType;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.Ignore;
@@ -41,6 +54,7 @@
 
 import commonj.sdo.DataObject;
 import commonj.sdo.Type;
+import commonj.sdo.helper.HelperContext;
 import commonj.sdo.helper.TypeHelper;
 import commonj.sdo.helper.XSDHelper;
 
@@ -48,17 +62,28 @@
  * Junit 4.1 test case. Tests XSD serialization/deserialization.
  * 
  */
-public class XSDSerializationTest {
+public class XSDHelperTest {
     private static final String TEST_MODEL = "/simple.xsd";
-
+    private XmlSchemaCollection col = new XmlSchemaCollection();
     private static URL modelURL;
+    HelperContext scope = null;
 
     /**
      * Obtains test model resource. Runs once before any of the test methods.
      */
     @BeforeClass
     public static void obtainResource() {
-        modelURL = XSDSerializationTest.class.getResource(TEST_MODEL);
+        modelURL = XSDHelperTest.class.getResource(TEST_MODEL);
+    }
+    
+    @Before public void setUp()
+    {
+      scope = test.sdo21.CTSSuite.getTestHelper().createHelperContext();
+    }
+    
+    @After public void tearDown()
+    {
+      scope = null;
     }
 
     /**
@@ -69,15 +94,40 @@
     public void testDefineWithLocation() {
         try {
 
-            XSDHelper xsdHelper = test.sdo21.CTSSuite.getTestHelper().getXSDHelper();
+            XSDHelper xsdHelper = scope.getXSDHelper();
             List types = xsdHelper.define(modelURL.openStream(), modelURL.toString());
-            assertEquals("XSDHelper.define() did not create the expected number of Types", 2, types.size());
+            checkTypes(modelURL, scope.getTypeHelper(), types);
+            //assertEquals("XSDHelper.define() did not create the expected number of Types", 2, types.size());
         } catch (Exception e) {
             e.printStackTrace();
             fail("Exception calling xsdHelper.define" + e.toString());
         }
     }
 
+    
+    private void checkTypes(URL modelUrl, TypeHelper typeHelper, List types) {
+      // Checking xsd type definition post condition ---
+      // for all t in schemaTypes there exists a t' in types such that QName(t) == QName(t')
+      try {
+          XmlSchema schema = col.read(new StreamSource(modelUrl.openStream()), null);
+          XmlSchemaObjectTable schemaTypes = schema.getSchemaTypes();
+          
+          Iterator<XmlSchemaType> it = schemaTypes.getValues();
+          XmlSchemaType schemaType;
+          while (it.hasNext()){
+              schemaType = it.next();
+              QName qname = schemaType.getQName();
+              Type sdoType = typeHelper.getType(qname.getNamespaceURI(), qname.getLocalPart());
+              assertNotNull("Type not known to SDO environment "+ qname, sdoType);
+              assertTrue("Sdo type not created from this invokation of type definition", types.contains(sdoType));
+          }
+      } catch (IOException e) {
+          // TODO Auto-generated catch block
+          e.printStackTrace();
+          fail("Exception parsing schema");
+      }
+  }
+
     /**
      * Verifies the performance of XSDHelper.define() when a SchemaLocation is
      * not provided.
@@ -85,10 +135,10 @@
     @Test
     public void testDefineWithNoLocation() {
         try {
-            XSDHelper xsdHelper = test.sdo21.CTSSuite.getTestHelper().getXSDHelper();
-            List types = xsdHelper.define(XSDSerializationTest.class.getResourceAsStream(TEST_MODEL), null);
-
-            assertEquals("XSDHelper.define() did not create the expected number of Types", 2, types.size());
+            XSDHelper xsdHelper = scope.getXSDHelper();
+            List types = xsdHelper.define(XSDHelperTest.class.getResourceAsStream(TEST_MODEL), null);
+            checkTypes(modelURL, scope.getTypeHelper(), types);
+            //assertEquals("XSDHelper.define() did not create the expected number of Types", 2, types.size());
 
         } catch (Exception e) {
             e.printStackTrace();
@@ -102,7 +152,7 @@
     @Test
     public void testDuplicateDefineWithLocation() {
         try {
-            XSDHelper xsdHelper = test.sdo21.CTSSuite.getTestHelper().getXSDHelper();
+            XSDHelper xsdHelper = scope.getXSDHelper();
             List types = xsdHelper.define(modelURL.openStream(), modelURL.toString());
             assertEquals("XSDHelper.define() did not create the expected number of Types", 2, types.size());
             // redefine type
@@ -127,7 +177,7 @@
             // test for dynamic SDOs that have no XSD model. Here the testcase
             // succeeds only if the
             // xsd is generated by XSDHelper in which case xsd must not be null
-            XSDHelper xsdHelper = test.sdo21.CTSSuite.getTestHelper().getXSDHelper();
+            XSDHelper xsdHelper = scope.getXSDHelper();
             DataObject quoteType = CTSSuite.getTestHelper().getDataFactory().create("commonj.sdo", "Type");
             quoteType.set("uri", "http://www.example.com/dynamic");
             quoteType.set("name", "DynamicQuote");



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org