From 0c76b25ef57b1079bcccbc5f7ae3dce17a21c5e7 Mon Sep 17 00:00:00 2001 From: Jeremy Bauer Date: Wed, 24 Feb 2010 16:01:26 +0000 Subject: [PATCH] OPENJPA-1529 Committing L2 shared cache mode test cases contributed by Dianne Richards. git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@915838 13f79535-47bb-0310-9956-ffa450edef68 --- .../cache/jpa/AbstractCacheTestCase.java | 20 +++- .../cache/jpa/TestCacheModeAll.java | 2 +- .../jpa/TestCacheModeDisableSelective.java | 2 +- .../cache/jpa/TestCacheModeEmpty.java | 2 +- .../jpa/TestCacheModeEnableSelective.java | 2 +- .../cache/jpa/TestCacheModeInvalid.java | 59 +++++++++++ .../cache/jpa/TestCacheModeNone.java | 2 +- .../cache/jpa/TestCacheModeUnspecified.java | 2 +- .../cache/jpa/TestPropertyCacheModeAll.java | 86 ++++++++++++++++ ...TestPropertyCacheModeDisableSelective.java | 94 ++++++++++++++++++ .../TestPropertyCacheModeEnableSelective.java | 99 +++++++++++++++++++ .../jpa/TestPropertyCacheModeInvalid.java | 56 +++++++++++ .../cache/jpa/TestPropertyCacheModeNone.java | 92 +++++++++++++++++ .../jpa/TestPropertyCacheModeUnspecified.java | 85 ++++++++++++++++ .../META-INF/caching-persistence-invalid.xml | 34 +++++++ 15 files changed, 626 insertions(+), 11 deletions(-) create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeInvalid.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeAll.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeDisableSelective.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeEnableSelective.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeInvalid.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeNone.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeUnspecified.java create mode 100644 openjpa-persistence-jdbc/src/test/resources/META-INF/caching-persistence-invalid.xml diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheTestCase.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheTestCase.java index 68f1305de..b24f768c8 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheTestCase.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheTestCase.java @@ -19,6 +19,8 @@ package org.apache.openjpa.persistence.cache.jpa; import java.lang.reflect.Modifier; +import java.util.Map; +import java.util.Set; import javax.persistence.EntityManager; @@ -60,13 +62,21 @@ public abstract class AbstractCacheTestCase extends AbstractPersistenceTestCase em.close(); } - public OpenJPAEntityManagerFactorySPI createEntityManagerFactory(String puName) { + public OpenJPAEntityManagerFactorySPI createEntityManagerFactory(String puName, + Map additionalProperties) { + Map propertiesMap = getPropertiesMap("openjpa.DataCache", "true", + "openjpa.QueryCache", "true", + "openjpa.RemoteCommitProvider", "sjvm", persistentTypes, + "openjpa.jdbc.JDBCListeners", new JDBCListener [] { getListener() }); + if (additionalProperties != null) { + Set keys = additionalProperties.keySet(); + for (String key : keys) { + propertiesMap.put(key, additionalProperties.get(key)); + } + } OpenJPAEntityManagerFactorySPI emf = (OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.createEntityManagerFactory(puName, - "META-INF/caching-persistence.xml", getPropertiesMap("openjpa.DataCache", "true", - "openjpa.QueryCache", "true", - "openjpa.RemoteCommitProvider", "sjvm", persistentTypes, - "openjpa.jdbc.JDBCListeners", new JDBCListener [] { getListener() } )); + "META-INF/caching-persistence.xml", propertiesMap ); return emf; } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAll.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAll.java index f504a6d29..f6746ac71 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAll.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAll.java @@ -39,7 +39,7 @@ public class TestCacheModeAll extends AbstractCacheModeTestCase { @Override public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() { if (emf == null) { - emf = createEntityManagerFactory("cache-mode-all"); + emf = createEntityManagerFactory("cache-mode-all",null); assertNotNull(emf); cache = emf.getCache(); assertNotNull(cache); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelective.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelective.java index c4007e4ba..787498ed6 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelective.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelective.java @@ -47,7 +47,7 @@ public class TestCacheModeDisableSelective extends AbstractCacheModeTestCase { @Override public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() { if (emf == null) { - emf = createEntityManagerFactory("cache-mode-disable"); + emf = createEntityManagerFactory("cache-mode-disable", null); assertNotNull(emf); cache = emf.getCache(); assertNotNull(cache); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEmpty.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEmpty.java index d8b73f76f..d3ccf33e4 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEmpty.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEmpty.java @@ -38,7 +38,7 @@ public class TestCacheModeEmpty extends AbstractCacheModeTestCase { @Override public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() { if (emf == null) { - emf = createEntityManagerFactory("cache-mode-empty"); + emf = createEntityManagerFactory("cache-mode-empty", null); assertNotNull(emf); cache = emf.getCache(); assertNotNull(cache); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelective.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelective.java index 2ed9effe5..5ec5bacb8 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelective.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelective.java @@ -47,7 +47,7 @@ public class TestCacheModeEnableSelective extends AbstractCacheModeTestCase { @Override public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() { if (emf == null) { - emf = createEntityManagerFactory("cache-mode-enable"); + emf = createEntityManagerFactory("cache-mode-enable", null); assertNotNull(emf); cache = emf.getCache(); assertNotNull(cache); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeInvalid.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeInvalid.java new file mode 100644 index 000000000..57220c059 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeInvalid.java @@ -0,0 +1,59 @@ +/* + * 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.openjpa.persistence.cache.jpa; + +import java.util.Map; + +import org.apache.openjpa.lib.jdbc.JDBCListener; +import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI; +import org.apache.openjpa.persistence.OpenJPAPersistence; + +public class TestCacheModeInvalid extends AbstractCacheTestCase { + + private static OpenJPAEntityManagerFactorySPI emf = null; + + @Override + public void setUp() {} + + public void testInvalidElement() { + try { + Map propertiesMap = getPropertiesMap("openjpa.DataCache", "true", + "openjpa.QueryCache", "true", + "openjpa.RemoteCommitProvider", "sjvm", persistentTypes, + "openjpa.jdbc.JDBCListeners", new JDBCListener [] { getListener() }); + emf = (OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.createEntityManagerFactory("cache-mode-invalid", + "META-INF/caching-persistence-invalid.xml", propertiesMap ); + } catch (Throwable e) { + assertException(e, org.apache.openjpa.util.GeneralException.class); + String msg = e.getMessage(); + assertTrue(msg.contains("org.xml.sax.SAXException")); + } + } + + @Override + public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() { + return null; + } + + @Override + public JDBCListener getListener() { + return null; + } + +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNone.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNone.java index 667190599..0d7c01446 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNone.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNone.java @@ -39,7 +39,7 @@ public class TestCacheModeNone extends AbstractCacheModeTestCase { @Override public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() { if (emf == null) { - emf = createEntityManagerFactory("cache-mode-none"); + emf = createEntityManagerFactory("cache-mode-none",null); assertNotNull(emf); cache = emf.getCache(); assertNotNull(cache); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeUnspecified.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeUnspecified.java index d1df5e31c..dc0f7f952 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeUnspecified.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeUnspecified.java @@ -38,7 +38,7 @@ public class TestCacheModeUnspecified extends AbstractCacheModeTestCase { @Override public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() { if (emf == null) { - emf = createEntityManagerFactory("cache-mode-unspecified"); + emf = createEntityManagerFactory("cache-mode-unspecified", null); assertNotNull(emf); cache = emf.getCache(); assertNotNull(cache); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeAll.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeAll.java new file mode 100644 index 000000000..7fd2a3c66 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeAll.java @@ -0,0 +1,86 @@ +/* + * 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.openjpa.persistence.cache.jpa; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.persistence.Cache; + +import org.apache.openjpa.lib.jdbc.JDBCListener; +import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI; + +public class TestPropertyCacheModeAll extends AbstractCacheModeTestCase { + + private static OpenJPAEntityManagerFactorySPI emf = null; + private static Cache cache = null; + private static List sql = new ArrayList(); + private static JDBCListener listener; + + private static Class[] expectedInCache = persistentTypes; + private static Class[] expectedNotInCache = {}; + + @Override + public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() { + if (emf == null) { + Map propertyMap = new HashMap(); + propertyMap.put("javax.persistence.sharedCache.mode", "ALL"); + emf = createEntityManagerFactory("cache-mode-empty",propertyMap); + assertNotNull(emf); + cache = emf.getCache(); + assertNotNull(cache); + } + return emf; + } + + public JDBCListener getListener() { + if (listener == null) { + listener = new Listener(); + } + return listener; + } + + public List getSql() { + return sql; + } + + public void testCacheables() { + assertCacheables(cache, true); + } + + public void testUncacheables() { + assertUncacheables(cache, true); + } + + public void testUnspecified() { + assertUnspecified(cache, true); + } + + @Override + protected Class[] getExpectedInCache() { + return expectedInCache; + } + + @Override + protected Class[] getExpectedNotInCache() { + return expectedNotInCache; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeDisableSelective.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeDisableSelective.java new file mode 100644 index 000000000..93ed63de1 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeDisableSelective.java @@ -0,0 +1,94 @@ +/* + * 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.openjpa.persistence.cache.jpa; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.persistence.Cache; + +import org.apache.openjpa.lib.jdbc.JDBCListener; +import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI; +import org.apache.openjpa.persistence.cache.jpa.model.CacheableEntity; +import org.apache.openjpa.persistence.cache.jpa.model.NegatedUncacheableEntity; +import org.apache.openjpa.persistence.cache.jpa.model.UncacheableEntity; +import org.apache.openjpa.persistence.cache.jpa.model.UnspecifiedEntity; +import org.apache.openjpa.persistence.cache.jpa.model.XmlCacheableEntity; +import org.apache.openjpa.persistence.cache.jpa.model.XmlUncacheableEntity; + +public class TestPropertyCacheModeDisableSelective extends AbstractCacheModeTestCase { + + private static OpenJPAEntityManagerFactorySPI emf = null; + private static Cache cache = null; + private static List sql = new ArrayList(); + private static JDBCListener listener; + + private static Class[] expectedInCache = + { CacheableEntity.class, XmlCacheableEntity.class, NegatedUncacheableEntity.class, UnspecifiedEntity.class, }; + private static Class[] expectedNotInCache = + { UncacheableEntity.class, XmlUncacheableEntity.class, }; + + @Override + public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() { + if (emf == null) { + Map propertyMap = new HashMap(); + propertyMap.put("javax.persistence.sharedCache.mode", "DISABLE_SELECTIVE"); + emf = createEntityManagerFactory("cache-mode-empty", propertyMap); + assertNotNull(emf); + cache = emf.getCache(); + assertNotNull(cache); + } + return emf; + } + + public JDBCListener getListener() { + if (listener == null) { + listener = new Listener(); + } + return listener; + } + + public List getSql() { + return sql; + } + + public void testCacheables() { + assertCacheables(cache, true); + } + + public void testUncacheables() { + assertUncacheables(cache, false); + } + + public void testUnspecified() { + assertUnspecified(cache, true); + } + + @Override + protected Class[] getExpectedInCache() { + return expectedInCache; + } + + @Override + protected Class[] getExpectedNotInCache() { + return expectedNotInCache; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeEnableSelective.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeEnableSelective.java new file mode 100644 index 000000000..dec116fbe --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeEnableSelective.java @@ -0,0 +1,99 @@ +/* + * 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.openjpa.persistence.cache.jpa; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.persistence.Cache; + +import org.apache.openjpa.lib.jdbc.JDBCListener; +import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI; +import org.apache.openjpa.persistence.cache.jpa.model.CacheableEntity; +import org.apache.openjpa.persistence.cache.jpa.model.NegatedUncacheableEntity; +import org.apache.openjpa.persistence.cache.jpa.model.UncacheableEntity; +import org.apache.openjpa.persistence.cache.jpa.model.UnspecifiedEntity; +import org.apache.openjpa.persistence.cache.jpa.model.XmlCacheableEntity; +import org.apache.openjpa.persistence.cache.jpa.model.XmlUncacheableEntity; + +public class TestPropertyCacheModeEnableSelective extends AbstractCacheModeTestCase { + + private static OpenJPAEntityManagerFactorySPI emf = null; + private static Cache cache = null; + private static List sql = new ArrayList(); + private static JDBCListener listener; + + private static Class[] expectedInCache = + { CacheableEntity.class, XmlCacheableEntity.class, NegatedUncacheableEntity.class, }; + private static Class[] expectedNotInCache = + { UncacheableEntity.class, XmlUncacheableEntity.class, UnspecifiedEntity.class, }; + + @Override + public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() { + if (emf == null) { + Map propertyMap = new HashMap(); + propertyMap.put("javax.persistence.sharedCache.mode", "ENABLE_SELECTIVE"); + emf = createEntityManagerFactory("cache-mode-empty", propertyMap); + assertNotNull(emf); + cache = emf.getCache(); + assertNotNull(cache); + } + return emf; + } + + public JDBCListener getListener() { + if (listener == null) { + listener = new Listener(); + } + return listener; + } + + public List getSql() { + return sql; + } + + @Override + protected Class[] getExpectedInCache() { + return expectedInCache; + } + + @Override + protected Class[] getExpectedNotInCache() { + return expectedNotInCache; + } + + // ======================================================================= + // Tests + // ======================================================================= + + public void testCacheables() { + assertCacheables(cache, true); + } + + public void testUncacheables() { + assertUncacheables(cache, false); + } + + public void testUnspecified() { + assertUnspecified(cache, false); + } + +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeInvalid.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeInvalid.java new file mode 100644 index 000000000..facd7a446 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeInvalid.java @@ -0,0 +1,56 @@ +/* + * 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.openjpa.persistence.cache.jpa; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.openjpa.lib.jdbc.JDBCListener; +import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI; + +public class TestPropertyCacheModeInvalid extends AbstractCacheTestCase { + + private static OpenJPAEntityManagerFactorySPI emf = null; + + @Override + public void setUp() {} + + public void testInvalidPropertyValue() { + try { + Map propertyMap = new HashMap(); + propertyMap.put("javax.persistence.sharedCache.mode", "INVALID"); + emf = createEntityManagerFactory("cache-mode-empty",propertyMap); + } catch (Throwable e) { + assertException(e, java.lang.IllegalArgumentException.class); + String msg = e.getMessage(); + assertTrue(msg.contains("javax.persistence.SharedCacheMode.INVALID")); + } + } + + @Override + public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() { + return null; + } + + @Override + public JDBCListener getListener() { + return null; + } + +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeNone.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeNone.java new file mode 100644 index 000000000..0504d7057 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeNone.java @@ -0,0 +1,92 @@ +/* + * 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.openjpa.persistence.cache.jpa; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.persistence.Cache; + +import org.apache.openjpa.lib.jdbc.JDBCListener; +import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI; + +public class TestPropertyCacheModeNone extends AbstractCacheModeTestCase { + + private static OpenJPAEntityManagerFactorySPI emf = null; + private static Cache cache = null; + private static List sql = new ArrayList(); + private static JDBCListener listener; + + private static Class[] expectedInCache = {}; + private static Class[] expectedNotInCache = persistentTypes; + + @Override + public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() { + if (emf == null) { + Map propertyMap = new HashMap(); + propertyMap.put("javax.persistence.sharedCache.mode", "NONE"); + emf = createEntityManagerFactory("cache-mode-empty", propertyMap); + assertNotNull(emf); + cache = emf.getCache(); + assertNotNull(cache); + } + return emf; + } + + public JDBCListener getListener() { + if (listener == null) { + listener = new Listener(); + } + return listener; + } + + public List getSql() { + return sql; + } + + @Override + public boolean getCacheEnabled() { + return false; + } + + public void testCacheables() { + assertCacheables(cache, false); + } + + public void testUncacheables() { + assertUncacheables(cache, false); + } + + public void testUnspecified() { + assertUnspecified(cache, false); + } + + @Override + protected Class[] getExpectedInCache() { + return expectedInCache; + } + + @Override + protected Class[] getExpectedNotInCache() { + return expectedNotInCache; + } + +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeUnspecified.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeUnspecified.java new file mode 100644 index 000000000..2c817778e --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeUnspecified.java @@ -0,0 +1,85 @@ +/* + * 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.openjpa.persistence.cache.jpa; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.persistence.Cache; + +import org.apache.openjpa.lib.jdbc.JDBCListener; +import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI; + +public class TestPropertyCacheModeUnspecified extends AbstractCacheModeTestCase { + private static OpenJPAEntityManagerFactorySPI emf = null; + private static Cache cache = null; + private static List sql = new ArrayList(); + private static JDBCListener listener; + + private static Class[] expectedInCache = persistentTypes; + private static Class[] expectedNotInCache = {}; + + @Override + public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() { + if (emf == null) { + Map propertyMap = new HashMap(); + propertyMap.put("javax.persistence.sharedCache.mode", "UNSPECIFIED"); + emf = createEntityManagerFactory("cache-mode-empty", propertyMap); + assertNotNull(emf); + cache = emf.getCache(); + assertNotNull(cache); + } + return emf; + } + + public JDBCListener getListener() { + if (listener == null) { + listener = new Listener(); + } + return listener; + } + + public List getSql() { + return sql; + } + + public void testCacheables() { + assertCacheables(cache, true); + } + + public void testUncacheables() { + assertUncacheables(cache, true); + } + + public void testUnspecified() { + assertUnspecified(cache, true); + } + + @Override + protected Class[] getExpectedInCache() { + return expectedInCache; + } + + @Override + protected Class[] getExpectedNotInCache() { + return expectedNotInCache; + } +} diff --git a/openjpa-persistence-jdbc/src/test/resources/META-INF/caching-persistence-invalid.xml b/openjpa-persistence-jdbc/src/test/resources/META-INF/caching-persistence-invalid.xml new file mode 100644 index 000000000..c01f83e62 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/resources/META-INF/caching-persistence-invalid.xml @@ -0,0 +1,34 @@ + + + + + + META-INF/caching-orm.xml + INVALID + + + + + + +