deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject git commit: DELTASPIKE-518 Refactored test for Arquillian
Date Mon, 10 Feb 2014 11:57:17 GMT
Updated Branches:
  refs/heads/master 631a3de54 -> fd5beb5b2


DELTASPIKE-518 Refactored test for Arquillian


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/fd5beb5b
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/fd5beb5b
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/fd5beb5b

Branch: refs/heads/master
Commit: fd5beb5b201acde0664f8fbde0f87c318e0df99d
Parents: 631a3de
Author: Thomas Hug <Thomas.Hug@ctp.com>
Authored: Mon Feb 10 12:54:40 2014 +0100
Committer: Thomas Hug <Thomas.Hug@ctp.com>
Committed: Mon Feb 10 12:54:40 2014 +0100

----------------------------------------------------------------------
 deltaspike/modules/data/impl/pom.xml            |   6 --
 .../jpa/QueryStringExtractorFactoryTest.java    | 104 ++++++++++++++-----
 2 files changed, 78 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fd5beb5b/deltaspike/modules/data/impl/pom.xml
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/pom.xml b/deltaspike/modules/data/impl/pom.xml
index 3661270..7b262fb 100755
--- a/deltaspike/modules/data/impl/pom.xml
+++ b/deltaspike/modules/data/impl/pom.xml
@@ -121,12 +121,6 @@
             <artifactId>shrinkwrap-resolver-impl-maven</artifactId>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>org.apache.openjpa</groupId>
-            <artifactId>openjpa</artifactId>
-            <version>2.3.0</version>
-            <scope>test</scope>
-        </dependency>
 
     </dependencies>
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fd5beb5b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/util/jpa/QueryStringExtractorFactoryTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/util/jpa/QueryStringExtractorFactoryTest.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/util/jpa/QueryStringExtractorFactoryTest.java
index 32fb06f..c77b175 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/util/jpa/QueryStringExtractorFactoryTest.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/util/jpa/QueryStringExtractorFactoryTest.java
@@ -18,48 +18,100 @@
  */
 package org.apache.deltaspike.data.impl.util.jpa;
 
-import org.junit.Assert;
-import org.junit.Test;
+import static java.lang.Thread.currentThread;
+import static java.lang.reflect.Proxy.newProxyInstance;
+import static org.apache.deltaspike.data.test.util.TestDeployments.initDeployment;
+import static org.junit.Assert.assertEquals;
 
-import javax.persistence.PersistenceException;
-import javax.persistence.Query;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 
+import javax.inject.Inject;
+import javax.persistence.PersistenceException;
+import javax.persistence.Query;
+
+import org.apache.deltaspike.test.category.WebProfileCategory;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.Archive;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+@RunWith(Arquillian.class)
+@Category(WebProfileCategory.class)
 public class QueryStringExtractorFactoryTest
 {
 
+    private static final String QUERY_STRING = "it works";
+
+    @Inject
+    private QueryStringExtractorFactory factory;
+
+    @Deployment
+    public static Archive<?> deployment()
+    {
+        return initDeployment();
+    }
+
     @Test
     public void should_unwrap_query_even_proxied()
     {
-        // given
-
         // when
-        String extractor = new QueryStringExtractorFactory().extract((Query) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
new Class[]{Query.class}, new InvocationHandler() {
-            @Override
-            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
-                if (method.getName().equals("toString")) return "Unknown provider wrapper
for tests.";
-                if (method.getName().equals("unwrap")) {
-                    Class<?> clazz = (Class<?>) args[0];
-                    if (clazz.getName().contains("hibernate") || clazz.getName().contains("openjpa")
|| clazz.getName().contains("eclipse")) {
-                        return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
new Class[]{clazz}, new InvocationHandler() {
-                            @Override
-                            public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
-                                if (method.getName().equals("getQueryString")) return "it
works";
-                                return null;
-                            }
-                        }); // we don't care of teh result actually
-                    } else {
-                        throw new PersistenceException("Unable to unwrap for " + clazz);
+        String extracted = factory.extract((Query) newProxyInstance(currentThread().getContextClassLoader(),
+                        new Class[] { Query.class }, new InvocationHandler()
+            {
+                @Override
+                public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+                {
+                    if (method.getName().equals("toString"))
+                    {
+                        return "Unknown provider wrapper for tests.";
+                    }
+                    if (method.getName().equals("unwrap"))
+                    {
+                        Class<?> clazz = (Class<?>) args[0];
+                        if (clazz.getName().contains("hibernate") ||
+                                clazz.getName().contains("openjpa") ||
+                                clazz.getName().contains("eclipse"))
+                        {
+                            return createProxy(clazz);
+                        }
+                        else
+                        {
+                            throw new PersistenceException("Unable to unwrap for " + clazz);
+                        }
                     }
+                    return null;
                 }
-                return null;
-            }
-        }));
+            })
+        );
 
         // then
-        Assert.assertEquals("it works", extractor);
+        assertEquals(QUERY_STRING, extracted);
+    }
+
+    private static Object createProxy(Class<?> forClass)
+    {
+        return Proxy.newProxyInstance(currentThread().getContextClassLoader(),
+                new Class[] { forClass },
+                new FakeQueryInvocationHandler());
+    }
+
+    private static class FakeQueryInvocationHandler implements InvocationHandler
+    {
+
+        @Override
+        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+        {
+            if (!method.getReturnType().equals(String.class))
+            {
+                return createProxy(method.getReturnType());
+            }
+            return QUERY_STRING; // we don't care of the result actually
+        }
+
     }
 
 }


Mime
View raw message