You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by gw...@apache.org on 2007/02/27 13:54:59 UTC
svn commit: r512241 [5/5] - in /incubator/tuscany/java/cts: sdo2.1-tuscany/
sdo2.1-tuscany/src/test/java/test/sdo21/vendor/tuscany/tests/ sdo2.1/
sdo2.1/src/main/java/test/sdo21/ sdo2.1/src/main/java/test/sdo21/framework/
sdo2.1/src/main/java/test/sdo2...
Added: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/general/XMLHelperTest.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/general/XMLHelperTest.java?view=auto&rev=512241
==============================================================================
--- incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/general/XMLHelperTest.java (added)
+++ incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/general/XMLHelperTest.java Tue Feb 27 04:54:57 2007
@@ -0,0 +1,537 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package test.sdo21.tests.general;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.net.URL;
+import test.sdo21.tests.util.XMLEqualityChecker;
+
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.junit.Ignore;
+import org.junit.runner.RunWith;
+
+import test.sdo21.CTSSuite;
+
+import commonj.sdo.ChangeSummary;
+import commonj.sdo.Property;
+import commonj.sdo.Sequence;
+import commonj.sdo.DataObject;
+import commonj.sdo.Type;
+import commonj.sdo.helper.DataFactory;
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.helper.XMLHelper;
+import commonj.sdo.helper.XSDHelper;
+import commonj.sdo.helper.XMLDocument;
+
+/**
+ * Junit 4.1 test case. Tests various concepts against the XMLHelper.
+ */
+public class XMLHelperTest {
+ private static final String CUSTOMER1_XML = "/customer1.xml";
+ private static final String CUSTOMER2_XML = "/customer2.xml";
+ private static final String OPEN_XML = "/open2.xml";
+ private static final String MIXED_XML = "/mixed2.xml";
+ private static final String MIXEDOPEN_XML = "/mixedopen.xml";
+
+ /**
+ * Verify how the XMLHelper handles ChangeSummary.
+ */
+ @Ignore("Awaiting ChangeSummary updates to be pulled into WAS.")
+ @Test
+ public void testChangeSummary() throws Exception {
+
+ final String TEST_MODEL = "/simpleWithChangeSummary.xsd";
+ final String TEST_NAMESPACE = "http://www.example.com/simpleCS";
+
+ final String TEST_DATA_BEFORE_UNDO = "/simpleWithChangeSummary.xml";
+ final String TEST_DATA_AFTER_UNDO = "/simpleWithChangeSummaryUndone.xml";
+
+ // Populate the meta data for the test (Stock Quote) model
+ URL url = getClass().getResource(TEST_MODEL);
+ InputStream inputStream = url.openStream();
+ CTSSuite.getTestHelper().getXSDHelper().define(inputStream, url.toString());
+ inputStream.close();
+
+ Type quoteType = CTSSuite.getTestHelper().getTypeHelper().getType(TEST_NAMESPACE, "RootQuote");
+ DataObject quote = CTSSuite.getTestHelper().getDataFactory().create(quoteType);
+
+ ChangeSummary cs = quote.getChangeSummary();
+ ChangeSummary csp = (ChangeSummary)quote.get("changes");
+
+ assertSame("The ChangeSummay Property should be returned by getChangeSummary.", cs, csp);
+
+ quote.setString("symbol", "fbnt");
+ quote.setString("companyName", "FlyByNightTechnology");
+ quote.setBigDecimal("price", new BigDecimal("1000.0"));
+ DataObject child = quote.createDataObject("quotes");
+ child.setBigDecimal("price", new BigDecimal("1500.0"));
+ child = quote.createDataObject("quotes");
+ child.setBigDecimal("price", new BigDecimal("2000.0"));
+ child = child.createDataObject("quotes");
+ child.setBigDecimal("price", new BigDecimal("2000.99"));
+ child = quote.createDataObject("quotes");
+ child.setBigDecimal("price", new BigDecimal("2500.0"));
+
+ // Begin logging changes
+ //
+ cs.beginLogging();
+
+ // Modify the data graph in various ways
+ //
+ quote.setString("symbol", "FBNT");
+ quote.setBigDecimal("price", new BigDecimal("999.0"));
+ quote.setDouble("volume", 1000);
+
+ child = quote.createDataObject("quotes");
+ child.setBigDecimal("price", new BigDecimal("3000.0"));
+ child = quote.createDataObject("quotes");
+ child.setBigDecimal("price", new BigDecimal("4000.0"));
+
+ quote.getDataObject("quotes[2]").delete();
+
+ // Stop logging changes and serialize the resulting data graph
+
+ cs.endLogging();
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ CTSSuite.getTestHelper().getXMLHelper().save(quote, TEST_NAMESPACE, "stockQuote", baos);
+
+ assertTrue("XMLHelper did not accurately reflect the ChangeSummary.", XMLEqualityChecker
+ .equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(TEST_DATA_BEFORE_UNDO)));
+
+ // Undo all changes and then serialize the resulting data graph again
+
+ cs.undoChanges();
+
+ baos = new ByteArrayOutputStream();
+ CTSSuite.getTestHelper().getXMLHelper().save(quote, TEST_NAMESPACE, "stockQuote", baos);
+
+ assertTrue("XMLHelper did not accurately reflect the ChangeSummary after undoChanges().", XMLEqualityChecker
+ .equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(TEST_DATA_AFTER_UNDO)));
+ }
+
+ /**
+ * Verify how the XMLHelper handles open content
+ */
+ @Test
+ public void testDefineOpenContentProperty() throws IOException {
+ final String TEST_MODEL = "/open.xsd";
+ final String TEST_NAMESPACE = "http://www.example.com/open";
+ final String TEST_DATA = "/openContentProperty.xml";
+
+ TypeHelper typeHelper;
+ XSDHelper xsdHelper;
+ XMLHelper xmlHelper;
+ DataFactory dataFactory;
+
+ typeHelper = CTSSuite.getTestHelper().getTypeHelper();
+ dataFactory = CTSSuite.getTestHelper().getDataFactory();
+ xsdHelper = CTSSuite.getTestHelper().getXSDHelper();
+ xmlHelper = CTSSuite.getTestHelper().getXMLHelper();
+
+ // Populate the meta data for the test (Stock Quote) model
+ URL url = getClass().getResource(TEST_MODEL);
+ InputStream inputStream = url.openStream();
+ xsdHelper.define(inputStream, url.toString());
+ inputStream.close();
+
+ Type quoteType = typeHelper.getType(TEST_NAMESPACE, "OpenQuote");
+ DataObject quote = dataFactory.create(quoteType);
+
+ quote.setString("symbol", "s1");
+
+ Property companyProperty = typeHelper.getOpenContentProperty(TEST_NAMESPACE, "company");
+ DataObject company = quote.createDataObject(companyProperty);
+ company.setString("name", "FlyByNightTechnology");
+
+ Property priceProperty = typeHelper.getOpenContentProperty(TEST_NAMESPACE, "price");
+ quote.getList(priceProperty).add(new BigDecimal("1000.0"));
+
+ // Define a new SDO open content property with simple type
+ DataObject p = dataFactory.create("commonj.sdo", "Property");
+ p.set("type", typeHelper.getType("commonj.sdo", "Decimal"));
+ p.set("name", "highPrice");
+ Property highPrice = typeHelper.defineOpenContentProperty(TEST_NAMESPACE, p);
+
+ quote.setBigDecimal(highPrice, new BigDecimal("1100.0"));
+
+ // Define a new SDO open content property with complex type
+ DataObject mutualFundQuotePropertyDef = dataFactory.create("commonj.sdo", "Property");
+ mutualFundQuotePropertyDef.set("type", quoteType);
+ mutualFundQuotePropertyDef.set("name", "mutualFundQuote");
+ mutualFundQuotePropertyDef.setBoolean("containment", true);
+ Property mutualFundQuoteProperty =
+ typeHelper.defineOpenContentProperty(TEST_NAMESPACE, mutualFundQuotePropertyDef);
+
+ DataObject mutualFundQuote = quote.createDataObject(mutualFundQuoteProperty);
+ mutualFundQuote.setString("symbol", "mutual-1");
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ xmlHelper.save(quote, TEST_NAMESPACE, "openStockQuote", baos);
+
+ assertTrue("XMLHelper.save() did not accurately reflect open content.", XMLEqualityChecker
+ .equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(TEST_DATA)));
+
+ // validate existing property condition
+ Property duplicateProp = typeHelper.defineOpenContentProperty(TEST_NAMESPACE, p);
+ assertTrue("The expected Property equality was not true", highPrice.equals(duplicateProp));
+
+ // validate error condition, where new property exists with different
+ // type
+ boolean errorCondition = false;
+ try {
+ p = dataFactory.create("commonj.sdo", "Property");
+ p.set("type", typeHelper.getType("commonj.sdo", "String"));
+ p.set("name", "highPrice");
+ highPrice = typeHelper.defineOpenContentProperty(TEST_NAMESPACE, p);
+ } catch (IllegalArgumentException ex) {
+ errorCondition = true;
+ }
+ assertTrue("Should not be able to redefine a Property with a different Type.", errorCondition);
+ }
+
+ /**
+ * Verify how the XMLHelper handles Types defined using the TypeHelper. Save
+ * and load the Dataobject with the XMLHelper as an intermediate step.
+ */
+ @Test
+ public void testDefineTypeRoundTrip() throws Exception {
+ TypeHelper types = CTSSuite.getTestHelper().getTypeHelper();
+ DataFactory factory = CTSSuite.getTestHelper().getDataFactory();
+ XMLHelper xmlHelper = CTSSuite.getTestHelper().getXMLHelper();
+
+ Type intType = types.getType("commonj.sdo", "Int");
+ Type stringType = types.getType("commonj.sdo", "String");
+
+ // create a new Type for Customers
+ DataObject customerType = factory.create("commonj.sdo", "Type");
+ customerType.set("uri", "http://example.com/customer");
+ customerType.set("name", "Customer");
+
+ // create a customer number property
+ DataObject custNumProperty = customerType.createDataObject("property");
+ custNumProperty.set("name", "custNum");
+ custNumProperty.set("type", intType);
+
+ // create a first name property
+ DataObject firstNameProperty = customerType.createDataObject("property");
+ firstNameProperty.set("name", "firstName");
+ firstNameProperty.set("type", stringType);
+
+ // create a last name property
+ DataObject lastNameProperty = customerType.createDataObject("property");
+ lastNameProperty.set("name", "lastName");
+ lastNameProperty.set("type", stringType);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ xmlHelper.save(customerType, "commonj.sdo", "type", baos);
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ XMLDocument xdoc = xmlHelper.load(bais);
+
+ customerType = xdoc.getRootObject();
+
+ // now define the Customer type so that customers can be made
+ types.define(customerType);
+
+ DataObject customer1 = factory.create("http://example.com/customer", "Customer");
+
+ customer1.setInt("custNum", 1);
+ customer1.set("firstName", "John");
+ customer1.set("lastName", "Adams");
+ DataObject customer2 = factory.create("http://example.com/customer", "Customer");
+ customer2.setInt("custNum", 2);
+ customer2.set("firstName", "Jeremy");
+ customer2.set("lastName", "Pavick");
+
+ assertNotNull("Customer1 should not be null", customer1);
+ Type type = customer1.getType();
+ assertNotNull("Customer1.custNum should not be null", type.getProperty("custNum"));
+ assertNotNull("Customer1.firstName should not be null", type.getProperty("firstName"));
+ assertNotNull("Customer1.lastName should not be null", type.getProperty("lastName"));
+ assertEquals("Customer1.custNum should be intType", type.getProperty("custNum").getType(), intType);
+ assertEquals("Customer1.firstName should be stringType", type.getProperty("firstName").getType(), stringType);
+ assertEquals("Customer1.lastName should be stringType", type.getProperty("lastName").getType(), stringType);
+
+ assertNotNull("Customer2 should not be null", customer2);
+ type = customer2.getType();
+ assertNotNull("Customer1.custNum should not be null", type.getProperty("custNum"));
+ assertNotNull("Customer1.custNum should not be null", type.getProperty("firstName"));
+ assertNotNull("Customer1.custNum should not be null", type.getProperty("lastName"));
+ assertEquals("Customer1.custNum should be intType", type.getProperty("custNum").getType(), intType);
+ assertEquals("Customer1.firstName should be stringType", type.getProperty("firstName").getType(), stringType);
+ assertEquals("Customer1.lastName should be stringType", type.getProperty("lastName").getType(), stringType);
+
+ baos = new ByteArrayOutputStream();
+ xmlHelper.save(customer1, "http://example.com/customer", "Customer", baos);
+ assertTrue("XMLHelper.save() did not accurately reflect customer1.", XMLEqualityChecker
+ .equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(CUSTOMER1_XML)));
+
+ baos = new ByteArrayOutputStream();
+ xmlHelper.save(customer2, "http://example.com/customer", "Customer", baos);
+ assertTrue("XMLHelper.save() did not accurately reflect customer2.", XMLEqualityChecker
+ .equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(CUSTOMER2_XML)));
+ }
+
+ /**
+ * Verify how the XMLHelper handles Types defined using the TypeHelper.
+ */
+ @Test
+ public void testDefineType() throws Exception {
+ TypeHelper types = CTSSuite.getTestHelper().getTypeHelper();
+ DataFactory factory = CTSSuite.getTestHelper().getDataFactory();
+ XMLHelper xmlHelper = CTSSuite.getTestHelper().getXMLHelper();
+
+ Type intType = types.getType("commonj.sdo", "Int");
+ Type stringType = types.getType("commonj.sdo", "String");
+
+ // create a new Type for Customers
+ DataObject customerType = factory.create("commonj.sdo", "Type");
+ customerType.set("uri", "http://example.com/customer");
+ customerType.set("name", "Customer");
+
+ // create a customer number property
+ DataObject custNumProperty = customerType.createDataObject("property");
+ custNumProperty.set("name", "custNum");
+ custNumProperty.set("type", intType);
+
+ // create a first name property
+ DataObject firstNameProperty = customerType.createDataObject("property");
+ firstNameProperty.set("name", "firstName");
+ firstNameProperty.set("type", stringType);
+
+ // create a last name property
+ DataObject lastNameProperty = customerType.createDataObject("property");
+ lastNameProperty.set("name", "lastName");
+ lastNameProperty.set("type", stringType);
+
+ // now define the Customer type so that customers can be made
+ types.define(customerType);
+
+ DataObject customer1 = factory.create("http://example.com/customer", "Customer");
+ customer1.setInt("custNum", 1);
+ customer1.set("firstName", "John");
+ customer1.set("lastName", "Adams");
+ DataObject customer2 = factory.create("http://example.com/customer", "Customer");
+ customer2.setInt("custNum", 2);
+ customer2.set("firstName", "Jeremy");
+ customer2.set("lastName", "Pavick");
+
+ assertNotNull("Customer1 should not be null", customer1);
+ Type type = customer1.getType();
+ assertNotNull("Customer1.custNum should not be null", type.getProperty("custNum"));
+ assertNotNull("Customer1.firstName should not be null", type.getProperty("firstName"));
+ assertNotNull("Customer1.lastName should not be null", type.getProperty("lastName"));
+ assertEquals("Customer1.custNum should be intType", type.getProperty("custNum").getType(), intType);
+ assertEquals("Customer1.firstName should be stringType", type.getProperty("firstName").getType(), stringType);
+ assertEquals("Customer1.lastName should be stringType", type.getProperty("lastName").getType(), stringType);
+
+ assertNotNull("Customer2 should not be null", customer2);
+ type = customer2.getType();
+ assertNotNull("Customer1.custNum should not be null", type.getProperty("custNum"));
+ assertNotNull("Customer1.custNum should not be null", type.getProperty("firstName"));
+ assertNotNull("Customer1.custNum should not be null", type.getProperty("lastName"));
+ assertEquals("Customer1.custNum should be intType", type.getProperty("custNum").getType(), intType);
+ assertEquals("Customer1.firstName should be stringType", type.getProperty("firstName").getType(), stringType);
+ assertEquals("Customer1.lastName should be stringType", type.getProperty("lastName").getType(), stringType);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ xmlHelper.save(customer1, "http://example.com/customer", "Customer", baos);
+ assertTrue("XMLhelper.save() did not accurately reflect customer1", XMLEqualityChecker
+ .equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(CUSTOMER1_XML)));
+
+ baos = new ByteArrayOutputStream();
+ xmlHelper.save(customer2, "http://example.com/customer", "Customer", baos);
+ assertTrue("XMLhelper.save() did not accurately reflect customer2", XMLEqualityChecker
+ .equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(CUSTOMER2_XML)));
+ }
+
+ /**
+ * Verify how the XMLHelper handles defined Sequence types.
+ */
+ @Test
+ public void testDefineSequencedType() throws Exception {
+
+ TypeHelper types = CTSSuite.getTestHelper().getTypeHelper();
+ DataFactory factory = CTSSuite.getTestHelper().getDataFactory();
+ XMLHelper xmlHelper = CTSSuite.getTestHelper().getXMLHelper();
+
+ Type stringType = types.getType("commonj.sdo", "String");
+ Type decimalType = types.getType("commonj.sdo", "Decimal");
+
+ // Define a new mixed type - MixedQuote
+ DataObject mixedQuoteType = factory.create("commonj.sdo", "Type");
+ mixedQuoteType.set("uri", "http://www.example.com/mixed");
+ mixedQuoteType.set("name", "MixedQuote");
+ mixedQuoteType.set("sequenced", Boolean.TRUE);
+
+ DataObject symbolProperty = mixedQuoteType.createDataObject("property");
+ symbolProperty.set("name", "symbol");
+ symbolProperty.set("type", stringType);
+
+ DataObject companyNameProperty = mixedQuoteType.createDataObject("property");
+ companyNameProperty.set("name", "companyName");
+ companyNameProperty.set("type", stringType);
+
+ DataObject priceProperty = mixedQuoteType.createDataObject("property");
+ priceProperty.set("name", "price");
+ priceProperty.set("type", decimalType);
+
+ DataObject quotesProperty = mixedQuoteType.createDataObject("property");
+ quotesProperty.set("name", "quotes");
+ quotesProperty.set("type", mixedQuoteType);
+ quotesProperty.set("many", Boolean.TRUE);
+ quotesProperty.set("containment", Boolean.TRUE);
+
+ types.define(mixedQuoteType);
+
+ DataObject quote = factory.create("http://www.example.com/mixed", "MixedQuote");
+
+ assertTrue("Quote type should be Sequenced", quote.getType().isSequenced());
+
+ Sequence sequence = quote.getSequence();
+
+ sequence.add("\n ");
+
+ quote.setString("symbol", "fbnt");
+
+ sequence.add("\n ");
+
+ quote.setString("companyName", "FlyByNightTechnology");
+
+ sequence.add("\n some text\n ");
+
+ DataObject child = quote.createDataObject("quotes");
+ child.setBigDecimal("price", new BigDecimal("2000.0"));
+
+ sequence.add("\n more text\n ");
+
+ // quote.setBigDecimal("price", new BigDecimal("1000.0"));
+ sequence.add("price", new BigDecimal("1000.0"));
+
+ sequence.add("\n");
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ xmlHelper.save(quote, "http://www.example.com/mixed", "mixedStockQuote", baos);
+ assertTrue("XMLHelper.save() did not accurately reflect quote.", XMLEqualityChecker
+ .equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(MIXED_XML)));
+ }
+
+ /**
+ * Verify how the XMLHelper handles Types which are Sequenced and Open.
+ */
+ @Test
+ public void testDefineSequencedOpenType() throws Exception {
+ TypeHelper types = CTSSuite.getTestHelper().getTypeHelper();
+ DataFactory factory = CTSSuite.getTestHelper().getDataFactory();
+ XMLHelper xmlHelper = CTSSuite.getTestHelper().getXMLHelper();
+
+ Type stringType = types.getType("commonj.sdo", "String");
+ Type decimalType = types.getType("commonj.sdo", "Decimal");
+
+ // Define a new mixed type - MixedQuote
+ DataObject mixedQuoteType = factory.create("commonj.sdo", "Type");
+ mixedQuoteType.set("uri", "http://www.example.com/mixed");
+ mixedQuoteType.set("name", "MixedOpenQuote");
+ mixedQuoteType.set("sequenced", Boolean.TRUE);
+ mixedQuoteType.set("open", Boolean.TRUE);
+
+ // DataObject symbolProperty =
+ // mixedQuoteType.createDataObject("property");
+ // symbolProperty.set("name", "symbol");
+ // symbolProperty.set("type", stringType);
+
+ DataObject companyNameProperty = mixedQuoteType.createDataObject("property");
+ companyNameProperty.set("name", "companyName");
+ companyNameProperty.set("type", stringType);
+
+ DataObject priceProperty = mixedQuoteType.createDataObject("property");
+ priceProperty.set("name", "price");
+ priceProperty.set("type", decimalType);
+
+ DataObject quotesProperty = mixedQuoteType.createDataObject("property");
+ quotesProperty.set("name", "quotes");
+ quotesProperty.set("type", mixedQuoteType);
+ quotesProperty.set("many", Boolean.TRUE);
+ quotesProperty.set("containment", Boolean.TRUE);
+
+ types.define(mixedQuoteType);
+
+ // Define a global type
+ DataObject globalType = factory.create("commonj.sdo", "Type");
+ globalType.set("uri", "http://www.example.com/open");
+ // Don't set the type's name - null is used for types containing global
+ // properties.
+
+ DataObject symbolProperty = globalType.createDataObject("property");
+ symbolProperty.set("name", "symbol");
+ symbolProperty.set("type", stringType);
+ symbolProperty.set("containment", Boolean.TRUE);
+
+ types.define(globalType);
+
+ DataObject quote = factory.create("http://www.example.com/mixed", "MixedOpenQuote");
+
+ assertTrue("Quote type should be Sequenced.", quote.getType().isSequenced());
+
+ Sequence sequence = quote.getSequence();
+
+ sequence.add("\n ");
+
+ Type definedGlobalType = types.getType("http://www.example.com/open", null);
+
+ Property definedSymbolProperty = definedGlobalType.getProperty("symbol");
+ quote.setString(definedSymbolProperty, "fbnt");
+
+ sequence.add("\n ");
+
+ quote.setString("companyName", "FlyByNightTechnology");
+
+ sequence.add("\n some text\n ");
+
+ DataObject child = quote.createDataObject("quotes");
+ child.setBigDecimal("price", new BigDecimal("2000.0"));
+
+ sequence.add("\n more text\n ");
+
+ // quote.setBigDecimal("price", new BigDecimal("1000.0"));
+ sequence.add("price", new BigDecimal("1000.0"));
+
+ sequence.add("\n");
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ xmlHelper.save(quote, "http://www.example.com/mixed", "mixedOpenStockQuote", baos);
+
+ FileOutputStream fos = new FileOutputStream("XMLTCOutput");
+ xmlHelper.save(quote, "http://www.example.com/mixed", "mixedOpenStockQuote", fos);
+ assertTrue("XMLHelper.save() did not accurately reflect quote.", XMLEqualityChecker
+ .equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(MIXEDOPEN_XML)));
+ }
+}
Propchange: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/general/XMLHelperTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/general/XMLHelperTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: 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/XSDSerializationTest.java?view=diff&rev=512241&r1=512240&r2=512241
==============================================================================
--- 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/XSDSerializationTest.java Tue Feb 27 04:54:57 2007
@@ -1,4 +1,4 @@
-/*
+/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -33,6 +33,7 @@
import org.junit.BeforeClass;
import org.junit.Test;
+import org.junit.Ignore;
import test.sdo21.CTSSuite;
@@ -45,15 +46,13 @@
* Junit 4.1 test case. Tests XSD serialization/deserialization.
*
*/
-
public class XSDSerializationTest {
private static final String TEST_MODEL = "/simple.xsd";
private static URL modelURL;
/**
- * Obtains test model resource.
- * Runs once before any of the test methods.
+ * Obtains test model resource. Runs once before any of the test methods.
*/
@BeforeClass
public static void obtainResource() {
@@ -61,13 +60,13 @@
}
/**
- * Verifies the performance of XSDHelper.define()
- * when a SchemaLocation is provided.
+ * Verifies the performance of XSDHelper.define() when a SchemaLocation is
+ * provided.
*/
@Test
public void testDefineWithLocation() {
try {
-
+
XSDHelper xsdHelper = test.sdo21.CTSSuite.getTestHelper().getXSDHelper();
List types = xsdHelper.define(modelURL.openStream(), modelURL.toString());
assertEquals("XSDHelper.define() did not create the expected number of Types", 2, types.size());
@@ -78,14 +77,15 @@
}
/**
- * Verifies the performance of XSDHelper.define()
- * when a SchemaLocation is not provided.
+ * Verifies the performance of XSDHelper.define() when a SchemaLocation is
+ * not provided.
*/
@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());
} catch (Exception e) {
@@ -100,7 +100,7 @@
@Test
public void testDuplicateDefineWithLocation() {
try {
- XSDHelper xsdHelper = test.sdo21.CTSSuite.getTestHelper().getXSDHelper();
+ XSDHelper xsdHelper = test.sdo21.CTSSuite.getTestHelper().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
@@ -113,9 +113,9 @@
}
}
-
/**
- * Verifies the performance of XSDHelper.generate for dynamic SDOs with no XSD model.
+ * Verifies the performance of XSDHelper.generate for dynamic SDOs with no
+ * XSD model.
*/
@Test
public void testXSDGeneration_DynamicSDOType() {
Modified: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/scenarios/DataObjectListTest.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/scenarios/DataObjectListTest.java?view=diff&rev=512241&r1=512240&r2=512241
==============================================================================
--- incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/scenarios/DataObjectListTest.java (original)
+++ incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/scenarios/DataObjectListTest.java Tue Feb 27 04:54:57 2007
@@ -38,519 +38,515 @@
*/
public class DataObjectListTest extends TestCase {
- /**
- * Number of iterations for data type tests (sets and retrieves random values for each data type)
- */
- public static final int DATA_TYPE_ITERATIONS = 10;
- private static int unique = 0;
-
- public DataObjectListTest(String title) {
- super(title);
- }
-
- protected void setUp() throws Exception {
- super.setUp();
- }
+ /**
+ * Number of iterations for data type tests (sets and retrieves random
+ * values for each data type)
+ */
+ public static final int DATA_TYPE_ITERATIONS = 10;
+ private static int unique = 0;
+
+ public DataObjectListTest(String title) {
+ super(title);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
/**
* Helper function for converions tests.
- */
- private DataObject createType(String uri,String name) {
- DataObject newType = DataFactory.INSTANCE.create("commonj.sdo", "Type" );
- newType.set( "uri", uri );
- newType.set( "name", name );
- return newType;
+ */
+ private DataObject createType(String uri, String name) {
+ DataObject newType = DataFactory.INSTANCE.create("commonj.sdo", "Type");
+ newType.set("uri", uri);
+ newType.set("name", name);
+ return newType;
}
-
+
/**
- * Helper function for converions tests.
- * Creates a new type property with unique name and data hold property
+ * Helper function for converions tests. Creates a new type property with
+ * unique name and data hold property
+ *
* @return the property DataObject.
- */
+ */
private DataObject createTestObjectType() {
String uri = "http://example.com/DataObjectImplTest/" + unique;
String name = "DataObjectImplTest" + unique;
- unique++;
- //create new DataType
- DataObject newType = createType(uri,name);
-
- // define the type
- TypeHelper types = TypeHelper.INSTANCE;
- types.define( newType );
- return newType;
+ unique++;
+ // create new DataType
+ DataObject newType = createType(uri, name);
+
+ // define the type
+ TypeHelper types = TypeHelper.INSTANCE;
+ types.define(newType);
+ return newType;
}
-
+
/**
* Helper function.
- *
- */
+ */
private Type getNewTestType() {
- String uri = "http://example.com/DataObjectImplTest/" + (unique-1);
- String name = "DataObjectImplTest" + (unique-1);
-
- return TypeHelper.INSTANCE.getType(uri,name);
+ String uri = "http://example.com/DataObjectImplTest/" + (unique - 1);
+ String name = "DataObjectImplTest" + (unique - 1);
+
+ return TypeHelper.INSTANCE.getType(uri, name);
}
-
+
/**
- * Helper function.
- * Creates a new DataObject with unique Name and URI
+ * Helper function. Creates a new DataObject with unique Name and URI
+ *
* @return the created DataObject.
- */
+ */
private DataObject createTestObject() {
- String uri = "http://example.com/DataObjectImplTest/" + (unique-1);
- String name = "DataObjectImplTest" + (unique-1);
-
- //create DataObject with new Type
- DataObject newObj = DataFactory.INSTANCE.create( uri, name );
- return newObj;
+ String uri = "http://example.com/DataObjectImplTest/" + (unique - 1);
+ String name = "DataObjectImplTest" + (unique - 1);
+
+ // create DataObject with new Type
+ DataObject newObj = DataFactory.INSTANCE.create(uri, name);
+ return newObj;
}
-
-
+
/**
- * See SDO Spec 2.1.0 3.1.13 DataObject Accessor Exceptions
- * General get(String path) returns null if path does not exist
+ * See SDO Spec 2.1.0 3.1.13 DataObject Accessor Exceptions General
+ * get(String path) returns null if path does not exist
*/
public void testGetInvalidInstanceProperty() {
createTestObjectType();
- DataObject testObj=createTestObject();
+ DataObject testObj = createTestObject();
assertNotNull(testObj);
commonj.sdo.Property property = testObj.getInstanceProperty("aaa[1]");
assertNull("testObj.getInstanceProperty(\"aaa[1]\") should return null", property);
}
-
+
private void createTestObjectTypes() {
- Type typeCheck=TypeHelper.INSTANCE.getType("","catalog2");
- if (typeCheck==null)
- {
- /*
- * create type system
- * catalog2
- * - product2:DataObject[isMany:true]
- *
- * product2
- * - nameTest:String
- *
- * my guess is that the intention is
- * catalog2
- * - product2:product2(isMany:true)
- * - nameTest:String
- */
- DataObject newType = createType("","catalog2");
+ Type typeCheck = TypeHelper.INSTANCE.getType("", "catalog2");
+ if (typeCheck == null) {
+ /*
+ * create type system catalog2 - product2:DataObject[isMany:true]
+ * product2 - nameTest:String my guess is that the intention is
+ * catalog2 - product2:product2(isMany:true) - nameTest:String
+ */
+ DataObject newType = createType("", "catalog2");
TypeHelper types = TypeHelper.INSTANCE;
-
- DataObject newType2 = createType("","product2");
- DataObject property = newType2.createDataObject( "property" );
- property.set( "name", "name" );
- property.set( "type", TypeHelper.INSTANCE.getType( "commonj.sdo", "String" ) );
-
- Type nt2 = types.define( newType2 );
-
- DataObject property2 = newType.createDataObject( "property" );
- property2.set( "name", "product2" );
- property2.set( "type", nt2 );
- property2.setBoolean( "many", true );
-
- types.define( newType );
-
+ DataObject newType2 = createType("", "product2");
+
+ DataObject property = newType2.createDataObject("property");
+ property.set("name", "name");
+ property.set("type", TypeHelper.INSTANCE.getType("commonj.sdo", "String"));
+
+ Type nt2 = types.define(newType2);
+
+ DataObject property2 = newType.createDataObject("property");
+ property2.set("name", "product2");
+ property2.set("type", nt2);
+ property2.setBoolean("many", true);
+
+ types.define(newType);
}
- }
-
+ }
+
private XMLDocument loadDocFromString(String strXML) {
- createTestObjectTypes();
- return XMLHelper.INSTANCE.load( strXML );
+ createTestObjectTypes();
+ return XMLHelper.INSTANCE.load(strXML);
}
-
+
private List createTestObj(XMLDocument doc) {
- return doc.getRootObject().getList( "product2" );
+ return doc.getRootObject().getList("product2");
}
-//// DataGraphImpl dataGraph = new DataGraphImpl(doc);
-//// XMLElement catalog = doc.getRootElement();
-//
-//// DataObjectImpl doRoot =(DataObjectImpl) dataGraph.getRootObject();
-// Property prop=doRoot.getDataObject("catalog2").getProperty("product2");
-// if (prop == null) {
-// throw new IllegalStateException();
-// }
-//
-// assertEquals("catalog2", catalog.getLocalPart());
-//
-//// List listTest=new List(dataGraph,doRoot,(XMLDocumentImpl)doc,(XMLElementImpl)catalog,prop);
-// List listTest = new List(dataGraph,doRoot,(XMLDocumentImpl)doc,(XMLElementImpl)catalog,prop);
-// assertNotNull(listTest);
-// return listTest;
-// }
-
- public void testClear(){
- XMLDocument doc=loadDocFromString("<catalog2><product2/><product2/></catalog2>");
- List listTest=createTestObj(doc);
+ // // DataGraphImpl dataGraph = new DataGraphImpl(doc);
+ // // XMLElement catalog = doc.getRootElement();
+ //
+ // // DataObjectImpl doRoot =(DataObjectImpl) dataGraph.getRootObject();
+ // Property prop=doRoot.getDataObject("catalog2").getProperty("product2");
+ // if (prop == null) {
+ // throw new IllegalStateException();
+ // }
+ //
+ // assertEquals("catalog2", catalog.getLocalPart());
+ //
+ // // List listTest=new
+ // List(dataGraph,doRoot,(XMLDocumentImpl)doc,(XMLElementImpl)catalog,prop);
+ // List listTest = new
+ // List(dataGraph,doRoot,(XMLDocumentImpl)doc,(XMLElementImpl)catalog,prop);
+ // assertNotNull(listTest);
+ // return listTest;
+ // }
+
+ public void testClear() {
+ XMLDocument doc = loadDocFromString("<catalog2><product2/><product2/></catalog2>");
+ List listTest = createTestObj(doc);
assertNotNull(listTest);
-
- assertEquals(2,listTest.size());
+
+ assertEquals(2, listTest.size());
listTest.clear();
- assertEquals(0,listTest.size());
+ assertEquals(0, listTest.size());
}
-
- public void testIsEmpty(){
- XMLDocument doc=loadDocFromString("<catalog2><product2/><product2/></catalog2>");
- List listTest=createTestObj(doc);
+
+ public void testIsEmpty() {
+ XMLDocument doc = loadDocFromString("<catalog2><product2/><product2/></catalog2>");
+ List listTest = createTestObj(doc);
assertNotNull(listTest);
-
- assertEquals(2,listTest.size());
+
+ assertEquals(2, listTest.size());
assertFalse(listTest.isEmpty());
-
- XMLDocument doc2=loadDocFromString("<catalog2></catalog2>");
- List listTest2=createTestObj(doc2);
+
+ XMLDocument doc2 = loadDocFromString("<catalog2></catalog2>");
+ List listTest2 = createTestObj(doc2);
assertNotNull(listTest2);
- assertEquals(0,listTest2.size());
+ assertEquals(0, listTest2.size());
assertTrue(listTest2.isEmpty());
}
-
- public void testToArray(){
- String xmldoc = "<catalog2><product2><name>name1</name></product2><product2><name>name2</name></product2></catalog2>";
- // "<catalog2><product2 nameTest=\"name1\"/><product2 nameTest=\"name2\"/></catalog2>"
- XMLDocument doc=loadDocFromString(xmldoc);
- List listTest=createTestObj(doc);
- assertNotNull(listTest);
-
- Object[] objArray=listTest.toArray();
-
+
+ public void testToArray() {
+ String xmldoc =
+ "<catalog2><product2><name>name1</name></product2><product2><name>name2</name></product2></catalog2>";
+ // "<catalog2><product2 nameTest=\"name1\"/><product2
+ // nameTest=\"name2\"/></catalog2>"
+ XMLDocument doc = loadDocFromString(xmldoc);
+ List listTest = createTestObj(doc);
+ assertNotNull(listTest);
+
+ Object[] objArray = listTest.toArray();
+
assertNotNull(objArray);
- assertEquals(2,objArray.length);
- //assertEquals("name1",((DataObject)objArray[0]).getString("nameTest"));
- assertEquals("name2",((DataObject)objArray[1]).getString("name"));
- }
-
- public void testAddNull(){
- XMLDocument doc=loadDocFromString("<catalog2><product2/><product2/></catalog2>");
- List listTest=createTestObj(doc);
+ assertEquals(2, objArray.length);
+ // assertEquals("name1",((DataObject)objArray[0]).getString("nameTest"));
+ assertEquals("name2", ((DataObject)objArray[1]).getString("name"));
+ }
+
+ public void testAddNull() {
+ XMLDocument doc = loadDocFromString("<catalog2><product2/><product2/></catalog2>");
+ List listTest = createTestObj(doc);
assertNotNull(listTest);
-
- try{
+
+ try {
listTest.add(null);
fail("no exception were thrown");
}
// TODO investigate interoperability issue
- catch(java.lang.NullPointerException e){
- //RogueWave success
- }
- catch (IllegalArgumentException e) {
- //Tuscany success
+ catch (java.lang.NullPointerException e) {
+ // RogueWave success
+ } catch (IllegalArgumentException e) {
+ // Tuscany success
}
}
-
- public void testAddObject(){
- XMLDocument doc=loadDocFromString("<catalog2></catalog2>");
- List listTest=createTestObj(doc);
- assertNotNull(listTest);
- assertEquals(0,listTest.size());
-
- DataObject doInsert=DataFactory.INSTANCE.create("","product2");
- assertNotNull(doInsert);
- doInsert.setString("name","aname");
- listTest.add(0,doInsert);
-
- assertEquals(1,listTest.size());
- DataObject doRes=(DataObject) listTest.get(0);
- assertEquals("aname",doRes.getString("name"));
- }
-
- public void testAddAll(){
- XMLDocument doc=loadDocFromString("<catalog2><product2/><product2/></catalog2>");
- List listTest=createTestObj(doc);
- assertNotNull(listTest);
- assertEquals(2,listTest.size());
-
- DataObject doInsert1=DataFactory.INSTANCE.create("","product2");
- assertNotNull(doInsert1);
- doInsert1.setString("name","aname1");
-
- DataObject doInsert2=DataFactory.INSTANCE.create("","product2");
- assertNotNull(doInsert2);
- doInsert2.setString("name","aname2");
-
- ArrayList arraylist2 = new ArrayList();
- arraylist2.add(doInsert1);
- arraylist2.add(doInsert2);
-
- listTest.addAll(0,arraylist2);
-
- assertEquals(4,listTest.size());
- DataObject doRes=(DataObject)listTest.get(0);
- assertEquals("aname1",doRes.getString("name"));
- }
-
- public void testAddAllCollection(){
- XMLDocument doc=loadDocFromString("<catalog2><product2/><product2/></catalog2>");
- List listTest=createTestObj(doc);
- assertNotNull(listTest);
- assertEquals(2,listTest.size());
-
- DataObject doInsert1=DataFactory.INSTANCE.create("","product2");
+
+ public void testAddObject() {
+ XMLDocument doc = loadDocFromString("<catalog2></catalog2>");
+ List listTest = createTestObj(doc);
+ assertNotNull(listTest);
+ assertEquals(0, listTest.size());
+
+ DataObject doInsert = DataFactory.INSTANCE.create("", "product2");
+ assertNotNull(doInsert);
+ doInsert.setString("name", "aname");
+ listTest.add(0, doInsert);
+
+ assertEquals(1, listTest.size());
+ DataObject doRes = (DataObject)listTest.get(0);
+ assertEquals("aname", doRes.getString("name"));
+ }
+
+ public void testAddAll() {
+ XMLDocument doc = loadDocFromString("<catalog2><product2/><product2/></catalog2>");
+ List listTest = createTestObj(doc);
+ assertNotNull(listTest);
+ assertEquals(2, listTest.size());
+
+ DataObject doInsert1 = DataFactory.INSTANCE.create("", "product2");
+ assertNotNull(doInsert1);
+ doInsert1.setString("name", "aname1");
+
+ DataObject doInsert2 = DataFactory.INSTANCE.create("", "product2");
+ assertNotNull(doInsert2);
+ doInsert2.setString("name", "aname2");
+
+ ArrayList arraylist2 = new ArrayList();
+ arraylist2.add(doInsert1);
+ arraylist2.add(doInsert2);
+
+ listTest.addAll(0, arraylist2);
+
+ assertEquals(4, listTest.size());
+ DataObject doRes = (DataObject)listTest.get(0);
+ assertEquals("aname1", doRes.getString("name"));
+ }
+
+ public void testAddAllCollection() {
+ XMLDocument doc = loadDocFromString("<catalog2><product2/><product2/></catalog2>");
+ List listTest = createTestObj(doc);
+ assertNotNull(listTest);
+ assertEquals(2, listTest.size());
+
+ DataObject doInsert1 = DataFactory.INSTANCE.create("", "product2");
assertNotNull(doInsert1);
- doInsert1.setString("name","aname1");
-
- DataObject doInsert2=DataFactory.INSTANCE.create("","product2");
+ doInsert1.setString("name", "aname1");
+
+ DataObject doInsert2 = DataFactory.INSTANCE.create("", "product2");
assertNotNull(doInsert2);
- doInsert2.setString("name","aname2");
-
+ doInsert2.setString("name", "aname2");
+
ArrayList arraylist2 = new ArrayList();
arraylist2.add(doInsert1);
arraylist2.add(doInsert2);
-
- boolean bRes=listTest.addAll(arraylist2);
-
- assertTrue(bRes);
- assertEquals(4,listTest.size());
- DataObject doRes=(DataObject)listTest.get(2);
- assertEquals("aname1",doRes.getString("name"));
- }
-
- public void testAddAllCollectionEmpty(){
- XMLDocument doc=loadDocFromString("<catalog2><product2/><product2/></catalog2>");
- List listTest=createTestObj(doc);
+
+ boolean bRes = listTest.addAll(arraylist2);
+
+ assertTrue(bRes);
+ assertEquals(4, listTest.size());
+ DataObject doRes = (DataObject)listTest.get(2);
+ assertEquals("aname1", doRes.getString("name"));
+ }
+
+ public void testAddAllCollectionEmpty() {
+ XMLDocument doc = loadDocFromString("<catalog2><product2/><product2/></catalog2>");
+ List listTest = createTestObj(doc);
assertNotNull(listTest);
- assertEquals(2,listTest.size());
-
+ assertEquals(2, listTest.size());
+
ArrayList arraylist2 = new ArrayList();
-
- boolean bRes=listTest.addAll(arraylist2);
-
- assertFalse(bRes);
- assertEquals(2,listTest.size());
- }
-
- public void testIndexOf(){
- XMLDocument doc=loadDocFromString("<catalog2><product2/><product2/></catalog2>");
- List listTest=createTestObj(doc);
- assertNotNull(listTest);
- assertEquals(2,listTest.size());
-
- DataObject do1=(DataObject)listTest.get(1);
+
+ boolean bRes = listTest.addAll(arraylist2);
+
+ assertFalse(bRes);
+ assertEquals(2, listTest.size());
+ }
+
+ public void testIndexOf() {
+ XMLDocument doc = loadDocFromString("<catalog2><product2/><product2/></catalog2>");
+ List listTest = createTestObj(doc);
+ assertNotNull(listTest);
+ assertEquals(2, listTest.size());
+
+ DataObject do1 = (DataObject)listTest.get(1);
assertNotNull(do1);
-
- int nIdx=listTest.indexOf(do1);
-
- assertEquals(1,nIdx);
- }
-
- public void testLastIndexOf(){
- XMLDocument doc=loadDocFromString("<catalog2><product2/><product2/></catalog2>");
- List listTest=createTestObj(doc);
- assertNotNull(listTest);
- assertEquals(2,listTest.size());
-
- DataObject do1=(DataObject)listTest.get(1);
+
+ int nIdx = listTest.indexOf(do1);
+
+ assertEquals(1, nIdx);
+ }
+
+ public void testLastIndexOf() {
+ XMLDocument doc = loadDocFromString("<catalog2><product2/><product2/></catalog2>");
+ List listTest = createTestObj(doc);
+ assertNotNull(listTest);
+ assertEquals(2, listTest.size());
+
+ DataObject do1 = (DataObject)listTest.get(1);
assertNotNull(do1);
-
- int nIdx=listTest.lastIndexOf(do1);
-
- assertEquals(1,nIdx);
- }
-
- public void testContains(){
- XMLDocument doc=loadDocFromString("<catalog2><product2/><product2/></catalog2>");
- List listTest=createTestObj(doc);
- assertNotNull(listTest);
- assertEquals(2,listTest.size());
-
- DataObject do1=(DataObject)listTest.get(1);
+
+ int nIdx = listTest.lastIndexOf(do1);
+
+ assertEquals(1, nIdx);
+ }
+
+ public void testContains() {
+ XMLDocument doc = loadDocFromString("<catalog2><product2/><product2/></catalog2>");
+ List listTest = createTestObj(doc);
+ assertNotNull(listTest);
+ assertEquals(2, listTest.size());
+
+ DataObject do1 = (DataObject)listTest.get(1);
assertNotNull(do1);
-
- boolean bRes=listTest.contains(do1);
-
+
+ boolean bRes = listTest.contains(do1);
+
assertTrue(bRes);
-
- DataObject doTest=DataFactory.INSTANCE.create("","product2");
+
+ DataObject doTest = DataFactory.INSTANCE.create("", "product2");
assertNotNull(doTest);
-
- bRes=listTest.contains(doTest);
-
+
+ bRes = listTest.contains(doTest);
+
assertFalse(bRes);
}
-
- public void testRemoveObject(){
- XMLDocument doc=loadDocFromString("<catalog2><product2/><product2/></catalog2>");
- List listTest=createTestObj(doc);
- assertNotNull(listTest);
- assertEquals(2,listTest.size());
-
- DataObject do1=(DataObject)listTest.get(1);
+
+ public void testRemoveObject() {
+ XMLDocument doc = loadDocFromString("<catalog2><product2/><product2/></catalog2>");
+ List listTest = createTestObj(doc);
+ assertNotNull(listTest);
+ assertEquals(2, listTest.size());
+
+ DataObject do1 = (DataObject)listTest.get(1);
assertNotNull(do1);
-
- boolean bRes=listTest.remove(do1);
+
+ boolean bRes = listTest.remove(do1);
assertTrue(bRes);
- assertEquals(1,listTest.size());
-
- DataObject doTest=DataFactory.INSTANCE.create("","product2");
+ assertEquals(1, listTest.size());
+
+ DataObject doTest = DataFactory.INSTANCE.create("", "product2");
assertNotNull(doTest);
-
- bRes=listTest.remove(doTest);
+
+ bRes = listTest.remove(doTest);
assertFalse(bRes);
- assertEquals(1,listTest.size());
+ assertEquals(1, listTest.size());
}
-
- public void testContainsAll(){
- XMLDocument doc=loadDocFromString("<catalog2><product2/><product2/></catalog2>");
- List listTest=createTestObj(doc);
- assertNotNull(listTest);
- assertEquals(2,listTest.size());
-
- DataObject do1=(DataObject)listTest.get(1);
+
+ public void testContainsAll() {
+ XMLDocument doc = loadDocFromString("<catalog2><product2/><product2/></catalog2>");
+ List listTest = createTestObj(doc);
+ assertNotNull(listTest);
+ assertEquals(2, listTest.size());
+
+ DataObject do1 = (DataObject)listTest.get(1);
assertNotNull(do1);
-
+
ArrayList arraylist1 = new ArrayList();
arraylist1.add(do1);
-
- boolean bRes=listTest.containsAll(arraylist1);
-
+
+ boolean bRes = listTest.containsAll(arraylist1);
+
assertTrue(bRes);
-
- DataObject doTest=DataFactory.INSTANCE.create("","product2");
+
+ DataObject doTest = DataFactory.INSTANCE.create("", "product2");
assertNotNull(doTest);
arraylist1.add(doTest);
-
- bRes=listTest.containsAll(arraylist1);
-
+
+ bRes = listTest.containsAll(arraylist1);
+
assertFalse(bRes);
}
-
- public void testRemoveAll(){
- XMLDocument doc=loadDocFromString("<catalog2><product2/><product2/></catalog2>");
- List listTest=createTestObj(doc);
- assertNotNull(listTest);
- assertEquals(2,listTest.size());
-
- DataObject do1=(DataObject)listTest.get(1);
+
+ public void testRemoveAll() {
+ XMLDocument doc = loadDocFromString("<catalog2><product2/><product2/></catalog2>");
+ List listTest = createTestObj(doc);
+ assertNotNull(listTest);
+ assertEquals(2, listTest.size());
+
+ DataObject do1 = (DataObject)listTest.get(1);
assertNotNull(do1);
-
+
ArrayList arraylist1 = new ArrayList();
arraylist1.add(do1);
-
- boolean bRes=listTest.removeAll(arraylist1);
-
+
+ boolean bRes = listTest.removeAll(arraylist1);
+
assertTrue(bRes);
- assertEquals(1,listTest.size());
+ assertEquals(1, listTest.size());
}
-
- public void testRetainAll(){
- XMLDocument doc=loadDocFromString("<catalog2><product2/><product2/></catalog2>");
- List listTest=createTestObj(doc);
- assertNotNull(listTest);
- assertEquals(2,listTest.size());
-
- DataObject do1=(DataObject)listTest.get(1);
+
+ public void testRetainAll() {
+ XMLDocument doc = loadDocFromString("<catalog2><product2/><product2/></catalog2>");
+ List listTest = createTestObj(doc);
+ assertNotNull(listTest);
+ assertEquals(2, listTest.size());
+
+ DataObject do1 = (DataObject)listTest.get(1);
assertNotNull(do1);
-
+
ArrayList arraylist1 = new ArrayList();
arraylist1.add(do1);
-
- boolean bRes=listTest.retainAll(arraylist1);
-
+
+ boolean bRes = listTest.retainAll(arraylist1);
+
assertTrue(bRes);
- assertEquals(1,listTest.size());
+ assertEquals(1, listTest.size());
}
-
- public void testIterator(){
- XMLDocument doc=loadDocFromString("<catalog2><product2/><product2/></catalog2>");
- List listTest=createTestObj(doc);
- assertNotNull(listTest);
- assertEquals(2,listTest.size());
-
- Iterator iterRes=listTest.iterator();
-
+
+ public void testIterator() {
+ XMLDocument doc = loadDocFromString("<catalog2><product2/><product2/></catalog2>");
+ List listTest = createTestObj(doc);
+ assertNotNull(listTest);
+ assertEquals(2, listTest.size());
+
+ Iterator iterRes = listTest.iterator();
+
assertNotNull(iterRes);
- DataObject doRes=(DataObject)iterRes.next();
+ DataObject doRes = (DataObject)iterRes.next();
assertNotNull(doRes);
}
-
- public void testSubList(){
- XMLDocument doc=loadDocFromString("<catalog2><product2/><product2/><product2/></catalog2>");
- List listTest=createTestObj(doc);
- assertNotNull(listTest);
- assertEquals(3,listTest.size());
-
- List listRes=listTest.subList(0,1);
-
+
+ public void testSubList() {
+ XMLDocument doc = loadDocFromString("<catalog2><product2/><product2/><product2/></catalog2>");
+ List listTest = createTestObj(doc);
+ assertNotNull(listTest);
+ assertEquals(3, listTest.size());
+
+ List listRes = listTest.subList(0, 1);
+
assertNotNull(listRes);
- assertEquals("listTest.subList(0,1)", 1,listRes.size());
- DataObject doRes=(DataObject)listRes.get(0);
+ assertEquals("listTest.subList(0,1)", 1, listRes.size());
+ DataObject doRes = (DataObject)listRes.get(0);
assertNotNull(doRes);
}
-
- public void testListIterator(){
- XMLDocument doc=loadDocFromString("<catalog2><product2/><product2/></catalog2>");
- List listTest=createTestObj(doc);
- assertNotNull(listTest);
- assertEquals(2,listTest.size());
-
- ListIterator iterRes=listTest.listIterator();
-
+
+ public void testListIterator() {
+ XMLDocument doc = loadDocFromString("<catalog2><product2/><product2/></catalog2>");
+ List listTest = createTestObj(doc);
+ assertNotNull(listTest);
+ assertEquals(2, listTest.size());
+
+ ListIterator iterRes = listTest.listIterator();
+
assertNotNull(iterRes);
- DataObject doRes=(DataObject)iterRes.next();
+ DataObject doRes = (DataObject)iterRes.next();
assertNotNull(doRes);
}
-
- public void testListIteratorIndex(){
- XMLDocument doc=loadDocFromString("<catalog2><product2/><product2/></catalog2>");
- List listTest=createTestObj(doc);
- assertNotNull(listTest);
- assertEquals(2,listTest.size());
-
- ListIterator iterRes=listTest.listIterator(0);
-
+
+ public void testListIteratorIndex() {
+ XMLDocument doc = loadDocFromString("<catalog2><product2/><product2/></catalog2>");
+ List listTest = createTestObj(doc);
+ assertNotNull(listTest);
+ assertEquals(2, listTest.size());
+
+ ListIterator iterRes = listTest.listIterator(0);
+
assertNotNull(iterRes);
- DataObject doRes=(DataObject)iterRes.next();
+ DataObject doRes = (DataObject)iterRes.next();
assertNotNull(doRes);
}
-
- public void testSetIndexObject(){
- XMLDocument doc=loadDocFromString("<catalog2><product2 name=\"aname1\"/><product2 name=\"aname2\"/></catalog2>");
- List listTest=createTestObj(doc);
- assertNotNull(listTest);
- assertEquals(2,listTest.size());
-
- DataObject doTest=DataFactory.INSTANCE.create("","product2");
+
+ public void testSetIndexObject() {
+ XMLDocument doc =
+ loadDocFromString("<catalog2><product2 name=\"aname1\"/><product2 name=\"aname2\"/></catalog2>");
+ List listTest = createTestObj(doc);
+ assertNotNull(listTest);
+ assertEquals(2, listTest.size());
+
+ DataObject doTest = DataFactory.INSTANCE.create("", "product2");
assertNotNull(doTest);
- doTest.setString("name","aname3");
-
- Object objRes=listTest.set(0,doTest);
-
+ doTest.setString("name", "aname3");
+
+ Object objRes = listTest.set(0, doTest);
+
assertNotNull(objRes);
assertTrue(objRes instanceof DataObject);
}
-
- public void testToArrayObject(){
- XMLDocument doc=loadDocFromString("<catalog2><product2 name=\"aname1\"/><product2 name=\"aname2\"/></catalog2>");
- List listTest=createTestObj(doc);
- assertNotNull(listTest);
- assertEquals(2,listTest.size());
-
- DataObject do1=(DataObject)listTest.get(1);
+
+ public void testToArrayObject() {
+ XMLDocument doc =
+ loadDocFromString("<catalog2><product2 name=\"aname1\"/><product2 name=\"aname2\"/></catalog2>");
+ List listTest = createTestObj(doc);
+ assertNotNull(listTest);
+ assertEquals(2, listTest.size());
+
+ DataObject do1 = (DataObject)listTest.get(1);
assertNotNull(do1);
-
+
ArrayList arraylist2 = new ArrayList();
-
- Object[] objRes=listTest.toArray(arraylist2.toArray());
-
+
+ Object[] objRes = listTest.toArray(arraylist2.toArray());
+
assertNotNull(objRes);
- assertEquals(2,objRes.length);
+ assertEquals(2, objRes.length);
}
-
- public void testToString(){
- XMLDocument doc=loadDocFromString("<catalog2><product2 name=\"aname1\"/><product2 name=\"aname2\"/></catalog2>");
- List listTest=createTestObj(doc);
- assertNotNull(listTest);
- assertEquals(2,listTest.size());
-
- String strRes=listTest.toString();
-
+
+ public void testToString() {
+ XMLDocument doc =
+ loadDocFromString("<catalog2><product2 name=\"aname1\"/><product2 name=\"aname2\"/></catalog2>");
+ List listTest = createTestObj(doc);
+ assertNotNull(listTest);
+ assertEquals(2, listTest.size());
+
+ String strRes = listTest.toString();
+
assertNotNull(strRes);
- assertTrue(strRes.length()>0);
- //assertEquals("List: [DataObjectImpl[ <sss> ]]",strRes);
+ assertTrue(strRes.length() > 0);
+ // assertEquals("List: [DataObjectImpl[ <sss> ]]",strRes);
}
}
Added: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/util/XMLEqualityChecker.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/util/XMLEqualityChecker.java?view=auto&rev=512241
==============================================================================
--- incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/util/XMLEqualityChecker.java (added)
+++ incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/util/XMLEqualityChecker.java Tue Feb 27 04:54:57 2007
@@ -0,0 +1,319 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package test.sdo21.tests.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.FactoryConfigurationError;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentType;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * Provides a series of methods for comparing output from the XMLHelper with an
+ * expected XML file.
+ */
+public class XMLEqualityChecker {
+ /**
+ * Places the nodes in nodeList into a indexed list.
+ *
+ * @param nodeList
+ * @param nodes
+ */
+ private static void getAllNodes(NodeList nodeList, List nodes) {
+ int length = nodeList.getLength();
+ if (length == 0)
+ return;
+
+ for (int i = 0; i < length; i++) {
+ Node node = nodeList.item(i);
+ nodes.add(node);
+ getAllNodes(node.getChildNodes(), nodes);
+ } // for
+ }
+
+ /**
+ * Returns true if the two input NamedNodeMaps are equivalent, false
+ * otherwise.
+ *
+ * @param mapA
+ * @param mapB
+ */
+ private static boolean equalNamedNodeMap(NamedNodeMap mapA, NamedNodeMap mapB) {
+ if (mapA == null) {
+ if (mapB == null) {
+ return true;
+ }
+ return false;
+ }
+ if (mapA.getLength() != mapB.getLength()) {
+ return false;
+ }
+ for (int i = 0; i < mapA.getLength(); i++) {
+ Node trialNode = mapA.item(i);
+ if (trialNode == null) {
+ return false;
+ }
+ Node checkNode = mapB.getNamedItem(trialNode.getNodeName());
+ if (checkNode == null) {
+ return false;
+ }
+ if (!equalNode(trialNode, checkNode)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Returns true of the two Nodes are equivalent, false otherwise.
+ *
+ * @param nodeA
+ * @param nodeB
+ */
+ private static boolean equalNode(Node nodeA, Node nodeB) {
+ if (nodeA == null) {
+ if (nodeB == null) {
+ return true;
+ }
+ return false;
+ }
+ // following is intended to provide same function as 1.5 isEqualNode()
+ if (nodeA.getNodeType() != nodeB.getNodeType()) {
+ return false;
+ }
+ if (!equalString(nodeA.getNodeName(), nodeB.getNodeName())) {
+ return false;
+ }
+ if (!equalString(nodeA.getLocalName(), nodeB.getLocalName())) {
+ return false;
+ }
+ if (!equalString(nodeA.getNamespaceURI(), nodeB.getNamespaceURI())) {
+ return false;
+ }
+ if (!equalString(nodeA.getNamespaceURI(), nodeB.getNamespaceURI())) {
+ return false;
+ }
+ if (!equalString(nodeA.getPrefix(), nodeB.getPrefix())) {
+ return false;
+ }
+ if (!equalString(nodeA.getNodeValue(), nodeB.getNodeValue())) {
+ return false;
+ }
+ if (!equalNamedNodeMap(nodeA.getAttributes(), nodeB.getAttributes())) {
+ return false;
+ }
+ if (!equalNodeList(nodeA.getChildNodes(), nodeB.getChildNodes())) {
+ return false;
+ }
+ if (nodeA.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
+ DocumentType documentTypeA = (DocumentType)nodeA;
+ DocumentType documentTypeB = (DocumentType)nodeB;
+ if (!equalString(documentTypeA.getPublicId(), documentTypeB.getPublicId())) {
+ return false;
+ }
+ if (!equalString(documentTypeA.getSystemId(), documentTypeB.getSystemId())) {
+ return false;
+ }
+ if (!equalString(documentTypeA.getInternalSubset(), documentTypeB.getInternalSubset())) {
+ return false;
+ }
+ if (!equalNamedNodeMap(documentTypeA.getEntities(), documentTypeB.getEntities())) {
+ return false;
+ }
+ if (!equalNamedNodeMap(documentTypeA.getNotations(), documentTypeB.getNotations())) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Returns true of the two NodeLists are equivalent, false otherwise.
+ *
+ * @param nodeListA
+ * @param nodeListB
+ */
+ private static boolean equalNodeList(NodeList nodeListA, NodeList nodeListB) {
+ if (nodeListA == null) {
+ if (nodeListB == null) {
+ return true;
+ }
+ return false;
+ }
+ return equalNodes(nodeListA, nodeListB);
+ }
+
+ /**
+ * Returns true of the two Strings are equivalent, false otherwise.
+ *
+ * @param stringA
+ * @param stringB
+ */
+ private static boolean equalString(String stringA, String stringB) {
+ if (stringA == null) {
+ if (stringB == null) {
+ return true;
+ }
+ return false;
+ }
+ return stringA.equals(stringB);
+ }
+
+ /**
+ * Returns true of the two NodeListss are equivalent, false otherwise.
+ *
+ * @param nodeListA
+ * @param nodeListB
+ */
+ private static boolean equalNodes(NodeList sourceNodeList, NodeList targetNodeList) {
+ ArrayList sourceNodes = new ArrayList();
+ ArrayList targetNodes = new ArrayList();
+
+ getAllNodes(sourceNodeList, sourceNodes);
+ getAllNodes(targetNodeList, targetNodes);
+
+ int sourceLength = sourceNodes.size();
+ int targetLength = targetNodes.size();
+
+ if (sourceLength != targetLength)
+ return false;
+
+ for (int i = 0; i < sourceLength; i++) {
+ Node sourceNode = (Node)sourceNodes.get(i);
+ Node targetNode = (Node)targetNodes.get(i);
+
+ /*
+ * remove comment when migrated to Java 1.5 if
+ * (!sourceNode.isEqualNode(targetNode)) return false;
+ */
+ // following is intended as 1.4 equivalent of isEqualNode()
+ if (!equalNode(sourceNode, targetNode))
+ return false;
+ } // for
+
+ return true;
+ }
+
+ /**
+ * Returns true of the two XML files are equivalent, false otherwise.
+ * Accepts as input two URLs which identify the XML files, and calls
+ * equalXMLFiles(InputStream, InputStream).
+ *
+ * @param source
+ * @param target
+ */
+ public static boolean equalXmlFiles(URL source, URL target) {
+ try {
+ return equalXmlFiles(source.openStream(), target.openStream());
+ } catch (IOException e) {
+ return false;
+ }
+ }
+
+ /**
+ * Returns true of the two XML files are equivalent, false otherwise.
+ * Accepts as input an InputStream and a URL which identify the XML files,
+ * and calls equalXMLFiles(InputStream, InputStream).
+ *
+ * @param sourceStream
+ * @param target
+ */
+ public static boolean equalXmlFiles(InputStream sourceStream, URL target) {
+ try {
+ return equalXmlFiles(sourceStream, target.openStream());
+ } catch (IOException e) {
+ return false;
+ }
+ }
+
+ /**
+ * Returns true of the two XML files are equivalent, false otherwise.
+ * Accepts as input a URL and an InputStream which identify the XML files,
+ * and calls equalXMLFiles(InputStream, InputStream).
+ *
+ * @param source
+ * @param targetStream
+ */
+ public static boolean equalXmlFiles(URL source, InputStream targetStream) {
+ try {
+ return equalXmlFiles(source.openStream(), targetStream);
+ } catch (IOException e) {
+ return false;
+ }
+ }
+
+ /**
+ * Returns true of the two XML files are equivalent, false otherwise.
+ * Accepts as input two InputStreams which identify the XML files.
+ *
+ * @param sourceStream
+ * @param targetStream
+ */
+ public static boolean equalXmlFiles(InputStream sourceStream, InputStream targetStream) {
+ DocumentBuilder builder;
+ Document sourceDocument;
+ Document targetDocument;
+
+ try {
+ builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ sourceDocument = builder.parse(sourceStream);
+ targetDocument = builder.parse(targetStream);
+ } catch (FactoryConfigurationError fce) {
+ return false;
+ } catch (ParserConfigurationException ce) {
+ return false;
+ } catch (SAXException se) {
+ return false;
+ } catch (IOException ie) {
+ return false;
+ }
+
+ sourceDocument.normalize();
+ targetDocument.normalize();
+
+ /*
+ * remove comment when migrated to Java 1.5 if
+ * (!sourceDocument.getXmlVersion().equals(targetDocument.getXmlVersion()))
+ * return false; String sourceXmlEncoding =
+ * sourceDocument.getXmlEncoding(); String targetXmlEncoding =
+ * targetDocument.getXmlEncoding(); if (sourceXmlEncoding != null &&
+ * targetXmlEncoding != null &&
+ * sourceXmlEncoding.equalsIgnoreCase(targetXmlEncoding)) { // continue }
+ * else { return false; }
+ */
+
+ NodeList sourceNodes = sourceDocument.getChildNodes();
+ NodeList targetNodes = targetDocument.getChildNodes();
+
+ return equalNodes(sourceNodes, targetNodes);
+ }
+}
Propchange: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/util/XMLEqualityChecker.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/util/XMLEqualityChecker.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org