Repository: cayenne Updated Branches: refs/heads/master 0933c1944 -> 30c2c6f12
splitting integration tests from unit tests Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/30c2c6f1 Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/30c2c6f1 Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/30c2c6f1 Branch: refs/heads/master Commit: 30c2c6f122f2a0590ef4fcd52f2010a65d6baf80 Parents: 0933c19 Author: Andrus Adamchik <[email protected]> Authored: Thu Aug 18 10:41:01 2016 +0300 Committer: Andrus Adamchik <[email protected]> Committed: Thu Aug 18 10:41:01 2016 +0300 ---------------------------------------------------------------------- .../cayenne/crypto/Runtime_AES128_GZIP_IT.java | 166 ++++++++++++++++++ .../crypto/Runtime_AES128_GZIP_Test.java | 166 ------------------ .../cayenne/crypto/Runtime_AES128_IT.java | 122 ++++++++++++++ .../cayenne/crypto/Runtime_AES128_Test.java | 122 -------------- .../value/DefaultValueTransformerFactoryIT.java | 168 +++++++++++++++++++ .../DefaultValueTransformerFactoryTest.java | 168 ------------------- 6 files changed, 456 insertions(+), 456 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cayenne/blob/30c2c6f1/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Runtime_AES128_GZIP_IT.java ---------------------------------------------------------------------- diff --git a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Runtime_AES128_GZIP_IT.java b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Runtime_AES128_GZIP_IT.java new file mode 100644 index 0000000..1013c91 --- /dev/null +++ b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Runtime_AES128_GZIP_IT.java @@ -0,0 +1,166 @@ +/***************************************************************** + * 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.cayenne.crypto; + +import org.apache.cayenne.ObjectContext; +import org.apache.cayenne.crypto.db.Table2; +import org.apache.cayenne.crypto.transformer.bytes.Header; +import org.apache.cayenne.crypto.unit.CryptoUnitUtils; +import org.apache.cayenne.query.SelectQuery; +import org.junit.Before; +import org.junit.Test; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +public class Runtime_AES128_GZIP_IT extends Runtime_AES128_Base { + + private static final int GZIP_THRESHOLD = 150; + + @Before + public void setUp() throws Exception { + super.setUp(true); + } + + @Test + public void testInsert() throws SQLException { + + ObjectContext context = runtime.newContext(); + + // make sure compression is on... + byte[] cryptoBytes = CryptoUnitUtils.bytesOfSize(GZIP_THRESHOLD + 100); + + Table2 t1 = context.newObject(Table2.class); + t1.setPlainBytes("plain_1".getBytes()); + t1.setCryptoBytes(cryptoBytes); + + context.commitChanges(); + + Object[] data = table2.select(); + assertArrayEquals("plain_1".getBytes(), (byte[]) data[1]); + + Header h = Header.create((byte[]) data[2], 0); + assertTrue(h.isCompressed()); + assertArrayEquals(cryptoBytes, + CryptoUnitUtils.gunzip(CryptoUnitUtils.decrypt_AES_CBC((byte[]) data[2], runtime))); + } + + @Test + public void testInsert_Small() throws SQLException { + + ObjectContext context = runtime.newContext(); + + // make sure compression is on... + byte[] cryptoBytes = CryptoUnitUtils.bytesOfSize(GZIP_THRESHOLD - 20); + + Table2 t1 = context.newObject(Table2.class); + t1.setPlainBytes("plain_1".getBytes()); + t1.setCryptoBytes(cryptoBytes); + + context.commitChanges(); + + Object[] data = table2.select(); + assertArrayEquals("plain_1".getBytes(), (byte[]) data[1]); + + Header h = Header.create((byte[]) data[2], 0); + assertFalse(h.isCompressed()); + assertArrayEquals(cryptoBytes, CryptoUnitUtils.decrypt_AES_CBC((byte[]) data[2], runtime)); + } + + @Test + public void testInsert_MultipleObjects() throws SQLException { + + ObjectContext context = runtime.newContext(); + + // make sure compression is on... + byte[] cryptoBytes1 = CryptoUnitUtils.bytesOfSize(GZIP_THRESHOLD + 101); + byte[] cryptoBytes2 = CryptoUnitUtils.bytesOfSize(GZIP_THRESHOLD + 102); + + Table2 t1 = context.newObject(Table2.class); + t1.setPlainBytes("a".getBytes()); + t1.setCryptoBytes(cryptoBytes1); + + Table2 t2 = context.newObject(Table2.class); + t2.setPlainBytes("b".getBytes()); + t2.setCryptoBytes(cryptoBytes2); + + Table2 t3 = context.newObject(Table2.class); + t3.setPlainBytes("c".getBytes()); + t3.setCryptoBytes(null); + + context.commitChanges(); + + List<Object[]> data = table2.selectAll(); + assertEquals(3, data.size()); + + Map<String, byte[]> cipherByPlain = new HashMap<>(); + for (Object[] r : data) { + cipherByPlain.put(new String((byte[]) r[1]), (byte[]) r[2]); + } + + assertArrayEquals(cryptoBytes1, + CryptoUnitUtils.gunzip(CryptoUnitUtils.decrypt_AES_CBC(cipherByPlain.get("a"), runtime))); + assertArrayEquals(cryptoBytes2, + CryptoUnitUtils.gunzip(CryptoUnitUtils.decrypt_AES_CBC(cipherByPlain.get("b"), runtime))); + assertNull(cipherByPlain.get("c")); + } + + @Test + public void test_SelectQuery() throws SQLException { + + // make sure compression is on... + byte[] cryptoBytes1 = CryptoUnitUtils.bytesOfSize(GZIP_THRESHOLD + 101); + byte[] cryptoBytes2 = CryptoUnitUtils.bytesOfSize(GZIP_THRESHOLD + 102); + + ObjectContext context = runtime.newContext(); + + Table2 t1 = context.newObject(Table2.class); + t1.setPlainBytes("a".getBytes()); + t1.setCryptoBytes(cryptoBytes1); + + Table2 t2 = context.newObject(Table2.class); + t2.setPlainBytes("b".getBytes()); + t2.setCryptoBytes(cryptoBytes2); + + Table2 t3 = context.newObject(Table2.class); + t3.setPlainBytes("c".getBytes()); + t3.setCryptoBytes(null); + + context.commitChanges(); + + SelectQuery<Table2> select = SelectQuery.query(Table2.class); + select.addOrdering(Table2.PLAIN_BYTES.asc()); + + List<Table2> result = runtime.newContext().select(select); + + assertEquals(3, result.size()); + assertArrayEquals(cryptoBytes1, result.get(0).getCryptoBytes()); + assertArrayEquals(cryptoBytes2, result.get(1).getCryptoBytes()); + assertArrayEquals(null, result.get(2).getCryptoBytes()); + } + +} http://git-wip-us.apache.org/repos/asf/cayenne/blob/30c2c6f1/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Runtime_AES128_GZIP_Test.java ---------------------------------------------------------------------- diff --git a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Runtime_AES128_GZIP_Test.java b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Runtime_AES128_GZIP_Test.java deleted file mode 100644 index 035578d..0000000 --- a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Runtime_AES128_GZIP_Test.java +++ /dev/null @@ -1,166 +0,0 @@ -/***************************************************************** - * 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.cayenne.crypto; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.sql.SQLException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.cayenne.ObjectContext; -import org.apache.cayenne.crypto.db.Table2; -import org.apache.cayenne.crypto.transformer.bytes.Header; -import org.apache.cayenne.crypto.unit.CryptoUnitUtils; -import org.apache.cayenne.query.SelectQuery; -import org.junit.Before; -import org.junit.Test; - -public class Runtime_AES128_GZIP_Test extends Runtime_AES128_Base { - - private static final int GZIP_THRESHOLD = 150; - - @Before - public void setUp() throws Exception { - super.setUp(true); - } - - @Test - public void testInsert() throws SQLException { - - ObjectContext context = runtime.newContext(); - - // make sure compression is on... - byte[] cryptoBytes = CryptoUnitUtils.bytesOfSize(GZIP_THRESHOLD + 100); - - Table2 t1 = context.newObject(Table2.class); - t1.setPlainBytes("plain_1".getBytes()); - t1.setCryptoBytes(cryptoBytes); - - context.commitChanges(); - - Object[] data = table2.select(); - assertArrayEquals("plain_1".getBytes(), (byte[]) data[1]); - - Header h = Header.create((byte[]) data[2], 0); - assertTrue(h.isCompressed()); - assertArrayEquals(cryptoBytes, - CryptoUnitUtils.gunzip(CryptoUnitUtils.decrypt_AES_CBC((byte[]) data[2], runtime))); - } - - @Test - public void testInsert_Small() throws SQLException { - - ObjectContext context = runtime.newContext(); - - // make sure compression is on... - byte[] cryptoBytes = CryptoUnitUtils.bytesOfSize(GZIP_THRESHOLD - 20); - - Table2 t1 = context.newObject(Table2.class); - t1.setPlainBytes("plain_1".getBytes()); - t1.setCryptoBytes(cryptoBytes); - - context.commitChanges(); - - Object[] data = table2.select(); - assertArrayEquals("plain_1".getBytes(), (byte[]) data[1]); - - Header h = Header.create((byte[]) data[2], 0); - assertFalse(h.isCompressed()); - assertArrayEquals(cryptoBytes, CryptoUnitUtils.decrypt_AES_CBC((byte[]) data[2], runtime)); - } - - @Test - public void testInsert_MultipleObjects() throws SQLException { - - ObjectContext context = runtime.newContext(); - - // make sure compression is on... - byte[] cryptoBytes1 = CryptoUnitUtils.bytesOfSize(GZIP_THRESHOLD + 101); - byte[] cryptoBytes2 = CryptoUnitUtils.bytesOfSize(GZIP_THRESHOLD + 102); - - Table2 t1 = context.newObject(Table2.class); - t1.setPlainBytes("a".getBytes()); - t1.setCryptoBytes(cryptoBytes1); - - Table2 t2 = context.newObject(Table2.class); - t2.setPlainBytes("b".getBytes()); - t2.setCryptoBytes(cryptoBytes2); - - Table2 t3 = context.newObject(Table2.class); - t3.setPlainBytes("c".getBytes()); - t3.setCryptoBytes(null); - - context.commitChanges(); - - List<Object[]> data = table2.selectAll(); - assertEquals(3, data.size()); - - Map<String, byte[]> cipherByPlain = new HashMap<>(); - for (Object[] r : data) { - cipherByPlain.put(new String((byte[]) r[1]), (byte[]) r[2]); - } - - assertArrayEquals(cryptoBytes1, - CryptoUnitUtils.gunzip(CryptoUnitUtils.decrypt_AES_CBC(cipherByPlain.get("a"), runtime))); - assertArrayEquals(cryptoBytes2, - CryptoUnitUtils.gunzip(CryptoUnitUtils.decrypt_AES_CBC(cipherByPlain.get("b"), runtime))); - assertNull(cipherByPlain.get("c")); - } - - @Test - public void test_SelectQuery() throws SQLException { - - // make sure compression is on... - byte[] cryptoBytes1 = CryptoUnitUtils.bytesOfSize(GZIP_THRESHOLD + 101); - byte[] cryptoBytes2 = CryptoUnitUtils.bytesOfSize(GZIP_THRESHOLD + 102); - - ObjectContext context = runtime.newContext(); - - Table2 t1 = context.newObject(Table2.class); - t1.setPlainBytes("a".getBytes()); - t1.setCryptoBytes(cryptoBytes1); - - Table2 t2 = context.newObject(Table2.class); - t2.setPlainBytes("b".getBytes()); - t2.setCryptoBytes(cryptoBytes2); - - Table2 t3 = context.newObject(Table2.class); - t3.setPlainBytes("c".getBytes()); - t3.setCryptoBytes(null); - - context.commitChanges(); - - SelectQuery<Table2> select = SelectQuery.query(Table2.class); - select.addOrdering(Table2.PLAIN_BYTES.asc()); - - List<Table2> result = runtime.newContext().select(select); - - assertEquals(3, result.size()); - assertArrayEquals(cryptoBytes1, result.get(0).getCryptoBytes()); - assertArrayEquals(cryptoBytes2, result.get(1).getCryptoBytes()); - assertArrayEquals(null, result.get(2).getCryptoBytes()); - } - -} http://git-wip-us.apache.org/repos/asf/cayenne/blob/30c2c6f1/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Runtime_AES128_IT.java ---------------------------------------------------------------------- diff --git a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Runtime_AES128_IT.java b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Runtime_AES128_IT.java new file mode 100644 index 0000000..e337d65 --- /dev/null +++ b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Runtime_AES128_IT.java @@ -0,0 +1,122 @@ +/***************************************************************** + * 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.cayenne.crypto; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.cayenne.ObjectContext; +import org.apache.cayenne.crypto.db.Table2; +import org.apache.cayenne.crypto.unit.CryptoUnitUtils; +import org.apache.cayenne.query.SelectQuery; +import org.junit.Before; +import org.junit.Test; + +public class Runtime_AES128_IT extends Runtime_AES128_Base { + + @Before + public void setUp() throws Exception { + super.setUp(false); + } + + @Test + public void testInsert() throws SQLException { + + ObjectContext context = runtime.newContext(); + + Table2 t1 = context.newObject(Table2.class); + t1.setPlainBytes("plain_1".getBytes()); + t1.setCryptoBytes("crypto_1".getBytes()); + + context.commitChanges(); + + Object[] data = table2.select(); + assertArrayEquals("plain_1".getBytes(), (byte[]) data[1]); + assertArrayEquals("crypto_1".getBytes(), CryptoUnitUtils.decrypt_AES_CBC((byte[]) data[2], runtime)); + } + + @Test + public void testInsert_MultipleObjects() throws SQLException { + + ObjectContext context = runtime.newContext(); + + Table2 t1 = context.newObject(Table2.class); + t1.setPlainBytes("a".getBytes()); + t1.setCryptoBytes("crypto_1".getBytes()); + + Table2 t2 = context.newObject(Table2.class); + t2.setPlainBytes("b".getBytes()); + t2.setCryptoBytes("crypto_2".getBytes()); + + Table2 t3 = context.newObject(Table2.class); + t3.setPlainBytes("c".getBytes()); + t3.setCryptoBytes(null); + + context.commitChanges(); + + List<Object[]> data = table2.selectAll(); + assertEquals(3, data.size()); + + Map<String, byte[]> cipherByPlain = new HashMap<>(); + for (Object[] r : data) { + cipherByPlain.put(new String((byte[]) r[1]), (byte[]) r[2]); + } + + assertArrayEquals("crypto_1".getBytes(), CryptoUnitUtils.decrypt_AES_CBC(cipherByPlain.get("a"), runtime)); + assertArrayEquals("crypto_2".getBytes(), CryptoUnitUtils.decrypt_AES_CBC(cipherByPlain.get("b"), runtime)); + assertNull(cipherByPlain.get("c")); + } + + @Test + public void test_SelectQuery() throws SQLException { + + ObjectContext context = runtime.newContext(); + + Table2 t1 = context.newObject(Table2.class); + t1.setPlainBytes("a".getBytes()); + t1.setCryptoBytes("crypto_1".getBytes()); + + Table2 t2 = context.newObject(Table2.class); + t2.setPlainBytes("b".getBytes()); + t2.setCryptoBytes("crypto_2".getBytes()); + + Table2 t3 = context.newObject(Table2.class); + t3.setPlainBytes("c".getBytes()); + t3.setCryptoBytes(null); + + context.commitChanges(); + + SelectQuery<Table2> select = SelectQuery.query(Table2.class); + select.addOrdering(Table2.PLAIN_BYTES.asc()); + + List<Table2> result = runtime.newContext().select(select); + + assertEquals(3, result.size()); + assertArrayEquals("crypto_1".getBytes(), result.get(0).getCryptoBytes()); + assertArrayEquals("crypto_2".getBytes(), result.get(1).getCryptoBytes()); + assertArrayEquals(null, result.get(2).getCryptoBytes()); + } + +} http://git-wip-us.apache.org/repos/asf/cayenne/blob/30c2c6f1/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Runtime_AES128_Test.java ---------------------------------------------------------------------- diff --git a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Runtime_AES128_Test.java b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Runtime_AES128_Test.java deleted file mode 100644 index 61b3453..0000000 --- a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Runtime_AES128_Test.java +++ /dev/null @@ -1,122 +0,0 @@ -/***************************************************************** - * 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.cayenne.crypto; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import java.sql.SQLException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.cayenne.ObjectContext; -import org.apache.cayenne.crypto.db.Table2; -import org.apache.cayenne.crypto.unit.CryptoUnitUtils; -import org.apache.cayenne.query.SelectQuery; -import org.junit.Before; -import org.junit.Test; - -public class Runtime_AES128_Test extends Runtime_AES128_Base { - - @Before - public void setUp() throws Exception { - super.setUp(false); - } - - @Test - public void testInsert() throws SQLException { - - ObjectContext context = runtime.newContext(); - - Table2 t1 = context.newObject(Table2.class); - t1.setPlainBytes("plain_1".getBytes()); - t1.setCryptoBytes("crypto_1".getBytes()); - - context.commitChanges(); - - Object[] data = table2.select(); - assertArrayEquals("plain_1".getBytes(), (byte[]) data[1]); - assertArrayEquals("crypto_1".getBytes(), CryptoUnitUtils.decrypt_AES_CBC((byte[]) data[2], runtime)); - } - - @Test - public void testInsert_MultipleObjects() throws SQLException { - - ObjectContext context = runtime.newContext(); - - Table2 t1 = context.newObject(Table2.class); - t1.setPlainBytes("a".getBytes()); - t1.setCryptoBytes("crypto_1".getBytes()); - - Table2 t2 = context.newObject(Table2.class); - t2.setPlainBytes("b".getBytes()); - t2.setCryptoBytes("crypto_2".getBytes()); - - Table2 t3 = context.newObject(Table2.class); - t3.setPlainBytes("c".getBytes()); - t3.setCryptoBytes(null); - - context.commitChanges(); - - List<Object[]> data = table2.selectAll(); - assertEquals(3, data.size()); - - Map<String, byte[]> cipherByPlain = new HashMap<>(); - for (Object[] r : data) { - cipherByPlain.put(new String((byte[]) r[1]), (byte[]) r[2]); - } - - assertArrayEquals("crypto_1".getBytes(), CryptoUnitUtils.decrypt_AES_CBC(cipherByPlain.get("a"), runtime)); - assertArrayEquals("crypto_2".getBytes(), CryptoUnitUtils.decrypt_AES_CBC(cipherByPlain.get("b"), runtime)); - assertNull(cipherByPlain.get("c")); - } - - @Test - public void test_SelectQuery() throws SQLException { - - ObjectContext context = runtime.newContext(); - - Table2 t1 = context.newObject(Table2.class); - t1.setPlainBytes("a".getBytes()); - t1.setCryptoBytes("crypto_1".getBytes()); - - Table2 t2 = context.newObject(Table2.class); - t2.setPlainBytes("b".getBytes()); - t2.setCryptoBytes("crypto_2".getBytes()); - - Table2 t3 = context.newObject(Table2.class); - t3.setPlainBytes("c".getBytes()); - t3.setCryptoBytes(null); - - context.commitChanges(); - - SelectQuery<Table2> select = SelectQuery.query(Table2.class); - select.addOrdering(Table2.PLAIN_BYTES.asc()); - - List<Table2> result = runtime.newContext().select(select); - - assertEquals(3, result.size()); - assertArrayEquals("crypto_1".getBytes(), result.get(0).getCryptoBytes()); - assertArrayEquals("crypto_2".getBytes(), result.get(1).getCryptoBytes()); - assertArrayEquals(null, result.get(2).getCryptoBytes()); - } - -} http://git-wip-us.apache.org/repos/asf/cayenne/blob/30c2c6f1/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/DefaultValueTransformerFactoryIT.java ---------------------------------------------------------------------- diff --git a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/DefaultValueTransformerFactoryIT.java b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/DefaultValueTransformerFactoryIT.java new file mode 100644 index 0000000..1bb896a --- /dev/null +++ b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/DefaultValueTransformerFactoryIT.java @@ -0,0 +1,168 @@ +/***************************************************************** + * 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.cayenne.crypto.transformer.value; + +import org.apache.cayenne.configuration.server.ServerRuntime; +import org.apache.cayenne.crypto.key.KeySource; +import org.apache.cayenne.map.DbAttribute; +import org.apache.cayenne.map.DbEntity; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.sql.Types; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class DefaultValueTransformerFactoryIT { + + private static DbEntity t1; + private static DbEntity t2; + private static DbEntity t3; + + @BeforeClass + public static void beforeClass() throws Exception { + ServerRuntime runtime = new ServerRuntime("cayenne-crypto.xml"); + t1 = runtime.getChannel().getEntityResolver().getDbEntity("TABLE1"); + t2 = runtime.getChannel().getEntityResolver().getDbEntity("TABLE2"); + t3 = runtime.getChannel().getEntityResolver().getDbEntity("TABLE3"); + } + + @Test + public void testGetJavaType() { + + DefaultValueTransformerFactory f = new DefaultValueTransformerFactory(mock(KeySource.class)); + + DbAttribute t1_ct = t1.getAttribute("CRYPTO_STRING"); + assertEquals("java.lang.String", f.getJavaType(t1_ct)); + + DbAttribute t2_cb = t2.getAttribute("CRYPTO_BYTES"); + assertEquals("byte[]", f.getJavaType(t2_cb)); + + DbEntity fakeEntity = mock(DbEntity.class); + when(fakeEntity.getDataMap()).thenReturn(t1.getDataMap()); + + DbAttribute fakeA1 = mock(DbAttribute.class); + when(fakeA1.getName()).thenReturn("fake1"); + when(fakeA1.getEntity()).thenReturn(fakeEntity); + when(fakeA1.getType()).thenReturn(Types.VARBINARY); + + assertEquals("byte[]", f.getJavaType(fakeA1)); + + DbAttribute fakeA2 = mock(DbAttribute.class); + when(fakeA2.getName()).thenReturn("fake2"); + when(fakeA2.getEntity()).thenReturn(fakeEntity); + when(fakeA2.getType()).thenReturn(Types.VARCHAR); + + assertEquals("java.lang.String", f.getJavaType(fakeA2)); + } + + @Test + public void testCreateEncryptor() { + DefaultValueTransformerFactory f = new DefaultValueTransformerFactory(mock(KeySource.class)); + + DbAttribute t1_ct = t1.getAttribute("CRYPTO_STRING"); + + ValueEncryptor t1 = f.createEncryptor(t1_ct); + assertNotNull(t1); + assertTrue(t1 instanceof DefaultValueEncryptor); + assertSame(Utf8StringConverter.INSTANCE, ((DefaultValueEncryptor) t1).getPreConverter()); + assertSame(Base64StringConverter.INSTANCE, ((DefaultValueEncryptor) t1).getPostConverter()); + + DbAttribute t2_cb = t2.getAttribute("CRYPTO_BYTES"); + + ValueEncryptor t2 = f.createEncryptor(t2_cb); + assertNotNull(t2); + assertTrue(t2 instanceof DefaultValueEncryptor); + assertSame(BytesToBytesConverter.INSTANCE, ((DefaultValueEncryptor) t2).getPreConverter()); + assertSame(BytesToBytesConverter.INSTANCE, ((DefaultValueEncryptor) t2).getPostConverter()); + } + + @Test + public void testCreateDecryptor() { + DefaultValueTransformerFactory f = new DefaultValueTransformerFactory(mock(KeySource.class)); + + DbAttribute t1_ct = t1.getAttribute("CRYPTO_STRING"); + + ValueDecryptor t1 = f.createDecryptor(t1_ct); + assertNotNull(t1); + assertTrue(t1 instanceof DefaultValueDecryptor); + assertSame(Base64StringConverter.INSTANCE, ((DefaultValueDecryptor) t1).getPreConverter()); + assertSame(Utf8StringConverter.INSTANCE, ((DefaultValueDecryptor) t1).getPostConverter()); + + DbAttribute t2_cb = t2.getAttribute("CRYPTO_BYTES"); + + ValueDecryptor t2 = f.createDecryptor(t2_cb); + assertNotNull(t2); + assertTrue(t2 instanceof DefaultValueDecryptor); + assertSame(BytesToBytesConverter.INSTANCE, ((DefaultValueDecryptor) t2).getPreConverter()); + assertSame(BytesToBytesConverter.INSTANCE, ((DefaultValueDecryptor) t2).getPostConverter()); + + DbAttribute t3_cb = t3.getAttribute("CRYPTO_BYTES"); + + ValueDecryptor t3 = f.createDecryptor(t3_cb); + assertNotNull(t3); + assertTrue(t3 instanceof DefaultValueDecryptor); + assertSame(BytesToBytesConverter.INSTANCE, ((DefaultValueDecryptor) t3).getPreConverter()); + assertSame(Utf8StringConverter.INSTANCE, ((DefaultValueDecryptor) t3).getPostConverter()); + } + + @Test + public void testEncryptor() { + DefaultValueTransformerFactory f = new DefaultValueTransformerFactory(mock(KeySource.class)); + + DbAttribute t1_ct = t1.getAttribute("CRYPTO_STRING"); + + ValueEncryptor t1 = f.encryptor(t1_ct); + assertNotNull(t1); + assertSame(t1, f.encryptor(t1_ct)); + assertSame(t1, f.encryptor(t1_ct)); + + DbAttribute t2_cb = t2.getAttribute("CRYPTO_BYTES"); + + ValueEncryptor t2 = f.encryptor(t2_cb); + assertNotNull(t2); + assertSame(t2, f.encryptor(t2_cb)); + assertSame(t2, f.encryptor(t2_cb)); + } + + @Test + public void testDecryptor() { + DefaultValueTransformerFactory f = new DefaultValueTransformerFactory(mock(KeySource.class)); + + DbAttribute t1_ct = t1.getAttribute("CRYPTO_STRING"); + + ValueDecryptor t1 = f.decryptor(t1_ct); + assertNotNull(t1); + assertSame(t1, f.decryptor(t1_ct)); + assertSame(t1, f.decryptor(t1_ct)); + + DbAttribute t2_cb = t2.getAttribute("CRYPTO_BYTES"); + + ValueDecryptor t2 = f.decryptor(t2_cb); + assertNotNull(t2); + assertSame(t2, f.decryptor(t2_cb)); + assertSame(t2, f.decryptor(t2_cb)); + } + +} http://git-wip-us.apache.org/repos/asf/cayenne/blob/30c2c6f1/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/DefaultValueTransformerFactoryTest.java ---------------------------------------------------------------------- diff --git a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/DefaultValueTransformerFactoryTest.java b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/DefaultValueTransformerFactoryTest.java deleted file mode 100644 index 5e9120e..0000000 --- a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/DefaultValueTransformerFactoryTest.java +++ /dev/null @@ -1,168 +0,0 @@ -/***************************************************************** - * 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.cayenne.crypto.transformer.value; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.sql.Types; - -import org.apache.cayenne.configuration.server.ServerRuntime; -import org.apache.cayenne.crypto.key.KeySource; -import org.apache.cayenne.map.DbAttribute; -import org.apache.cayenne.map.DbEntity; -import org.junit.Before; -import org.junit.Test; - -public class DefaultValueTransformerFactoryTest { - - private DbEntity t1; - private DbEntity t2; - private DbEntity t3; - - @Before - public void setUp() throws Exception { - ServerRuntime runtime = new ServerRuntime("cayenne-crypto.xml"); - this.t1 = runtime.getChannel().getEntityResolver().getDbEntity("TABLE1"); - this.t2 = runtime.getChannel().getEntityResolver().getDbEntity("TABLE2"); - this.t3 = runtime.getChannel().getEntityResolver().getDbEntity("TABLE3"); - } - - @Test - public void testGetJavaType() { - - DefaultValueTransformerFactory f = new DefaultValueTransformerFactory(mock(KeySource.class)); - - DbAttribute t1_ct = t1.getAttribute("CRYPTO_STRING"); - assertEquals("java.lang.String", f.getJavaType(t1_ct)); - - DbAttribute t2_cb = t2.getAttribute("CRYPTO_BYTES"); - assertEquals("byte[]", f.getJavaType(t2_cb)); - - DbEntity fakeEntity = mock(DbEntity.class); - when(fakeEntity.getDataMap()).thenReturn(t1.getDataMap()); - - DbAttribute fakeA1 = mock(DbAttribute.class); - when(fakeA1.getName()).thenReturn("fake1"); - when(fakeA1.getEntity()).thenReturn(fakeEntity); - when(fakeA1.getType()).thenReturn(Types.VARBINARY); - - assertEquals("byte[]", f.getJavaType(fakeA1)); - - DbAttribute fakeA2 = mock(DbAttribute.class); - when(fakeA2.getName()).thenReturn("fake2"); - when(fakeA2.getEntity()).thenReturn(fakeEntity); - when(fakeA2.getType()).thenReturn(Types.VARCHAR); - - assertEquals("java.lang.String", f.getJavaType(fakeA2)); - } - - @Test - public void testCreateEncryptor() { - DefaultValueTransformerFactory f = new DefaultValueTransformerFactory(mock(KeySource.class)); - - DbAttribute t1_ct = t1.getAttribute("CRYPTO_STRING"); - - ValueEncryptor t1 = f.createEncryptor(t1_ct); - assertNotNull(t1); - assertTrue(t1 instanceof DefaultValueEncryptor); - assertSame(Utf8StringConverter.INSTANCE, ((DefaultValueEncryptor) t1).getPreConverter()); - assertSame(Base64StringConverter.INSTANCE, ((DefaultValueEncryptor) t1).getPostConverter()); - - DbAttribute t2_cb = t2.getAttribute("CRYPTO_BYTES"); - - ValueEncryptor t2 = f.createEncryptor(t2_cb); - assertNotNull(t2); - assertTrue(t2 instanceof DefaultValueEncryptor); - assertSame(BytesToBytesConverter.INSTANCE, ((DefaultValueEncryptor) t2).getPreConverter()); - assertSame(BytesToBytesConverter.INSTANCE, ((DefaultValueEncryptor) t2).getPostConverter()); - } - - @Test - public void testCreateDecryptor() { - DefaultValueTransformerFactory f = new DefaultValueTransformerFactory(mock(KeySource.class)); - - DbAttribute t1_ct = t1.getAttribute("CRYPTO_STRING"); - - ValueDecryptor t1 = f.createDecryptor(t1_ct); - assertNotNull(t1); - assertTrue(t1 instanceof DefaultValueDecryptor); - assertSame(Base64StringConverter.INSTANCE, ((DefaultValueDecryptor) t1).getPreConverter()); - assertSame(Utf8StringConverter.INSTANCE, ((DefaultValueDecryptor) t1).getPostConverter()); - - DbAttribute t2_cb = t2.getAttribute("CRYPTO_BYTES"); - - ValueDecryptor t2 = f.createDecryptor(t2_cb); - assertNotNull(t2); - assertTrue(t2 instanceof DefaultValueDecryptor); - assertSame(BytesToBytesConverter.INSTANCE, ((DefaultValueDecryptor) t2).getPreConverter()); - assertSame(BytesToBytesConverter.INSTANCE, ((DefaultValueDecryptor) t2).getPostConverter()); - - DbAttribute t3_cb = t3.getAttribute("CRYPTO_BYTES"); - - ValueDecryptor t3 = f.createDecryptor(t3_cb); - assertNotNull(t3); - assertTrue(t3 instanceof DefaultValueDecryptor); - assertSame(BytesToBytesConverter.INSTANCE, ((DefaultValueDecryptor) t3).getPreConverter()); - assertSame(Utf8StringConverter.INSTANCE, ((DefaultValueDecryptor) t3).getPostConverter()); - } - - @Test - public void testEncryptor() { - DefaultValueTransformerFactory f = new DefaultValueTransformerFactory(mock(KeySource.class)); - - DbAttribute t1_ct = t1.getAttribute("CRYPTO_STRING"); - - ValueEncryptor t1 = f.encryptor(t1_ct); - assertNotNull(t1); - assertSame(t1, f.encryptor(t1_ct)); - assertSame(t1, f.encryptor(t1_ct)); - - DbAttribute t2_cb = t2.getAttribute("CRYPTO_BYTES"); - - ValueEncryptor t2 = f.encryptor(t2_cb); - assertNotNull(t2); - assertSame(t2, f.encryptor(t2_cb)); - assertSame(t2, f.encryptor(t2_cb)); - } - - @Test - public void testDecryptor() { - DefaultValueTransformerFactory f = new DefaultValueTransformerFactory(mock(KeySource.class)); - - DbAttribute t1_ct = t1.getAttribute("CRYPTO_STRING"); - - ValueDecryptor t1 = f.decryptor(t1_ct); - assertNotNull(t1); - assertSame(t1, f.decryptor(t1_ct)); - assertSame(t1, f.decryptor(t1_ct)); - - DbAttribute t2_cb = t2.getAttribute("CRYPTO_BYTES"); - - ValueDecryptor t2 = f.decryptor(t2_cb); - assertNotNull(t2); - assertSame(t2, f.decryptor(t2_cb)); - assertSame(t2, f.decryptor(t2_cb)); - } - -}
