From 9833a542bb75c2008c71809e4fdfebc41e67fb46 Mon Sep 17 00:00:00 2001 From: lresende Date: Tue, 10 Nov 2009 19:18:51 +0000 Subject: Move the SDO folder as new trunk for SDO sub project git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@834610 13f79535-47bb-0310-9956-ffa450edef68 --- sdo-java/trunk/tools-test/pom.xml | 264 +++++++++++++++++++++ .../src/main/resources/CustomerAccount.xsd | 41 ++++ .../src/main/resources/InternalInElement.xsd | 31 +++ .../trunk/tools-test/src/main/resources/Open.xsd | 33 +++ .../src/main/resources/extensible/customer.xsd | 47 ++++ .../src/main/resources/extensible/customers.xml | 39 +++ .../src/main/resources/extensible/infostreet.xml | 24 ++ .../src/main/resources/extensible/infostreet.xsd | 36 +++ .../src/main/resources/extensible/infozipcode.xml | 24 ++ .../src/main/resources/extensible/infozipcode.xsd | 36 +++ .../src/main/resources/extensible/nonamespace.xsd | 25 ++ .../tools-test/src/main/resources/listAccess.xsd | 53 +++++ .../src/main/resources/mixedTypesStatic.xsd | 41 ++++ .../trunk/tools-test/src/main/resources/simple.xsd | 41 ++++ .../tools-test/src/main/resources/simpleNoIF.xsd | 41 ++++ .../tools-test/src/main/resources/simpleNoTns.xsd | 37 +++ .../src/main/resources/simpleWithChangeSummary.xsd | 49 ++++ .../tools-test/src/main/resources/subgroup.xsd | 48 ++++ .../tools-test/src/main/resources/subgroup1.xml | 23 ++ .../resources/substitutionWithExtensionValues.xsd | 105 ++++++++ .../resources/substitutionWithExtensionValues1.xml | 48 ++++ .../resources/substitutionWithExtensionValues2.xsd | 62 +++++ .../src/main/resources/xsdImportOnly.wsdl | 55 +++++ .../src/main/resources/xsdImportOnly_1.xsd | 37 +++ .../tools-test/src/main/resources/xsdlistitem.xsd | 50 ++++ .../java/org/apache/tuscany/sdo/test/AllTests.java | 57 +++++ .../tuscany/sdo/test/ChangeSummaryGenTestCase.java | 131 ++++++++++ .../sdo/test/DataObjectGetListTestCase.java | 99 ++++++++ .../tuscany/sdo/test/ExtensibleTestCase.java | 96 ++++++++ .../tuscany/sdo/test/GenPatternsTestCase.java | 115 +++++++++ .../tuscany/sdo/test/InheritanceTestCase.java | 102 ++++++++ .../sdo/test/InternalInElementTestCase.java | 63 +++++ .../tuscany/sdo/test/ListWithDefaultTestCase.java | 53 +++++ .../tuscany/sdo/test/MixedTypesTestCase.java | 86 +++++++ .../tuscany/sdo/test/OpenContentTestCase.java | 75 ++++++ .../tuscany/sdo/test/SimpleStaticTestCase.java | 110 +++++++++ .../SubstitutionWithExtensionValuesTestCase.java | 155 ++++++++++++ .../src/test/resources/mixedTypesDynamic.xsd | 50 ++++ .../tools-test/src/test/resources/stockquote.xml | 32 +++ 39 files changed, 2514 insertions(+) create mode 100644 sdo-java/trunk/tools-test/pom.xml create mode 100644 sdo-java/trunk/tools-test/src/main/resources/CustomerAccount.xsd create mode 100644 sdo-java/trunk/tools-test/src/main/resources/InternalInElement.xsd create mode 100644 sdo-java/trunk/tools-test/src/main/resources/Open.xsd create mode 100644 sdo-java/trunk/tools-test/src/main/resources/extensible/customer.xsd create mode 100644 sdo-java/trunk/tools-test/src/main/resources/extensible/customers.xml create mode 100644 sdo-java/trunk/tools-test/src/main/resources/extensible/infostreet.xml create mode 100644 sdo-java/trunk/tools-test/src/main/resources/extensible/infostreet.xsd create mode 100644 sdo-java/trunk/tools-test/src/main/resources/extensible/infozipcode.xml create mode 100644 sdo-java/trunk/tools-test/src/main/resources/extensible/infozipcode.xsd create mode 100644 sdo-java/trunk/tools-test/src/main/resources/extensible/nonamespace.xsd create mode 100644 sdo-java/trunk/tools-test/src/main/resources/listAccess.xsd create mode 100644 sdo-java/trunk/tools-test/src/main/resources/mixedTypesStatic.xsd create mode 100644 sdo-java/trunk/tools-test/src/main/resources/simple.xsd create mode 100644 sdo-java/trunk/tools-test/src/main/resources/simpleNoIF.xsd create mode 100644 sdo-java/trunk/tools-test/src/main/resources/simpleNoTns.xsd create mode 100644 sdo-java/trunk/tools-test/src/main/resources/simpleWithChangeSummary.xsd create mode 100644 sdo-java/trunk/tools-test/src/main/resources/subgroup.xsd create mode 100644 sdo-java/trunk/tools-test/src/main/resources/subgroup1.xml create mode 100644 sdo-java/trunk/tools-test/src/main/resources/substitutionWithExtensionValues.xsd create mode 100644 sdo-java/trunk/tools-test/src/main/resources/substitutionWithExtensionValues1.xml create mode 100644 sdo-java/trunk/tools-test/src/main/resources/substitutionWithExtensionValues2.xsd create mode 100644 sdo-java/trunk/tools-test/src/main/resources/xsdImportOnly.wsdl create mode 100644 sdo-java/trunk/tools-test/src/main/resources/xsdImportOnly_1.xsd create mode 100644 sdo-java/trunk/tools-test/src/main/resources/xsdlistitem.xsd create mode 100644 sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/AllTests.java create mode 100644 sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/ChangeSummaryGenTestCase.java create mode 100644 sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/DataObjectGetListTestCase.java create mode 100644 sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/ExtensibleTestCase.java create mode 100644 sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/GenPatternsTestCase.java create mode 100644 sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/InheritanceTestCase.java create mode 100644 sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/InternalInElementTestCase.java create mode 100644 sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/ListWithDefaultTestCase.java create mode 100644 sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/MixedTypesTestCase.java create mode 100644 sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/OpenContentTestCase.java create mode 100644 sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/SimpleStaticTestCase.java create mode 100644 sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/SubstitutionWithExtensionValuesTestCase.java create mode 100644 sdo-java/trunk/tools-test/src/test/resources/mixedTypesDynamic.xsd create mode 100644 sdo-java/trunk/tools-test/src/test/resources/stockquote.xml (limited to 'sdo-java/trunk/tools-test') diff --git a/sdo-java/trunk/tools-test/pom.xml b/sdo-java/trunk/tools-test/pom.xml new file mode 100644 index 0000000000..999e3c91e5 --- /dev/null +++ b/sdo-java/trunk/tools-test/pom.xml @@ -0,0 +1,264 @@ + + + + + tuscany-sdo + org.apache.tuscany.sdo + 1.2-SNAPSHOT + + 4.0.0 + org.apache.tuscany.sdo + tuscany-sdo-tools-test + 1.2-SNAPSHOT + Test the SDO Generator Tools and Tool Outputs + + + + org.apache.tuscany.sdo + tuscany-sdo-impl + ${sdo.version} + + + org.apache.tuscany.sdo + tuscany-sdo-lib + ${sdo.version} + + + org.apache.tuscany.sdo + tuscany-sdo-tools + ${sdo.version} + + + junit + junit + 4.3.1 + test + + + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.0 + + + add-test-source + generate-sources + + add-test-source + + + + target/sdo-source + + + + + + + org.apache.tuscany.sdo + tuscany-sdo-plugin + ${sdo.version} + + + simple + + + ${basedir}/src/main/resources/simple.xsd + + + + generate + + + + simpleWithChangeSummary + + + ${basedir}/src/main/resources/simpleWithChangeSummary.xsd + + CS + + + generate + + + + xsdListItem + + + ${basedir}/src/main/resources/xsdlistitem.xsd + + LI + + + generate + + + + simpleNoInterfaces + + + ${basedir}/src/main/resources/simpleNoIF.xsd + + + com.example.noInterfaces.simple + + true + + + generate + + + + customer + + + ${basedir}/src/main/resources/CustomerAccount.xsd + + Customer + + + generate + + + + extensible + + + ${basedir}/src/main/resources/extensible/customer.xsd + + + + generate + + + + extensible_infostreet + + + ${basedir}/src/main/resources/extensible/infostreet.xsd + + + + generate + + + + subgroup + + + ${basedir}/src/main/resources/subgroup.xsd + + + + generate + + + + openContent + + + ${basedir}/src/main/resources/Open.xsd + + + + generate + + + + MixedTypesStaticPart + + + ${basedir}/src/main/resources/mixedTypesStatic.xsd + + + + generate + + + + SimpleNoTns + + + ${basedir}/src/main/resources/simpleNoTns.xsd + + + + generate + + + + XSDImportOnly + + + ${basedir}/src/main/resources/xsdImportOnly.wsdl + + all + + + generate + + + + listAccess + + + ${basedir}/src/main/resources/listAccess.xsd + + + + generate + + + + SubstitutionWithExtensionValues + + + ${basedir}/src/main/resources/substitutionWithExtensionValues.xsd + + SEV + + + generate + + + + InternalInElement + + + ${basedir}/src/main/resources/InternalInElement.xsd + + + + generate + + + + + + + + + diff --git a/sdo-java/trunk/tools-test/src/main/resources/CustomerAccount.xsd b/sdo-java/trunk/tools-test/src/main/resources/CustomerAccount.xsd new file mode 100644 index 0000000000..a720670e3b --- /dev/null +++ b/sdo-java/trunk/tools-test/src/main/resources/CustomerAccount.xsd @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/sdo-java/trunk/tools-test/src/main/resources/InternalInElement.xsd b/sdo-java/trunk/tools-test/src/main/resources/InternalInElement.xsd new file mode 100644 index 0000000000..6144b1e117 --- /dev/null +++ b/sdo-java/trunk/tools-test/src/main/resources/InternalInElement.xsd @@ -0,0 +1,31 @@ + + + + + + + + + + + + diff --git a/sdo-java/trunk/tools-test/src/main/resources/Open.xsd b/sdo-java/trunk/tools-test/src/main/resources/Open.xsd new file mode 100644 index 0000000000..0f158e591a --- /dev/null +++ b/sdo-java/trunk/tools-test/src/main/resources/Open.xsd @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + diff --git a/sdo-java/trunk/tools-test/src/main/resources/extensible/customer.xsd b/sdo-java/trunk/tools-test/src/main/resources/extensible/customer.xsd new file mode 100644 index 0000000000..1a0531e040 --- /dev/null +++ b/sdo-java/trunk/tools-test/src/main/resources/extensible/customer.xsd @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sdo-java/trunk/tools-test/src/main/resources/extensible/customers.xml b/sdo-java/trunk/tools-test/src/main/resources/extensible/customers.xml new file mode 100644 index 0000000000..40558f6cf8 --- /dev/null +++ b/sdo-java/trunk/tools-test/src/main/resources/extensible/customers.xml @@ -0,0 +1,39 @@ + + + + + Pat Walmsley + + 21043 + + 15465 + + + Priscilla Walmsley + 15466 + + 341 Duckworth Way + + + diff --git a/sdo-java/trunk/tools-test/src/main/resources/extensible/infostreet.xml b/sdo-java/trunk/tools-test/src/main/resources/extensible/infostreet.xml new file mode 100644 index 0000000000..c57b0b98c1 --- /dev/null +++ b/sdo-java/trunk/tools-test/src/main/resources/extensible/infostreet.xml @@ -0,0 +1,24 @@ + + + + 21043 Jones Way + diff --git a/sdo-java/trunk/tools-test/src/main/resources/extensible/infostreet.xsd b/sdo-java/trunk/tools-test/src/main/resources/extensible/infostreet.xsd new file mode 100644 index 0000000000..4b71628c89 --- /dev/null +++ b/sdo-java/trunk/tools-test/src/main/resources/extensible/infostreet.xsd @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + diff --git a/sdo-java/trunk/tools-test/src/main/resources/extensible/infozipcode.xml b/sdo-java/trunk/tools-test/src/main/resources/extensible/infozipcode.xml new file mode 100644 index 0000000000..a5f551908a --- /dev/null +++ b/sdo-java/trunk/tools-test/src/main/resources/extensible/infozipcode.xml @@ -0,0 +1,24 @@ + + + + 21043 + diff --git a/sdo-java/trunk/tools-test/src/main/resources/extensible/infozipcode.xsd b/sdo-java/trunk/tools-test/src/main/resources/extensible/infozipcode.xsd new file mode 100644 index 0000000000..cd1c55c138 --- /dev/null +++ b/sdo-java/trunk/tools-test/src/main/resources/extensible/infozipcode.xsd @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + diff --git a/sdo-java/trunk/tools-test/src/main/resources/extensible/nonamespace.xsd b/sdo-java/trunk/tools-test/src/main/resources/extensible/nonamespace.xsd new file mode 100644 index 0000000000..b551c8aae2 --- /dev/null +++ b/sdo-java/trunk/tools-test/src/main/resources/extensible/nonamespace.xsd @@ -0,0 +1,25 @@ + + + + + + diff --git a/sdo-java/trunk/tools-test/src/main/resources/listAccess.xsd b/sdo-java/trunk/tools-test/src/main/resources/listAccess.xsd new file mode 100644 index 0000000000..917ce78f8a --- /dev/null +++ b/sdo-java/trunk/tools-test/src/main/resources/listAccess.xsd @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sdo-java/trunk/tools-test/src/main/resources/mixedTypesStatic.xsd b/sdo-java/trunk/tools-test/src/main/resources/mixedTypesStatic.xsd new file mode 100644 index 0000000000..436c1ec9a4 --- /dev/null +++ b/sdo-java/trunk/tools-test/src/main/resources/mixedTypesStatic.xsd @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/sdo-java/trunk/tools-test/src/main/resources/simple.xsd b/sdo-java/trunk/tools-test/src/main/resources/simple.xsd new file mode 100644 index 0000000000..aff9f9c5bf --- /dev/null +++ b/sdo-java/trunk/tools-test/src/main/resources/simple.xsd @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/sdo-java/trunk/tools-test/src/main/resources/simpleNoIF.xsd b/sdo-java/trunk/tools-test/src/main/resources/simpleNoIF.xsd new file mode 100644 index 0000000000..aff9f9c5bf --- /dev/null +++ b/sdo-java/trunk/tools-test/src/main/resources/simpleNoIF.xsd @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/sdo-java/trunk/tools-test/src/main/resources/simpleNoTns.xsd b/sdo-java/trunk/tools-test/src/main/resources/simpleNoTns.xsd new file mode 100644 index 0000000000..4702f57251 --- /dev/null +++ b/sdo-java/trunk/tools-test/src/main/resources/simpleNoTns.xsd @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + diff --git a/sdo-java/trunk/tools-test/src/main/resources/simpleWithChangeSummary.xsd b/sdo-java/trunk/tools-test/src/main/resources/simpleWithChangeSummary.xsd new file mode 100644 index 0000000000..c81e10ee00 --- /dev/null +++ b/sdo-java/trunk/tools-test/src/main/resources/simpleWithChangeSummary.xsd @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sdo-java/trunk/tools-test/src/main/resources/subgroup.xsd b/sdo-java/trunk/tools-test/src/main/resources/subgroup.xsd new file mode 100644 index 0000000000..61e0642dfa --- /dev/null +++ b/sdo-java/trunk/tools-test/src/main/resources/subgroup.xsd @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sdo-java/trunk/tools-test/src/main/resources/subgroup1.xml b/sdo-java/trunk/tools-test/src/main/resources/subgroup1.xml new file mode 100644 index 0000000000..007aef9aa3 --- /dev/null +++ b/sdo-java/trunk/tools-test/src/main/resources/subgroup1.xml @@ -0,0 +1,23 @@ + + + + thisIsElB + + diff --git a/sdo-java/trunk/tools-test/src/main/resources/substitutionWithExtensionValues.xsd b/sdo-java/trunk/tools-test/src/main/resources/substitutionWithExtensionValues.xsd new file mode 100644 index 0000000000..72474a62eb --- /dev/null +++ b/sdo-java/trunk/tools-test/src/main/resources/substitutionWithExtensionValues.xsd @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sdo-java/trunk/tools-test/src/main/resources/substitutionWithExtensionValues1.xml b/sdo-java/trunk/tools-test/src/main/resources/substitutionWithExtensionValues1.xml new file mode 100644 index 0000000000..45c592a333 --- /dev/null +++ b/sdo-java/trunk/tools-test/src/main/resources/substitutionWithExtensionValues1.xml @@ -0,0 +1,48 @@ + + + + ZZZZZZZZZZZZZZZZZZZZ + + 00000000000000000000 + + 11111111111111111111 + name1 + 1 + + + 22222222222222222222 + myName2 + 2 + + comment0 + + + AAAAAAAAAAAAAAAAAAAA + + BBBBBBBBBBBBBBBBBBBB + myNameB + 11 + + commentA + + + commentZZZZZZZZZZZZZZZZZZ + + diff --git a/sdo-java/trunk/tools-test/src/main/resources/substitutionWithExtensionValues2.xsd b/sdo-java/trunk/tools-test/src/main/resources/substitutionWithExtensionValues2.xsd new file mode 100644 index 0000000000..769cce4f65 --- /dev/null +++ b/sdo-java/trunk/tools-test/src/main/resources/substitutionWithExtensionValues2.xsd @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sdo-java/trunk/tools-test/src/main/resources/xsdImportOnly.wsdl b/sdo-java/trunk/tools-test/src/main/resources/xsdImportOnly.wsdl new file mode 100644 index 0000000000..576997a0a4 --- /dev/null +++ b/sdo-java/trunk/tools-test/src/main/resources/xsdImportOnly.wsdl @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sdo-java/trunk/tools-test/src/main/resources/xsdImportOnly_1.xsd b/sdo-java/trunk/tools-test/src/main/resources/xsdImportOnly_1.xsd new file mode 100644 index 0000000000..a62c26d948 --- /dev/null +++ b/sdo-java/trunk/tools-test/src/main/resources/xsdImportOnly_1.xsd @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sdo-java/trunk/tools-test/src/main/resources/xsdlistitem.xsd b/sdo-java/trunk/tools-test/src/main/resources/xsdlistitem.xsd new file mode 100644 index 0000000000..e416efaa25 --- /dev/null +++ b/sdo-java/trunk/tools-test/src/main/resources/xsdlistitem.xsd @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/AllTests.java b/sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/AllTests.java new file mode 100644 index 0000000000..7c10cb2c62 --- /dev/null +++ b/sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/AllTests.java @@ -0,0 +1,57 @@ +/** + * + * 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(MixedTypesTestCase.class); + suite.addTestSuite(DataObjectGetListTestCase.class); + suite.addTestSuite(ListWithDefaultTestCase.class); + suite.addTestSuite(SubstitutionWithExtensionValuesTestCase.class); + suite.addTestSuite(InternalInElementTestCase.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/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/ChangeSummaryGenTestCase.java b/sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/ChangeSummaryGenTestCase.java new file mode 100644 index 0000000000..37759458b9 --- /dev/null +++ b/sdo-java/trunk/tools-test/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 testChangeSummaryOnDataGraphWithIntAndFloat() 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/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/DataObjectGetListTestCase.java b/sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/DataObjectGetListTestCase.java new file mode 100644 index 0000000000..b6650cade3 --- /dev/null +++ b/sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/DataObjectGetListTestCase.java @@ -0,0 +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.IOException; +import java.util.List; + +import org.apache.tuscany.sdo.api.SDOUtil; + +import com.example.get.list.ListFactory; + +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"; + + + /** + * 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(); + ListFactory.INSTANCE.register(hc); + + 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"); + } +} diff --git a/sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/ExtensibleTestCase.java b/sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/ExtensibleTestCase.java new file mode 100644 index 0000000000..c9cc384beb --- /dev/null +++ b/sdo-java/trunk/tools-test/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/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/GenPatternsTestCase.java b/sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/GenPatternsTestCase.java new file mode 100644 index 0000000000..e63697738e --- /dev/null +++ b/sdo-java/trunk/tools-test/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.api.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/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/InheritanceTestCase.java b/sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/InheritanceTestCase.java new file mode 100644 index 0000000000..0b291b3365 --- /dev/null +++ b/sdo-java/trunk/tools-test/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.api.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/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/InternalInElementTestCase.java b/sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/InternalInElementTestCase.java new file mode 100644 index 0000000000..dfa4b02221 --- /dev/null +++ b/sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/InternalInElementTestCase.java @@ -0,0 +1,63 @@ +/** + * + * 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.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.api.SDOUtil; +import org.apache.tuscany.sdo.generate.XSD2JavaGenerator; + +import com.example.internal.InternalFactory; +import com.example.internal.Wrapper; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; + +public class InternalInElementTestCase extends TestCase { + HelperContext scope; + + /*TUSCANy-1483 check correct code generation for internalAbc */ + public void testPackageValidityWithInternalInElement() throws Exception { + //if dob is instantiated, it proves that the code got generated without any duplicates + //without the fix, + //public final static int INTERNAL_ABC = 1; + //public final static int INTERNAL_ABC = 0; + //was getting generated and so invalid java class WrapperImpl.java. + InternalFactory.INSTANCE.register(scope); + DataObject dob = scope.getDataFactory().create(Wrapper.class); + + assertTrue(true); + } + + protected void setUp() throws Exception { + super.setUp(); + scope = SDOUtil.createHelperContext(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/ListWithDefaultTestCase.java b/sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/ListWithDefaultTestCase.java new file mode 100644 index 0000000000..59799bf23e --- /dev/null +++ b/sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/ListWithDefaultTestCase.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 java.util.List; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.api.SDOUtil; +import org.example.address.with.list.LIFactory; +import org.example.address.with.list.SubCategoryType; + +import commonj.sdo.helper.HelperContext; + +public class ListWithDefaultTestCase extends TestCase { + HelperContext scope = null; + + public void testListWithDefault() { + SubCategoryType sct = (SubCategoryType)scope.getDataFactory().create(SubCategoryType.class); + List l = sct.getCategoryType(); + assertTrue(l.size() == 1); + assertEquals((String)l.get(0), "myCat"); + } + + + protected void setUp() throws Exception { + super.setUp(); + scope = SDOUtil.createHelperContext(); + + LIFactory.INSTANCE.register(scope); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } +} diff --git a/sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/MixedTypesTestCase.java b/sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/MixedTypesTestCase.java new file mode 100644 index 0000000000..e716076366 --- /dev/null +++ b/sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/MixedTypesTestCase.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.io.InputStream; +import java.net.URL; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.api.SDOUtil; + +import com.example.mixedtypes.statictypes.StatictypesFactory; +import com.example.mixedtypes.statictypes.Address; +import com.example.mixedtypes.statictypes.Customer; +import commonj.sdo.DataObject; +import commonj.sdo.helper.DataFactory; +import commonj.sdo.helper.HelperContext; + +public class MixedTypesTestCase extends TestCase { + + private final String[] MODELS = new String[] { + "/mixedTypesDynamic.xsd" + }; + + private final String NS_DYNAMIC = "http://www.example.com/mixedtypes/dynamictypes"; + + private HelperContext scope; + + public void testSetDynamicToStatic() { + DataFactory factory = scope.getDataFactory(); + + DataObject staticCustomer = factory.create(Customer.class); + assertTrue("The account property type has to be abstract, pre condition to this test.", + staticCustomer.getInstanceProperty("account").getType().isAbstract()); + + DataObject dynamicSavingsAccount = factory.create(NS_DYNAMIC, "SavingsAccount"); + staticCustomer.set("account", dynamicSavingsAccount); + assertNotNull("The account property in the static customer has to be set", + ((Customer)staticCustomer).getAccount()); + } + + public void testSetStaticToDynamic() { + DataFactory factory = scope.getDataFactory(); + + DataObject dynamicSavingsAccount = factory.create(NS_DYNAMIC, "SavingsAccount"); + DataObject staticAddress = factory.create(Address.class); + + dynamicSavingsAccount.set("alternateAddress", staticAddress); + assertTrue("The address property on the dynamic account object has to be set", + dynamicSavingsAccount.isSet("alternateAddress")); + } + + protected void setUp() throws Exception { + super.setUp(); + scope = SDOUtil.createHelperContext(); + + StatictypesFactory.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/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/OpenContentTestCase.java b/sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/OpenContentTestCase.java new file mode 100644 index 0000000000..cff0c3ba85 --- /dev/null +++ b/sdo-java/trunk/tools-test/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.api.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/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/SimpleStaticTestCase.java b/sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/SimpleStaticTestCase.java new file mode 100644 index 0000000000..c085245f13 --- /dev/null +++ b/sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/SimpleStaticTestCase.java @@ -0,0 +1,110 @@ +/** + * + * 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.math.BigDecimal; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.dom.DOMSource; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.api.SDOUtil; + +import com.example.simple.Quote; +import com.example.simple.SimpleFactory; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.impl.HelperProvider; + + +public class SimpleStaticTestCase extends TestCase +{ + + HelperContext scope; + /** + * Simple Static SDO 2 test. + */ + public void testSimpleStatic() + { + try + { + 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(); + } + } + + public void testSimpleStaticViaDomSource() throws Exception { + // created for TUSCANY-2080 + + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + + DocumentBuilder builder = factory.newDocumentBuilder(); + + java.net.URL url = getClass().getResource("/stockquote.xml"); + InputStream inputStream = url.openStream(); + org.w3c.dom.Document dom = builder.parse(inputStream); + + // Now load from dom to object + DOMSource source = new DOMSource(dom); + + XMLDocument xml = scope.getXMLHelper().load(source, null, null); + assertTrue("Root element is not an instance of the generated class", xml + .getRootObject() instanceof Quote); + + } + + protected void setUp() throws Exception { + scope = SDOUtil.createHelperContext(); + SimpleFactory.INSTANCE.register(scope); + + super.setUp(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + +} diff --git a/sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/SubstitutionWithExtensionValuesTestCase.java b/sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/SubstitutionWithExtensionValuesTestCase.java new file mode 100644 index 0000000000..92cef546a6 --- /dev/null +++ b/sdo-java/trunk/tools-test/src/test/java/org/apache/tuscany/sdo/test/SubstitutionWithExtensionValuesTestCase.java @@ -0,0 +1,155 @@ +/** + * + * 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.net.URL; +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.api.SDOUtil; +import org.eclipse.emf.ecore.EDataType; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.util.ExtendedMetaData; + +import com.example.substitution.ev.SEVFactory; +import com.example.substitution.ev.impl.SEVFactoryImpl; +import commonj.sdo.DataGraph; +import commonj.sdo.DataObject; +import commonj.sdo.Type; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.impl.HelperProvider; + +public final class SubstitutionWithExtensionValuesTestCase extends TestCase +{ + private static String sev2NamespaceURI; + private HelperContext hc; + private DataObject dataObject; + + protected void setUp() throws Exception { + super.setUp(); + hc = HelperProvider.getDefaultContext(); + registerSEV(hc, true); + + InputStream inputStream = null; + URL url = getClass().getResource("/substitutionWithExtensionValues2.xsd"); + inputStream = url.openStream(); + List sev2TypeList = hc.getXSDHelper().define(inputStream, url.toString()); + inputStream.close(); + + inputStream = getClass().getResourceAsStream("/substitutionWithExtensionValues1.xml"); + dataObject = hc.getXMLHelper().load(inputStream).getRootObject(); + inputStream.close(); + + if (sev2NamespaceURI == null) + { + sev2NamespaceURI = ((Type) sev2TypeList.get(0)).getURI(); + } + } + + private void registerSEV(HelperContext hc, boolean useStaticRegistration) throws IOException + { + if (useStaticRegistration) + { + SEVFactory.INSTANCE.register(hc); + } + else + { + InputStream inputStream = null; + URL url = getClass().getResource("/substitutionWithExtensionValues.xsd"); + inputStream = url.openStream(); + hc.getXSDHelper().define(inputStream, url.toString()); + inputStream.close(); + } + } + + public void testComplexTypeWithSubstitutionExtension() throws IOException + { + TypeHelper typeHelper = hc.getTypeHelper(); + + Type resultsType = typeHelper.getType(SEVFactoryImpl.NAMESPACE_URI, "ResultsType"); + Type results2Type = typeHelper.getType(sev2NamespaceURI, "Results2Type"); + assertTrue("Results2 type does not report Results as a base type", + results2Type.getBaseTypes().contains(resultsType)); + + assertEquals("results.1/myResult.0/id has unexpected value", + "BBBBBBBBBBBBBBBBBBBB", dataObject.getString("results.1/myResult.0/id")); + } + + public void testComplexTypeWithSimpleContentExtensionMetaData() + { + TypeHelper typeHelper = hc.getTypeHelper(); + + Type commentType = typeHelper.getType(SEVFactoryImpl.NAMESPACE_URI, "CommentType"); + Type myCommentType = typeHelper.getType(SEVFactoryImpl.NAMESPACE_URI, "MyCommentType"); + Type _myCommentType = typeHelper.getType(SEVFactoryImpl.NAMESPACE_URI, "_MyCommentType"); + Type comment2Type = typeHelper.getType(sev2NamespaceURI, "Comment2Type"); + Type _comment2Type = typeHelper.getType(sev2NamespaceURI, "_Comment2Type"); + assertTrue("MyComment type does not report Comment as a base type", + myCommentType.getBaseTypes().contains(commentType)); + assertTrue("Comment2 type does not report Comment as a base type", + comment2Type.getBaseTypes().contains(commentType)); + + // Test length facets - resort to EMF APIs until Tuscany SDO exposes these directly + ExtendedMetaData extendedMetaData = ExtendedMetaData.INSTANCE; + + EStructuralFeature simpleFeature = null; + EDataType commentSimpleType = null; + + // FIXME Work-around EMF's lack of support for re-definable features - SEE TUSCANY-1832 + commentSimpleType = (EDataType) _myCommentType; + assertEquals(40, extendedMetaData.getMaxLengthFacet(commentSimpleType)); + + // FIXME Work-around EMF's lack of support for re-definable features - SEE TUSCANY-1832 + commentSimpleType = (EDataType) _comment2Type; + assertEquals(20, extendedMetaData.getMaxLengthFacet(commentSimpleType)); + } + + public void testComplexTypeWithSimpleContentExtensionChangeSummary() throws IOException + { + DataGraph dg = SDOUtil.createDataGraph(); + SDOUtil.setRootObject(dg, dataObject); + dg.getChangeSummary().beginLogging(); + dataObject.getDataObject("results.1/myResult.0").delete(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + SDOUtil.saveDataGraph(dg, baos, null); + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + SDOUtil.loadDataGraph(bais, null, hc); + } + + public void testSimpleTypeExtension() + { + TypeHelper typeHelper = hc.getTypeHelper(); + + Type asciiStringType = typeHelper.getType(SEVFactoryImpl.NAMESPACE_URI, "AsciiStringType"); + Type idType = typeHelper.getType(SEVFactoryImpl.NAMESPACE_URI, "IdType"); + assertTrue("IdType does not report AsciiStringType as a base type", + idType.getBaseTypes().contains(asciiStringType)); + + Type id2Type = typeHelper.getType(sev2NamespaceURI, "Id2Type"); + assertTrue("Id2Type does not report IdType as a base type", + id2Type.getBaseTypes().contains(idType)); + } +} diff --git a/sdo-java/trunk/tools-test/src/test/resources/mixedTypesDynamic.xsd b/sdo-java/trunk/tools-test/src/test/resources/mixedTypesDynamic.xsd new file mode 100644 index 0000000000..25276792fc --- /dev/null +++ b/sdo-java/trunk/tools-test/src/test/resources/mixedTypesDynamic.xsd @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sdo-java/trunk/tools-test/src/test/resources/stockquote.xml b/sdo-java/trunk/tools-test/src/test/resources/stockquote.xml new file mode 100644 index 0000000000..526743868d --- /dev/null +++ b/sdo-java/trunk/tools-test/src/test/resources/stockquote.xml @@ -0,0 +1,32 @@ + + + + fbnt + FlyByNightTechnology + 1000.0 + 1000.0 + 1000.0 + 1000.0 + 1000.0 + 1000.0 + + 2000.0 + + \ No newline at end of file -- cgit v1.2.3