You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-commits@db.apache.org by mc...@apache.org on 2008/02/24 08:51:37 UTC
svn commit: r630599 - in /db/jdo/trunk/tck2/src: conf/
java/org/apache/jdo/tck/api/persistencemanagerfactory/config/
Author: mcaisse
Date: Sat Feb 23 23:51:35 2008
New Revision: 630599
URL: http://svn.apache.org/viewvc?rev=630599&view=rev
Log:
JDO-576 Tests for listeners defined through jdoconfig.xml or overrides.
Added:
db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/config/JDOConfigListener.java (with props)
db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/config/StoreListener.java (with props)
db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/config/StoreListenerGetInstance.java (with props)
Modified:
db/jdo/trunk/tck2/src/conf/jdori-jdoconfig.xml
db/jdo/trunk/tck2/src/conf/pmf.conf
Modified: db/jdo/trunk/tck2/src/conf/jdori-jdoconfig.xml
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/conf/jdori-jdoconfig.xml?rev=630599&r1=630598&r2=630599&view=diff
==============================================================================
--- db/jdo/trunk/tck2/src/conf/jdori-jdoconfig.xml (original)
+++ db/jdo/trunk/tck2/src/conf/jdori-jdoconfig.xml Sat Feb 23 23:51:35 2008
@@ -105,7 +105,7 @@
</persistence-manager-factory>
<persistence-manager-factory
- name="pmfTestInstanceLifecycleListener"
+ name="testInstanceLifecycleListenerStore"
class="org.jpox.PersistenceManagerFactoryImpl"
connection-driver-name="org.apache.derby.jdbc.EmbeddedDriver"
connection-url="jdbc:derby:jdotckdb"
@@ -131,11 +131,105 @@
<property name="org.jpox.implementationCreatorName" value="asm"/>
<instance-lifecycle-listener
- listener="listener.listener0"
- classes="classes.classes0"
+ listener="org.apache.jdo.tck.api.persistencemanagerfactory.config.StoreListener"
+ classes="org.apache.jdo.tck.pc.mylib.PCPoint"
/>
+ </persistence-manager-factory>
+
- </persistence-manager-factory>
-
-</jdoconfig>
+ <persistence-manager-factory
+ name="testInstanceLifecycleListenerStoreGetInstance"
+ class="org.jpox.PersistenceManagerFactoryImpl"
+ connection-driver-name="org.apache.derby.jdbc.EmbeddedDriver"
+ connection-url="jdbc:derby:jdotckdb"
+ connection-user-name="tckuser"
+ connection-password="tckuser"
+ optimistic="false"
+ restore-values="false"
+ retain-values="false"
+ >
+
+ <property name="javax.jdo.mapping.Schema" value="schemaDoesNotExist"/>
+ <property name="javax.jdo.option.Mapping" value="standard"/>
+ <property name="org.jpox.metadata.validate" value="false"/>
+ <property name="org.jpox.validateTables" value="false"/>
+ <property name="org.jpox.validateConstraints" value="false"/>
+ <property name="org.jpox.autoCreateSchema" value="false"/>
+ <property name="org.jpox.autoCreateTables" value="false"/>
+ <property name="org.jpox.autoCreateConstraints" value="false"/>
+ <property name="org.jpox.autoCreateColumns" value="false"/>
+ <property name="org.jpox.rdbms.CheckExistTablesOrViews" value="false"/>
+ <property name="org.jpox.autoStartMechanism" value="None"/>
+ <property name="org.jpox.connectionPoolingType" value="C3P0"/>
+ <property name="org.jpox.implementationCreatorName" value="asm"/>
+
+ <instance-lifecycle-listener
+ listener="org.apache.jdo.tck.api.persistencemanagerfactory.config.StoreListenerGetInstance"
+ classes="org.apache.jdo.tck.pc.mylib.PCPoint"
+ />
+ </persistence-manager-factory>
+
+ <persistence-manager-factory
+ name="testInstanceLifecycleListenerStoreOverrides"
+ class="org.jpox.PersistenceManagerFactoryImpl"
+ connection-driver-name="org.apache.derby.jdbc.EmbeddedDriver"
+ connection-url="jdbc:derby:jdotckdb"
+ connection-user-name="tckuser"
+ connection-password="tckuser"
+ optimistic="false"
+ restore-values="false"
+ retain-values="false"
+ >
+
+ <property name="javax.jdo.mapping.Schema" value="schemaDoesNotExist"/>
+ <property name="javax.jdo.option.Mapping" value="standard"/>
+ <property name="org.jpox.metadata.validate" value="false"/>
+ <property name="org.jpox.validateTables" value="false"/>
+ <property name="org.jpox.validateConstraints" value="false"/>
+ <property name="org.jpox.autoCreateSchema" value="false"/>
+ <property name="org.jpox.autoCreateTables" value="false"/>
+ <property name="org.jpox.autoCreateConstraints" value="false"/>
+ <property name="org.jpox.autoCreateColumns" value="false"/>
+ <property name="org.jpox.rdbms.CheckExistTablesOrViews" value="false"/>
+ <property name="org.jpox.autoStartMechanism" value="None"/>
+ <property name="org.jpox.connectionPoolingType" value="C3P0"/>
+ <property name="org.jpox.implementationCreatorName" value="asm"/>
+
+ />
+ </persistence-manager-factory>
+
+
+ <persistence-manager-factory
+ name="testInstanceLifecycleListenerClassesNull"
+ class="org.jpox.PersistenceManagerFactoryImpl"
+ connection-driver-name="org.apache.derby.jdbc.EmbeddedDriver"
+ connection-url="jdbc:derby:jdotckdb"
+ connection-user-name="tckuser"
+ connection-password="tckuser"
+ optimistic="false"
+ restore-values="false"
+ retain-values="false"
+ >
+
+ <property name="javax.jdo.mapping.Schema" value="schemaDoesNotExist"/>
+ <property name="javax.jdo.option.Mapping" value="standard"/>
+ <property name="org.jpox.metadata.validate" value="false"/>
+ <property name="org.jpox.validateTables" value="false"/>
+ <property name="org.jpox.validateConstraints" value="false"/>
+ <property name="org.jpox.autoCreateSchema" value="false"/>
+ <property name="org.jpox.autoCreateTables" value="false"/>
+ <property name="org.jpox.autoCreateConstraints" value="false"/>
+ <property name="org.jpox.autoCreateColumns" value="false"/>
+ <property name="org.jpox.rdbms.CheckExistTablesOrViews" value="false"/>
+ <property name="org.jpox.autoStartMechanism" value="None"/>
+ <property name="org.jpox.connectionPoolingType" value="C3P0"/>
+ <property name="org.jpox.implementationCreatorName" value="asm"/>
+
+ <!-- Use no classes attribute here - testing null classes behavior -->
+ <instance-lifecycle-listener
+ listener="org.apache.jdo.tck.api.persistencmanagerfactory.config.JDOConfigListener"
+ />
+
+ </persistence-manager-factory>
+</jdoconfig>
Modified: db/jdo/trunk/tck2/src/conf/pmf.conf
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/conf/pmf.conf?rev=630599&r1=630598&r2=630599&view=diff
==============================================================================
--- db/jdo/trunk/tck2/src/conf/pmf.conf (original)
+++ db/jdo/trunk/tck2/src/conf/pmf.conf Sat Feb 23 23:51:35 2008
@@ -49,5 +49,7 @@
org.apache.jdo.tck.api.persistencemanagerfactory.SetRetainValues \
org.apache.jdo.tck.api.persistencemanagerfactory.SupportedOptions \
org.apache.jdo.tck.api.persistencemanagerfactory.config.Jdoconfig \
-org.apache.jdo.tck.api.persistencemanagerfactory.config.Persistence
+org.apache.jdo.tck.api.persistencemanagerfactory.config.Persistence \
+org.apache.jdo.tck.api.persistencemanagerfactory.config.JDOConfigListener
+
Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/config/JDOConfigListener.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/config/JDOConfigListener.java?rev=630599&view=auto
==============================================================================
--- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/config/JDOConfigListener.java (added)
+++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/config/JDOConfigListener.java Sat Feb 23 23:51:35 2008
@@ -0,0 +1,163 @@
+/*
+ * 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.jdo.tck.api.persistencemanagerfactory.config;
+
+import java.util.HashMap;
+import javax.jdo.JDOHelper;
+import javax.jdo.PersistenceManager;
+import javax.jdo.PersistenceManagerFactory;
+import javax.jdo.Transaction;
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.mylib.PCPoint;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B>JDOConfigListener
+ *<BR/>
+ *<B>Keywords:</B> persistencemanagerfactory, jdoconfig.xml
+ *<BR/>
+ *<B>Assertion IDs:</B> A11.1-40
+ *<BR/>
+ *<B>Assertion Description: </B>
+ Properties whose key begins with the prefix
+ * "javax.jdo.listener.InstanceLifecycleListener." have special treatment.
+ * The part of the key following the prefix is used as the class name of a class
+ * that implements javax.jdo.listener.InstanceLifecycleListener.
+ * The implementation first attempts to get an instance via the static method
+ * getInstance() that returns an instance that implements the
+ * javax.jdo.listener.InstanceLifecycleListener. If this is unsuccessful,
+ * an instance of this class is constructed via a no-args constructor.
+ * The value of the key is a comma-separated list of classes to which
+ * the instantiated listener is registered to listen.
+ */
+
+public class JDOConfigListener extends JDO_Test {
+
+ /** Creates a new instance of JDOConfigListener */
+ public JDOConfigListener() {
+ }
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertions 11.1-40 failed: ";
+ private static final String ANONYMOUS_PMF_NAME = "";
+ // Do not use superclass pmf, pm
+ private PersistenceManagerFactory pmf = null;
+ private PersistenceManager pm = null;
+ private HashMap overrides = new HashMap();
+
+ /**
+ * The <code>main</code> is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(JDOConfigListener.class);
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ /* Instance can be persisted ONLY if javax.jdo.mapping.Schema
+ * is overriden with
+ * JDOHelper.getPersistenceManagerFactory(Map overrides, ...).
+ * The value depends on identity type so can only be known at runtime.
+ */
+ if (isTestToBePerformed()) {
+ overrides.put("javax.jdo.mapping.Schema", schemaname);
+ }
+ }
+
+ /**
+ * Test instantiation of InstanceLifecycleListener where listener class
+ * and target classes are specified in jdoconfig.xml where listener
+ * class provides only a public no-args constructor.
+ */
+ public void testPCPointListener() {
+ String pmfname = "testInstanceLifecycleListenerStore";
+ pmf = JDOHelper.getPersistenceManagerFactory(overrides, pmfname);
+ makePersistent();
+ assertTrue("Expected preStore() to have been invoked.",
+ StoreListener.isPreStore());
+ assertTrue("Expected postStore() to have been invoked.",
+ StoreListener.isPostStore());
+ }
+
+ /**
+ * Test instantiation of InstanceLifecycleListener where listener class
+ * and target classes are specified in jdoconfig.xml where listener
+ * class provides a static method getInstance().
+ */
+ public void testPCPointListenerGetInstance() {
+ String pmfname = "testInstanceLifecycleListenerStoreGetInstance";
+ pmf = JDOHelper.getPersistenceManagerFactory(overrides, pmfname);
+ makePersistent();
+ assertTrue("Expected preStore() to have been invoked.",
+ StoreListenerGetInstance.isPreStore());
+ assertTrue("Expected postStore() to have been invoked.",
+ StoreListenerGetInstance.isPostStore());
+ }
+
+ /**
+ * Test instantiation of Instance LifeCycleListener specified via
+ * property overrides.
+ */
+ public void testPCPointListenerOverrides() {
+ overrides.put("javax.jdo.listener.InstanceLifecycleListener.org.apache.jdo.tck.api.persistencemanagerfactory.config.StoreListener",
+ "org.apache.jdo.tck.pc.mylib.PCPoint");
+ String pmfname = "testInstanceLifecycleListenerStoreOverrides";
+ pmf = JDOHelper.getPersistenceManagerFactory(overrides, pmfname);
+ makePersistent();
+ assertTrue("Expected preStore() to have been invoked.",
+ StoreListener.isPreStore());
+ assertTrue("Expected postStore() to have been invoked.",
+ StoreListener.isPostStore());
+ }
+
+ /**
+ * Test instantiation of InstanceLifecycleListener where class value
+ * is null
+ */
+ public void testPCPointListenerNullClasses() {
+ String pmfname = "testInstanceLifecycleListenerClassesNull";
+ pmf = JDOHelper.getPersistenceManagerFactory(overrides, pmfname);
+ makePersistent();
+ assertTrue("Expected preStore() to have been invoked.",
+ StoreListener.isPreStore());
+ assertTrue("Expected postStore() to have been invoked.",
+ StoreListener.isPostStore());
+ }
+
+ protected void makePersistent() {
+ addTearDownClass(PCPoint.class);
+ pm = pmf.getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+ tx.begin();
+ PCPoint comp = new PCPoint(1, 2);
+ pm.makePersistent(comp);
+ tx.commit();
+ }
+
+ @Override
+ protected void localTearDown() {
+ super.localTearDown();
+ StoreListener.resetValues();
+ StoreListenerGetInstance.resetValues();
+ pmf.close();
+ pmf = null;
+ }
+}
Propchange: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/config/JDOConfigListener.java
------------------------------------------------------------------------------
svn:eol-style = LF
Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/config/StoreListener.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/config/StoreListener.java?rev=630599&view=auto
==============================================================================
--- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/config/StoreListener.java (added)
+++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/config/StoreListener.java Sat Feb 23 23:51:35 2008
@@ -0,0 +1,60 @@
+/*
+ * 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.jdo.tck.api.persistencemanagerfactory.config;
+
+import javax.jdo.listener.InstanceLifecycleEvent;
+import javax.jdo.listener.StoreLifecycleListener;
+
+/**
+ * A StoreLivecycleListener implementation that provides a public no-args
+ * constructor that may be invoked by a JDO implementation,
+ * but NO getInstance() method.
+ */
+public class StoreListener implements StoreLifecycleListener {
+
+ private static boolean preStore = false;
+ private static boolean postStore = false;
+ private static int instanceCount = 0;
+
+ public StoreListener() {
+ instanceCount++;
+ }
+
+ public static boolean isPreStore() {
+ return preStore;
+ }
+
+ public static boolean isPostStore() {
+ return postStore;
+ }
+
+ public static void resetValues() {
+ preStore = false;
+ postStore = false;
+ }
+
+ public void preStore(InstanceLifecycleEvent event) {
+// System.out.println("preStore: event is " + event);
+ preStore = true;
+ }
+
+ public void postStore(InstanceLifecycleEvent event) {
+// System.out.println("postStore: event is " + event);
+ postStore = true;
+ }
+}
Propchange: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/config/StoreListener.java
------------------------------------------------------------------------------
svn:eol-style = LF
Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/config/StoreListenerGetInstance.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/config/StoreListenerGetInstance.java?rev=630599&view=auto
==============================================================================
--- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/config/StoreListenerGetInstance.java (added)
+++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/config/StoreListenerGetInstance.java Sat Feb 23 23:51:35 2008
@@ -0,0 +1,64 @@
+/*
+ * 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.jdo.tck.api.persistencemanagerfactory.config;
+
+import javax.jdo.listener.InstanceLifecycleEvent;
+import javax.jdo.listener.StoreLifecycleListener;
+
+/**
+ * A StoreLifecycleListener implementation that provides a getInstance() method
+ * that may be invoked by a JDO implementation.
+ */
+public class StoreListenerGetInstance implements StoreLifecycleListener {
+
+ private static boolean preStore = false;
+ private static boolean postStore = false;
+ private static int instanceCount = 0;
+ private static StoreListenerGetInstance slInstance =
+ new StoreListenerGetInstance();
+
+ private StoreListenerGetInstance() {
+ instanceCount++;
+ }
+
+ public static StoreListenerGetInstance getInstance() {
+ return slInstance;
+ }
+
+ public static boolean isPreStore() {
+ return preStore;
+ }
+
+ public static boolean isPostStore() {
+ return postStore;
+ }
+
+ public static void resetValues() {
+ preStore = false;
+ postStore = false;
+ }
+
+ public void preStore(InstanceLifecycleEvent event) {
+// System.out.println("preStore: event is " + event);
+ preStore = true;
+ }
+
+ public void postStore(InstanceLifecycleEvent event) {
+// System.out.println("postStore: event is " + event);
+ postStore = true;
+ }
+}
Propchange: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/config/StoreListenerGetInstance.java
------------------------------------------------------------------------------
svn:eol-style = LF