[jboss-cvs] JBossAS SVN: r95666 - in projects/jpa/trunk/impl/src: test/java/org/jboss/jpa/impl/test and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Oct 28 03:42:01 EDT 2009
Author: wolfc
Date: 2009-10-28 03:42:01 -0400 (Wed, 28 Oct 2009)
New Revision: 95666
Added:
projects/jpa/trunk/impl/src/test/java/org/jboss/jpa/impl/test/common/BrainlessContext.java
projects/jpa/trunk/impl/src/test/java/org/jboss/jpa/impl/test/deployment/
projects/jpa/trunk/impl/src/test/java/org/jboss/jpa/impl/test/deployment/PersistenceUnitInfoImplTestCase.java
Modified:
projects/jpa/trunk/impl/src/main/java/org/jboss/jpa/impl/deployment/PersistenceUnitInfoImpl.java
Log:
JBJPA-15: fixed NPE when caching mode is unspecified
Modified: projects/jpa/trunk/impl/src/main/java/org/jboss/jpa/impl/deployment/PersistenceUnitInfoImpl.java
===================================================================
--- projects/jpa/trunk/impl/src/main/java/org/jboss/jpa/impl/deployment/PersistenceUnitInfoImpl.java 2009-10-28 07:31:11 UTC (rev 95665)
+++ projects/jpa/trunk/impl/src/main/java/org/jboss/jpa/impl/deployment/PersistenceUnitInfoImpl.java 2009-10-28 07:42:01 UTC (rev 95666)
@@ -41,8 +41,8 @@
import org.hibernate.ejb.HibernatePersistence;
import org.jboss.logging.Logger;
import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
+import org.jboss.metadata.jpa.spec.SharedCacheMode;
import org.jboss.metadata.jpa.spec.TransactionType;
-import org.jboss.metadata.jpa.spec.SharedCacheMode;
/**
* Comment
@@ -169,6 +169,8 @@
private Caching convertToCaching(SharedCacheMode sharedCacheMode)
{
+ if(sharedCacheMode == null) return null;
+
switch (sharedCacheMode) {
case ALL:
return Caching.ALL;
Copied: projects/jpa/trunk/impl/src/test/java/org/jboss/jpa/impl/test/common/BrainlessContext.java (from rev 95602, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/naming/BrainlessContext.java)
===================================================================
--- projects/jpa/trunk/impl/src/test/java/org/jboss/jpa/impl/test/common/BrainlessContext.java (rev 0)
+++ projects/jpa/trunk/impl/src/test/java/org/jboss/jpa/impl/test/common/BrainlessContext.java 2009-10-28 07:42:01 UTC (rev 95666)
@@ -0,0 +1,191 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jpa.impl.test.common;
+
+import java.util.Hashtable;
+
+import javax.naming.Binding;
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NameClassPair;
+import javax.naming.NameParser;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.OperationNotSupportedException;
+
+/**
+ * A naming context which can't do anything.
+ *
+ * @author carlo
+ */
+public class BrainlessContext implements Context
+{
+ public BrainlessContext()
+ {
+ super();
+ }
+
+ public Object lookup(Name name) throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+
+ public Object lookup(String name) throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+
+ public void bind(Name name, Object obj) throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+
+ public void bind(String name, Object obj) throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+
+ public void rebind(Name name, Object obj) throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+
+ public void rebind(String name, Object obj) throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+
+ public void unbind(Name name) throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+
+ public void unbind(String name) throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+
+ public void rename(Name oldName, Name newName) throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+
+ public void rename(String oldName, String newName) throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+
+ public NamingEnumeration<NameClassPair> list(Name name) throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+
+ public NamingEnumeration<NameClassPair> list(String name) throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+
+ public NamingEnumeration<Binding> listBindings(Name name) throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+
+ public NamingEnumeration<Binding> listBindings(String name) throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+
+ public void destroySubcontext(Name name) throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+
+ public void destroySubcontext(String name) throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+
+ public Context createSubcontext(Name name) throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+
+ public Context createSubcontext(String name) throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+
+ public Object lookupLink(Name name) throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+
+ public Object lookupLink(String name) throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+
+ public NameParser getNameParser(Name name) throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+
+ public NameParser getNameParser(String name) throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+
+ public Name composeName(Name name, Name prefix) throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+
+ public String composeName(String name, String prefix) throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+
+ public Object addToEnvironment(String propName, Object propVal) throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+
+ public Object removeFromEnvironment(String propName) throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+
+ public Hashtable<?, ?> getEnvironment() throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+
+ public void close() throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+
+ public String getNameInNamespace() throws NamingException
+ {
+ throw new OperationNotSupportedException();
+ }
+}
Added: projects/jpa/trunk/impl/src/test/java/org/jboss/jpa/impl/test/deployment/PersistenceUnitInfoImplTestCase.java
===================================================================
--- projects/jpa/trunk/impl/src/test/java/org/jboss/jpa/impl/test/deployment/PersistenceUnitInfoImplTestCase.java (rev 0)
+++ projects/jpa/trunk/impl/src/test/java/org/jboss/jpa/impl/test/deployment/PersistenceUnitInfoImplTestCase.java 2009-10-28 07:42:01 UTC (rev 95666)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jpa.impl.test.deployment;
+
+import static junit.framework.Assert.assertNull;
+
+import java.net.URL;
+import java.util.List;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import org.jboss.jpa.impl.deployment.PersistenceUnitInfoImpl;
+import org.jboss.jpa.impl.test.common.BrainlessContext;
+import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
+import org.jboss.metadata.jpa.spec.ValidationMode;
+import org.junit.Test;
+
+/**
+ * Generic tests against PersistenceUnitInfoImpl that provide coverage
+ * and test general conditions.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class PersistenceUnitInfoImplTestCase
+{
+ /**
+ * If I don't specify cache mode I don't want a NPE.
+ */
+ @Test
+ public void testUnspecifiedCacheMode() throws Exception
+ {
+ PersistenceUnitMetaData metaData = new PersistenceUnitMetaData();
+ metaData.setJtaDataSource("dummy-datasource");
+ metaData.setName("dummy-name");
+ metaData.setValidationMode(ValidationMode.AUTO);
+ Properties props = new Properties();
+ ClassLoader classLoader = null;
+ URL persistenceUnitRootUrl = null;
+ List<URL> jarFiles = null;
+ Context ctx = new BrainlessContext() {
+ @Override
+ public Object lookup(String name) throws NamingException
+ {
+ return null;
+ }
+ };
+ PersistenceUnitInfoImpl puii = new PersistenceUnitInfoImpl(metaData, props, classLoader, persistenceUnitRootUrl, jarFiles, ctx);
+ assertNull(puii.getCaching());
+ }
+}
More information about the jboss-cvs-commits
mailing list