db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c..@apache.org
Subject svn commit: r219270 - /incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/
Date Sat, 16 Jul 2005 00:24:29 GMT
Author: clr
Date: Fri Jul 15 17:24:28 2005
New Revision: 219270

URL: http://svn.apache.org/viewcvs?rev=219270&view=rev
Log:
added getPMF tests

Added:
    incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/AbstractGetPMF.java
    incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByFile.java
    incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByFileAndClassLoader.java
    incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByJNDILocation.java
    incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByJNDILocationAndClassLoader.java
    incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByResource.java
    incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByResourceAndClassLoader.java
    incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByStream.java
    incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByStreamAndClassLoader.java

Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/AbstractGetPMF.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/AbstractGetPMF.java?rev=219270&view=auto
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/AbstractGetPMF.java
(added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/AbstractGetPMF.java
Fri Jul 15 17:24:28 2005
@@ -0,0 +1,217 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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;
+
+import java.lang.reflect.Method;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.jdo.JDOFatalUserException;
+import javax.jdo.PersistenceManagerFactory;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.mylib.PCPoint;
+
+/**
+ * The abstract super class for all GetPMF test cases. 
+ * @author Michael Watzek
+ */
+
+abstract class AbstractGetPMF extends JDO_Test {
+    
+    /** 
+     * Used as the PMF name in positive tests.
+     * The variable is set to test/conf/jdori.properties.
+     * This file contains valid JDO properties.
+     */
+    protected static final String validPropertiesFile = PMFProperties;
+    
+    /** 
+     * Used as the PMF name in negative tests.
+     * The variable is set to test/conf/logging.properties.
+     * This file does not contain valid JDO properties.
+     */
+/*    protected static final String invalidPropertiesFile =
+        //we use '/' instead of File.separatorChar because
+        //this character is passed by maven
+        validPropertiesFile.substring(0, validPropertiesFile.lastIndexOf('/')+1) +
+        "logging.properties";
+*/
+    protected static String invalidPropertiesFile;
+    static
+    {
+        if (validPropertiesFile==null)
+            System.out.println ("******************************");
+        //we use '/' instead of File.separatorChar because
+        //this character is passed by maven
+        invalidPropertiesFile = validPropertiesFile.substring(0, validPropertiesFile.lastIndexOf('/')+1)
+
+        "logging.properties";
+    }
+
+    /**
+     * Used as the PMF name in positive JNDI tests.
+     * The variable is set to jdori.properties.
+     * This resource contains valid JDO properties.
+     */
+    protected static final String jndiName =
+        //we use '/' instead of File.separatorChar because
+        //this character is passed by maven
+        validPropertiesFile.substring(0, validPropertiesFile.lastIndexOf('/')+1) +
+        "pmf.ser";
+    
+    /**
+     * Removing the path prefix from argument <code>name</code>.
+     * @return argument <code>name</code> removed by the path prefix.
+     */
+    protected String removePathPrefix(String name) {
+        //we use '/' instead of File.separatorChar because
+        //this character is passed by maven
+        int index = name.lastIndexOf('/');
+        if (index!=-1) {
+            name = name.substring(index+1);
+        }
+        return name;
+    }
+
+    protected void makePersistent() {
+        pm = pmf.getPersistenceManager();
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+        PCPoint comp = new PCPoint(1, 2);
+        pm.makePersistent(comp);
+        tx.commit();
+        addTearDownInstance(comp);
+    }
+
+    /**
+     * Returns pmf instance for the given name.
+     * Subclasses may use argument <code>name</code> as file name,
+     * resource name etc.
+     * @param name the name
+     * @return the pmf instance
+     */
+    protected abstract PersistenceManagerFactory getPMF(String name);
+
+    /**
+     * This method creates a PMF calling 
+     * method AbstractGetPMF#getPMF(name).
+     * It passes an name of an invalid properties file as parameter.
+     * The method expects the PMF creation to fail.
+     * @param assertionMessage the assertion message if the test fails. 
+     */
+    protected void checkGetPMFWithInvalidProperties(String assertionMessage) {
+        try {
+            pmf = getPMF(invalidPropertiesFile);
+            fail(assertionMessage);
+        } catch (JDOFatalUserException e) {
+            // expected exception
+            if (debug)
+                logger.debug("caught expected exception " + e.toString());
+        }
+    }
+    
+    /**
+     * This method creates a PMF calling 
+     * method AbstractGetPMF#getPMF(name).
+     * It passes an name of a valid properties file as parameter.
+     * The method expects the PMF creation to succeed.
+     */
+    protected void checkGetPMFWithValidProperties() {
+        pmf = getPMF(validPropertiesFile);
+        verifyProperties(pmf, loadProperties(validPropertiesFile));
+        makePersistent();
+    }
+    
+    /** 
+     * Verify that the Properties are correctly set in the PMF.
+     */
+    protected void verifyProperties(PersistenceManagerFactory pmf,
+            Properties props) {
+        Object[] noArgs = new Object[]{};
+        String javaxjdooption = "javax.jdo.option.";
+        Class pmfclass = pmf.getClass();
+        Set entries = props.entrySet();
+        StringBuffer buffer = new StringBuffer();
+        for (Iterator it = entries.iterator(); it.hasNext();) {
+            Entry entry = (Entry)it.next();
+            String key = (String)entry.getKey();
+            if (key.equals("javax.jdo.option.ConnectionPassword")) {
+                continue;
+            }
+            if (key.equals("javax.jdo.option.ConnectionUserName")) {
+                continue;
+            }
+            String expected = (String)entry.getValue();
+            if (key.startsWith(javaxjdooption)) {
+                String optionName = key.substring(javaxjdooption.length());
+                Method getMethod = getGetMethod(pmfclass, optionName);
+                Object actual = getValue(getMethod, pmf, noArgs);
+                if (actual == null) {
+                    buffer.append("\n");
+                    buffer.append("Key ");
+                    buffer.append(key);
+                    buffer.append(" was null.");
+                    continue;
+                }
+                String actualString = actual.toString();
+                if (!expected.equals(actualString)) {
+                    buffer.append("\n");
+                    buffer.append("Key ");
+                    buffer.append(key);
+                    buffer.append(" expected: \"");
+                    buffer.append(expected);
+                    buffer.append("\" actual: \"");
+                    buffer.append(actual);
+                    buffer.append("\".");
+                }
+            }
+        }
+        if (buffer.length() != 0) {
+            fail(buffer.toString());
+        }
+    }
+    
+    /** Get the "get" method corresponding to the option name.
+     */
+    Method getGetMethod(Class cls, String optionName) {
+        try {
+            return cls.getMethod("get" + optionName, new Class[]{});
+        } catch (Exception ex) {
+            fail("Unexpected exception thrown from getMethod on PMF class with option name"
+ 
+                    optionName);
+            return null;
+        }
+    }
+    
+    /** 
+     * Get the result of executing the Method.
+     */
+    Object getValue(Method method, Object obj, Object[] args) {
+        try {
+            return method.invoke(obj, args);
+        } catch (Exception ex) {
+            fail("Unexpected exception executing method " + 
+                    method.getName() + ".");
+            return null;
+        }
+    }
+}

Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByFile.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByFile.java?rev=219270&view=auto
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByFile.java
(added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByFile.java
Fri Jul 15 17:24:28 2005
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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;
+
+import java.io.File;
+
+import javax.jdo.JDOHelper;
+import javax.jdo.PersistenceManagerFactory;
+
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B>GetPMFByFile of PersistenceManagerFactory  
+ *<BR>
+ *<B>Keywords:</B> persistencemanagerfactory
+ *<BR>
+ *<B>Assertion IDs:</B> A8.6-13.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * Uses the parameter(s) passed as arguments to construct a Properties 
+ * instance, and then delegates to the static method 
+ * getPersistenceManagerFactory in the class named in the property 
+ * javax.jdo.PersistenceManagerFactoryClass. 
+ * If there are any exceptions while trying to construct the Properties
+ * instance or to call the static method, 
+ * then either A8.6-4 [JDOFatalUserException] or 
+ * A8.6-5 [JDOFatalInternalException is thrown], 
+ * depending on whether the exception is due to the user 
+ * or the implementation. 
+ * The nested exception indicates the cause of the exception.
+ * 
+ * @author Michael Watzek
+ */
+
+public class GetPMFByFile extends AbstractGetPMF {
+    
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A8.6-13 (GetPMFByFile) failed: ";
+    
+    /**
+     * 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(GetPMFByFile.class);
+    }
+
+    /** */
+    public void testInvalidGetPMF() {
+        checkGetPMFWithInvalidProperties(ASSERTION_FAILED);
+    }
+
+    /** */
+    public void testValidGetPMF() {
+        checkGetPMFWithValidProperties();
+    }
+
+    /**
+     * @see AbstractGetPMF#getPMF(String)
+     */
+    protected PersistenceManagerFactory getPMF(String name) {
+        return JDOHelper.getPersistenceManagerFactory(new File(name));
+    }
+}

Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByFileAndClassLoader.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByFileAndClassLoader.java?rev=219270&view=auto
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByFileAndClassLoader.java
(added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByFileAndClassLoader.java
Fri Jul 15 17:24:28 2005
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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;
+
+import java.io.File;
+
+import javax.jdo.JDOHelper;
+import javax.jdo.PersistenceManagerFactory;
+
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B>GetPMFByFileAndClassLoader of PersistenceManagerFactory  
+ *<BR>
+ *<B>Keywords:</B> persistencemanagerfactory
+ *<BR>
+ *<B>Assertion IDs:</B> A8.6-14.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * Uses the parameter(s) passed as arguments to construct a Properties 
+ * instance, and then delegates to the static method 
+ * getPersistenceManagerFactory in the class named in the property 
+ * javax.jdo.PersistenceManagerFactoryClass. 
+ * If there are any exceptions while trying to construct the Properties
+ * instance or to call the static method, 
+ * then either A8.6-4 [JDOFatalUserException] or 
+ * A8.6-5 [JDOFatalInternalException is thrown], 
+ * depending on whether the exception is due to the user 
+ * or the implementation. 
+ * The nested exception indicates the cause of the exception.
+ * 
+ * @author Michael Watzek
+ */
+
+public class GetPMFByFileAndClassLoader extends AbstractGetPMF {
+    
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A8.6-14 (GetPMFByFileAndClassLoader) failed: ";
+    
+    private static final String propertiesFileDoesNotExist = 
+        "FileDoesNotExist.properties";
+    private static final String propertiesFileExists = 
+        System.getProperty("PMFProperties");
+    
+    /**
+     * 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(GetPMFByFileAndClassLoader.class);
+    }
+
+    /** */
+    public void testInvalidGetPMF() {
+        checkGetPMFWithInvalidProperties(ASSERTION_FAILED);
+    }
+
+    /** */
+    public void testValidGetPMF() {
+        checkGetPMFWithValidProperties();
+    }
+
+    /**
+     * @see AbstractGetPMF#getPMF(String)
+     */
+    protected PersistenceManagerFactory getPMF(String name) {
+        return JDOHelper.getPersistenceManagerFactory(new File(name), 
+                Thread.currentThread().getContextClassLoader());
+    }
+}

Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByJNDILocation.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByJNDILocation.java?rev=219270&view=auto
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByJNDILocation.java
(added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByJNDILocation.java
Fri Jul 15 17:24:28 2005
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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;
+
+import java.io.File;
+
+import javax.jdo.JDOFatalException;
+import javax.jdo.JDOHelper;
+import javax.jdo.PersistenceManagerFactory;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B>GetPMFByJNDILocation of PersistenceManagerFactory  
+ *<BR>
+ *<B>Keywords:</B> persistencemanagerfactory
+ *<BR>
+ *<B>Assertion IDs:</B> A8.6-19.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * Uses the parameter(s) passed as arguments to construct a Properties 
+ * instance, and then delegates to the static method 
+ * getPersistenceManagerFactory in the class named in the property 
+ * javax.jdo.PersistenceManagerFactoryClass. 
+ * If there are any exceptions while trying to construct the Properties
+ * instance or to call the static method, 
+ * then either A8.6-4 [JDOFatalUserException] or 
+ * A8.6-5 [JDOFatalInternalException is thrown], 
+ * depending on whether the exception is due to the user 
+ * or the implementation. 
+ * The nested exception indicates the cause of the exception.
+ * 
+ * @author Michael Watzek
+ */
+
+public class GetPMFByJNDILocation extends AbstractGetPMF {
+    
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A8.6-19 (GetPMFByJNDILocation) failed: ";
+    
+    /**
+     * 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(GetPMFByJNDILocation.class);
+    }
+
+    /** */
+    public void testInvalidGetPMF() {
+        checkGetPMFWithInvalidProperties(ASSERTION_FAILED);
+    }
+
+    /** */
+    public void testValidGetPMF() {
+        checkGetPMFWithValidProperties();
+    }
+
+    /**
+     * @see AbstractGetPMF#getPMF(String)
+     */
+    protected PersistenceManagerFactory getPMF(String name) {
+        Context context = null;
+        try {
+            //We need a JNDI context which contains a PMF instance.
+            //For this reason, we create a JNDI context,
+            //create a PMF instance and bind that to the context. 
+            context = new InitialContext();
+            if (name.equals(validPropertiesFile)) {
+                PersistenceManagerFactory pmf = 
+                    JDOHelper.getPersistenceManagerFactory(new File(name));
+                verifyProperties(pmf, loadProperties(validPropertiesFile));
+                context.bind(jndiName, pmf);
+            }
+            return JDOHelper.getPersistenceManagerFactory(jndiName, context);
+        } catch (NamingException e) {
+            throw new JDOFatalException("Caught NamingException trying to bind " + 
+                    e.getMessage(), e);
+        } finally {
+            if (context != null) {
+                try {
+                    context.unbind(jndiName);
+                    context.close();
+                } catch (NamingException e) {
+                    fail("Caught NamingException trying to unbind or close." +
+                            e.getMessage());
+                    // stay quiet
+                }
+            }
+        }
+    }
+}

Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByJNDILocationAndClassLoader.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByJNDILocationAndClassLoader.java?rev=219270&view=auto
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByJNDILocationAndClassLoader.java
(added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByJNDILocationAndClassLoader.java
Fri Jul 15 17:24:28 2005
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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;
+
+import java.io.File;
+
+import javax.jdo.JDOFatalException;
+import javax.jdo.JDOHelper;
+import javax.jdo.PersistenceManagerFactory;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B>GetPMFByJNDILocationAndClassLoader of PersistenceManagerFactory
 
+ *<BR>
+ *<B>Keywords:</B> persistencemanagerfactory
+ *<BR>
+ *<B>Assertion IDs:</B> A8.6-20.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * Uses the parameter(s) passed as arguments to construct a Properties 
+ * instance, and then delegates to the static method 
+ * getPersistenceManagerFactory in the class named in the property 
+ * javax.jdo.PersistenceManagerFactoryClass. 
+ * If there are any exceptions while trying to construct the Properties
+ * instance or to call the static method, 
+ * then either A8.6-4 [JDOFatalUserException] or 
+ * A8.6-5 [JDOFatalInternalException is thrown], 
+ * depending on whether the exception is due to the user 
+ * or the implementation. 
+ * The nested exception indicates the cause of the exception.
+ * 
+ * @author Michael Watzek
+ */
+
+public class GetPMFByJNDILocationAndClassLoader extends AbstractGetPMF {
+    
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A8.6-20 (GetPMFByJNDILocationAndClassLoader) failed: ";
+    
+    /**
+     * 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(GetPMFByJNDILocationAndClassLoader.class);
+    }
+
+    /** */
+    public void testInvalidGetPMF() {
+        checkGetPMFWithInvalidProperties(ASSERTION_FAILED);
+    }
+
+    /** */
+    public void testValidGetPMF() {
+        checkGetPMFWithValidProperties();
+    }
+
+    /**
+     * @see AbstractGetPMF#getPMF(String)
+     */
+    protected PersistenceManagerFactory getPMF(String name) {
+        Context context = null;
+        try {
+            //We need a JNDI context which contains a PMF instance.
+            //For this reason, we create a JNDI context,
+            //create a PMF instance and bind that to the context. 
+            context = new InitialContext();
+            if (name.equals(validPropertiesFile)) {
+                PersistenceManagerFactory pmf = 
+                    JDOHelper.getPersistenceManagerFactory(new File(name));
+                context.bind(jndiName, pmf);
+            }
+            return JDOHelper.getPersistenceManagerFactory(jndiName, context, 
+                    Thread.currentThread().getContextClassLoader());
+        } catch (NamingException e) {
+            throw new JDOFatalException("", e);
+        } finally {
+            if (context != null) {
+                try {
+                    context.unbind(jndiName);
+                    context.close();
+                } catch (NamingException e) {
+                    // stay quiet
+                }
+            }
+        }
+    }
+}

Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByResource.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByResource.java?rev=219270&view=auto
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByResource.java
(added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByResource.java
Fri Jul 15 17:24:28 2005
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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;
+
+import javax.jdo.JDOHelper;
+import javax.jdo.PersistenceManagerFactory;
+
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B>GetPMFByResource of PersistenceManagerFactory  
+ *<BR>
+ *<B>Keywords:</B> persistencemanagerfactory
+ *<BR>
+ *<B>Assertion IDs:</B> A8.6-15.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * Uses the parameter(s) passed as arguments to construct a Properties 
+ * instance, and then delegates to the static method 
+ * getPersistenceManagerFactory in the class named in the property 
+ * javax.jdo.PersistenceManagerFactoryClass. 
+ * If there are any exceptions while trying to construct the Properties
+ * instance or to call the static method, 
+ * then either A8.6-4 [JDOFatalUserException] or 
+ * A8.6-5 [JDOFatalInternalException is thrown], 
+ * depending on whether the exception is due to the user 
+ * or the implementation. 
+ * The nested exception indicates the cause of the exception.
+ * 
+ * @author Michael Watzek
+ */
+
+public class GetPMFByResource extends AbstractGetPMF {
+    
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A8.6-15 (GetPMFByResource) failed: ";
+    
+    /**
+     * 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(GetPMFByResource.class);
+    }
+
+    /** */
+    public void testInvalidGetPMF() {
+        checkGetPMFWithInvalidProperties(ASSERTION_FAILED);
+    }
+
+    /** */
+    public void testValidGetPMF() {
+        checkGetPMFWithValidProperties();
+    }
+
+    /**
+     * @see AbstractGetPMF#getPMF(String)
+     */
+    protected PersistenceManagerFactory getPMF(String name) {
+        return JDOHelper.getPersistenceManagerFactory(removePathPrefix(name));
+    }
+}

Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByResourceAndClassLoader.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByResourceAndClassLoader.java?rev=219270&view=auto
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByResourceAndClassLoader.java
(added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByResourceAndClassLoader.java
Fri Jul 15 17:24:28 2005
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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;
+
+import javax.jdo.JDOHelper;
+import javax.jdo.PersistenceManagerFactory;
+
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B>GetPMFByResourceAndClassLoader of PersistenceManagerFactory  
+ *<BR>
+ *<B>Keywords:</B> persistencemanagerfactory
+ *<BR>
+ *<B>Assertion IDs:</B> A8.6-16.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * Uses the parameter(s) passed as arguments to construct a Properties 
+ * instance, and then delegates to the static method 
+ * getPersistenceManagerFactory in the class named in the property 
+ * javax.jdo.PersistenceManagerFactoryClass. 
+ * If there are any exceptions while trying to construct the Properties
+ * instance or to call the static method, 
+ * then either A8.6-4 [JDOFatalUserException] or 
+ * A8.6-5 [JDOFatalInternalException is thrown], 
+ * depending on whether the exception is due to the user 
+ * or the implementation. 
+ * The nested exception indicates the cause of the exception.
+ * 
+ * @author Michael Watzek
+ */
+
+public class GetPMFByResourceAndClassLoader extends AbstractGetPMF {
+    
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A8.6-16 (GetPMFByResourceAndClassLoader) failed: ";
+    
+    /**
+     * 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(GetPMFByResourceAndClassLoader.class);
+    }
+
+    /** */
+    public void testInvalidGetPMF() {
+        checkGetPMFWithInvalidProperties(ASSERTION_FAILED);
+    }
+
+    /** */
+    public void testValidGetPMF() {
+        checkGetPMFWithValidProperties();
+    }
+
+    /**
+     * @see AbstractGetPMF#getPMF(String)
+     */
+    protected PersistenceManagerFactory getPMF(String name) {
+        return JDOHelper.getPersistenceManagerFactory(removePathPrefix(name), 
+                Thread.currentThread().getContextClassLoader());
+    }
+}

Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByStream.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByStream.java?rev=219270&view=auto
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByStream.java
(added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByStream.java
Fri Jul 15 17:24:28 2005
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import javax.jdo.JDOHelper;
+import javax.jdo.PersistenceManagerFactory;
+
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B>GetPMFByStream of PersistenceManagerFactory  
+ *<BR>
+ *<B>Keywords:</B> persistencemanagerfactory
+ *<BR>
+ *<B>Assertion IDs:</B> A8.6-17.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * Uses the parameter(s) passed as arguments to construct a Properties 
+ * instance, and then delegates to the static method 
+ * getPersistenceManagerFactory in the class named in the property 
+ * javax.jdo.PersistenceManagerFactoryClass. 
+ * If there are any exceptions while trying to construct the Properties
+ * instance or to call the static method, 
+ * then either A8.6-4 [JDOFatalUserException] or 
+ * A8.6-5 [JDOFatalInternalException is thrown], 
+ * depending on whether the exception is due to the user 
+ * or the implementation. 
+ * The nested exception indicates the cause of the exception.
+ * 
+ * @author Michael Watzek
+ */
+
+public class GetPMFByStream extends AbstractGetPMF {
+    
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A8.6-17 (GetPMFByStream) failed: ";
+    
+    /**
+     * 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(GetPMFByStream.class);
+    }
+
+    /** */
+    public void testInvalidGetPMF() {
+        checkGetPMFWithInvalidProperties(ASSERTION_FAILED);
+    }
+
+    /** */
+    public void testValidGetPMF() {
+        checkGetPMFWithValidProperties();
+    }
+
+    /**
+     * @see AbstractGetPMF#getPMF(String)
+     */
+    protected PersistenceManagerFactory getPMF(String name) {
+        FileInputStream stream = null;
+        try {
+            stream = new FileInputStream(name);
+            return JDOHelper.getPersistenceManagerFactory(stream);
+        } catch (FileNotFoundException e) {
+            throw new RuntimeException("", e);
+        } finally {
+            if (stream != null) {
+                try {
+                    stream.close();
+                } catch (IOException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        }
+    }
+}

Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByStreamAndClassLoader.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByStreamAndClassLoader.java?rev=219270&view=auto
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByStreamAndClassLoader.java
(added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/GetPMFByStreamAndClassLoader.java
Fri Jul 15 17:24:28 2005
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import javax.jdo.JDOHelper;
+import javax.jdo.PersistenceManagerFactory;
+
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B>GetPMFByStreamAndClassLoader of PersistenceManagerFactory  
+ *<BR>
+ *<B>Keywords:</B> persistencemanagerfactory
+ *<BR>
+ *<B>Assertion IDs:</B> A8.6-18.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * Uses the parameter(s) passed as arguments to construct a Properties 
+ * instance, and then delegates to the static method 
+ * getPersistenceManagerFactory in the class named in the property 
+ * javax.jdo.PersistenceManagerFactoryClass. 
+ * If there are any exceptions while trying to construct the Properties
+ * instance or to call the static method, 
+ * then either A8.6-4 [JDOFatalUserException] or 
+ * A8.6-5 [JDOFatalInternalException is thrown], 
+ * depending on whether the exception is due to the user 
+ * or the implementation. 
+ * The nested exception indicates the cause of the exception.
+ * 
+ * @author Michael Watzek
+ */
+
+public class GetPMFByStreamAndClassLoader extends AbstractGetPMF {
+    
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A8.6-18 (GetPMFByStreamAndClassLoader) failed: ";
+    
+    /**
+     * 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(GetPMFByStreamAndClassLoader.class);
+    }
+
+    /** */
+    public void testInvalidGetPMF() {
+        checkGetPMFWithInvalidProperties(ASSERTION_FAILED);
+    }
+
+    /** */
+    public void testValidGetPMF() {
+        checkGetPMFWithValidProperties();
+    }
+
+    /**
+     * @see AbstractGetPMF#getPMF(String)
+     */
+    protected PersistenceManagerFactory getPMF(String name) {
+        FileInputStream stream = null;
+        try {
+            stream = new FileInputStream(name);
+            return JDOHelper.getPersistenceManagerFactory(stream, 
+                    Thread.currentThread().getContextClassLoader());
+        } catch (FileNotFoundException e) {
+            throw new RuntimeException("", e);
+        } finally {
+            if (stream != null) {
+                try {
+                    stream.close();
+                } catch (IOException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        }
+    }
+}



Mime
View raw message