tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r1199884 - in /openejb/trunk/openejb/arquillian-tomee: arquillian-tomee-tests/ arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/ arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/ext/enventries...
Date Wed, 09 Nov 2011 17:27:23 GMT
Author: dblevins
Date: Wed Nov  9 17:27:21 2011
New Revision: 1199884

URL: http://svn.apache.org/viewvc?rev=1199884&view=rev
Log:
Fixed tests so that they can be run from an IDE.

Added:
    openejb/trunk/openejb/arquillian-tomee/ziplock/src/main/java/org/apache/ziplock/JarLocation.java
Modified:
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/pom.xml
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/TestSetup.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/ext/enventries/StratocasterTest.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/getresources/GetResourcesTest.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/persistence/ServletPersistenceInjectionTest.java

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/pom.xml?rev=1199884&r1=1199883&r2=1199884&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/pom.xml (original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/pom.xml Wed Nov  9 17:27:21
2011
@@ -33,11 +33,19 @@
     </dependency>
 
     <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>ziplock</artifactId>
+      <version>${project.version}</version>
+      <type>jar</type>
+    </dependency>
+
+    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>4.9</version>
       <scope>test</scope>
     </dependency>
+
     <dependency>
       <groupId>org.jboss.arquillian.junit</groupId>
       <artifactId>arquillian-junit-container</artifactId>

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/TestSetup.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/TestSetup.java?rev=1199884&r1=1199883&r2=1199884&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/TestSetup.java
(original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/TestSetup.java
Wed Nov  9 17:27:21 2011
@@ -16,6 +16,7 @@
  */
 package org.apache.openejb.arquillian.tests;
 
+import org.apache.ziplock.JarLocation;
 import org.jboss.shrinkwrap.api.ArchivePaths;
 import org.jboss.shrinkwrap.api.ShrinkWrap;
 import org.jboss.shrinkwrap.api.asset.EmptyAsset;
@@ -24,6 +25,7 @@ import org.jboss.shrinkwrap.api.spec.Web
 import org.jboss.shrinkwrap.descriptor.api.Descriptors;
 import org.jboss.shrinkwrap.descriptor.api.spec.servlet.web.WebAppDescriptor;
 import org.junit.Assert;
+import org.junit.Test;
 
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
@@ -48,7 +50,7 @@ public abstract class TestSetup {
 
         WebArchive archive = ShrinkWrap.create(WebArchive.class, getTestContextName() + ".war")
                 .setWebXML(new StringAsset(descriptor.exportAsString()))
-                .addAsLibraries(new File("target/test-libs/junit.jar"))
+                .addAsLibraries(JarLocation.jarLocation(Test.class))
                 .addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));
         
         if (archiveClasses != null) {

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/ext/enventries/StratocasterTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/ext/enventries/StratocasterTest.java?rev=1199884&r1=1199883&r2=1199884&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/ext/enventries/StratocasterTest.java
(original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/ext/enventries/StratocasterTest.java
Wed Nov  9 17:27:21 2011
@@ -19,6 +19,7 @@ package org.apache.openejb.arquillian.te
 import org.apache.openejb.arquillian.tests.Tests;
 import org.apache.openejb.arquillian.tests.enventry.Code;
 import org.apache.openejb.arquillian.tests.enventry.PojoServlet;
+import org.apache.ziplock.JarLocation;
 import org.jboss.arquillian.container.test.api.Deployment;
 import org.jboss.arquillian.junit.Arquillian;
 import org.jboss.shrinkwrap.api.ShrinkWrap;
@@ -66,7 +67,7 @@ public class StratocasterTest {
                 .addClass(Pickup.class)
                 .addClass(PickupEditor.class)
                 .addClass(Style.class)
-                .addAsLibraries(new File("target/test-libs/junit.jar"))
+                .addAsLibraries(JarLocation.jarLocation(Test.class))
                 .setWebXML(new StringAsset(descriptor.exportAsString()));
 
 

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/getresources/GetResourcesTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/getresources/GetResourcesTest.java?rev=1199884&r1=1199883&r2=1199884&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/getresources/GetResourcesTest.java
(original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/getresources/GetResourcesTest.java
Wed Nov  9 17:27:21 2011
@@ -1,5 +1,6 @@
 package org.apache.openejb.arquillian.tests.getresources;
 
+import org.apache.ziplock.JarLocation;
 import org.jboss.arquillian.container.test.api.Deployment;
 import org.jboss.arquillian.junit.Arquillian;
 import org.jboss.shrinkwrap.api.ShrinkWrap;
@@ -31,7 +32,7 @@ import static org.apache.openejb.arquill
                 .addClass(GetResourcesHolder.class)
                 .addAsWebResource(Thread.currentThread().getContextClassLoader().getResource("test.getresources"),
"/config/test.getresources")
                 .addAsWebResource(Thread.currentThread().getContextClassLoader().getResource("test.getresources"),
"/config/test.getresources2")
-                .addAsLibraries(new File("target/test-libs/junit.jar"))
+                .addAsLibraries(JarLocation.jarLocation(Test.class))
                 .setWebXML(new StringAsset(
                       Descriptors.create(WebAppDescriptor.class)
                         .version("3.0").exportAsString()));

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/persistence/ServletPersistenceInjectionTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/persistence/ServletPersistenceInjectionTest.java?rev=1199884&r1=1199883&r2=1199884&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/persistence/ServletPersistenceInjectionTest.java
(original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/persistence/ServletPersistenceInjectionTest.java
Wed Nov  9 17:27:21 2011
@@ -17,6 +17,7 @@
 package org.apache.openejb.arquillian.tests.persistence;
 
 import org.apache.openejb.arquillian.tests.Runner;
+import org.apache.ziplock.JarLocation;
 import org.jboss.arquillian.container.test.api.Deployment;
 import org.jboss.arquillian.junit.Arquillian;
 import org.jboss.shrinkwrap.api.ArchivePaths;
@@ -70,7 +71,7 @@ public class ServletPersistenceInjection
                 .addClass(PersistenceServlet.class)
                 .addClass(Address.class)
                 .addClass(Runner.class)
-                .addAsLibraries(new File("target/test-libs/junit.jar"))
+                .addAsLibraries(JarLocation.jarLocation(Test.class))
                 .addAsManifestResource("persistence.xml", ArchivePaths.create("persistence.xml"))
                 .setWebXML(new StringAsset(descriptor.exportAsString()));
 

Added: openejb/trunk/openejb/arquillian-tomee/ziplock/src/main/java/org/apache/ziplock/JarLocation.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/ziplock/src/main/java/org/apache/ziplock/JarLocation.java?rev=1199884&view=auto
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/ziplock/src/main/java/org/apache/ziplock/JarLocation.java
(added)
+++ openejb/trunk/openejb/arquillian-tomee/ziplock/src/main/java/org/apache/ziplock/JarLocation.java
Wed Nov  9 17:27:21 2011
@@ -0,0 +1,123 @@
+/*
+ * 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.ziplock;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JarLocation {
+
+    public static File get() {
+        return jarLocation(JarLocation.class);
+    }
+
+    public static File jarLocation(Class clazz) {
+        try {
+            String classFileName = clazz.getName().replace(".", "/") + ".class";
+
+            ClassLoader loader = clazz.getClassLoader();
+            URL url;
+            if (loader != null) {
+                url = loader.getResource(classFileName);
+            } else {
+                url = clazz.getResource(classFileName);
+            }
+
+            if (url == null) {
+                throw new IllegalStateException("classloader.getResource(classFileName) returned
a null URL");
+            }
+
+            if ("jar".equals(url.getProtocol())) {
+                String spec = url.getFile();
+
+                int separator = spec.indexOf('!');
+                /*
+                 * REMIND: we don't handle nested JAR URLs
+                 */
+                if (separator == -1) throw new MalformedURLException("no ! found in jar url
spec:" + spec);
+
+                url = new URL(spec.substring(0, separator++));
+
+                return new File(decode(url.getFile()));
+
+            } else if ("file".equals(url.getProtocol())) {
+                return toFile(classFileName, url);
+            } else {
+                throw new IllegalArgumentException("Unsupported URL scheme: " + url.toExternalForm());
+            }
+        } catch (RuntimeException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    private static File toFile(String classFileName, URL url) {
+        String path = url.getFile();
+        path = path.substring(0, path.length() - classFileName.length());
+        return new File(decode(path));
+    }
+
+
+    public static String decode(String fileName) {
+        if (fileName.indexOf('%') == -1) return fileName;
+
+        StringBuilder result = new StringBuilder(fileName.length());
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+        for (int i = 0; i < fileName.length();) {
+            char c = fileName.charAt(i);
+
+            if (c == '%') {
+                out.reset();
+                do {
+                    if (i + 2 >= fileName.length()) {
+                        throw new IllegalArgumentException("Incomplete % sequence at: " +
i);
+                    }
+
+                    int d1 = Character.digit(fileName.charAt(i + 1), 16);
+                    int d2 = Character.digit(fileName.charAt(i + 2), 16);
+
+                    if (d1 == -1 || d2 == -1) {
+                        throw new IllegalArgumentException("Invalid % sequence (" + fileName.substring(i,
i + 3) + ") at: " + String.valueOf(i));
+                    }
+
+                    out.write((byte) ((d1 << 4) + d2));
+
+                    i += 3;
+
+                } while (i < fileName.length() && fileName.charAt(i) == '%');
+
+
+                result.append(out.toString());
+
+                continue;
+            } else {
+                result.append(c);
+            }
+
+            i++;
+        }
+        return result.toString();
+    }
+
+}



Mime
View raw message