diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:56:01 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:56:01 +0000 |
commit | cf61fc6ced05607d9674781ebfc0c45fa1300124 (patch) | |
tree | 0aa8205859f8315055f820e13b7636765cd99a78 /sca-java-1.x/contrib/modules/implementation-data-xml/src/test/java | |
parent | 3a23c5a6a783a4b7330d9be300013919d4256ca4 (diff) |
Moving 1.x contribs
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835167 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-1.x/contrib/modules/implementation-data-xml/src/test/java')
5 files changed, 497 insertions, 0 deletions
diff --git a/sca-java-1.x/contrib/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/DATACollectionTestCaseFIXME.java b/sca-java-1.x/contrib/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/DATACollectionTestCaseFIXME.java new file mode 100644 index 0000000000..458025dd66 --- /dev/null +++ b/sca-java-1.x/contrib/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/DATACollectionTestCaseFIXME.java @@ -0,0 +1,118 @@ +/* + * 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.sca.implementation.data; + +import java.io.FileInputStream; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; +import junit.framework.TestCase; +import org.apache.tuscany.sca.databinding.xml.XMLStreamReader2String; +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.apache.tuscany.sca.implementation.data.DATACollection; + +public class DATACollectionTestCaseFIXME extends TestCase { + + private SCADomain scaDomain; + private DATACollection dataService; + + /** + * @throws java.lang.Exception + */ + @Override + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("data.composite"); + dataService = scaDomain.getService(DATACollection.class, "DataComponent/COMPANY"); + } + + /** + * @throws java.lang.Exception + */ + @Override + protected void tearDown() throws Exception { + scaDomain.close(); + } + + public void testInsert() throws Exception { + System.out.println(">testInsert"); + + //Read and process the XML file + FileInputStream fileInputStream = new FileInputStream("src/test/resources/insert.xml"); + XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(fileInputStream); + + String result = dataService.post(null, reader); + assertEquals(result, "2"); + + System.out.println("Number of rows inserted: " + result); + + reader.close(); + } + + public void testGet() throws Exception { + + System.out.println(">testGet"); + + XMLStreamReader reader = dataService.get(null); + assertNotNull(reader); + String xml = new XMLStreamReader2String().transform(reader, null); + System.out.println(xml); + reader.close(); + } + + public void testUpdate() throws Exception { + + System.out.println(">testUpdate"); + + //Read and process the XML file + FileInputStream fileInputStream = new FileInputStream("src/test/resources/update.xml"); + XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(fileInputStream); + + dataService.put(null,reader); + + reader.close(); + } + + public void testGetByID() throws Exception { + System.out.println(">testGetByID"); + + Integer companyID = new Integer(4); + + XMLStreamReader reader = dataService.get(companyID.toString()); + assertNotNull(reader); + String xml = new XMLStreamReader2String().transform(reader, null); + System.out.println(xml); + reader.close(); + } + + public void testDeleteByID() throws Exception { + System.out.println(">testDeleteByID"); + + Integer companyID = new Integer(4); + dataService.delete(companyID.toString()); + } + + public void testDelete() throws Exception { + System.out.println(">testDelete"); + + dataService.delete(null); + + System.out.println("recreating database..."); + //Helper.createDB(); + System.out.println("done!"); + } +} diff --git a/sca-java-1.x/contrib/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/DATAImplementationProcessorTestCase.java b/sca-java-1.x/contrib/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/DATAImplementationProcessorTestCase.java new file mode 100644 index 0000000000..dcf87d8c68 --- /dev/null +++ b/sca-java-1.x/contrib/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/DATAImplementationProcessorTestCase.java @@ -0,0 +1,133 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.implementation.data; + +import java.io.StringReader; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.data.engine.config.ConnectionInfo; +import org.apache.tuscany.sca.data.engine.config.ConnectionProperties; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; + +/** + * @version $Rev: 538445 $ $Date: 2007-05-15 23:20:37 -0700 (Tue, 15 May 2007) $ + */ +public class DATAImplementationProcessorTestCase extends TestCase { + + protected static final QName IMPLEMENTATION_DATA = new QName(Constants.SCA10_TUSCANY_NS, "implementation.data.xml"); + + private static final String COMPOSITE_USING_DATASOURCE = + "<?xml version=\"1.0\" encoding=\"ASCII\"?>" + + "<composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:tuscany=\"http://tuscany.apache.org/xmlns/sca/1.0\" targetNamespace=\"http://data\" name=\"data\">" + + " <component name=\"DataComponent\">" + + " <tuscany:implementation.data.xml>" + + " <tuscany:connectionInfo datasource=\"dataSource\"/>" + + " </tuscany:implementation.data.xml>" + + " </component>" + + "</composite>"; + + private static final String COMPOSITE_USING_CONNECTION_PROPERTIES = + "<?xml version=\"1.0\" encoding=\"ASCII\"?>" + + "<composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:tuscany=\"http://tuscany.apache.org/xmlns/sca/1.0\" targetNamespace=\"http://data\" name=\"data\">" + + " <component name=\"DataComponent\">" + + " <tuscany:implementation.data.xml>" + + " <tuscany:connectionInfo>" + + " <tuscany:connectionProperties" + + " driverClass=\"driverClass\"" + + " databaseURL=\"databaseURL\"" + + " loginTimeout=\"1\"/>" + + " </tuscany:connectionInfo>" + + " </tuscany:implementation.data.xml>" + + " </component>" + + "</composite>"; + + private XMLInputFactory inputFactory; + private StAXArtifactProcessor<Object> staxProcessor; + private CompositeBuilder compositeBuilder; + + @Override + protected void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + SCABindingFactory scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class); + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class); + IntentAttachPointTypeFactory attachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class); + compositeBuilder = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, attachPointTypeFactory, mapper, null); + } + + public void testLoadCompositeUsingDatasource() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE_USING_DATASOURCE)); + + Composite composite = (Composite)staxProcessor.read(reader); + DATAImplementation implementation = (DATAImplementation)composite.getComponents().get(0).getImplementation(); + assertNotNull(implementation); + + ConnectionInfo connInfo = implementation.getConnectionInfo(); + assertNotNull(connInfo); + assertEquals("dataSource", connInfo.getDataSource()); + + ConnectionProperties connProperties = connInfo.getConnectionProperties(); + assertNull(connProperties); + } + + public void testLoadCompositeUsingConnectionProperties() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE_USING_CONNECTION_PROPERTIES)); + + Composite composite = (Composite)staxProcessor.read(reader); + DATAImplementation implementation = (DATAImplementation)composite.getComponents().get(0).getImplementation(); + assertNotNull(implementation); + + ConnectionInfo connInfo = implementation.getConnectionInfo(); + assertNotNull(connInfo); + assertNull("dataSource", connInfo.getDataSource()); + + ConnectionProperties connProperties = connInfo.getConnectionProperties(); + assertNotNull(connProperties); + assertEquals("driverClass",connProperties.getDriverClass()); + assertEquals("databaseURL",connProperties.getDatabaseURL()); + assertEquals(1,connProperties.getLoginTimeout().intValue()); + } +} diff --git a/sca-java-1.x/contrib/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/DATATestCase.java b/sca-java-1.x/contrib/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/DATATestCase.java new file mode 100644 index 0000000000..4010cb63d3 --- /dev/null +++ b/sca-java-1.x/contrib/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/DATATestCase.java @@ -0,0 +1,133 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.implementation.data; + +import java.io.FileInputStream; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.databinding.xml.XMLStreamReader2String; +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.apache.tuscany.sca.implementation.data.DATA; + +/** + * Tests the DAS service + * + * @version $Rev$ $Date$ + */ +public class DATATestCase extends TestCase { + private SCADomain scaDomain; + private DATA dataService; + + /** + * @throws java.lang.Exception + */ + @Override + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("data.composite"); + dataService = scaDomain.getService(DATA.class, "DataComponent/COMPANY_DATA"); + } + + /** + * @throws java.lang.Exception + */ + @Override + protected void tearDown() throws Exception { + scaDomain.close(); + } + + public void testInsert() throws Exception { + System.out.println(">testInsert"); + + //Read and process the XML file + FileInputStream fileInputStream = new FileInputStream("src/test/resources/insert.xml"); + XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(fileInputStream); + + int result = dataService.insert(reader); + assertEquals(result,2); + + System.out.println("Number of rows inserted: "+result); + + reader.close(); + } + + public void testGet() throws Exception { + + System.out.println(">testGet"); + + XMLStreamReader reader = dataService.get(null); + assertNotNull(reader); + String xml = new XMLStreamReader2String().transform(reader, null); + System.out.println(xml); + reader.close(); + } + + public void testUpdate() throws Exception { + + System.out.println(">testUpdate"); + + //Read and process the XML file + FileInputStream fileInputStream = new FileInputStream("src/test/resources/update.xml"); + XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(fileInputStream); + + int result = dataService.update(reader); + assertEquals(result,1); + System.out.println("Number of rows affected: "+result); + + reader.close(); + } + + public void testGetByID() throws Exception { + System.out.println(">testGetByID"); + + Integer companyID = new Integer(4); + + XMLStreamReader reader = dataService.get(companyID.toString()); + assertNotNull(reader); + String xml = new XMLStreamReader2String().transform(reader, null); + System.out.println(xml); + reader.close(); + } + + public void testDeleteByID() throws Exception { + System.out.println(">testDeleteByID"); + + Integer companyID = new Integer(4); + int result = dataService.delete(companyID.toString()); + assertEquals(result,1); + System.out.println("Number of rows deleted: "+result); + } + + public void testDelete() throws Exception { + System.out.println(">testDelete"); + + int result = dataService.delete(null); + assertEquals(result,4); + System.out.println("Number of rows deleted: "+result); + + System.out.println("recreating database..."); + //Helper.createDB(); + System.out.println("done!"); + } + +} diff --git a/sca-java-1.x/contrib/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/companyFeed/CompanyFeed.java b/sca-java-1.x/contrib/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/companyFeed/CompanyFeed.java new file mode 100644 index 0000000000..7f0707c0bc --- /dev/null +++ b/sca-java-1.x/contrib/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/companyFeed/CompanyFeed.java @@ -0,0 +1,62 @@ +/*
+ * 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.sca.implementation.data.companyFeed;
+
+import org.apache.tuscany.sca.data.collection.Collection;
+import org.apache.tuscany.sca.data.collection.Entry;
+import org.apache.tuscany.sca.data.collection.NotFoundException;
+import org.apache.tuscany.sca.implementation.data.DATA;
+import org.osoa.sca.annotations.Reference;
+
+import commonj.sdo.DataObject;
+
+public class CompanyFeed implements Collection<String, DataObject> {
+
+ @Reference
+ protected DATA dataService;
+
+ public Entry<String, DataObject>[] getAll() {
+ return null;
+ }
+
+ public DataObject get(String id) throws NotFoundException{
+
+ DataObject data = null;//dataService.get(id);
+ if(data == null) {
+ throw new NotFoundException();
+ } else {
+ return data;
+ }
+ }
+
+ public void delete(String id) throws NotFoundException {
+ }
+
+ public String post(String key, DataObject item) {
+ return null;
+ }
+
+ public void put(String key, DataObject item) throws NotFoundException {
+ }
+
+ public Entry<String, DataObject>[] query(String queryString) {
+ return null;
+ }
+}
diff --git a/sca-java-1.x/contrib/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/companyFeed/CompanyFeedTestCaseFIXME.java b/sca-java-1.x/contrib/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/companyFeed/CompanyFeedTestCaseFIXME.java new file mode 100644 index 0000000000..b72ff89e3b --- /dev/null +++ b/sca-java-1.x/contrib/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/companyFeed/CompanyFeedTestCaseFIXME.java @@ -0,0 +1,51 @@ +/*
+ * 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.sca.implementation.data.companyFeed;
+
+import java.io.IOException;
+import java.net.Socket;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.host.embedded.SCADomain;
+
+/**
+ * @version $Rev: 543175 $ $Date: 2007-05-31 09:09:12 -0700 (Thu, 31 May 2007) $
+ */
+public class CompanyFeedTestCaseFIXME extends TestCase {
+ private SCADomain scaDomain;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ scaDomain = SCADomain.newInstance("data-feed.composite");
+ //System.in.read();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ scaDomain.close();
+ }
+
+ public void testPing() throws IOException {
+ new Socket("127.0.0.1", 8085);
+ }
+
+}
|