Author: rmannibucau
Date: Tue Jun 18 09:30:43 2013
New Revision: 1494080
URL: http://svn.apache.org/r1494080
Log:
OWB-876 virtual resource handling in arquillian
Added:
openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/test/java/org/apache/webbeans/arquillian/test/VirtualResourceTest.java
Modified:
openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/main/java/org/apache/webbeans/arquillian/standalone/OwbStandaloneContainer.java
Modified:
openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/main/java/org/apache/webbeans/arquillian/standalone/OwbStandaloneContainer.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/main/java/org/apache/webbeans/arquillian/standalone/OwbStandaloneContainer.java?rev=1494080&r1=1494079&r2=1494080&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/main/java/org/apache/webbeans/arquillian/standalone/OwbStandaloneContainer.java
(original)
+++
openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/main/java/org/apache/webbeans/arquillian/standalone/OwbStandaloneContainer.java
Tue Jun 18 09:30:43 2013
@@ -35,6 +35,7 @@ import org.jboss.arquillian.container.sp
import org.jboss.arquillian.core.api.InstanceProducer;
import org.jboss.arquillian.core.api.annotation.Inject;
import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.classloader.ShrinkWrapClassLoader;
import org.jboss.shrinkwrap.descriptor.api.Descriptor;
/**
@@ -55,6 +56,8 @@ public class OwbStandaloneContainer impl
private OwbArquillianSingletonService singletonService;
private WebBeansContext webBeansContext;
+ private final ThreadLocal<ClassLoader> originalLoader = new
ThreadLocal<ClassLoader>();
+
@Override
public Class<OwbStandaloneConfiguration> getConfigurationClass()
{
@@ -109,6 +112,10 @@ public class OwbStandaloneContainer impl
throw new DeploymentException(e.getMessage(), e);
}
+ final ClassLoader parentLoader =
Thread.currentThread().getContextClassLoader();
+ originalLoader.set(parentLoader);
+ Thread.currentThread().setContextClassLoader(new
ShrinkWrapClassLoader(parentLoader, archive));
+
return new ProtocolMetaData();
}
@@ -126,6 +133,9 @@ public class OwbStandaloneContainer impl
lifecycle.stopApplication(null);
}
+
+ Thread.currentThread().setContextClassLoader(originalLoader.get());
+ originalLoader.remove();
}
@Override
Added:
openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/test/java/org/apache/webbeans/arquillian/test/VirtualResourceTest.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/test/java/org/apache/webbeans/arquillian/test/VirtualResourceTest.java?rev=1494080&view=auto
==============================================================================
---
openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/test/java/org/apache/webbeans/arquillian/test/VirtualResourceTest.java
(added)
+++
openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/src/test/java/org/apache/webbeans/arquillian/test/VirtualResourceTest.java
Tue Jun 18 09:30:43 2013
@@ -0,0 +1,69 @@
+/*
+ * 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.webbeans.arquillian.test;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.StringAsset;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+@RunWith(Arquillian.class)
+public class VirtualResourceTest
+{
+ @Deployment
+ public static Archive<?> jar()
+ {
+ return ShrinkWrap.create(JavaArchive.class).addAsResource(new
StringAsset("virtual"), "resource.txt");
+ }
+
+ @Test
+ public void checkResourceIsAvailable() throws IOException
+ {
+ final InputStream is =
Thread.currentThread().getContextClassLoader().getResourceAsStream("resource.txt");
+ assertNotNull(is);
+
+ try
+ {
+ assertEquals("virtual", new BufferedReader(new
InputStreamReader(is)).readLine());
+ }
+ finally
+ {
+ try
+ {
+ is.close();
+ }
+ catch (final IOException e)
+ {
+ // no-op
+ }
+ }
+ }
+}