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 2008/07/28 16:30:24 UTC
svn commit: r680370 [14/22] - in /tuscany/java/sdo:
distribution/src/main/assembly/ distribution/src/main/release/bin/
distribution/src/main/release/bin/samples/ impl/
impl/src/main/java/org/apache/tuscany/sdo/helper/
impl/src/main/java/org/apache/tusc...
Modified: tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DataObjectGetListTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DataObjectGetListTestCase.java?rev=680370&r1=680369&r2=680370&view=diff
==============================================================================
--- tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DataObjectGetListTestCase.java (original)
+++ tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DataObjectGetListTestCase.java Mon Jul 28 07:30:12 2008
@@ -1,129 +1,129 @@
-/**
- *
- * 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 org.apache.tuscany.sdo.test;
-
-
-import java.io.IOException;
-import java.util.List;
-
-import org.apache.tuscany.sdo.api.SDOUtil;
-
-import commonj.sdo.DataObject;
-import commonj.sdo.helper.HelperContext;
-import junit.framework.TestCase;
-
-public class DataObjectGetListTestCase extends TestCase {
- private HelperContext hc;
- private DataObject companyDataObject;
-
- private final String TEST_NAMESPACE = "http://www.example.com/getList";
-
- private String xsdString =
- "<xsd:schema " +
- "xmlns:getList=\"http://www.example.com/getList\" " +
- "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
- "targetNamespace=\"http://www.example.com/getList\">" +
-
- "<xsd:element name=\"company\" type=\"getList:Company\"/>" +
- "<xsd:element name=\"employee\" type=\"xsd:string\"/>" +
-
- "<xsd:complexType name=\"Company\">" +
- "<xsd:sequence>" +
- "<xsd:element name=\"openCompany\" type=\"getList:OpenCompany\"/>" +
- "<xsd:element name=\"closeCompany\" type=\"getList:CloseCompany\"/>" +
- "</xsd:sequence>" +
- "</xsd:complexType>" +
-
- "<xsd:complexType name=\"OpenCompany\">" +
- "<xsd:sequence>" +
- "<xsd:element name=\"company\" type=\"xsd:string\"/>" +
- "<xsd:element name=\"employees\" maxOccurs=\"unbounded\" type=\"xsd:string\"/>" +
- "<xsd:any maxOccurs=\"unbounded\" namespace=\"##any\"/>" +
- "</xsd:sequence>" +
- "</xsd:complexType>" +
-
- "<xsd:complexType name=\"CloseCompany\">" +
- "<xsd:sequence>" +
- "<xsd:element name=\"company\" type=\"xsd:string\"/>" +
- "<xsd:element name=\"employees\" maxOccurs=\"unbounded\" type=\"xsd:string\"/>" +
- "</xsd:sequence>" +
- "</xsd:complexType>" +
-
- "</xsd:schema>";
-
- /**
- * Test DataObject.getList() on open type
- */
- public void testUnknownPropertyOnOpenType() throws IOException {
- String companyName = companyDataObject.getString("openCompany/company");
- assertEquals(companyName, "OpenCompany");
- List unknownProperty = companyDataObject.getList("openCompany/unknownProperty");
- assertNotNull(unknownProperty);
- assertTrue(unknownProperty instanceof List);
-
- List unknownProperty2 = companyDataObject.getList("openCompany/unknownProperty");
- assertNotNull(unknownProperty2);
- assertTrue(unknownProperty2 instanceof List);
-
- // unknownProperty and unknownProperty2 are in fact the same value for the same property
-
- unknownProperty.add("employee1");
- assertTrue(unknownProperty.size() == 1);
-
- unknownProperty2.add("employee2");
- assertTrue(unknownProperty2.size() == 2);
-
- unknownProperty.remove(0);
- assertTrue(unknownProperty.size() == 1);
-
- assertEquals(unknownProperty.get(0), "employee2");
- }
-
- /**
- * Test DataObject.getList() on non-open type
- */
- public void testUnknownPropertyOnClosedType() throws IOException {
- String companyName = companyDataObject.getString("closeCompany/company");
- assertEquals(companyName, "CloseCompany");
- List unknownProperty = companyDataObject.getList("closeCompany/unknownProperty");
- assertNotNull(unknownProperty);
- assertTrue(unknownProperty instanceof List);
-
- try {
- unknownProperty.add("employee1");
- fail("An exception should have been thrown.");
- }
- catch (Exception e) {
- }
- }
-
- protected void setUp() throws Exception {
- super.setUp();
-
- hc = SDOUtil.createHelperContext();
- hc.getXSDHelper().define(xsdString);
-
- companyDataObject = hc.getDataFactory().create(TEST_NAMESPACE, "Company");
- DataObject openCompany = companyDataObject.createDataObject("openCompany");
- openCompany.setString("company", "OpenCompany");
- DataObject closeCompany = companyDataObject.createDataObject("closeCompany");
- closeCompany.setString("company", "CloseCompany");
- }
-}
+/**
+ *
+ * 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 org.apache.tuscany.sdo.test;
+
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.tuscany.sdo.api.SDOUtil;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.HelperContext;
+import junit.framework.TestCase;
+
+public class DataObjectGetListTestCase extends TestCase {
+ private HelperContext hc;
+ private DataObject companyDataObject;
+
+ private final String TEST_NAMESPACE = "http://www.example.com/getList";
+
+ private String xsdString =
+ "<xsd:schema " +
+ "xmlns:getList=\"http://www.example.com/getList\" " +
+ "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
+ "targetNamespace=\"http://www.example.com/getList\">" +
+
+ "<xsd:element name=\"company\" type=\"getList:Company\"/>" +
+ "<xsd:element name=\"employee\" type=\"xsd:string\"/>" +
+
+ "<xsd:complexType name=\"Company\">" +
+ "<xsd:sequence>" +
+ "<xsd:element name=\"openCompany\" type=\"getList:OpenCompany\"/>" +
+ "<xsd:element name=\"closeCompany\" type=\"getList:CloseCompany\"/>" +
+ "</xsd:sequence>" +
+ "</xsd:complexType>" +
+
+ "<xsd:complexType name=\"OpenCompany\">" +
+ "<xsd:sequence>" +
+ "<xsd:element name=\"company\" type=\"xsd:string\"/>" +
+ "<xsd:element name=\"employees\" maxOccurs=\"unbounded\" type=\"xsd:string\"/>" +
+ "<xsd:any maxOccurs=\"unbounded\" namespace=\"##any\"/>" +
+ "</xsd:sequence>" +
+ "</xsd:complexType>" +
+
+ "<xsd:complexType name=\"CloseCompany\">" +
+ "<xsd:sequence>" +
+ "<xsd:element name=\"company\" type=\"xsd:string\"/>" +
+ "<xsd:element name=\"employees\" maxOccurs=\"unbounded\" type=\"xsd:string\"/>" +
+ "</xsd:sequence>" +
+ "</xsd:complexType>" +
+
+ "</xsd:schema>";
+
+ /**
+ * Test DataObject.getList() on open type
+ */
+ public void testUnknownPropertyOnOpenType() throws IOException {
+ String companyName = companyDataObject.getString("openCompany/company");
+ assertEquals(companyName, "OpenCompany");
+ List unknownProperty = companyDataObject.getList("openCompany/unknownProperty");
+ assertNotNull(unknownProperty);
+ assertTrue(unknownProperty instanceof List);
+
+ List unknownProperty2 = companyDataObject.getList("openCompany/unknownProperty");
+ assertNotNull(unknownProperty2);
+ assertTrue(unknownProperty2 instanceof List);
+
+ // unknownProperty and unknownProperty2 are in fact the same value for the same property
+
+ unknownProperty.add("employee1");
+ assertTrue(unknownProperty.size() == 1);
+
+ unknownProperty2.add("employee2");
+ assertTrue(unknownProperty2.size() == 2);
+
+ unknownProperty.remove(0);
+ assertTrue(unknownProperty.size() == 1);
+
+ assertEquals(unknownProperty.get(0), "employee2");
+ }
+
+ /**
+ * Test DataObject.getList() on non-open type
+ */
+ public void testUnknownPropertyOnClosedType() throws IOException {
+ String companyName = companyDataObject.getString("closeCompany/company");
+ assertEquals(companyName, "CloseCompany");
+ List unknownProperty = companyDataObject.getList("closeCompany/unknownProperty");
+ assertNotNull(unknownProperty);
+ assertTrue(unknownProperty instanceof List);
+
+ try {
+ unknownProperty.add("employee1");
+ fail("An exception should have been thrown.");
+ }
+ catch (Exception e) {
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ hc = SDOUtil.createHelperContext();
+ hc.getXSDHelper().define(xsdString);
+
+ companyDataObject = hc.getDataFactory().create(TEST_NAMESPACE, "Company");
+ DataObject openCompany = companyDataObject.createDataObject("openCompany");
+ openCompany.setString("company", "OpenCompany");
+ DataObject closeCompany = companyDataObject.createDataObject("closeCompany");
+ closeCompany.setString("company", "CloseCompany");
+ }
+}
Propchange: tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DataObjectGetListTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DefineOpenContentPropertyTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DefineOpenContentPropertyTestCase.java?rev=680370&r1=680369&r2=680370&view=diff
==============================================================================
--- tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DefineOpenContentPropertyTestCase.java (original)
+++ tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DefineOpenContentPropertyTestCase.java Mon Jul 28 07:30:12 2008
@@ -1,133 +1,133 @@
-/**
- *
- * 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 org.apache.tuscany.sdo.test;
-
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.math.BigDecimal;
-import java.net.URL;
-
-import org.apache.tuscany.sdo.util.SDOUtil;
-
-import commonj.sdo.DataObject;
-import commonj.sdo.Property;
-import commonj.sdo.Type;
-import commonj.sdo.helper.DataFactory;
-import commonj.sdo.helper.HelperContext;
-import commonj.sdo.helper.TypeHelper;
-import commonj.sdo.helper.XMLHelper;
-import commonj.sdo.helper.XSDHelper;
-import junit.framework.TestCase;
-
-
-public class DefineOpenContentPropertyTestCase extends TestCase {
- private final String TEST_MODEL = "/open.xsd";
- private final String TEST_NAMESPACE = "http://www.example.com/open";
- private final String TEST_DATA = "/openContentProperty.xml";
-
- private TypeHelper typeHelper;
- private XSDHelper xsdHelper;
- private XMLHelper xmlHelper;
- private DataFactory dataFactory;
-
- public void testDefineOpenContentProperty() throws IOException {
- Type quoteType = typeHelper.getType(TEST_NAMESPACE, "OpenQuote");
- DataObject quote = dataFactory.create(quoteType);
-
- Property symbolProperty = quoteType.getProperty("symbol");
- assertFalse(symbolProperty.isOpenContent());
-
- quote.setString(symbolProperty, "s1");
-
- Property companyProperty = typeHelper.getOpenContentProperty(TEST_NAMESPACE, "company");
- assertTrue(companyProperty.isOpenContent());
-
- DataObject company = quote.createDataObject(companyProperty);
- company.setString("name", "FlyByNightTechnology");
-
- Property priceProperty = typeHelper.getOpenContentProperty(TEST_NAMESPACE, "price");
- assertTrue(priceProperty.isOpenContent());
-
- 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);
- assertTrue(highPrice.isOpenContent());
-
- 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);
- assertTrue(mutualFundQuoteProperty.isOpenContent());
-
- DataObject mutualFundQuote = quote.createDataObject(mutualFundQuoteProperty);
- mutualFundQuote.setString("symbol", "mutual-1");
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- xmlHelper.save(quote, TEST_NAMESPACE, "openStockQuote", baos);
-
- assertTrue(TestUtil.equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(TEST_DATA)));
-
- // validate existing property condition
- Property duplicateProp = typeHelper.defineOpenContentProperty(TEST_NAMESPACE, p);
- assertTrue(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(errorCondition);
- }
-
- protected void setUp() throws Exception {
- super.setUp();
-
- HelperContext hc = SDOUtil.createHelperContext();
- typeHelper = hc.getTypeHelper();
- dataFactory = hc.getDataFactory();
- xsdHelper = hc.getXSDHelper();
- xmlHelper = hc.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();
- }
-}
+/**
+ *
+ * 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 org.apache.tuscany.sdo.test;
+
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.math.BigDecimal;
+import java.net.URL;
+
+import org.apache.tuscany.sdo.util.SDOUtil;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.Property;
+import commonj.sdo.Type;
+import commonj.sdo.helper.DataFactory;
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.helper.XMLHelper;
+import commonj.sdo.helper.XSDHelper;
+import junit.framework.TestCase;
+
+
+public class DefineOpenContentPropertyTestCase extends TestCase {
+ private final String TEST_MODEL = "/open.xsd";
+ private final String TEST_NAMESPACE = "http://www.example.com/open";
+ private final String TEST_DATA = "/openContentProperty.xml";
+
+ private TypeHelper typeHelper;
+ private XSDHelper xsdHelper;
+ private XMLHelper xmlHelper;
+ private DataFactory dataFactory;
+
+ public void testDefineOpenContentProperty() throws IOException {
+ Type quoteType = typeHelper.getType(TEST_NAMESPACE, "OpenQuote");
+ DataObject quote = dataFactory.create(quoteType);
+
+ Property symbolProperty = quoteType.getProperty("symbol");
+ assertFalse(symbolProperty.isOpenContent());
+
+ quote.setString(symbolProperty, "s1");
+
+ Property companyProperty = typeHelper.getOpenContentProperty(TEST_NAMESPACE, "company");
+ assertTrue(companyProperty.isOpenContent());
+
+ DataObject company = quote.createDataObject(companyProperty);
+ company.setString("name", "FlyByNightTechnology");
+
+ Property priceProperty = typeHelper.getOpenContentProperty(TEST_NAMESPACE, "price");
+ assertTrue(priceProperty.isOpenContent());
+
+ 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);
+ assertTrue(highPrice.isOpenContent());
+
+ 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);
+ assertTrue(mutualFundQuoteProperty.isOpenContent());
+
+ DataObject mutualFundQuote = quote.createDataObject(mutualFundQuoteProperty);
+ mutualFundQuote.setString("symbol", "mutual-1");
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ xmlHelper.save(quote, TEST_NAMESPACE, "openStockQuote", baos);
+
+ assertTrue(TestUtil.equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(TEST_DATA)));
+
+ // validate existing property condition
+ Property duplicateProp = typeHelper.defineOpenContentProperty(TEST_NAMESPACE, p);
+ assertTrue(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(errorCondition);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ HelperContext hc = SDOUtil.createHelperContext();
+ typeHelper = hc.getTypeHelper();
+ dataFactory = hc.getDataFactory();
+ xsdHelper = hc.getXSDHelper();
+ xmlHelper = hc.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();
+ }
+}
Propchange: tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DefineOpenContentPropertyTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DeserializationNoSchemaTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DeserializationNoSchemaTestCase.java?rev=680370&r1=680369&r2=680370&view=diff
==============================================================================
--- tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DeserializationNoSchemaTestCase.java (original)
+++ tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DeserializationNoSchemaTestCase.java Mon Jul 28 07:30:12 2008
@@ -1,124 +1,124 @@
-/**
- *
- * 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 org.apache.tuscany.sdo.test;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.net.URL;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.apache.tuscany.sdo.util.SDOUtil;
-
-import commonj.sdo.DataObject;
-import commonj.sdo.helper.HelperContext;
-import commonj.sdo.helper.TypeHelper;
-import commonj.sdo.helper.XMLDocument;
-import commonj.sdo.helper.XMLHelper;
-
-
-public class DeserializationNoSchemaTestCase extends TestCase
-{
- HelperContext hc;
-
- TypeHelper th;
-
- private final String xmlStr =
- "<?xml version=\"1.0\" encoding=\"ASCII\"?> " +
- "<simple:stockQuote xmlns:simple=\"www.example.com/simple\"> " +
- "<symbol>fbnt</symbol> " +
- "<companyName>FlyByNightTechnology</companyName> " +
- "<price>1000.0</price> " +
- "<open1>1000.0</open1> " +
- "<high>1000.0</high> " +
- "<low>1000.0</low> " +
- "<volume>1000.0</volume> " +
- "<change1>1000.0</change1> " +
- "<quotes> " +
- "<price>2000.0</price> " +
- "</quotes> " +
- "</simple:stockQuote>";
-
- public void testLoadQuoteXMLDoc() throws IOException
- {
- XMLHelper xmlHelper = hc.getXMLHelper();
-/* URL url = getClass().getResource("/quote.xml");
- InputStream inputStream = url.openStream();*/
- XMLDocument doc = xmlHelper.load(xmlStr);
- DataObject root = doc.getRootObject();
-
- List symbols = root.getList("symbol");
- DataObject symbol = (DataObject)symbols.get(0);
-
- String seqValue = (String)symbol.getSequence().getValue(0);
- assertEquals(seqValue, "fbnt");
-
- //String symbol = root.getString("symbol");
- //System.out.println("symbol: " + symbol);
- }
-
- public void testAnyTypeContainer() throws Exception
- {
- HelperContext hc = SDOUtil.createHelperContext();
-
- URL url = getClass().getResource("/simple.xsd");
- InputStream inputStream = url.openStream();
- hc.getXSDHelper().define(inputStream, url.toString());
-
- XMLHelper xmlHelper = hc.getXMLHelper();
- url = getClass().getResource("/quoteInSOAP.xml");
- inputStream = url.openStream();
- XMLDocument doc = xmlHelper.load(inputStream);
- DataObject root = doc.getRootObject();
- DataObject body = (DataObject)root.getList("Body").get(0);
- DataObject stockQuote = (DataObject)body.getList("stockQuote").get(0);
-
- //xmlHelper.save(stockQuote, stockQuote.getType().getURI(), "stockQuote", System.out);
-
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- ObjectOutputStream oos = SDOUtil.createObjectOutputStream(bos, hc);
- oos.writeObject(stockQuote);
- oos.close();
- bos.close();
-
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- ObjectInputStream ois = SDOUtil.createObjectInputStream(bis, hc);
- DataObject objectCopy = (DataObject)ois.readObject();
- ois.close();
- bis.close();
-
- assertEquals(objectCopy.getString("symbol"), "fbnt");
-
- //xmlHelper.save(objectCopy, stockQuote.getType().getURI(), "stockQuote", System.out);
- }
-
- protected void setUp() throws Exception
- {
- super.setUp();
-
- hc = SDOUtil.createHelperContext();
- th = hc.getTypeHelper();
- }
-}
+/**
+ *
+ * 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 org.apache.tuscany.sdo.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.net.URL;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sdo.util.SDOUtil;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.helper.XMLDocument;
+import commonj.sdo.helper.XMLHelper;
+
+
+public class DeserializationNoSchemaTestCase extends TestCase
+{
+ HelperContext hc;
+
+ TypeHelper th;
+
+ private final String xmlStr =
+ "<?xml version=\"1.0\" encoding=\"ASCII\"?> " +
+ "<simple:stockQuote xmlns:simple=\"www.example.com/simple\"> " +
+ "<symbol>fbnt</symbol> " +
+ "<companyName>FlyByNightTechnology</companyName> " +
+ "<price>1000.0</price> " +
+ "<open1>1000.0</open1> " +
+ "<high>1000.0</high> " +
+ "<low>1000.0</low> " +
+ "<volume>1000.0</volume> " +
+ "<change1>1000.0</change1> " +
+ "<quotes> " +
+ "<price>2000.0</price> " +
+ "</quotes> " +
+ "</simple:stockQuote>";
+
+ public void testLoadQuoteXMLDoc() throws IOException
+ {
+ XMLHelper xmlHelper = hc.getXMLHelper();
+/* URL url = getClass().getResource("/quote.xml");
+ InputStream inputStream = url.openStream();*/
+ XMLDocument doc = xmlHelper.load(xmlStr);
+ DataObject root = doc.getRootObject();
+
+ List symbols = root.getList("symbol");
+ DataObject symbol = (DataObject)symbols.get(0);
+
+ String seqValue = (String)symbol.getSequence().getValue(0);
+ assertEquals(seqValue, "fbnt");
+
+ //String symbol = root.getString("symbol");
+ //System.out.println("symbol: " + symbol);
+ }
+
+ public void testAnyTypeContainer() throws Exception
+ {
+ HelperContext hc = SDOUtil.createHelperContext();
+
+ URL url = getClass().getResource("/simple.xsd");
+ InputStream inputStream = url.openStream();
+ hc.getXSDHelper().define(inputStream, url.toString());
+
+ XMLHelper xmlHelper = hc.getXMLHelper();
+ url = getClass().getResource("/quoteInSOAP.xml");
+ inputStream = url.openStream();
+ XMLDocument doc = xmlHelper.load(inputStream);
+ DataObject root = doc.getRootObject();
+ DataObject body = (DataObject)root.getList("Body").get(0);
+ DataObject stockQuote = (DataObject)body.getList("stockQuote").get(0);
+
+ //xmlHelper.save(stockQuote, stockQuote.getType().getURI(), "stockQuote", System.out);
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = SDOUtil.createObjectOutputStream(bos, hc);
+ oos.writeObject(stockQuote);
+ oos.close();
+ bos.close();
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ ObjectInputStream ois = SDOUtil.createObjectInputStream(bis, hc);
+ DataObject objectCopy = (DataObject)ois.readObject();
+ ois.close();
+ bis.close();
+
+ assertEquals(objectCopy.getString("symbol"), "fbnt");
+
+ //xmlHelper.save(objectCopy, stockQuote.getType().getURI(), "stockQuote", System.out);
+ }
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ hc = SDOUtil.createHelperContext();
+ th = hc.getTypeHelper();
+ }
+}
Propchange: tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DeserializationNoSchemaTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DupElementTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DupElementTestCase.java?rev=680370&r1=680369&r2=680370&view=diff
==============================================================================
--- tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DupElementTestCase.java (original)
+++ tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DupElementTestCase.java Mon Jul 28 07:30:12 2008
@@ -1,99 +1,99 @@
-/**
- *
- * 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 org.apache.tuscany.sdo.test;
-
-import java.io.InputStream;
-import java.net.URL;
-import java.util.List;
-//import java.util.regex.MatchResult;
-//import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import junit.framework.TestCase;
-
-import org.apache.tuscany.sdo.api.SDOUtil;
-
-import commonj.sdo.DataObject;
-import commonj.sdo.Type;
-import commonj.sdo.helper.HelperContext;
-
-public class DupElementTestCase extends TestCase {
- HelperContext hc;
-
- private final String TEST_MODEL = "/dupelement.xsd";
- private final String TEST_URI = "http://www.example.com/dupelement";
-
- protected void setUp() throws Exception {
- super.setUp();
-
- URL url = getClass().getResource(TEST_MODEL);
- InputStream inputStream = url.openStream();
-
- hc = SDOUtil.createHelperContext();
-
- hc.getXSDHelper().define(inputStream, url.toString());
-
- inputStream.close();
- }
-
-
- public void test() {
- Type quoteType = hc.getTypeHelper().getType(TEST_URI, "Quote");
-
- DataObject quote = hc.getDataFactory().create(quoteType);
- quote.set("symbol", "ACME");
- quote.set("companyName", "ACME Corp.");
-
- DataObject quote2 = hc.getDataFactory().create(quoteType);
-
- List quotes = quote.getList("quotes");
- quotes.add(quote2);
-
- try {
- quote.set("quotes.0/symbol", "ACME-CHILD");
- quote.set("quotes.0/companyName", "ACME subsidiary corp.");
- quote.setInt("quotes.0/companyNameInInt", 99);
- quote.setInt("quotes.0/symbolInInt", 55);
- }
- catch (Exception e) {
- fail("Set value on the wrong properties with the same name");
- }
- assert(quote.get("quotes.0/companyName") instanceof String);
- assert(quote.get("quotes.0/symbol") instanceof String);
- assert(quote.get("quotes.0/companyNameInInt") instanceof Integer);
- assert(quote.get("quotes.0/symbolInInt") instanceof Integer);
-
- String doc = hc.getXMLHelper().save(quote, "http://www.example.com/dupelement", "stockQuote");
- //System.out.println(doc);
- assertTrue(
- Pattern.matches("[\\s\\S]*<companyName>[\\s]*ACME Corp.[\\s]*</companyName>[\\s\\S]*",
- doc));
- assertTrue(
- Pattern.matches("[\\s\\S]*<companyName>[\\s]*99[\\s]*</companyName>[\\s\\S]*",
- doc));
- assertTrue(
- Pattern.matches("[\\s\\S]*symbol[\\s]*=[\\s]*\"55\"[\\s\\S]*",
- doc));
- assertTrue(
- Pattern.matches("[\\s\\S]*<symbol>[\\s]*ACME-CHILD[\\s]*</symbol>[\\s\\S]*",
- doc));
-
- }
-}
+/**
+ *
+ * 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 org.apache.tuscany.sdo.test;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.List;
+//import java.util.regex.MatchResult;
+//import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sdo.api.SDOUtil;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.Type;
+import commonj.sdo.helper.HelperContext;
+
+public class DupElementTestCase extends TestCase {
+ HelperContext hc;
+
+ private final String TEST_MODEL = "/dupelement.xsd";
+ private final String TEST_URI = "http://www.example.com/dupelement";
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ URL url = getClass().getResource(TEST_MODEL);
+ InputStream inputStream = url.openStream();
+
+ hc = SDOUtil.createHelperContext();
+
+ hc.getXSDHelper().define(inputStream, url.toString());
+
+ inputStream.close();
+ }
+
+
+ public void test() {
+ Type quoteType = hc.getTypeHelper().getType(TEST_URI, "Quote");
+
+ DataObject quote = hc.getDataFactory().create(quoteType);
+ quote.set("symbol", "ACME");
+ quote.set("companyName", "ACME Corp.");
+
+ DataObject quote2 = hc.getDataFactory().create(quoteType);
+
+ List quotes = quote.getList("quotes");
+ quotes.add(quote2);
+
+ try {
+ quote.set("quotes.0/symbol", "ACME-CHILD");
+ quote.set("quotes.0/companyName", "ACME subsidiary corp.");
+ quote.setInt("quotes.0/companyNameInInt", 99);
+ quote.setInt("quotes.0/symbolInInt", 55);
+ }
+ catch (Exception e) {
+ fail("Set value on the wrong properties with the same name");
+ }
+ assert(quote.get("quotes.0/companyName") instanceof String);
+ assert(quote.get("quotes.0/symbol") instanceof String);
+ assert(quote.get("quotes.0/companyNameInInt") instanceof Integer);
+ assert(quote.get("quotes.0/symbolInInt") instanceof Integer);
+
+ String doc = hc.getXMLHelper().save(quote, "http://www.example.com/dupelement", "stockQuote");
+ //System.out.println(doc);
+ assertTrue(
+ Pattern.matches("[\\s\\S]*<companyName>[\\s]*ACME Corp.[\\s]*</companyName>[\\s\\S]*",
+ doc));
+ assertTrue(
+ Pattern.matches("[\\s\\S]*<companyName>[\\s]*99[\\s]*</companyName>[\\s\\S]*",
+ doc));
+ assertTrue(
+ Pattern.matches("[\\s\\S]*symbol[\\s]*=[\\s]*\"55\"[\\s\\S]*",
+ doc));
+ assertTrue(
+ Pattern.matches("[\\s\\S]*<symbol>[\\s]*ACME-CHILD[\\s]*</symbol>[\\s\\S]*",
+ doc));
+
+ }
+}
Propchange: tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DupElementTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DynamicTypesComparisonTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DynamicTypesComparisonTestCase.java?rev=680370&r1=680369&r2=680370&view=diff
==============================================================================
--- tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DynamicTypesComparisonTestCase.java (original)
+++ tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DynamicTypesComparisonTestCase.java Mon Jul 28 07:30:12 2008
@@ -1,256 +1,256 @@
-/**
- *
- * 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 org.apache.tuscany.sdo.test;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.apache.tuscany.sdo.util.SDOUtil;
-
-import commonj.sdo.DataObject;
-import commonj.sdo.Sequence;
-import commonj.sdo.Type;
-import commonj.sdo.helper.DataFactory;
-import commonj.sdo.helper.HelperContext;
-import commonj.sdo.helper.TypeHelper;
-import commonj.sdo.helper.XMLDocument;
-import commonj.sdo.helper.XMLHelper;
-import commonj.sdo.helper.XSDHelper;
-
-/**
- * Test to compare data objects created with SDO API with one created from XML
- */
-public class DynamicTypesComparisonTestCase extends TestCase {
- private final String COMMONJ_SDO = "commonj.sdo";
-
- private final String DYNAMIC_ROOT_TYPE_0 = "TestType0";
-
- private final String DYNAMIC_TYPES_SCHEMA_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<xsd:schema\n"
- + " targetNamespace=\"http://www.example.com/dynamicTypesFromSchemaSimple\"\n"
- + " xmlns:dtfs=\"http://www.example.com/dynamicTypesFromSchemaSimple\"\n"
- + " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n" + " \n"
- + " <xsd:complexType name=\"TestType0\" mixed=\"true\">\n" + " <xsd:sequence>\n"
- + " <xsd:element name=\"aString\" minOccurs=\"0\" maxOccurs=\"unbounded\" type=\"xsd:string\"/>\n"
- + " <xsd:element name=\"aBoolean\" minOccurs=\"0\" maxOccurs=\"unbounded\" type=\"xsd:boolean\"/>\n"
- + " <xsd:element name=\"aFloat\" minOccurs=\"0\" maxOccurs=\"unbounded\" type=\"xsd:float\"/>\n"
- + " </xsd:sequence>\n" + " </xsd:complexType>\n" + " \n"
- + " <xsd:element name=\"testElement0\" type=\"dtfs:TestType0\"/>\n" + " \n" + "</xsd:schema>\n";
-
- private final String DYNAMIC_TYPES_URI = "http://www.example.com/dynamicTypesFromSchemaSimple";
-
- private final String SDO_FROM_API_AND_DYN = "object created with API with dynamic type ";
-
- private final String SDO_FROM_API_AND_REF = "object created with API with type from XSD";
-
- private final String SDO_FROM_XML_AND_REF = "object created with XML with type from XSD";
-
- private final String TEST_XML_DOC_0_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
- + "<dtfs:testElement0 xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
- + " xmlns:dtfs=\"http://www.example.com/dynamicTypesFromSchemaSimple\">\n"
- + " <aString>This is a repeated string.</aString>\n" + " <aString>This is a repeated string.</aString>\n"
- + " <aBoolean>true</aBoolean>\n" + " <aBoolean>false</aBoolean>\n" + " <aBoolean>true</aBoolean>\n"
- + " <aBoolean>1</aBoolean>\n" + " <aBoolean>0</aBoolean>\n" + " <aFloat>0</aFloat>\n"
- + " <aFloat>12.5</aFloat>\n" + " <aFloat>0</aFloat>\n" + "</dtfs:testElement0>\n";
-
- private void comparePropertyObjects(String propName, String name1, String name2, Object propObj1, Object propObj2) {
- if (propObj1 == null) {
- if (propObj2 != null) {
- localFail("property " + propName + " for " + name1 + " was null but " + name2 + " was '" + propObj2
- + "'");
- }
- } else if (propObj2 == null) {
- localFail("property " + propName + " for " + name2 + " was null but " + name1 + " was '" + propObj1 + "'");
- } else {
- if (!propObj1.equals(propObj2)) {
- localFail("property " + propName + " for " + name1 + " was '" + propObj1 + "' but " + name2 + " was '"
- + propObj2 + "'");
- }
- }
- }
-
- private void compareSequencesIgnoringWhitespace(String name1, String name2, Sequence sequence1, Sequence sequence2) {
- if (sequence1 == null) {
- if (sequence2 != null) {
- localFail("sequence for " + name1 + " was null but " + name2 + " was not null");
- }
- } else if (sequence2 == null) {
- localFail("sequence for " + name2 + " was null but " + name1 + " was not null");
- } else {
- List trimmedSeq1 = new ArrayList();
- List trimmedSeq2 = new ArrayList();
- trimWhitespaceFromSequence(trimmedSeq1, sequence1);
- trimWhitespaceFromSequence(trimmedSeq2, sequence2);
- int size1 = trimmedSeq1.size();
- int size2 = trimmedSeq2.size();
- if (size1 != size2) {
- localFail("lengths of trimmed sequences differ: " + name1 + " was " + size1 + ", " + name2 + " was "
- + size2);
- } else {
- Object[] objArr1 = trimmedSeq1.toArray();
- Object[] objArr2 = trimmedSeq2.toArray();
- for (int i = 0; i < size1; i++) {
- Object obj1 = objArr1[i];
- Object obj2 = objArr2[i];
- if (obj1 == null) {
- if (obj2 != null) {
- localFail("sequence for " + name1 + " had null element for which " + name2 + " had '" + obj2
- + "'");
- }
- } else if (obj2 == null) {
- localFail("sequence for " + name2 + " had null element for which " + name1 + " had '" + obj1 + "'");
- } else {
- if (!obj1.equals(obj2)) {
- localFail("sequences did not match: " + name1 + " had '" + obj1 + "' but " + name2 + " had '"
- + obj2 + "'");
- }
- }
- }
- }
- }
- }
-
- private void getAndCompareProperties(String propName, DataObject xmlAndRefTypDO, DataObject apiAndDynTypDO,
- DataObject apiAndRefTypDO) {
- Object xmlRefProperty = xmlAndRefTypDO.get(propName);
- Object apiDynProperty = apiAndDynTypDO.get(propName);
- Object apiRefProperty = apiAndRefTypDO.get(propName);
- comparePropertyObjects(propName, SDO_FROM_XML_AND_REF, SDO_FROM_API_AND_DYN, xmlRefProperty, apiDynProperty);
- comparePropertyObjects(propName, SDO_FROM_XML_AND_REF, SDO_FROM_API_AND_REF, xmlRefProperty, apiRefProperty);
- }
-
- private void localFail(String message) {
- // System.err.println(message);
- fail(message);
- }
-
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- private void specifyProperty(DataObject containingTypeDO, String nameString, Type typ, boolean isMany) {
- DataObject subordinateProperty = containingTypeDO.createDataObject("property");
- subordinateProperty.set("name", nameString);
- subordinateProperty.set("type", typ);
- subordinateProperty.setBoolean("many", isMany);
- }
-
- /**
- * test #0 of Data Object primitive datatypes
- */
- public void testDynamicTypesGroup0DO() throws IOException {
- HelperContext hcDO = SDOUtil.createHelperContext();
-
- TypeHelper thDO = hcDO.getTypeHelper();
- DataFactory dfDO = hcDO.getDataFactory();
-
- // create a container object type
- DataObject containerTypeDO = dfDO.create("commonj.sdo", "Type");
- containerTypeDO.set("uri", DYNAMIC_TYPES_URI);
- containerTypeDO.set("name", DYNAMIC_ROOT_TYPE_0);
- containerTypeDO.set("sequenced", Boolean.TRUE);
-
- specifyProperty(containerTypeDO, "aString", thDO.getType(COMMONJ_SDO, "String"), true);
- specifyProperty(containerTypeDO, "aBoolean", thDO.getType(COMMONJ_SDO, "Boolean"), true);
- specifyProperty(containerTypeDO, "aFloat", thDO.getType(COMMONJ_SDO, "Float"), true);
-
- Type containerType = thDO.define(containerTypeDO);
- assertNotNull(containerType);
-
- DataObject doFromApiAndDynTyp = dfDO.create(containerType);
- assertNotNull(doFromApiAndDynTyp);
- doFromApiAndDynTyp.getList("aString").add("This is a repeated string.");
- doFromApiAndDynTyp.getList("aString").add("This is a repeated string.");
- doFromApiAndDynTyp.getList("aBoolean").add(new Boolean(true));
- doFromApiAndDynTyp.getList("aBoolean").add(new Boolean(false));
- doFromApiAndDynTyp.getList("aBoolean").add(new Boolean(true));
- doFromApiAndDynTyp.getList("aBoolean").add(new Boolean(true));
- doFromApiAndDynTyp.getList("aBoolean").add(new Boolean(false));
- doFromApiAndDynTyp.getList("aFloat").add(new Float(0));
- doFromApiAndDynTyp.getList("aFloat").add(new Float(12.5));
- doFromApiAndDynTyp.getList("aFloat").add(new Float(0));
-
- Type rootType = thDO.getType(DYNAMIC_TYPES_URI, DYNAMIC_ROOT_TYPE_0);
- assertNotNull(rootType);
- assertSame(containerType, rootType);
-
- // now load xml to get a reference data object using schema
- HelperContext hcRef = SDOUtil.createHelperContext();
- XSDHelper xsdHelper = hcRef.getXSDHelper();
- List typeList = xsdHelper.define(DYNAMIC_TYPES_SCHEMA_STRING);
- assertNotNull(typeList);
- TypeHelper thRef = hcRef.getTypeHelper();
- Type rootTypeRef = thRef.getType(DYNAMIC_TYPES_URI, DYNAMIC_ROOT_TYPE_0);
-
- assertNotNull(rootTypeRef);
-
- XMLHelper xhRef = hcRef.getXMLHelper();
- // XMLDocument docRef =
- // xhRef.load(getClass().getResourceAsStream(TEST_XML_DOC_0));
- XMLDocument docRef = xhRef.load(TEST_XML_DOC_0_STRING);
- DataObject doFromXmlAndRefTyp = docRef.getRootObject();
-
- assertNotNull(doFromXmlAndRefTyp);
-
- // create a data object using dynamic API from reference type
- DataFactory dfRef = hcRef.getDataFactory();
- DataObject doFromApiAndRefTyp = dfRef.create(rootTypeRef);
- assertNotNull(doFromApiAndRefTyp);
- doFromApiAndRefTyp.getList("aString").add("This is a repeated string.");
- doFromApiAndRefTyp.getList("aString").add("This is a repeated string.");
- doFromApiAndRefTyp.getList("aBoolean").add(new Boolean(true));
- doFromApiAndRefTyp.getList("aBoolean").add(new Boolean(false));
- doFromApiAndRefTyp.getList("aBoolean").add(new Boolean(true));
- doFromApiAndRefTyp.getList("aBoolean").add(new Boolean(true));
- doFromApiAndRefTyp.getList("aBoolean").add(new Boolean(false));
- doFromApiAndRefTyp.getList("aFloat").add(new Float(0));
- doFromApiAndRefTyp.getList("aFloat").add(new Float(12.5));
- doFromApiAndRefTyp.getList("aFloat").add(new Float(0));
-
- getAndCompareProperties("aString", doFromXmlAndRefTyp, doFromApiAndDynTyp, doFromApiAndRefTyp);
- getAndCompareProperties("aBoolean", doFromXmlAndRefTyp, doFromApiAndDynTyp, doFromApiAndRefTyp);
- getAndCompareProperties("aFloat", doFromXmlAndRefTyp, doFromApiAndDynTyp, doFromApiAndRefTyp);
- Sequence seqFromXmlAndRefTyp = doFromXmlAndRefTyp.getSequence();
- Sequence seqFromApiAndDynTyp = doFromApiAndDynTyp.getSequence();
- Sequence seqFromApiAndRefTyp = doFromApiAndRefTyp.getSequence();
- compareSequencesIgnoringWhitespace(SDO_FROM_XML_AND_REF, SDO_FROM_API_AND_DYN, seqFromXmlAndRefTyp,
- seqFromApiAndDynTyp);
- compareSequencesIgnoringWhitespace(SDO_FROM_XML_AND_REF, SDO_FROM_API_AND_REF, seqFromXmlAndRefTyp,
- seqFromApiAndRefTyp);
- }
-
- private void trimWhitespaceFromSequence(List trimmedSeq, Sequence sequence) {
- if (sequence != null) {
- for (int i = 0; i < sequence.size(); i++) {
- Object obj = sequence.getValue(i);
- if (obj instanceof String) {
- String str = ((String) obj).trim();
- if (str.length() > 0) {
- trimmedSeq.add(str);
- }
- } else {
- trimmedSeq.add(obj);
- }
- }
- }
- }
-}
+/**
+ *
+ * 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 org.apache.tuscany.sdo.test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sdo.util.SDOUtil;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.Sequence;
+import commonj.sdo.Type;
+import commonj.sdo.helper.DataFactory;
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.helper.XMLDocument;
+import commonj.sdo.helper.XMLHelper;
+import commonj.sdo.helper.XSDHelper;
+
+/**
+ * Test to compare data objects created with SDO API with one created from XML
+ */
+public class DynamicTypesComparisonTestCase extends TestCase {
+ private final String COMMONJ_SDO = "commonj.sdo";
+
+ private final String DYNAMIC_ROOT_TYPE_0 = "TestType0";
+
+ private final String DYNAMIC_TYPES_SCHEMA_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<xsd:schema\n"
+ + " targetNamespace=\"http://www.example.com/dynamicTypesFromSchemaSimple\"\n"
+ + " xmlns:dtfs=\"http://www.example.com/dynamicTypesFromSchemaSimple\"\n"
+ + " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n" + " \n"
+ + " <xsd:complexType name=\"TestType0\" mixed=\"true\">\n" + " <xsd:sequence>\n"
+ + " <xsd:element name=\"aString\" minOccurs=\"0\" maxOccurs=\"unbounded\" type=\"xsd:string\"/>\n"
+ + " <xsd:element name=\"aBoolean\" minOccurs=\"0\" maxOccurs=\"unbounded\" type=\"xsd:boolean\"/>\n"
+ + " <xsd:element name=\"aFloat\" minOccurs=\"0\" maxOccurs=\"unbounded\" type=\"xsd:float\"/>\n"
+ + " </xsd:sequence>\n" + " </xsd:complexType>\n" + " \n"
+ + " <xsd:element name=\"testElement0\" type=\"dtfs:TestType0\"/>\n" + " \n" + "</xsd:schema>\n";
+
+ private final String DYNAMIC_TYPES_URI = "http://www.example.com/dynamicTypesFromSchemaSimple";
+
+ private final String SDO_FROM_API_AND_DYN = "object created with API with dynamic type ";
+
+ private final String SDO_FROM_API_AND_REF = "object created with API with type from XSD";
+
+ private final String SDO_FROM_XML_AND_REF = "object created with XML with type from XSD";
+
+ private final String TEST_XML_DOC_0_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ + "<dtfs:testElement0 xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
+ + " xmlns:dtfs=\"http://www.example.com/dynamicTypesFromSchemaSimple\">\n"
+ + " <aString>This is a repeated string.</aString>\n" + " <aString>This is a repeated string.</aString>\n"
+ + " <aBoolean>true</aBoolean>\n" + " <aBoolean>false</aBoolean>\n" + " <aBoolean>true</aBoolean>\n"
+ + " <aBoolean>1</aBoolean>\n" + " <aBoolean>0</aBoolean>\n" + " <aFloat>0</aFloat>\n"
+ + " <aFloat>12.5</aFloat>\n" + " <aFloat>0</aFloat>\n" + "</dtfs:testElement0>\n";
+
+ private void comparePropertyObjects(String propName, String name1, String name2, Object propObj1, Object propObj2) {
+ if (propObj1 == null) {
+ if (propObj2 != null) {
+ localFail("property " + propName + " for " + name1 + " was null but " + name2 + " was '" + propObj2
+ + "'");
+ }
+ } else if (propObj2 == null) {
+ localFail("property " + propName + " for " + name2 + " was null but " + name1 + " was '" + propObj1 + "'");
+ } else {
+ if (!propObj1.equals(propObj2)) {
+ localFail("property " + propName + " for " + name1 + " was '" + propObj1 + "' but " + name2 + " was '"
+ + propObj2 + "'");
+ }
+ }
+ }
+
+ private void compareSequencesIgnoringWhitespace(String name1, String name2, Sequence sequence1, Sequence sequence2) {
+ if (sequence1 == null) {
+ if (sequence2 != null) {
+ localFail("sequence for " + name1 + " was null but " + name2 + " was not null");
+ }
+ } else if (sequence2 == null) {
+ localFail("sequence for " + name2 + " was null but " + name1 + " was not null");
+ } else {
+ List trimmedSeq1 = new ArrayList();
+ List trimmedSeq2 = new ArrayList();
+ trimWhitespaceFromSequence(trimmedSeq1, sequence1);
+ trimWhitespaceFromSequence(trimmedSeq2, sequence2);
+ int size1 = trimmedSeq1.size();
+ int size2 = trimmedSeq2.size();
+ if (size1 != size2) {
+ localFail("lengths of trimmed sequences differ: " + name1 + " was " + size1 + ", " + name2 + " was "
+ + size2);
+ } else {
+ Object[] objArr1 = trimmedSeq1.toArray();
+ Object[] objArr2 = trimmedSeq2.toArray();
+ for (int i = 0; i < size1; i++) {
+ Object obj1 = objArr1[i];
+ Object obj2 = objArr2[i];
+ if (obj1 == null) {
+ if (obj2 != null) {
+ localFail("sequence for " + name1 + " had null element for which " + name2 + " had '" + obj2
+ + "'");
+ }
+ } else if (obj2 == null) {
+ localFail("sequence for " + name2 + " had null element for which " + name1 + " had '" + obj1 + "'");
+ } else {
+ if (!obj1.equals(obj2)) {
+ localFail("sequences did not match: " + name1 + " had '" + obj1 + "' but " + name2 + " had '"
+ + obj2 + "'");
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private void getAndCompareProperties(String propName, DataObject xmlAndRefTypDO, DataObject apiAndDynTypDO,
+ DataObject apiAndRefTypDO) {
+ Object xmlRefProperty = xmlAndRefTypDO.get(propName);
+ Object apiDynProperty = apiAndDynTypDO.get(propName);
+ Object apiRefProperty = apiAndRefTypDO.get(propName);
+ comparePropertyObjects(propName, SDO_FROM_XML_AND_REF, SDO_FROM_API_AND_DYN, xmlRefProperty, apiDynProperty);
+ comparePropertyObjects(propName, SDO_FROM_XML_AND_REF, SDO_FROM_API_AND_REF, xmlRefProperty, apiRefProperty);
+ }
+
+ private void localFail(String message) {
+ // System.err.println(message);
+ fail(message);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ private void specifyProperty(DataObject containingTypeDO, String nameString, Type typ, boolean isMany) {
+ DataObject subordinateProperty = containingTypeDO.createDataObject("property");
+ subordinateProperty.set("name", nameString);
+ subordinateProperty.set("type", typ);
+ subordinateProperty.setBoolean("many", isMany);
+ }
+
+ /**
+ * test #0 of Data Object primitive datatypes
+ */
+ public void testDynamicTypesGroup0DO() throws IOException {
+ HelperContext hcDO = SDOUtil.createHelperContext();
+
+ TypeHelper thDO = hcDO.getTypeHelper();
+ DataFactory dfDO = hcDO.getDataFactory();
+
+ // create a container object type
+ DataObject containerTypeDO = dfDO.create("commonj.sdo", "Type");
+ containerTypeDO.set("uri", DYNAMIC_TYPES_URI);
+ containerTypeDO.set("name", DYNAMIC_ROOT_TYPE_0);
+ containerTypeDO.set("sequenced", Boolean.TRUE);
+
+ specifyProperty(containerTypeDO, "aString", thDO.getType(COMMONJ_SDO, "String"), true);
+ specifyProperty(containerTypeDO, "aBoolean", thDO.getType(COMMONJ_SDO, "Boolean"), true);
+ specifyProperty(containerTypeDO, "aFloat", thDO.getType(COMMONJ_SDO, "Float"), true);
+
+ Type containerType = thDO.define(containerTypeDO);
+ assertNotNull(containerType);
+
+ DataObject doFromApiAndDynTyp = dfDO.create(containerType);
+ assertNotNull(doFromApiAndDynTyp);
+ doFromApiAndDynTyp.getList("aString").add("This is a repeated string.");
+ doFromApiAndDynTyp.getList("aString").add("This is a repeated string.");
+ doFromApiAndDynTyp.getList("aBoolean").add(new Boolean(true));
+ doFromApiAndDynTyp.getList("aBoolean").add(new Boolean(false));
+ doFromApiAndDynTyp.getList("aBoolean").add(new Boolean(true));
+ doFromApiAndDynTyp.getList("aBoolean").add(new Boolean(true));
+ doFromApiAndDynTyp.getList("aBoolean").add(new Boolean(false));
+ doFromApiAndDynTyp.getList("aFloat").add(new Float(0));
+ doFromApiAndDynTyp.getList("aFloat").add(new Float(12.5));
+ doFromApiAndDynTyp.getList("aFloat").add(new Float(0));
+
+ Type rootType = thDO.getType(DYNAMIC_TYPES_URI, DYNAMIC_ROOT_TYPE_0);
+ assertNotNull(rootType);
+ assertSame(containerType, rootType);
+
+ // now load xml to get a reference data object using schema
+ HelperContext hcRef = SDOUtil.createHelperContext();
+ XSDHelper xsdHelper = hcRef.getXSDHelper();
+ List typeList = xsdHelper.define(DYNAMIC_TYPES_SCHEMA_STRING);
+ assertNotNull(typeList);
+ TypeHelper thRef = hcRef.getTypeHelper();
+ Type rootTypeRef = thRef.getType(DYNAMIC_TYPES_URI, DYNAMIC_ROOT_TYPE_0);
+
+ assertNotNull(rootTypeRef);
+
+ XMLHelper xhRef = hcRef.getXMLHelper();
+ // XMLDocument docRef =
+ // xhRef.load(getClass().getResourceAsStream(TEST_XML_DOC_0));
+ XMLDocument docRef = xhRef.load(TEST_XML_DOC_0_STRING);
+ DataObject doFromXmlAndRefTyp = docRef.getRootObject();
+
+ assertNotNull(doFromXmlAndRefTyp);
+
+ // create a data object using dynamic API from reference type
+ DataFactory dfRef = hcRef.getDataFactory();
+ DataObject doFromApiAndRefTyp = dfRef.create(rootTypeRef);
+ assertNotNull(doFromApiAndRefTyp);
+ doFromApiAndRefTyp.getList("aString").add("This is a repeated string.");
+ doFromApiAndRefTyp.getList("aString").add("This is a repeated string.");
+ doFromApiAndRefTyp.getList("aBoolean").add(new Boolean(true));
+ doFromApiAndRefTyp.getList("aBoolean").add(new Boolean(false));
+ doFromApiAndRefTyp.getList("aBoolean").add(new Boolean(true));
+ doFromApiAndRefTyp.getList("aBoolean").add(new Boolean(true));
+ doFromApiAndRefTyp.getList("aBoolean").add(new Boolean(false));
+ doFromApiAndRefTyp.getList("aFloat").add(new Float(0));
+ doFromApiAndRefTyp.getList("aFloat").add(new Float(12.5));
+ doFromApiAndRefTyp.getList("aFloat").add(new Float(0));
+
+ getAndCompareProperties("aString", doFromXmlAndRefTyp, doFromApiAndDynTyp, doFromApiAndRefTyp);
+ getAndCompareProperties("aBoolean", doFromXmlAndRefTyp, doFromApiAndDynTyp, doFromApiAndRefTyp);
+ getAndCompareProperties("aFloat", doFromXmlAndRefTyp, doFromApiAndDynTyp, doFromApiAndRefTyp);
+ Sequence seqFromXmlAndRefTyp = doFromXmlAndRefTyp.getSequence();
+ Sequence seqFromApiAndDynTyp = doFromApiAndDynTyp.getSequence();
+ Sequence seqFromApiAndRefTyp = doFromApiAndRefTyp.getSequence();
+ compareSequencesIgnoringWhitespace(SDO_FROM_XML_AND_REF, SDO_FROM_API_AND_DYN, seqFromXmlAndRefTyp,
+ seqFromApiAndDynTyp);
+ compareSequencesIgnoringWhitespace(SDO_FROM_XML_AND_REF, SDO_FROM_API_AND_REF, seqFromXmlAndRefTyp,
+ seqFromApiAndRefTyp);
+ }
+
+ private void trimWhitespaceFromSequence(List trimmedSeq, Sequence sequence) {
+ if (sequence != null) {
+ for (int i = 0; i < sequence.size(); i++) {
+ Object obj = sequence.getValue(i);
+ if (obj instanceof String) {
+ String str = ((String) obj).trim();
+ if (str.length() > 0) {
+ trimmedSeq.add(str);
+ }
+ } else {
+ trimmedSeq.add(obj);
+ }
+ }
+ }
+ }
+}
Propchange: tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DynamicTypesComparisonTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native