diff options
Diffstat (limited to 'sandbox/old/contrib/persistence/store.jdbc/src/test/java/org/apache/tuscany/service/persistence/store')
8 files changed, 686 insertions, 0 deletions
diff --git a/sandbox/old/contrib/persistence/store.jdbc/src/test/java/org/apache/tuscany/service/persistence/store/jdbc/JDBCStoreInsertTestCase.java b/sandbox/old/contrib/persistence/store.jdbc/src/test/java/org/apache/tuscany/service/persistence/store/jdbc/JDBCStoreInsertTestCase.java new file mode 100644 index 0000000000..3d8afc2e3b --- /dev/null +++ b/sandbox/old/contrib/persistence/store.jdbc/src/test/java/org/apache/tuscany/service/persistence/store/jdbc/JDBCStoreInsertTestCase.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.service.persistence.store.jdbc; + +import java.io.Serializable; +import java.sql.ResultSet; +import java.sql.Statement; +import java.util.UUID; +import javax.sql.DataSource; + +import org.apache.tuscany.spi.component.SCAObject; +import org.apache.tuscany.spi.services.store.Store; + +import junit.framework.Assert; +import junit.framework.TestCase; +import org.apache.tuscany.spi.services.store.StoreMonitor; + +import org.apache.tuscany.service.persistence.store.jdbc.converter.AbstractConverter; +import org.apache.tuscany.service.persistence.store.jdbc.converter.HSQLDBConverter; +import org.easymock.EasyMock; + +/** + * Verifies store insert operations using HSQLDB + * + * @version $Rev$ $Date$ + */ +public class JDBCStoreInsertTestCase extends TestCase { + private DataSource ds; + private JDBCStore store; + + public void testInsertMetaData() throws Exception { + SCAObject object = EasyMock.createMock(SCAObject.class); + EasyMock.expect(object.getCanonicalName()).andReturn("foo").atLeastOnce(); + EasyMock.replay(object); + store.init(); + JDBCStoreInsertTestCase.Foo foo = new JDBCStoreInsertTestCase.Foo("test"); + String id = UUID.randomUUID().toString(); + store.insertRecord(object, id, foo, Store.NEVER); + Statement stmt = ds.getConnection().createStatement(); + ResultSet rs = stmt.executeQuery(TestUtils.SELECT_SQL); + rs.next(); + assertEquals(id, rs.getString(AbstractConverter.ID)); + Assert.assertEquals(Store.NEVER, rs.getLong(AbstractConverter.EXPIRATION)); + } + + public void testInsertRead() throws Exception { + store.init(); + SCAObject object = EasyMock.createMock(SCAObject.class); + EasyMock.expect(object.getCanonicalName()).andReturn("foo").atLeastOnce(); + EasyMock.replay(object); + JDBCStoreInsertTestCase.Foo foo = new JDBCStoreInsertTestCase.Foo("test"); + String id = UUID.randomUUID().toString(); + store.insertRecord(object, id, foo, Store.NEVER); + Foo foo2 = (Foo) store.readRecord(object, id); + assertEquals("test", foo2.data); + } + + public void testInsertOverwriteRead() throws Exception { + store.init(); + SCAObject object = EasyMock.createMock(SCAObject.class); + EasyMock.expect(object.getCanonicalName()).andReturn("foo").atLeastOnce(); + EasyMock.replay(object); + JDBCStoreInsertTestCase.Foo foo = new JDBCStoreInsertTestCase.Foo("test"); + String id = UUID.randomUUID().toString(); + store.insertRecord(object, id, foo, Store.NEVER); + foo.data = "test2"; + store.insertRecord(object, id, foo, Store.NEVER); + Foo foo2 = (Foo) store.readRecord(object, id); + assertEquals("test2", foo2.data); + } + + /** + * Verifies multiple resources belonging to different owners but sharing the same id are inserted + */ + public void testMultipleInsert() throws Exception { + SCAObject owner1 = EasyMock.createMock(SCAObject.class); + EasyMock.expect(owner1.getCanonicalName()).andReturn("baz").atLeastOnce(); + EasyMock.replay(owner1); + SCAObject owner2 = EasyMock.createMock(SCAObject.class); + EasyMock.expect(owner2.getCanonicalName()).andReturn("bar").atLeastOnce(); + EasyMock.replay(owner2); + store.init(); + Foo foo1 = new Foo("test"); + String id1 = UUID.randomUUID().toString(); + Foo foo2 = new Foo("test2"); + store.insertRecord(owner1, id1, foo1, Store.NEVER); + store.insertRecord(owner2, id1, foo2, Store.NEVER); + Foo retFoo1 = (Foo) store.readRecord(owner1, id1); + assertEquals("test", retFoo1.data); + Foo retFoo2 = (Foo) store.readRecord(owner2, id1); + assertEquals("test2", retFoo2.data); + } + + + protected void setUp() throws Exception { + super.setUp(); + ds = TestUtils.createTables(); + store = new JDBCStore(ds, new HSQLDBConverter(), EasyMock.createNiceMock(StoreMonitor.class)); + } + + + protected void tearDown() throws Exception { + super.tearDown(); + TestUtils.cleanup(ds); + } + + @SuppressWarnings({"SerializableHasSerializationMethods"}) + public static class Foo implements Serializable { + private static final long serialVersionUID = -4284779882741318884L; + private String data; + + public Foo(String data) { + this.data = data; + } + } + +} diff --git a/sandbox/old/contrib/persistence/store.jdbc/src/test/java/org/apache/tuscany/service/persistence/store/jdbc/JDBCStoreTestCase.java b/sandbox/old/contrib/persistence/store.jdbc/src/test/java/org/apache/tuscany/service/persistence/store/jdbc/JDBCStoreTestCase.java new file mode 100644 index 0000000000..418899be86 --- /dev/null +++ b/sandbox/old/contrib/persistence/store.jdbc/src/test/java/org/apache/tuscany/service/persistence/store/jdbc/JDBCStoreTestCase.java @@ -0,0 +1,100 @@ +/* + * 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.service.persistence.store.jdbc; + +import java.io.Serializable; +import java.util.UUID; +import javax.sql.DataSource; + +import org.apache.tuscany.spi.component.SCAObject; + +import junit.framework.TestCase; +import static org.apache.tuscany.spi.services.store.Store.NEVER; +import org.apache.tuscany.spi.services.store.StoreMonitor; +import org.apache.tuscany.service.persistence.store.jdbc.converter.HSQLDBConverter; +import org.easymock.EasyMock; + +/** + * Verifies store operations using HSQLDB + * + * @version $Rev$ $Date$ + */ +public class JDBCStoreTestCase extends TestCase { + private DataSource ds; + private JDBCStore store; + + public void testNotFound() throws Exception { + store.init(); + SCAObject object = EasyMock.createMock(SCAObject.class); + EasyMock.expect(object.getCanonicalName()).andReturn("foo").atLeastOnce(); + EasyMock.replay(object); + String id = UUID.randomUUID().toString(); + assertNull(store.readRecord(object, id)); + } + + public void testRemoveRecord() throws Exception { + store.init(); + SCAObject object = EasyMock.createMock(SCAObject.class); + EasyMock.expect(object.getCanonicalName()).andReturn("foo").atLeastOnce(); + EasyMock.replay(object); + Foo foo = new Foo("test"); + String id = UUID.randomUUID().toString(); + store.insertRecord(object, id, foo, NEVER); + Foo foo2 = (Foo) store.readRecord(object, id); + assertEquals("test", foo2.data); + store.removeRecord(object, id); + assertNull(store.readRecord(object, id)); + } + + public void testExpirationFromStore() throws Exception { + store.setReaperInterval(10); + store.init(); + SCAObject object = EasyMock.createMock(SCAObject.class); + EasyMock.expect(object.getCanonicalName()).andReturn("foo").atLeastOnce(); + EasyMock.replay(object); + Foo foo = new Foo("test"); + String id = UUID.randomUUID().toString(); + store.insertRecord(object, id, foo, System.currentTimeMillis() + 20); + Thread.sleep(100); + assertNull(store.readRecord(object, id)); + } + + protected void setUp() throws Exception { + super.setUp(); + ds = TestUtils.createTables(); + store = new JDBCStore(ds, new HSQLDBConverter(), EasyMock.createNiceMock(StoreMonitor.class)); + } + + + protected void tearDown() throws Exception { + super.tearDown(); + TestUtils.cleanup(ds); + } + + @SuppressWarnings({"SerializableHasSerializationMethods"}) + public static class Foo implements Serializable { + private static final long serialVersionUID = -4284779882741318884L; + private String data; + + public Foo(String data) { + this.data = data; + } + } + +} diff --git a/sandbox/old/contrib/persistence/store.jdbc/src/test/java/org/apache/tuscany/service/persistence/store/jdbc/JDBCStoreUpdateTestCase.java b/sandbox/old/contrib/persistence/store.jdbc/src/test/java/org/apache/tuscany/service/persistence/store/jdbc/JDBCStoreUpdateTestCase.java new file mode 100644 index 0000000000..b9b0500572 --- /dev/null +++ b/sandbox/old/contrib/persistence/store.jdbc/src/test/java/org/apache/tuscany/service/persistence/store/jdbc/JDBCStoreUpdateTestCase.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.service.persistence.store.jdbc; + +import java.io.Serializable; +import java.util.UUID; +import javax.sql.DataSource; + +import org.apache.tuscany.spi.component.SCAObject; + +import junit.framework.TestCase; +import org.apache.tuscany.spi.services.store.Store; +import static org.apache.tuscany.spi.services.store.Store.NEVER; +import org.apache.tuscany.spi.services.store.StoreMonitor; +import org.apache.tuscany.service.persistence.store.jdbc.converter.HSQLDBConverter; +import org.easymock.EasyMock; + +/** + * Verifies store operations using HSQLDB + * + * @version $Rev$ $Date$ + */ +public class JDBCStoreUpdateTestCase extends TestCase { + private DataSource ds; + private JDBCStore store; + + public void testMultipleUpdate() throws Exception { + SCAObject owner1 = EasyMock.createMock(SCAObject.class); + EasyMock.expect(owner1.getCanonicalName()).andReturn("baz").atLeastOnce(); + EasyMock.replay(owner1); + SCAObject owner2 = EasyMock.createMock(SCAObject.class); + EasyMock.expect(owner2.getCanonicalName()).andReturn("bar").atLeastOnce(); + EasyMock.replay(owner2); + store.init(); + Foo foo1 = new Foo("test"); + String id1 = UUID.randomUUID().toString(); + Foo foo2 = new Foo("test2"); + store.insertRecord(owner1, id1, foo1, Store.NEVER); + store.insertRecord(owner2, id1, foo2, Store.NEVER); + foo1.data = "testA"; + foo2.data = "test2A"; + store.updateRecord(owner1, id1, foo1, Store.NEVER); + store.updateRecord(owner2, id1, foo2, Store.NEVER); + Foo retFoo1 = (Foo) store.readRecord(owner1, id1); + assertEquals("testA", retFoo1.data); + Foo retFoo2 = (Foo) store.readRecord(owner2, id1); + assertEquals("test2A", retFoo2.data); + } + + public void testUpdateRead() throws Exception { + store.init(); + SCAObject object = EasyMock.createMock(SCAObject.class); + EasyMock.expect(object.getCanonicalName()).andReturn("foo").atLeastOnce(); + EasyMock.replay(object); + Foo foo = new Foo("test"); + String id = UUID.randomUUID().toString(); + store.insertRecord(object, id, foo, NEVER); + foo.data = "test2"; + store.updateRecord(object, id, foo, Store.NEVER); + Foo foo2 = (Foo) store.readRecord(object, id); + assertEquals("test2", foo2.data); + } + + + protected void setUp() throws Exception { + super.setUp(); + ds = TestUtils.createTables(); + store = new JDBCStore(ds, new HSQLDBConverter(), EasyMock.createNiceMock(StoreMonitor.class)); + } + + protected void tearDown() throws Exception { + super.tearDown(); + TestUtils.cleanup(ds); + } + + @SuppressWarnings({"SerializableHasSerializationMethods"}) + public static class Foo implements Serializable { + private static final long serialVersionUID = -4284779882741318884L; + private String data; + + public Foo(String data) { + this.data = data; + } + } + +} diff --git a/sandbox/old/contrib/persistence/store.jdbc/src/test/java/org/apache/tuscany/service/persistence/store/jdbc/RecordTestCase.java b/sandbox/old/contrib/persistence/store.jdbc/src/test/java/org/apache/tuscany/service/persistence/store/jdbc/RecordTestCase.java new file mode 100644 index 0000000000..660e906cef --- /dev/null +++ b/sandbox/old/contrib/persistence/store.jdbc/src/test/java/org/apache/tuscany/service/persistence/store/jdbc/RecordTestCase.java @@ -0,0 +1,66 @@ +/* + * 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.service.persistence.store.jdbc; + +import java.util.UUID; + +import junit.framework.TestCase; +import static org.apache.tuscany.spi.services.store.Store.NEVER; + +/** + * @version $Rev$ $Date$ + */ +public class RecordTestCase extends TestCase { + + public void testInsertCompare() { + Record record = new Record(null, UUID.randomUUID().toString(), "foo", NEVER, Record.INSERT); + Record record2 = new Record(null, UUID.randomUUID().toString(), "bar", NEVER, Record.INSERT); + assertEquals(0, record.compareTo(record2)); + } + + public void testUpdateCompare() { + Record record = new Record(null, UUID.randomUUID().toString(), "foo", NEVER, Record.UPDATE); + Record record2 = new Record(null, UUID.randomUUID().toString(), "bar", NEVER, Record.UPDATE); + assertEquals(0, record.compareTo(record2)); + } + + public void testInsertUpdateCompare() { + Record record = new Record(null, UUID.randomUUID().toString(), "foo", NEVER, Record.INSERT); + Record record2 = new Record(null, UUID.randomUUID().toString(), "bar", NEVER, Record.UPDATE); + assertEquals(-1, record.compareTo(record2)); + } + + public void testUpdateInsertCompare() { + Record record = new Record(null, UUID.randomUUID().toString(), "foo", NEVER, Record.UPDATE); + Record record2 = new Record(null, UUID.randomUUID().toString(), "bar", NEVER, Record.INSERT); + assertEquals(1, record.compareTo(record2)); + } + + public void testAssertion() { + Record record = new Record(null, UUID.randomUUID().toString(), "foo", NEVER, 4); + Record record2 = new Record(null, UUID.randomUUID().toString(), "bar", NEVER, 5); + try { + record.compareTo(record2); + fail(); + } catch (AssertionError e) { + // expected + } + } + +} diff --git a/sandbox/old/contrib/persistence/store.jdbc/src/test/java/org/apache/tuscany/service/persistence/store/jdbc/TestUtils.java b/sandbox/old/contrib/persistence/store.jdbc/src/test/java/org/apache/tuscany/service/persistence/store/jdbc/TestUtils.java new file mode 100644 index 0000000000..8fb1c966c9 --- /dev/null +++ b/sandbox/old/contrib/persistence/store.jdbc/src/test/java/org/apache/tuscany/service/persistence/store/jdbc/TestUtils.java @@ -0,0 +1,72 @@ +/* + * 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.service.persistence.store.jdbc; + +import java.sql.Connection; +import java.sql.SQLException; +import javax.sql.DataSource; + +import org.apache.commons.dbcp.BasicDataSource; + +/** + * @version $Rev$ $Date$ + */ +public final class TestUtils { + + public static final String CREATE_TABLE = + "CREATE TABLE CONVERSATION_STATE(OWNER VARCHAR, ID VARCHAR, EXPIRATION BIGINT, " + + "OBJECT LONGVARBINARY);"; + + public static final String DROP_TABLE = "DROP TABLE CONVERSATION_STATE IF EXISTS"; + public static final String SELECT_SQL = "SELECT * FROM CONVERSATION_STATE"; + + private TestUtils() { + } + + public static DataSource createTables() throws SQLException { + BasicDataSource ds = new BasicDataSource(); + ds.setDriverClassName("org.hsqldb.jdbcDriver"); + ds.setUrl("jdbc:hsqldb:mem:test"); + Connection conn = null; + try { + conn = ds.getConnection(); + conn.createStatement().execute(CREATE_TABLE); + conn.commit(); + } finally { + if (conn != null) { + conn.close(); + } + } + return ds; + } + + public static void cleanup(DataSource ds) throws SQLException { + Connection conn = null; + try { + conn = ds.getConnection(); + conn.createStatement().execute(DROP_TABLE); + conn.createStatement().execute("SHUTDOWN"); + conn.commit(); + } finally { + if (conn != null) { + conn.close(); + } + } + } +} diff --git a/sandbox/old/contrib/persistence/store.jdbc/src/test/java/org/apache/tuscany/service/persistence/store/jdbc/converter/AbstractConverterTestCase.java b/sandbox/old/contrib/persistence/store.jdbc/src/test/java/org/apache/tuscany/service/persistence/store/jdbc/converter/AbstractConverterTestCase.java new file mode 100644 index 0000000000..0d8f48e126 --- /dev/null +++ b/sandbox/old/contrib/persistence/store.jdbc/src/test/java/org/apache/tuscany/service/persistence/store/jdbc/converter/AbstractConverterTestCase.java @@ -0,0 +1,88 @@ +/* + * 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.service.persistence.store.jdbc.converter; + +import java.io.IOException; +import java.io.Serializable; +import java.sql.Connection; +import java.sql.PreparedStatement; + +import org.apache.tuscany.spi.services.store.StoreReadException; + +import junit.framework.TestCase; +import org.apache.tuscany.spi.services.store.StoreWriteException; + +/** + * @version $Rev$ $Date$ + */ +public class AbstractConverterTestCase extends TestCase { + + public void testSerializeDeserialize() throws Exception { + TestConverter converter = new TestConverter(); + Foo foo = new Foo(); + foo.data = "test"; + byte[] bytes = converter.serialize(foo); + Foo foo2 = (Foo) converter.deserialize(bytes); + assertEquals("test", foo2.data); + } + + private class TestConverter extends AbstractConverter { + + public void insert(PreparedStatement stmt, String ownerId, String id, long expiration, Serializable object) + throws StoreWriteException { + + } + + public void update(PreparedStatement stmt, String ownerId, String id, Serializable object) + throws StoreWriteException { + + } + + public boolean findAndLock(PreparedStatement stmt, + String ownerId, + String id + ) throws StoreWriteException { + return false; + } + + public Object read(Connection conn, String ownerId, String id) throws StoreReadException { + return null; + } + + public void delete(PreparedStatement stmt, String ownerId, String id) throws StoreWriteException { + + } + + @Override + public byte[] serialize(Serializable serializable) throws IOException { + return super.serialize(serializable); + } + + @Override + public Object deserialize(byte[] bytes) throws IOException, ClassNotFoundException { + return super.deserialize(bytes); + } + } + + @SuppressWarnings({"SerializableHasSerializationMethods"}) + private static class Foo implements Serializable { + private static final long serialVersionUID = -3774909621298751358L; + private String data; + } +} diff --git a/sandbox/old/contrib/persistence/store.jdbc/src/test/java/org/apache/tuscany/service/persistence/store/jdbc/converter/HSQLDBConverterTestCase.java b/sandbox/old/contrib/persistence/store.jdbc/src/test/java/org/apache/tuscany/service/persistence/store/jdbc/converter/HSQLDBConverterTestCase.java new file mode 100644 index 0000000000..472c523217 --- /dev/null +++ b/sandbox/old/contrib/persistence/store.jdbc/src/test/java/org/apache/tuscany/service/persistence/store/jdbc/converter/HSQLDBConverterTestCase.java @@ -0,0 +1,89 @@ +/* + * 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.service.persistence.store.jdbc.converter; + +import java.io.Serializable; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.util.UUID; +import javax.sql.DataSource; + +import org.apache.tuscany.spi.services.store.Store; + +import junit.framework.TestCase; +import org.apache.tuscany.service.persistence.store.jdbc.Converter; +import static org.apache.tuscany.service.persistence.store.jdbc.TestUtils.cleanup; +import static org.apache.tuscany.service.persistence.store.jdbc.TestUtils.createTables; + +/** + * @version $Rev$ $Date$ + */ +public class HSQLDBConverterTestCase extends TestCase { + + private Converter converter; + private DataSource ds; + + public void testWriteRead() throws Exception { + Connection conn = ds.getConnection(); + conn.setAutoCommit(false); + PreparedStatement stmt = conn.prepareStatement(converter.getInsertSql()); + String id = UUID.randomUUID().toString(); + Foo foo = new Foo(); + foo.data = "test"; + converter.insert(stmt, "foo", id, Store.NEVER, foo); + stmt.addBatch(); + stmt.execute(); + stmt.close(); + conn.commit(); + conn.close(); + conn = ds.getConnection(); + conn.setAutoCommit(false); + Foo foo2 = (Foo) converter.read(conn, "foo", id); + assertEquals("test", foo2.data); + conn.commit(); + conn.close(); + } + + public void testNotFound() throws Exception { + Connection conn = ds.getConnection(); + conn.setAutoCommit(false); + String id = UUID.randomUUID().toString(); + assertNull(converter.read(conn, null, id)); + conn.commit(); + conn.close(); + } + + protected void setUp() throws Exception { + super.setUp(); + converter = new HSQLDBConverter(); + ds = createTables(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + cleanup(ds); + } + + @SuppressWarnings({"SerializableHasSerializationMethods"}) + private static class Foo implements Serializable { + private static final long serialVersionUID = -6119188073169441225L; + private String data; + } + +} diff --git a/sandbox/old/contrib/persistence/store.jdbc/src/test/java/org/apache/tuscany/service/persistence/store/jdbc/integration/BootstrapTestCase.java b/sandbox/old/contrib/persistence/store.jdbc/src/test/java/org/apache/tuscany/service/persistence/store/jdbc/integration/BootstrapTestCase.java new file mode 100644 index 0000000000..4225cf65ba --- /dev/null +++ b/sandbox/old/contrib/persistence/store.jdbc/src/test/java/org/apache/tuscany/service/persistence/store/jdbc/integration/BootstrapTestCase.java @@ -0,0 +1,36 @@ +/* + * 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.service.persistence.store.jdbc.integration; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class BootstrapTestCase extends TestCase { + + public void testBoot() throws Exception { + // TODO + } + + protected void setUp() throws Exception { + super.setUp(); + + } +} |