geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r997064 - in /geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests: jpa-ear/src/test/java/org/apache/geronimo/testsuite/jpa/ jpa-ejb/src/main/resources/META-INF/ jpa-war/src/main/java/org/apache/geronimo/itest/
Date Tue, 14 Sep 2010 20:03:32 GMT
Author: gawor
Date: Tue Sep 14 20:03:32 2010
New Revision: 997064

URL: http://svn.apache.org/viewvc?rev=997064&view=rev
Log:
GERONIMO-5606: Updated the jpa test case to replicate the problem when persistenceUnitRoot
of a PU is wrong

Added:
    geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-ejb/src/main/resources/META-INF/orm.xml
  (with props)
Modified:
    geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-ear/src/test/java/org/apache/geronimo/testsuite/jpa/JPATest.java
    geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-war/src/main/java/org/apache/geronimo/itest/TestServlet.java

Modified: geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-ear/src/test/java/org/apache/geronimo/testsuite/jpa/JPATest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-ear/src/test/java/org/apache/geronimo/testsuite/jpa/JPATest.java?rev=997064&r1=997063&r2=997064&view=diff
==============================================================================
--- geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-ear/src/test/java/org/apache/geronimo/testsuite/jpa/JPATest.java
(original)
+++ geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-ear/src/test/java/org/apache/geronimo/testsuite/jpa/JPATest.java
Tue Sep 14 20:03:32 2010
@@ -31,11 +31,17 @@ import org.testng.annotations.Test;
 public class JPATest extends TestSupport {
 
     @Test
-    public void testIndexContent() throws Exception {
-        URL url = new URL("http://localhost:8080/jpa/servlet");
+    public void testEjb() throws Exception {
+        URL url = new URL("http://localhost:8080/jpa/servlet?test=testEjb");
         String reply = HttpUtils.doGET(url);
         assertTrue("EJB container managed", reply.contains("Test EJB container managed entity
manager test OK: true"));
         assertTrue("EJB app managed", reply.contains("Test EJB app managed entity manager
factory test OK: true"));
+    }
+    
+    @Test
+    public void testServlet() throws Exception {
+        URL url = new URL("http://localhost:8080/jpa/servlet?test=testServlet");
+        String reply = HttpUtils.doGET(url);
         assertTrue("Servlet container managed", reply.contains("Test servlet container managed
entity manager test OK: true"));
         assertTrue("Serlvet app managed", reply.contains("Test servlet app managed entity
manager factory test OK: true"));
         assertTrue("Commit", reply.contains("commit OK"));

Added: geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-ejb/src/main/resources/META-INF/orm.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-ejb/src/main/resources/META-INF/orm.xml?rev=997064&view=auto
==============================================================================
--- geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-ejb/src/main/resources/META-INF/orm.xml
(added)
+++ geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-ejb/src/main/resources/META-INF/orm.xml
Tue Sep 14 20:03:32 2010
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" version="1.0">
+    <persistence-unit-metadata>
+        <persistence-unit-defaults>
+            <entity-listeners>
+                <entity-listener class="org.apache.geronimo.itest.TestListener"/>
+            </entity-listeners>
+        </persistence-unit-defaults>
+    </persistence-unit-metadata>
+</entity-mappings>

Propchange: geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-ejb/src/main/resources/META-INF/orm.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-ejb/src/main/resources/META-INF/orm.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-ejb/src/main/resources/META-INF/orm.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-war/src/main/java/org/apache/geronimo/itest/TestServlet.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-war/src/main/java/org/apache/geronimo/itest/TestServlet.java?rev=997064&r1=997063&r2=997064&view=diff
==============================================================================
--- geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-war/src/main/java/org/apache/geronimo/itest/TestServlet.java
(original)
+++ geronimo/server/trunk/testsuite/enterprise-testsuite/jpa-tests/jpa-war/src/main/java/org/apache/geronimo/itest/TestServlet.java
Tue Sep 14 20:03:32 2010
@@ -17,74 +17,101 @@
 package org.apache.geronimo.itest;
 
 import java.io.IOException;
-import java.rmi.RemoteException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
 
+import javax.naming.InitialContext;
+import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import javax.servlet.ServletException;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.ejb.CreateException;
 import javax.transaction.UserTransaction;
-import javax.transaction.SystemException;
-import javax.transaction.NotSupportedException;
-import javax.transaction.HeuristicMixedException;
-import javax.transaction.HeuristicRollbackException;
-import javax.transaction.RollbackException;
-
 
 /**
  * @version $Rev$ $Date$
  */
 public class TestServlet extends HttpServlet {
 
-    public void init() {
-        System.out.println("Test Servlet init");
-    }
-
-    protected void service(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
throws ServletException, IOException {
-        httpServletResponse.getOutputStream().print("TestServlet\n");
+    @Override
+    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
+        String testName = request.getParameter("test");
+        if (testName == null || !testName.startsWith("test")) {
+            throw new ServletException("Invalid test name");
+        }
+        Method testMethod = null;
         try {
-            InitialContext ctx = new InitialContext();
-
-            //test ejb access using geronimo plan refs
-            TestSessionHome home = (TestSessionHome)ctx.lookup("java:comp/env/TestSession");
-            boolean result = home.create().testEntityManager();
-            httpServletResponse.getOutputStream().print("Test EJB container managed entity
manager test OK: " + result);
-            result = home.create().testEntityManagerFactory();
-            httpServletResponse.getOutputStream().print("\nTest EJB app managed entity manager
factory test OK: " + result);
-
-            //test servlet access using spec dd refs
-            TestSessionBean bean = new TestSessionBean();
-            UserTransaction ut = (UserTransaction) ctx.lookup("java:comp/UserTransaction");
-            ut.begin();
-            result = bean.testEntityManager();
-            httpServletResponse.getOutputStream().print("\nTest servlet container managed
entity manager test OK: " + result);
-            result = bean.testEntityManagerFactory();
-            httpServletResponse.getOutputStream().print("\nTest servlet app managed entity
manager factory test OK: " + result);
-            ut.commit();
-            httpServletResponse.getOutputStream().print("\ncommit OK");
-        } catch (NamingException e) {
-            System.out.print("Exception:");
-            e.printStackTrace();
-        } catch (RemoteException e) {
-            e.printStackTrace();
-        } catch (CreateException e) {
-            e.printStackTrace();
-        } catch (SystemException e) {
-            e.printStackTrace();
-        } catch (NotSupportedException e) {
-            e.printStackTrace();
-        } catch (HeuristicMixedException e) {
-            e.printStackTrace();
-        } catch (HeuristicRollbackException e) {
-            e.printStackTrace();
-        } catch (RollbackException e) {
-            e.printStackTrace();
+            testMethod = getClass().getMethod(testName, new Class[] {HttpServletRequest.class,
HttpServletResponse.class});
+        } catch (Exception e1) {
+            throw new ServletException("No such test: " + testName);
+        }
+        try {
+            testMethod.invoke(this, new Object[] {request, response});
+        } catch (IllegalArgumentException e) {
+            throw new ServletException("Error invoking test: " + e.getMessage());
+        } catch (IllegalAccessException e) {
+            throw new ServletException("Error invoking test: " + e.getMessage());
+        } catch (InvocationTargetException e) {
+            Throwable root = e.getTargetException();
+            ServletException ex = new ServletException("Test '" + testName + "' failed");
+            ex.initCause(root);
+            throw ex;
+        }
+        response.setContentType("text/plain");
+    }
+    
+    public void testEjb(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
throws Exception {
+        TestListener.getCallbacks().clear();
+        
+        InitialContext ctx = new InitialContext();
+        //test ejb access using geronimo plan refs
+        TestSessionHome home = (TestSessionHome)ctx.lookup("java:comp/env/TestSession");
+        boolean result = home.create().testEntityManager();
+        httpServletResponse.getOutputStream().print("Test EJB container managed entity manager
test OK: " + result);
+        result = home.create().testEntityManagerFactory();
+        httpServletResponse.getOutputStream().print("\nTest EJB app managed entity manager
factory test OK: " + result);
+        
+        verifyCallbacks();
+    }
+    
+    public void testServlet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
throws Exception {
+        TestListener.getCallbacks().clear();
+        
+        InitialContext ctx = new InitialContext();
+        //test servlet access using spec dd refs
+        TestSessionBean bean = new TestSessionBean();
+        UserTransaction ut = (UserTransaction) ctx.lookup("java:comp/UserTransaction");
+        ut.begin();
+        boolean result = bean.testEntityManager();
+        httpServletResponse.getOutputStream().print("\nTest servlet container managed entity
manager test OK: " + result);
+        result = bean.testEntityManagerFactory();
+        httpServletResponse.getOutputStream().print("\nTest servlet app managed entity manager
factory test OK: " + result);
+        ut.commit();
+        httpServletResponse.getOutputStream().print("\ncommit OK");
+        
+        verifyCallbacks();
+    }
+    
+    private static void verifyCallbacks() throws Exception {
+        List<String> callbacks;        
+        callbacks = getCallbacks("prePersist");
+        if (callbacks.size() != 2) {
+            throw new Exception("Unexpected number of prePersist callbacks: " + callbacks);
+        }
+        callbacks = getCallbacks("postPersist");
+        if (callbacks.size() != 2) {
+            throw new Exception("Unexpected number of postPersist callbacks: " + callbacks);
         }
-        httpServletResponse.flushBuffer();
     }
 
-
+    private static List<String> getCallbacks(String type) {
+        List<String> selected = new ArrayList<String>();
+        for (String callback : TestListener.getCallbacks()) {
+            if (callback.startsWith(type)) {
+                selected.add(callback);
+            }
+        }
+        return selected;
+    }
 }



Mime
View raw message