You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by jo...@apache.org on 2013/12/29 15:42:09 UTC
git commit: DELTASPIKE-399 Refactored tests to not require OWB
changes.
Updated Branches:
refs/heads/master ed5e33687 -> 1620ea708
DELTASPIKE-399 Refactored tests to not require OWB changes.
Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/1620ea70
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/1620ea70
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/1620ea70
Branch: refs/heads/master
Commit: 1620ea7081d399c958120f64dcca517d18f305e2
Parents: ed5e336
Author: John D. Ament <jo...@gmail.com>
Authored: Sun Dec 29 09:41:37 2013 -0500
Committer: John D. Ament <jo...@gmail.com>
Committed: Sun Dec 29 09:41:37 2013 -0500
----------------------------------------------------------------------
.../core/impl/resourceloader/Cdi10Bean.java | 57 --------------
.../core/impl/resourceloader/Cdi11Bean.java | 79 -------------------
.../resourceloader/ClasspathResourceTest.java | 55 ++++++-------
.../resourceloader/ClasspathWebProfileTest.java | 80 +++++++++++++++++++
.../impl/resourceloader/FileResourceTest.java | 81 +++++++-------------
.../impl/resourceloader/TestResourceHolder.java | 38 ---------
deltaspike/parent/code/pom.xml | 2 +-
7 files changed, 131 insertions(+), 261 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1620ea70/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/Cdi10Bean.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/Cdi10Bean.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/Cdi10Bean.java
deleted file mode 100644
index 45c390b..0000000
--- a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/Cdi10Bean.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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.deltaspike.test.core.impl.resourceloader;
-
-import javax.enterprise.inject.Instance;
-import java.io.InputStream;
-import java.util.List;
-import java.util.Properties;
-
-public class Cdi10Bean implements TestResourceHolder
-{
- @Override
- public InputStream getInputStream()
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Properties getProperties()
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Instance<InputStream> getInputStreamInstance()
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Instance<Properties> getPropertiesInstance()
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public List<InputStream> getInputStreams()
- {
- throw new UnsupportedOperationException();
- }
-}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1620ea70/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/Cdi11Bean.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/Cdi11Bean.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/Cdi11Bean.java
deleted file mode 100644
index 47b7df6..0000000
--- a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/Cdi11Bean.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * 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.deltaspike.test.core.impl.resourceloader;
-
-import org.apache.deltaspike.core.api.resourceloader.ClasspathStorage;
-import org.apache.deltaspike.core.api.resourceloader.ExternalResource;
-
-import javax.enterprise.context.Dependent;
-import javax.enterprise.inject.Any;
-import javax.enterprise.inject.Instance;
-import javax.inject.Inject;
-import java.io.InputStream;
-import java.util.List;
-import java.util.Properties;
-
-@Dependent
-public class Cdi11Bean implements TestResourceHolder
-{
- @Inject
- @ExternalResource(storage = ClasspathStorage.class,location="testconfig.properties")
- private InputStream inputStream;
-
- @Inject
- @ExternalResource(storage = ClasspathStorage.class,location="testconfig.properties")
- private Properties properties;
-
- @Inject
- @ExternalResource(storage = ClasspathStorage.class,location="META-INF/beans.xml")
- private List<InputStream> inputStreams;
-
- @Inject
- @Any
- private Instance<InputStream> inputStreamInstance;
-
- @Inject
- @Any
- private Instance<Properties> propertiesInstance;
-
- public InputStream getInputStream()
- {
- return inputStream;
- }
-
- public Properties getProperties()
- {
- return properties;
- }
-
- public Instance<InputStream> getInputStreamInstance()
- {
- return inputStreamInstance;
- }
-
- public Instance<Properties> getPropertiesInstance()
- {
- return propertiesInstance;
- }
-
- @Override
- public List<InputStream> getInputStreams() {
- return inputStreams;
- }
-}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1620ea70/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/ClasspathResourceTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/ClasspathResourceTest.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/ClasspathResourceTest.java
index 3c91ad0..1fb0435 100644
--- a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/ClasspathResourceTest.java
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/ClasspathResourceTest.java
@@ -21,6 +21,8 @@ package org.apache.deltaspike.test.core.impl.resourceloader;
import org.apache.deltaspike.core.api.literal.ExternalResourceLiteral;
import org.apache.deltaspike.core.api.resourceloader.ClasspathStorage;
+import org.apache.deltaspike.core.api.resourceloader.ExternalResource;
+import org.apache.deltaspike.test.category.SeCategory;
import org.apache.deltaspike.test.util.ArchiveUtils;
import org.apache.deltaspike.test.utils.CdiContainerUnderTest;
import org.apache.deltaspike.test.utils.CdiImplementation;
@@ -34,6 +36,7 @@ import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import javax.inject.Inject;
@@ -43,69 +46,55 @@ import java.util.List;
import java.util.Properties;
@RunWith(Arquillian.class)
+@Category(SeCategory.class)
public class ClasspathResourceTest
{
@Deployment
public static Archive<?> createResourceLoaderArchive()
{
- Class versionDependentImplementation = Cdi11Bean.class;
- if (isOwbForCdi10())
- {
- versionDependentImplementation = Cdi10Bean.class;
- }
-
Archive<?> arch = ShrinkWrap.create(WebArchive.class, ClasspathResourceTest.class.getSimpleName() + ".war")
- .addClass(TestResourceHolder.class)
- .addClass(versionDependentImplementation)
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
- .add(new StringAsset("some.propertykey = somevalue"), "WEB-INF/classes/testconfig.properties")
.addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive());
return arch;
}
@Inject
- private TestResourceHolder testResourceHolder;
+ @ExternalResource(storage = ClasspathStorage.class,location="myconfig.properties")
+ private InputStream inputStream;
+
+ @Inject
+ @ExternalResource(storage = ClasspathStorage.class,location="myconfig.properties")
+ private Properties properties;
+
@Test
public void testInputStream() throws IOException
{
- Assume.assumeTrue(!isOwbForCdi10());
-
- Assert.assertNotNull(testResourceHolder.getInputStream());
+ Assert.assertNotNull(inputStream);
Properties p = new Properties();
- p.load(testResourceHolder.getInputStream());
+ p.load(inputStream);
Assert.assertEquals("somevalue", p.getProperty("some.propertykey", "wrong answer"));
}
@Test
public void testProperties()
{
- Assume.assumeTrue(!isOwbForCdi10());
-
Assert.assertEquals("somevalue",
- testResourceHolder.getProperties().getProperty("some.propertykey", "wrong answer"));
- }
-
- @Test(expected = RuntimeException.class)
- public void testAmbiguousFileLookup()
- {
- Assume.assumeTrue(!isOwbForCdi10());
-
- testResourceHolder.getInputStreamInstance()
- .select(new ExternalResourceLiteral(ClasspathStorage.class, "META-INF/beans.xml")).get();
+ properties.getProperty("some.propertykey", "wrong answer"));
}
@Test
- public void testSuccessfulAmbiguousLookup()
+ public void testAmbiguousFileLookup(@ExternalResource(storage=ClasspathStorage.class,
+ location="META-INF/beans.xml") InputStream inputStream)
{
- Assume.assumeTrue(!isOwbForCdi10());
- //note, we only test this on classpath, since File impl is always getting 1.
- List<InputStream> streams = testResourceHolder.getInputStreams();
- Assert.assertTrue(streams.size() > 1); //the count is different on as7 compared to the standalone setup
+ // for some reason, this works
+ Assert.assertNull(inputStream);
}
- private static boolean isOwbForCdi10()
+ @Test
+ public void testSuccessfulAmbiguousLookup(@ExternalResource(storage = ClasspathStorage.class,
+ location="META-INF/beans.xml") List<InputStream> inputStreams)
{
- return CdiContainerUnderTest.isCdiVersion(CdiImplementation.OWB11) || CdiContainerUnderTest.isCdiVersion(CdiImplementation.OWB12);
+ Assert.assertTrue(inputStreams.size() > 1); //the count is different on as7 compared to the standalone setup
}
}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1620ea70/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/ClasspathWebProfileTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/ClasspathWebProfileTest.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/ClasspathWebProfileTest.java
new file mode 100644
index 0000000..b565d6b
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/ClasspathWebProfileTest.java
@@ -0,0 +1,80 @@
+package org.apache.deltaspike.test.core.impl.resourceloader;
+
+import org.apache.deltaspike.core.api.resourceloader.ClasspathStorage;
+import org.apache.deltaspike.core.api.resourceloader.ExternalResource;
+import org.apache.deltaspike.test.category.WebProfileCategory;
+import org.apache.deltaspike.test.util.ArchiveUtils;
+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.EmptyAsset;
+import org.jboss.shrinkwrap.api.asset.StringAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import javax.inject.Inject;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * web profile will run in a separate JVM, as a result need to manually add the properties to the archive.
+ */
+@RunWith(Arquillian.class)
+@Category(WebProfileCategory.class)
+public class ClasspathWebProfileTest
+{
+ @Deployment
+ public static Archive<?> createResourceLoaderArchive()
+ {
+ Archive<?> arch = ShrinkWrap.create(WebArchive.class, ClasspathWebProfileTest.class.getSimpleName() + ".war")
+ .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
+ .addAsResource(new StringAsset("some.propertykey = somevalue"), "myconfig.properties")
+ .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive());
+ return arch;
+ }
+
+ @Inject
+ @ExternalResource(storage = ClasspathStorage.class,location="myconfig.properties")
+ private InputStream inputStream;
+
+ @Inject
+ @ExternalResource(storage = ClasspathStorage.class,location="myconfig.properties")
+ private Properties properties;
+
+ @Test
+ public void testInputStream() throws IOException
+ {
+ Assert.assertNotNull(inputStream);
+ Properties p = new Properties();
+ p.load(inputStream);
+ Assert.assertEquals("somevalue", p.getProperty("some.propertykey", "wrong answer"));
+ }
+
+ @Test
+ public void testProperties()
+ {
+ Assert.assertEquals("somevalue",
+ properties.getProperty("some.propertykey", "wrong answer"));
+ }
+
+ @Test
+ public void testAmbiguousFileLookup(@ExternalResource(storage=ClasspathStorage.class,
+ location="META-INF/beans.xml") InputStream inputStream)
+ {
+ // for some reason, this works
+ Assert.assertNull(inputStream);
+ }
+
+ @Test
+ public void testSuccessfulAmbiguousLookup(@ExternalResource(storage = ClasspathStorage.class,
+ location="META-INF/beans.xml") List<InputStream> inputStreams)
+ {
+ Assert.assertTrue(inputStreams.size() > 1); //the count is different on as7 compared to the standalone setup
+ }
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1620ea70/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/FileResourceTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/FileResourceTest.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/FileResourceTest.java
index bb3e229..d0766a7 100644
--- a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/FileResourceTest.java
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/FileResourceTest.java
@@ -19,12 +19,10 @@
package org.apache.deltaspike.test.core.impl.resourceloader;
-import org.apache.deltaspike.core.api.literal.ExternalResourceLiteral;
+import org.apache.deltaspike.core.api.resourceloader.ExternalResource;
import org.apache.deltaspike.core.api.resourceloader.FileSystemStorage;
import org.apache.deltaspike.core.util.ExceptionUtils;
import org.apache.deltaspike.test.util.ArchiveUtils;
-import org.apache.deltaspike.test.utils.CdiContainerUnderTest;
-import org.apache.deltaspike.test.utils.CdiImplementation;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
@@ -32,13 +30,10 @@ import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
-import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import javax.enterprise.inject.Any;
-import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import java.io.File;
import java.io.FileWriter;
@@ -49,60 +44,47 @@ import java.util.Properties;
@RunWith(Arquillian.class)
public class FileResourceTest
{
- private static String tempFileName;
-
+ private boolean created = false;
@Before
public void createTempFile()
{
- String javaiotmpdir = System.getProperty("java.io.tmpdir","/tmp");
- File tmpDir = new File(javaiotmpdir);
- try
- {
- File f = File.createTempFile("props",System.currentTimeMillis()+"",tmpDir);
- FileWriter fw = new FileWriter(f);
- fw.write("some.propertykey=somevalue");
- fw.close();
- tempFileName = f.getAbsolutePath();
- f.deleteOnExit();
- }
- catch (IOException e)
+ if (!created)
{
- throw ExceptionUtils.throwAsRuntimeException(e);
+ String javaiotmpdir = System.getProperty("java.io.tmpdir","/tmp");
+ File tmpDir = new File(javaiotmpdir);
+ try
+ {
+ File dest = new File(tmpDir,"/propsdsfileresource.properties");
+ FileWriter fw = new FileWriter(dest);
+ fw.write("some.propertykey=somevalue");
+ fw.close();
+ dest.deleteOnExit();
+ }
+ catch (IOException e)
+ {
+ throw ExceptionUtils.throwAsRuntimeException(e);
+ }
+ finally
+ {
+ created = true;
+ }
}
}
@Deployment
public static Archive<?> createResourceLoaderArchive()
{
- Class versionDependentImplementation = Cdi11Bean.class;
- if (isOwbForCdi10())
- {
- versionDependentImplementation = Cdi10Bean.class;
- }
-
Archive<?> arch = ShrinkWrap.create(WebArchive.class, FileResourceTest.class.getSimpleName() + ".war")
- .addClass(TestResourceHolder.class)
- .addClass(versionDependentImplementation)
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
.addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive());
return arch;
}
- @Inject
- @Any
- private Instance<InputStream> inputStreamInst;
-
- @Inject
- @Any
- private Instance<Properties> propsInst;
-
@Test
- public void testInputStream() throws IOException
+ public void testInputStream(@ExternalResource(storage=FileSystemStorage.class,
+ location="/tmp/propsdsfileresource.properties")
+ InputStream inputStream) throws IOException
{
- Assume.assumeTrue(!isOwbForCdi10());
-
- InputStream inputStream = inputStreamInst
- .select(new ExternalResourceLiteral(FileSystemStorage.class, tempFileName)).get();
Assert.assertNotNull(inputStream);
Properties p = new Properties();
p.load(inputStream);
@@ -110,17 +92,10 @@ public class FileResourceTest
}
@Test
- public void testProperties()
- {
- Assume.assumeTrue(!isOwbForCdi10());
-
- Properties props = this.propsInst.select(new ExternalResourceLiteral(FileSystemStorage.class,tempFileName))
- .get();
- Assert.assertEquals("somevalue", props.getProperty("some.propertykey", "wrong answer"));
- }
-
- private static boolean isOwbForCdi10()
+ public void testProperties(@ExternalResource(storage=FileSystemStorage.class,
+ location="/tmp/propsdsfileresource.properties")
+ Properties properties)
{
- return CdiContainerUnderTest.isCdiVersion(CdiImplementation.OWB11) || CdiContainerUnderTest.isCdiVersion(CdiImplementation.OWB12);
+ Assert.assertEquals("somevalue", properties.getProperty("some.propertykey", "wrong answer"));
}
}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1620ea70/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/TestResourceHolder.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/TestResourceHolder.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/TestResourceHolder.java
deleted file mode 100644
index 730efba..0000000
--- a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/resourceloader/TestResourceHolder.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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.deltaspike.test.core.impl.resourceloader;
-
-import javax.enterprise.inject.Instance;
-import java.io.InputStream;
-import java.util.List;
-import java.util.Properties;
-
-//just needed to build different archives - otherwise injection would fail with owb implementing cdi 1.0
-public interface TestResourceHolder
-{
- InputStream getInputStream();
-
- Properties getProperties();
-
- Instance<InputStream> getInputStreamInstance();
-
- Instance<Properties> getPropertiesInstance();
-
- List<InputStream> getInputStreams();
-}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1620ea70/deltaspike/parent/code/pom.xml
----------------------------------------------------------------------
diff --git a/deltaspike/parent/code/pom.xml b/deltaspike/parent/code/pom.xml
index 91122ad..a2fa4f6 100644
--- a/deltaspike/parent/code/pom.xml
+++ b/deltaspike/parent/code/pom.xml
@@ -481,7 +481,7 @@
<!--
* JBoss AS-7 will be downloaded as maven dependency
*
- * JBOSS_HOME must be set for this work correctly!
+ * JBOSS_HOME need not be set for this.
*
* Start the build with:
* $> mvn clean install -Pjbossas-build-managed-7