From 28f92c6fc62f3bc0637ac77681aabcc8c0b5e42c Mon Sep 17 00:00:00 2001 From: lresende Date: Thu, 11 Sep 2008 04:12:24 +0000 Subject: Renaming branch git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@694107 13f79535-47bb-0310-9956-ffa450edef68 --- .../data/DATACollectionTestCaseFIXME.java | 118 ++++++++++++++++++ .../data/DATAImplementationProcessorTestCase.java | 133 +++++++++++++++++++++ .../sca/implementation/data/DATATestCase.java | 133 +++++++++++++++++++++ .../data/companyFeed/CompanyFeed.java | 62 ++++++++++ .../data/companyFeed/CompanyFeedTestCaseFIXME.java | 51 ++++++++ .../src/test/resources/data-feed.composite | 50 ++++++++ .../src/test/resources/data.composite | 36 ++++++ .../src/test/resources/insert.xml | 9 ++ .../src/test/resources/update.xml | 7 ++ 9 files changed, 599 insertions(+) create mode 100644 branches/sca-trunk-20080910/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/DATACollectionTestCaseFIXME.java create mode 100644 branches/sca-trunk-20080910/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/DATAImplementationProcessorTestCase.java create mode 100644 branches/sca-trunk-20080910/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/DATATestCase.java create mode 100644 branches/sca-trunk-20080910/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/companyFeed/CompanyFeed.java create mode 100644 branches/sca-trunk-20080910/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/companyFeed/CompanyFeedTestCaseFIXME.java create mode 100644 branches/sca-trunk-20080910/modules/implementation-data-xml/src/test/resources/data-feed.composite create mode 100644 branches/sca-trunk-20080910/modules/implementation-data-xml/src/test/resources/data.composite create mode 100644 branches/sca-trunk-20080910/modules/implementation-data-xml/src/test/resources/insert.xml create mode 100644 branches/sca-trunk-20080910/modules/implementation-data-xml/src/test/resources/update.xml (limited to 'branches/sca-trunk-20080910/modules/implementation-data-xml/src/test') diff --git a/branches/sca-trunk-20080910/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/DATACollectionTestCaseFIXME.java b/branches/sca-trunk-20080910/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/branches/sca-trunk-20080910/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/branches/sca-trunk-20080910/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/DATAImplementationProcessorTestCase.java b/branches/sca-trunk-20080910/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/branches/sca-trunk-20080910/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 = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + ""; + + private static final String COMPOSITE_USING_CONNECTION_PROPERTIES = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + private XMLInputFactory inputFactory; + private StAXArtifactProcessor 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/branches/sca-trunk-20080910/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/DATATestCase.java b/branches/sca-trunk-20080910/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/branches/sca-trunk-20080910/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/branches/sca-trunk-20080910/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/companyFeed/CompanyFeed.java b/branches/sca-trunk-20080910/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/branches/sca-trunk-20080910/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 { + + @Reference + protected DATA dataService; + + public Entry[] 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[] query(String queryString) { + return null; + } +} diff --git a/branches/sca-trunk-20080910/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/companyFeed/CompanyFeedTestCaseFIXME.java b/branches/sca-trunk-20080910/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/branches/sca-trunk-20080910/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); + } + +} diff --git a/branches/sca-trunk-20080910/modules/implementation-data-xml/src/test/resources/data-feed.composite b/branches/sca-trunk-20080910/modules/implementation-data-xml/src/test/resources/data-feed.composite new file mode 100644 index 0000000000..40c755b134 --- /dev/null +++ b/branches/sca-trunk-20080910/modules/implementation-data-xml/src/test/resources/data-feed.composite @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-trunk-20080910/modules/implementation-data-xml/src/test/resources/data.composite b/branches/sca-trunk-20080910/modules/implementation-data-xml/src/test/resources/data.composite new file mode 100644 index 0000000000..f30b15e34c --- /dev/null +++ b/branches/sca-trunk-20080910/modules/implementation-data-xml/src/test/resources/data.composite @@ -0,0 +1,36 @@ + + + + + + + + + + + + + diff --git a/branches/sca-trunk-20080910/modules/implementation-data-xml/src/test/resources/insert.xml b/branches/sca-trunk-20080910/modules/implementation-data-xml/src/test/resources/insert.xml new file mode 100644 index 0000000000..c0a5ada4bf --- /dev/null +++ b/branches/sca-trunk-20080910/modules/implementation-data-xml/src/test/resources/insert.xml @@ -0,0 +1,9 @@ + + + + New Coorporation I + + + New Coorporation II + + diff --git a/branches/sca-trunk-20080910/modules/implementation-data-xml/src/test/resources/update.xml b/branches/sca-trunk-20080910/modules/implementation-data-xml/src/test/resources/update.xml new file mode 100644 index 0000000000..c6cef75274 --- /dev/null +++ b/branches/sca-trunk-20080910/modules/implementation-data-xml/src/test/resources/update.xml @@ -0,0 +1,7 @@ + + + + 4 + Update Coorporation + + -- cgit v1.2.3