From c993ba575bdd1530b7bbc0c6a19c32e66fce4b89 Mon Sep 17 00:00:00 2001 From: lresende Date: Tue, 10 Nov 2009 19:19:15 +0000 Subject: moving SDO branches git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@834612 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/tuscany/sdo/test/AllTests.java | 53 ++++ .../tuscany/sdo/test/ChangeSummaryGenTestCase.java | 131 ++++++++++ .../apache/tuscany/sdo/test/CreateTestClasses.java | 55 ++++ .../tuscany/sdo/test/ExtensibleTestCase.java | 96 +++++++ .../tuscany/sdo/test/GenPatternsTestCase.java | 115 ++++++++ .../sdo/test/GeneratedPackagesTestCase.java | 76 ++++++ .../tuscany/sdo/test/InheritanceTestCase.java | 102 ++++++++ .../tuscany/sdo/test/OpenContentTestCase.java | 75 ++++++ .../tuscany/sdo/test/SimpleStaticTestCase.java | 86 ++++++ .../java/org/apache/tuscany/sdo/test/TestUtil.java | 288 +++++++++++++++++++++ 10 files changed, 1077 insertions(+) create mode 100644 sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/AllTests.java create mode 100644 sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/ChangeSummaryGenTestCase.java create mode 100644 sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/CreateTestClasses.java create mode 100644 sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/ExtensibleTestCase.java create mode 100644 sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/GenPatternsTestCase.java create mode 100644 sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/GeneratedPackagesTestCase.java create mode 100644 sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/InheritanceTestCase.java create mode 100644 sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/OpenContentTestCase.java create mode 100644 sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/SimpleStaticTestCase.java create mode 100644 sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/TestUtil.java (limited to 'sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo') diff --git a/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/AllTests.java b/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/AllTests.java new file mode 100644 index 0000000000..f54313e9bf --- /dev/null +++ b/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/AllTests.java @@ -0,0 +1,53 @@ +/** + * + * 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 junit.framework.TestCase; +import junit.framework.TestSuite; + +public class AllTests extends TestCase { + + + public static TestSuite suite() { + + TestSuite suite = new TestSuite(); + + suite.addTestSuite(ChangeSummaryGenTestCase.class); + suite.addTestSuite(ExtensibleTestCase.class); + suite.addTestSuite(GenPatternsTestCase.class); + suite.addTestSuite(InheritanceTestCase.class); + suite.addTestSuite(OpenContentTestCase.class); + suite.addTestSuite(SimpleStaticTestCase.class); + suite.addTestSuite(GeneratedPackagesTestCase.class); + + return suite; + } + + + + /** + * Runs the test suite using the textual runner. + */ + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } +} + + diff --git a/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/ChangeSummaryGenTestCase.java b/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/ChangeSummaryGenTestCase.java new file mode 100644 index 0000000000..f58d607cba --- /dev/null +++ b/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/ChangeSummaryGenTestCase.java @@ -0,0 +1,131 @@ +/** + * + * 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.math.BigDecimal; +import java.util.List; + +import org.apache.tuscany.sdo.api.SDOUtil; + +import junit.framework.TestCase; + +import com.example.customer.Account; +import com.example.customer.Customer; +import com.example.customer.CustomerFactory; +import com.example.simple.cs.CSFactory; +import com.example.simple.cs.Quote; +import com.example.simple.cs.QuoteBase; +import commonj.sdo.ChangeSummary; +import commonj.sdo.DataGraph; +import commonj.sdo.DataObject; +import commonj.sdo.Type; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.impl.HelperProvider; + + +public class ChangeSummaryGenTestCase extends TestCase { + + public void testMixedQuoteType() throws IOException { + QuoteBase quote = CSFactory.INSTANCE.createQuoteBase(); + DataObject dQuote = (DataObject)quote; + + // ChangeSummary csp = quote.getChanges(); + ChangeSummary cs = dQuote.getChangeSummary(); + ChangeSummary csp = quote.getChanges(); + cs.beginLogging(); + + assertSame(cs, csp); + + quote.setSymbol("fbnt"); + quote.setCompanyName("FlyByNightTechnology"); + quote.setPrice(new BigDecimal("1000.0")); + quote.setOpen1(new BigDecimal("1000.0")); + quote.setHigh(new BigDecimal("1000.0")); + quote.setLow(new BigDecimal("1000.0")); + quote.setVolume(1000); + quote.setChange1(1000); + + List quotes = quote.getQuotes(); + Quote innerQuote = CSFactory.INSTANCE.createQuote(); + + quotes.add(innerQuote); + innerQuote.setPrice(new BigDecimal("2000.0")); + + cs.endLogging(); + + //XMLHelper.INSTANCE.save(dQuote, "http://www.example.com/simpleCS", "quoteBase", System.out); + + cs.undoChanges(); + + //System.out.println("\nAfter Undo Changes:"); + //XMLHelper.INSTANCE.save(dQuote, "http://www.example.com/simpleCS", "quoteBase", System.out); + } + + public void testChangeSummaryOnDatagraphWithContainmentStatic() throws Exception { + + HelperContext hc = HelperProvider.getDefaultContext(); + CustomerFactory.INSTANCE.register(hc); + + Type customerType = hc.getTypeHelper().getType(Customer.class); + DataGraph dataGraph = SDOUtil.createDataGraph(); + Customer customer = (Customer) dataGraph.createRootObject(customerType); + + Account account = CustomerFactory.INSTANCE.createAccount(); + customer.setAccount(account); + customer.setFirstName("John"); + customer.getAccount().setAccountNum(1234); + + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + SDOUtil.saveDataGraph(dataGraph, outputStream, null); + DataGraph loadDataGraph = SDOUtil.loadDataGraph(new ByteArrayInputStream(outputStream.toByteArray()), null); + + loadDataGraph.getChangeSummary().beginLogging(); + + customer = (Customer) loadDataGraph.getRootObject(); + customer.getAccount().setAccountNum(987); + + loadDataGraph.getChangeSummary().endLogging(); + + List changedDataObjects = loadDataGraph.getChangeSummary().getChangedDataObjects(); + assertEquals("in fact 1 Object was changed in the code", 1, changedDataObjects.size()); + } + + public void testChangeSummaryOnDataGraphWithInt() throws Exception { + + HelperContext hc = HelperProvider.getDefaultContext(); + CustomerFactory factory = CustomerFactory.INSTANCE; + factory.register(hc); + Customer customer = factory.createCustomer(); + Account account = factory.createAccount(); + customer.setAccount(account); + DataObject customerDO = (DataObject) customer; + DataGraph dg = SDOUtil.createDataGraph(); + SDOUtil.setRootObject(dg, customerDO); + dg.getChangeSummary().beginLogging(); + dg.getRootObject().getDataObject(0).delete(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + SDOUtil.saveDataGraph(dg, baos, null); + } + +} diff --git a/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/CreateTestClasses.java b/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/CreateTestClasses.java new file mode 100644 index 0000000000..6d81ebaf77 --- /dev/null +++ b/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/CreateTestClasses.java @@ -0,0 +1,55 @@ +/** + * + * 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 org.apache.tuscany.sdo.generate.JavaGenerator; +import org.apache.tuscany.sdo.generate.XSD2JavaGenerator; + +/** + * A utility class to regenerate the classes for the test cases + */ +public class CreateTestClasses { + + /** + * @param args + */ + public static void main(String[] args) { + + CreateTestClasses ctc = new CreateTestClasses(); + ctc.run(); + + + } + + private void run() { + XSD2JavaGenerator.generateFromXMLSchema(getClass().getResource("/CustomerAccount.xsd").getFile(), null, "src/test/java/", null, null, 0); + XSD2JavaGenerator.generateFromXMLSchema(getClass().getResource("/extensible/customer.xsd").getFile(), null, "src/test/java/", null, null, 0); + XSD2JavaGenerator.generateFromXMLSchema(getClass().getResource("/open.xsd").getFile(), null, "src/test/java/", null, null, 0); + XSD2JavaGenerator.generateFromXMLSchema(getClass().getResource("/simpleWithChangeSummary.xsd").getFile(), "http://www.example.com/simpleCS", "src/test/java/", "com.example.simple.cs", "CS", 0); + XSD2JavaGenerator.generateFromXMLSchema(getClass().getResource("/simple.xsd").getFile(), null, "src/test/java/", null, null, 0); + XSD2JavaGenerator.generateFromXMLSchema(getClass().getResource("/simple.xsd").getFile(), null, "src/test/java/", "com.example.noInterfaces.simple", null, JavaGenerator.OPTION_NO_INTERFACES); + + XSD2JavaGenerator.generateFromXMLSchema(getClass().getResource("/repeatingChoice.xsd").getFile(), null, "src/test/java/", null, null, 0); + XSD2JavaGenerator.generateFromXMLSchema(getClass().getResource("/sequences.xsd").getFile(), null, "src/test/java/", null, null, 0); + XSD2JavaGenerator.generateFromXMLSchema(getClass().getResource("/subgroup.xsd").getFile(), null, "src/test/java/", null, null, 0); + + } + +} diff --git a/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/ExtensibleTestCase.java b/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/ExtensibleTestCase.java new file mode 100644 index 0000000000..be65951ba5 --- /dev/null +++ b/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/ExtensibleTestCase.java @@ -0,0 +1,96 @@ +/** + * + * 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.io.InputStream; +import java.net.URL; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.api.SDOUtil; + +import com.example.extensible.customer.CustomerFactory; +import com.example.extensible.customer.CustomersType; +import com.example.extensible.customer.InfoType; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; + +public class ExtensibleTestCase extends TestCase { + + private final String[] MODELS = new String[] { + "/extensible/nonamespace.xsd", + "/extensible/infostreet.xsd", + "/extensible/infozipcode.xsd" + }; + + private final String CUSTOMERS_XML = "/extensible/customers.xml"; + private final String INFOSTREET_XML = "/extensible/infostreet.xml"; + private final String INFOZIPCODE_XML = "/extensible/infozipcode.xml"; + + private HelperContext scope; + + public void testCustomersLoad() throws IOException { + XMLDocument doc = scope.getXMLHelper().load( + getClass().getResourceAsStream(CUSTOMERS_XML)); + assertEquals("customers", doc.getRootElementName()); + assertTrue("RootObject of " + CUSTOMERS_XML + " should be instanceof CustomersType", + doc.getRootObject() instanceof CustomersType); + String strdoc = scope.getXMLHelper().save( + doc.getRootObject(), doc.getRootElementURI(), doc.getRootElementName()); + assertTrue(strdoc.indexOf("341 Duckworth Way") != -1); + } + + public void testInfoLoad() throws IOException { + String[] infoXmls = new String[] {INFOSTREET_XML, INFOZIPCODE_XML}; + for (int i = 0; i < infoXmls.length; i++) { + String infoXml = infoXmls[i]; + XMLDocument doc = scope.getXMLHelper().load( + getClass().getResourceAsStream(infoXml)); + assertEquals("info", doc.getRootElementName()); + assertTrue("RootObject of " + infoXml + " should be instanceof InfoType", + doc.getRootObject() instanceof InfoType); + String strdoc = scope.getXMLHelper().save( + doc.getRootObject(), doc.getRootElementURI(), doc.getRootElementName()); + String elementName = (i == 0) ? "street" : "zipcode"; + String valuePrefix = "21043"; + assertTrue(strdoc.indexOf("<" + elementName + ">") != -1); + assertTrue(strdoc.indexOf("") != -1); + assertTrue(strdoc.indexOf(">" + valuePrefix) != -1); + } + } + + protected void setUp() throws Exception { + super.setUp(); + scope = SDOUtil.createHelperContext(); + + CustomerFactory.INSTANCE.register(scope); + + // Populate the meta data for the models + for (int i = 0; i < MODELS.length; i++) { + String model = MODELS[i]; + URL url = getClass().getResource(model); + InputStream inputStream = url.openStream(); + scope.getXSDHelper().define(inputStream, url.toString()); + inputStream.close(); + } + } + +} diff --git a/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/GenPatternsTestCase.java b/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/GenPatternsTestCase.java new file mode 100644 index 0000000000..19fbc7b10e --- /dev/null +++ b/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/GenPatternsTestCase.java @@ -0,0 +1,115 @@ +/** + * + * 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.math.BigDecimal; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.util.SDOUtil; + +import com.example.simple.SimpleFactory; +import commonj.sdo.helper.HelperContext; + + +public class GenPatternsTestCase extends TestCase +{ + /** + * Simple Default Generation Pattern Static SDO 2.1 test. + */ + public void testSimpleDefaultGeneratedClasses() + { + try + { + HelperContext scope = SDOUtil.createHelperContext(); + com.example.simple.SimpleFactory.INSTANCE.register(scope); + + com.example.simple.Quote quote = + (com.example.simple.Quote)scope.getDataFactory().create(com.example.simple.Quote.class); + + quote.setSymbol("fbnt"); + quote.setCompanyName("FlyByNightTechnology"); + quote.setPrice(new BigDecimal("1000.0")); + quote.setOpen1(new BigDecimal("1000.0")); + quote.setHigh(new BigDecimal("1000.0")); + quote.setLow(new BigDecimal("1000.0")); + quote.setVolume(1000); + quote.setChange1(1000); + + com.example.simple.Quote child = + (com.example.simple.Quote)scope.getDataFactory().create(com.example.simple.Quote.class); + quote.getQuotes().add(child); + child.setPrice(new BigDecimal("2000.0")); + + //XMLHelper.INSTANCE.save((DataObject)quote, "http://www.example.com/simple", "stockQuote", System.out); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + /** + * Simple Default Generation Pattern Static SDO 2.1 test. + */ + public void testSimpleNoInterfaceGeneratedClasses() + { + try + { + HelperContext scope = SDOUtil.createHelperContext(); + com.example.noInterfaces.simple.SimpleFactory.INSTANCE.register(scope); + + com.example.noInterfaces.simple.Quote quote = + (com.example.noInterfaces.simple.Quote)scope.getDataFactory().create(com.example.noInterfaces.simple.Quote.class); + + quote.setSymbol("fbnt"); + quote.setCompanyName("FlyByNightTechnology"); + quote.setPrice(new BigDecimal("1000.0")); + quote.setOpen1(new BigDecimal("1000.0")); + quote.setHigh(new BigDecimal("1000.0")); + quote.setLow(new BigDecimal("1000.0")); + quote.setVolume(1000); + quote.setChange1(1000); + + com.example.noInterfaces.simple.Quote child = + (com.example.noInterfaces.simple.Quote)scope.getDataFactory().create(com.example.noInterfaces.simple.Quote.class); + quote.getQuotes().add(child); + child.setPrice(new BigDecimal("2000.0")); + + //XMLHelper.INSTANCE.save((DataObject)quote, "http://www.example.com/simple", "stockQuote", System.out); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + public void testFailureOnNullScope() { + try { + SimpleFactory.INSTANCE.register(null); + assertTrue("Should not be able to register in null scope", false); + } + catch (Exception e) { + // caught expected exception + } + } + + +} diff --git a/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/GeneratedPackagesTestCase.java b/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/GeneratedPackagesTestCase.java new file mode 100644 index 0000000000..3e6267623c --- /dev/null +++ b/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/GeneratedPackagesTestCase.java @@ -0,0 +1,76 @@ +/* + * 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.util.Iterator; +import java.util.List; + +import org.apache.tuscany.sdo.generate.XSD2JavaGenerator; + +import junit.framework.TestCase; + + +public class GeneratedPackagesTestCase extends TestCase +{ + static String expectedNamespace = "http://www.example.com/sequences"; + + public void testPackageValidity() + { + XSD2JavaGenerator codeGen = new XSD2JavaGenerator(); + String [] genArgs = { "-schemaNamespace", "all", "-noGenerate", "src/test/resources/sequences.xsd" }; + codeGen.generateFromXMLSchema( genArgs ); + List packages = codeGen.getGeneratedPackageInfo(); + + for (Iterator iter = packages.iterator(); iter.hasNext();) + { + XSD2JavaGenerator.GeneratedPackage packageInfo = (XSD2JavaGenerator.GeneratedPackage)iter.next(); + assertTrue(expectedNamespace.equals(packageInfo.getNamespace())); + + String name; + boolean validatedDocRoot = false; + boolean validatedMixedQuote = false; + boolean validatedSymbol = false; + for (Iterator iterClass = packageInfo.getClasses().iterator(); iterClass.hasNext();) + { + XSD2JavaGenerator.GeneratedPackage.PackageClassInfo classInfo = (XSD2JavaGenerator.GeneratedPackage.PackageClassInfo)iterClass.next(); + name = classInfo.getName(); + + if( "MixedQuote".equals(name)) + { + assertTrue("com.example.sequences.MixedQuote".equals(classInfo.getClassName())); + validatedMixedQuote = true; + } + if( "".equals(name)) + { + assertTrue("com.example.sequences.DocumentRoot".equals(classInfo.getClassName())); + validatedDocRoot = true; + } + if( "symbol".equals(name)) + { + assertTrue("java.lang.String".equals(classInfo.getClassName())); + validatedSymbol = true; + } + } + assertTrue(validatedMixedQuote); + assertTrue(validatedDocRoot); + assertTrue(validatedSymbol); + } + } +} diff --git a/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/InheritanceTestCase.java b/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/InheritanceTestCase.java new file mode 100644 index 0000000000..a971f79f0f --- /dev/null +++ b/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/InheritanceTestCase.java @@ -0,0 +1,102 @@ +/** + * + * 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 junit.framework.TestCase; + +import org.apache.tuscany.sdo.util.SDOUtil; + +import com.example.subgroup.A; +import com.example.subgroup.B; +import com.example.subgroup.Bprime; +import com.example.subgroup.SubgroupFactory; +import com.example.subgroup.impl.AImpl; +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; + +public class InheritanceTestCase extends TestCase { + + private HelperContext scope; + + public void testSubGroupLoad() throws IOException { + XMLDocument doc = scope.getXMLHelper().load( + getClass().getResourceAsStream("/subgroup1.xml")); + assertEquals("a", doc.getRootElementName()); + String strdoc = scope.getXMLHelper().save( + doc.getRootObject(), doc.getRootElementURI(), doc.getRootElementName()); + assertTrue(strdoc.indexOf("thisIsElB") != -1); + } + + public void testSubGroup_AcontainsB() { + A a = (A) scope.getDataFactory().create(A.class); + B b = (B) scope.getDataFactory().create(B.class); + b.setImInTypeB("thisIsElB"); + a.setGe1(b); + + assertSame(b, a.getGe1()); + assertSame(b, ((AImpl) a).get(AImpl.GE1)); + + String doc = scope.getXMLHelper().save((DataObject) a, + "http://example.com/subgroup", "a"); + assertTrue(doc.indexOf("thisIsElB") != -1); + + } + + public void testSubGroup_AcontainsBprime() { + A a = (A) scope.getDataFactory().create(A.class); + Bprime bp = (Bprime) scope.getDataFactory().create(Bprime.class); + bp.setImInTypeBprime("thisIsElBprime"); + a.setGe1(bp); + + assertSame(bp, a.getGe1()); + assertSame(bp, ((AImpl) a).get(AImpl.GE1)); + + String doc = scope.getXMLHelper().save((DataObject) a, + "http://example.com/subgroup", "a"); + + assertTrue(doc.indexOf("thisIsElBprime") != -1); + + } + + public void testSubGroup_Bprime() { + Bprime bp = (Bprime) scope.getDataFactory().create(Bprime.class); + bp.setImInTypeB("bValue"); + bp.setImInTypeBprime("bpvalue"); + String doc = scope.getXMLHelper().save((DataObject) bp, + "http://example.com/subgroup", "bp"); + assertTrue(doc.indexOf("bValue") != -1); + assertTrue(doc.indexOf("bpvalue") != -1); + } + + protected void setUp() throws Exception { + super.setUp(); + scope = SDOUtil.createHelperContext(); + + SubgroupFactory.INSTANCE.register(scope); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/OpenContentTestCase.java b/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/OpenContentTestCase.java new file mode 100644 index 0000000000..f2b1bb08b8 --- /dev/null +++ b/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/OpenContentTestCase.java @@ -0,0 +1,75 @@ +/** + * + * 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 junit.framework.TestCase; + +import org.apache.tuscany.sdo.util.SDOUtil; + +import com.example.open.OneElementAndAnyAttr; +import com.example.open.OpenFactory; +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Sequence; +import commonj.sdo.helper.HelperContext; + + +public class OpenContentTestCase extends TestCase +{ + + HelperContext scope; + + public void testAnyAttribute() throws IOException + { + + OpenFactory.INSTANCE.register(scope); + DataObject dob = scope.getDataFactory().create(OneElementAndAnyAttr.class); + OneElementAndAnyAttr staticDob = (OneElementAndAnyAttr)dob; + + staticDob.setName("fred"); + + assertEquals(1, dob.getInstanceProperties().size()); + Sequence s = ((OneElementAndAnyAttr)dob).getAnyAttribute(); + + assertFalse(dob.getType().isSequenced()); + assertTrue(dob.getType().isOpen()); + assertNull(dob.getSequence()); + + Property prop = scope.getTypeHelper().getOpenContentProperty("http://www.example.com/open", "globAttribute"); + s.add(prop, "foo"); + assertEquals(2, dob.getInstanceProperties().size()); + assertTrue(dob.getInstanceProperties().contains(prop)); + + // scope.getXMLHelper().save((DataObject)dob, "http://www.example.com/open", "bar", System.out); + } + + protected void setUp() throws Exception { + scope = SDOUtil.createHelperContext(); + super.setUp(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + +} diff --git a/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/SimpleStaticTestCase.java b/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/SimpleStaticTestCase.java new file mode 100644 index 0000000000..207ccd4484 --- /dev/null +++ b/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/SimpleStaticTestCase.java @@ -0,0 +1,86 @@ +/** + * + * 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.math.BigDecimal; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.util.SDOUtil; + +import com.example.simple.Quote; +import com.example.simple.SimpleFactory; +import com.example.simple.impl.SimpleFactoryImpl; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLHelper; + + +public class SimpleStaticTestCase extends TestCase +{ + + HelperContext scope; + /** + * Simple Static SDO 2 test. + */ + public void testSimpleStatic() + { + try + { + SimpleFactory.INSTANCE.register(scope); + // System.out.println(SimpleFactoryImpl.PATTERN_VERSION); + + //Quote quote = (Quote)DataFactory.INSTANCE.create(Quote.class); + Quote quote = SimpleFactory.INSTANCE.createQuote(); + + quote.setSymbol("fbnt"); + quote.setCompanyName("FlyByNightTechnology"); + quote.setPrice(new BigDecimal("1000.0")); + quote.setOpen1(new BigDecimal("1000.0")); + quote.setHigh(new BigDecimal("1000.0")); + quote.setLow(new BigDecimal("1000.0")); + quote.setVolume(1000); + quote.setChange1(1000); + + //Quote child = (Quote)((DataObject)quote).createDataObject(8); + Quote child = SimpleFactory.INSTANCE.createQuote(); + quote.getQuotes().add(child); + child.setPrice(new BigDecimal("2000.0")); + + // scope.getXMLHelper().save((DataObject)quote, "http://www.example.com/simple", "stockQuote", System.out); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + protected void setUp() throws Exception { + scope = SDOUtil.createHelperContext(); + super.setUp(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + +} diff --git a/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/TestUtil.java b/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/TestUtil.java new file mode 100644 index 0000000000..0ca49b6122 --- /dev/null +++ b/sdo-java/branches/sdo-1.0-incubating/tools/src/test/java/org/apache/tuscany/sdo/test/TestUtil.java @@ -0,0 +1,288 @@ +/** + * + * 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.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; + +public class TestUtil +{ + private static void getAllNodes(NodeList nodeList, List nodes) + { + int length = nodeList.getLength(); + if (length == 0) + { + return; + } + + for (int i=0; i