summaryrefslogtreecommitdiffstats
path: root/sandbox/amita/sca/modules/implementation-data-sdo/test
diff options
context:
space:
mode:
authordims <dims@13f79535-47bb-0310-9956-ffa450edef68>2008-06-17 00:23:01 +0000
committerdims <dims@13f79535-47bb-0310-9956-ffa450edef68>2008-06-17 00:23:01 +0000
commitbdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a (patch)
tree38a92061c0793434c4be189f1d70c3458b6bc41d /sandbox/amita/sca/modules/implementation-data-sdo/test
Move Tuscany from Incubator to top level.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox/amita/sca/modules/implementation-data-sdo/test')
-rw-r--r--sandbox/amita/sca/modules/implementation-data-sdo/test/java/org/apache/tuscany/sca/implementation/sdo/ImplSDOTestCase.java158
-rw-r--r--sandbox/amita/sca/modules/implementation-data-sdo/test/resources/dbConfig.xml32
-rw-r--r--sandbox/amita/sca/modules/implementation-data-sdo/test/resources/sdo.composite36
3 files changed, 226 insertions, 0 deletions
diff --git a/sandbox/amita/sca/modules/implementation-data-sdo/test/java/org/apache/tuscany/sca/implementation/sdo/ImplSDOTestCase.java b/sandbox/amita/sca/modules/implementation-data-sdo/test/java/org/apache/tuscany/sca/implementation/sdo/ImplSDOTestCase.java
new file mode 100644
index 0000000000..8d04664e17
--- /dev/null
+++ b/sandbox/amita/sca/modules/implementation-data-sdo/test/java/org/apache/tuscany/sca/implementation/sdo/ImplSDOTestCase.java
@@ -0,0 +1,158 @@
+/*
+ * 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.sdo;
+
+import junit.framework.*;
+
+import org.apache.tuscany.das.rdb.dbconfig.DBInitializer;
+import org.apache.tuscany.sca.host.embedded.*;
+import org.apache.tuscany.sca.implementation.data.collection.NotFoundException;
+import org.apache.commons.logging.*;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.XMLHelper;
+
+import java.util.*;
+
+public class ImplSDOTestCase extends TestCase {
+ private SCADomain domain;
+ private org.apache.tuscany.sca.implementation.data.collection.Collection dataService;
+
+ //TODO way to initialize db during setup
+ public void setUp() {
+ try {
+ DBInitializer dbInitializer = new DBInitializer("dbConfig.xml");
+ dbInitializer.initializeDatabase(true);
+ } catch(Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+
+ domain = SCADomain.newInstance("sdo.composite");
+ dataService = domain.getService(org.apache.tuscany.sca.implementation.data.collection.Collection.class, "SDOComponent");
+
+ }
+
+ public void testGet() {
+ String i = "51";
+ ArrayList pk = new ArrayList();
+ pk.add(i);
+ try {
+ DataObject resultDO = (DataObject)dataService.get(pk);
+ assertEquals(51, resultDO.getDataObject("COMPANY[ID=51]").getInt("ID"));
+ }catch(NotFoundException nfe) {
+ nfe.printStackTrace();
+ }
+ }
+
+ public void testGetAll() {
+ Object result = dataService.getAll();
+ HashMap<ArrayList, DataObject> resultHash = (HashMap<ArrayList, DataObject>)result;
+ Set<ArrayList> keysArray = resultHash.keySet();
+ assertEquals(3, keysArray.size());
+ Iterator<ArrayList> keysItr = keysArray.iterator();
+ while(keysItr.hasNext()) {
+ ArrayList currentKeys = keysItr.next();
+ DataObject currentDO = resultHash.get(currentKeys);
+ assertNotNull(currentDO);
+ }
+ }
+
+ public void testQuery() {
+ Object result = dataService.query("select * from COMPANY where ID=51");
+ HashMap<ArrayList, DataObject> resultHash = (HashMap<ArrayList, DataObject>)result;
+ Set<ArrayList> keysArray = resultHash.keySet();
+ Iterator<ArrayList> keysItr = keysArray.iterator();
+ DataObject currentDO = null;
+ ArrayList currentKeys = null;
+ while(keysItr.hasNext()) {
+ currentKeys = keysItr.next();
+ currentDO = resultHash.get(currentKeys);
+ assertEquals(51, currentKeys.get(0));
+ assertNotNull(currentDO);
+ }
+ }
+
+ public void testPut() {
+ DataObject resultDO = null;
+ String i = "51";
+ ArrayList pk = new ArrayList();
+ pk.add(i);
+ try {
+ Object result = dataService.get(pk);
+ resultDO = (DataObject)result;
+ assertEquals(51, resultDO.getDataObject("COMPANY[ID=51]").getInt("ID"));
+ }catch(NotFoundException nfe) {
+ nfe.printStackTrace();
+ }
+
+ resultDO.getDataObject("COMPANY[ID=51]").set("NAME", "MODIFIED NAME");
+ ArrayList currentKeys = new ArrayList();
+ currentKeys.add("51");
+ try {
+ dataService.put(currentKeys, resultDO);
+ Object result = dataService.get(pk);
+ resultDO = (DataObject)result;
+ assertEquals("MODIFIED NAME", resultDO.getDataObject("COMPANY[ID=51]").getString("NAME"));
+ } catch(NotFoundException e) {
+ e.printStackTrace();
+ fail("Unexpected failure "+e.getMessage());
+ }
+ }
+
+ public void testPost() {
+ DataObject resultDO = null;
+ String i = "51";//"1";
+ ArrayList pk = new ArrayList();
+ pk.add(i);
+ try {
+ Object result = dataService.get(pk);
+ resultDO = (DataObject)result;
+ assertEquals(51, resultDO.getDataObject("COMPANY[ID=51]").getInt("ID"));
+ //assertEquals(1, resultDO.getDataObject("COMPANY[ID=1]").getInt("ID"));
+ }catch(NotFoundException nfe) {
+ nfe.printStackTrace();
+ }
+
+ DataObject insDO = resultDO.getDataObject("COMPANY[ID=51]");
+ //DataObject insDO = resultDO.getDataObject("COMPANY[ID=1]");
+ insDO.set("ID", 54);//auto-incr of PK is not configured
+ //insDO.set("ID", null);//auto-incr of PK is configured
+ ArrayList pkIns = (ArrayList)dataService.post(insDO);
+ assertEquals(1, pkIns.size());
+ }
+
+ public void testDelete() {
+ DataObject resultDO = null;
+ String i = "53";
+ ArrayList pk = new ArrayList();
+ pk.add(i);
+ try {
+ dataService.delete(pk);
+ assertTrue(true);
+ }catch(NotFoundException nfe) {
+ nfe.printStackTrace();
+ fail("Exception in delete");
+ }
+ }
+
+ public void tearDown() {
+ domain.close();
+ }
+}
diff --git a/sandbox/amita/sca/modules/implementation-data-sdo/test/resources/dbConfig.xml b/sandbox/amita/sca/modules/implementation-data-sdo/test/resources/dbConfig.xml
new file mode 100644
index 0000000000..f88aae37eb
--- /dev/null
+++ b/sandbox/amita/sca/modules/implementation-data-sdo/test/resources/dbConfig.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="ASCII"?>
+<!--
+ 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.
+ -->
+<DBConfig xmlns="http:///org.apache.tuscany.das.rdb/dbconfig.xsd">
+ <ConnectionInfo>
+ <ConnectionProperties
+ driverClass="org.apache.derby.jdbc.EmbeddedDriver"
+ databaseURL="jdbc:derby:target/dastest; create = true"
+ loginTimeout="600000"/>
+ </ConnectionInfo>
+ <Table name="COMPANY" SQLCreate="CREATE TABLE COMPANY (ID INT PRIMARY KEY NOT NULL, NAME VARCHAR(30), EOTMID INT)">
+ <row>51, 'ACME Publishing', 0</row>
+ <row>52, 'Do-rite plumbing', 0</row>
+ <row>53, 'MegaCorp', 0</row>
+ </Table>
+</DBConfig>
diff --git a/sandbox/amita/sca/modules/implementation-data-sdo/test/resources/sdo.composite b/sandbox/amita/sca/modules/implementation-data-sdo/test/resources/sdo.composite
new file mode 100644
index 0000000000..e4da159d52
--- /dev/null
+++ b/sandbox/amita/sca/modules/implementation-data-sdo/test/resources/sdo.composite
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0"
+ targetNamespace="http://sample/sdo"
+ name="impl-data-sdo">
+
+ <component name="SDOComponent">
+ <tuscany:implementation.sdo table="COMPANY" key="ID">
+ <tuscany:connectionInfo>
+ <tuscany:connectionProperties
+ driverClass="org.apache.derby.jdbc.EmbeddedDriver"
+ databaseURL="jdbc:derby:target/dastest; create = true"
+ loginTimeout="600000"/>
+ </tuscany:connectionInfo>
+ </tuscany:implementation.sdo>
+ </component>
+
+</composite> \ No newline at end of file