Permalink
Browse files

Added some tests

  • Loading branch information...
1 parent 070677b commit e24c40c58e402462bda18c82f8e73df0f97754a5 @hasalex hasalex committed Dec 30, 2011
View
8 README
@@ -11,7 +11,7 @@ Configuration example :
</container>
API URL, key and secret are in ~/.cloudbees/cloudbees-api.properties.
-CDI is working on my example.
+CDI is working when deployed in a jar file. Not in a war or ear.
JAX-RS as-client is working on my example.
@@ -23,3 +23,9 @@ It does not work with a simple @EJB
Greeter greeter;
The EJB enricher does not work because the JNDI names in Cloudbees are not compliant with Arquillian's lookup.
+EAR deployment is not supported yet.
+
+
+Restrictions
+============
+Multiple @Deployment per test class does not work because only one archive is really deployed in an application.
View
22 pom.xml
@@ -98,13 +98,6 @@
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.jboss.arquillian.ajocado</groupId>
- <artifactId>arquillian-ajocado-junit</artifactId>
- <scope>test</scope>
- <type>pom</type>
- <version>${version.arquillian_ajocado}</version>
- </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -141,19 +134,4 @@
</dependency>
</dependencies>
</dependencyManagement>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <includes>
- <include>**/ArchiveUtilTestCase*</include>
- <include>**/ProtocolMetadataParserTestCase*</include>
- </includes>
- </configuration>
- </plugin>
- </plugins>
- </build>
</project>
@@ -38,7 +38,10 @@
void deployWar(String appId, String description, String archivePath, String containerType) throws DeploymentException {
deployArchive(appId, description, archivePath, ArchiveType.WAR, containerType);
}
-
+ void deployEar(String appId, String description, String archivePath, String containerType) throws DeploymentException {
+ deployArchive(appId, description, archivePath, ArchiveType.EAR, containerType);
+ }
+
private void deployArchive(String appId, String description, String archivePath, ArchiveType archiveType, String containerType) throws DeploymentException {
try {
Map<String, String> parameters = new HashMap<String, String>();
@@ -50,11 +53,11 @@ private void deployArchive(String appId, String description, String archivePath,
}
}
- void delete(String appId) throws LifecycleException {
+ void delete(String appId) throws DeploymentException {
try {
- client.applicationDelete(appId);
+// client.applicationDelete(appId);
} catch (Exception ex) {
- throw new LifecycleException("Cannot delete app " + appId, ex);
+ throw new DeploymentException("Cannot delete app " + appId, ex);
}
}
boolean isExisting(String appId) throws LifecycleException {
@@ -21,6 +21,8 @@
import org.jboss.arquillian.core.spi.ServiceLoader;
import org.jboss.arquillian.protocol.servlet.ServletMethodExecutor;
import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.descriptor.api.Descriptor;
/**
@@ -66,8 +68,6 @@ public void start() throws LifecycleException {
@Override
public void stop() throws LifecycleException {
log.info("Stop");
- CloudbeesConfiguration conf = configuration.get();
- cloudbees.delete(conf.getAppId());
}
@Override
@@ -82,27 +82,43 @@ public void undeploy(Descriptor descriptor) throws DeploymentException {
@Override
public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
- log.info("Deploy archive");
+ log.info("Deploy archive of type " + archive.getClass().getSimpleName());
Validate.notNull(archive, "Archive must not be null");
CloudbeesConfiguration conf = configuration.get();
String appId = conf.getAppId();
String archivePath = ShrinkWrapUtil.toURL(archive).getPath();
- cloudbees.deployWar(appId, "Test war from Arquillian", archivePath, conf.getContainerType());
+ if (archive instanceof WebArchive) {
+ cloudbees.deployWar(appId, "Test war from Arquillian", archivePath, conf.getContainerType());
+ return buildWarMetadata(conf);
+ } else if (archive instanceof EnterpriseArchive) {
+ cloudbees.deployEar(appId, "Test ear from Arquillian", archivePath, conf.getContainerType());
+ return buildEarMetadata(conf);
+ } else {
+ throw new UnsupportedOperationException("undeploy with descriptor not implemented");
+ }
- return buildMetadata(conf);
}
@Override
public void undeploy(Archive<?> archive) throws DeploymentException {
log.info("Undeploy archive");
+ CloudbeesConfiguration conf = configuration.get();
+ cloudbees.delete(conf.getAppId());
}
- private ProtocolMetaData buildMetadata(CloudbeesConfiguration conf) {
+ private ProtocolMetaData buildWarMetadata(CloudbeesConfiguration conf) {
ProtocolMetaData metaData = new ProtocolMetaData();
HTTPContext context = new HTTPContext(conf.getHostName(), 80);
context.add(new Servlet(ServletMethodExecutor.ARQUILLIAN_SERVLET_NAME, ""));
metaData.addContext(context);
return metaData;
}
+ private ProtocolMetaData buildEarMetadata(CloudbeesConfiguration conf) {
+ ProtocolMetaData metaData = new ProtocolMetaData();
+ HTTPContext context = new HTTPContext(conf.getHostName(), 80);
+ context.add(new Servlet(ServletMethodExecutor.ARQUILLIAN_SERVLET_NAME, "test"));
+ metaData.addContext(context);
+ return metaData;
+ }
}
@@ -0,0 +1,38 @@
+package org.jboss.arquillian.container.cloudbees;
+
+import javax.inject.Inject;
+import org.jboss.arquillian.container.cloudbees.cdi.EchoService;
+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.spec.JavaArchive;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import org.junit.runner.RunWith;
+
+/**
+ *
+ * @author alexis
+ */
+@RunWith(Arquillian.class)
+public class CloudbeesCdiJarTest {
+
+ @Deployment
+ public static Archive<?> deploy() {
+ return ShrinkWrap.create(JavaArchive.class)
+ .addClasses(EchoService.class)
+ .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
+ }
+
+ @Inject
+ EchoService bean;
+
+ @Test
+ public void shouldBeanBeInjected() {
+ assertNotNull("Bean has not bean injected", bean);
+ String message = "azerty";
+ assertEquals("Bean has bean injected, but is not able to repeat", message, bean.repeatAfterMe(message));
+ }
+}
@@ -0,0 +1,39 @@
+package org.jboss.arquillian.container.cloudbees;
+
+import javax.inject.Inject;
+import org.jboss.arquillian.container.cloudbees.cdi.EchoService;
+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.spec.WebArchive;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import org.junit.Ignore;
+import org.junit.runner.RunWith;
+
+/**
+ *
+ * @author alexis
+ */
+@RunWith(Arquillian.class)
+public class CloudbeesCdiWarTest {
+
+ @Deployment
+ public static Archive<?> deploy() {
+ return ShrinkWrap.create(WebArchive.class)
+ .addClasses(EchoService.class)
+ .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
+ }
+
+ @Inject
+ EchoService bean;
+
+ @Test @Ignore // FAILS
+ public void shouldBeanBeInjected() {
+ assertNotNull("Bean has not bean injected", bean);
+ String message = "azerty";
+ assertEquals("Bean has bean injected, but is not able to repeat", message, bean.repeatAfterMe(message));
+ }
+}
@@ -0,0 +1,50 @@
+/*
+ * To change this template, choose Tools | Templates and open the template in
+ * the editor.
+ */
+package org.jboss.arquillian.container.cloudbees;
+
+import javax.ejb.EJB;
+import org.jboss.arquillian.container.cloudbees.ejb.EchoService;
+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.spec.EnterpriseArchive;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import org.junit.Ignore;
+import org.junit.runner.RunWith;
+
+/**
+ *
+ * @author alexis
+ */
+@RunWith(Arquillian.class)
+public class CloudbeesEjbEarTest {
+
+ @Deployment
+ public static Archive<?> deploy() {
+ return ShrinkWrap.create(EnterpriseArchive.class)
+ .addAsModule(ShrinkWrap.create(JavaArchive.class, "test.jar")
+ .addClasses(EchoService.class))
+ .setApplicationXML("application.xml");
+ }
+
+ @EJB
+ EchoService bean;
+
+ @EJB(beanName="EchoService")
+ EchoService namedBean;
+
+ @Test @Ignore // It fails :-(
+ public void shouldEjbBeInjected() {
+ assertNotNull("Anonymous bean has not bean injected", bean);
+ }
+
+ @Test
+ public void shouldNamedEjbBeInjected() {
+ assertNotNull("Named bean has not bean injected", namedBean);
+ }
+}
@@ -0,0 +1,48 @@
+/*
+ * To change this template, choose Tools | Templates and open the template in
+ * the editor.
+ */
+package org.jboss.arquillian.container.cloudbees;
+
+import javax.ejb.EJB;
+import org.jboss.arquillian.container.cloudbees.ejb.EchoService;
+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.spec.JavaArchive;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import org.junit.Ignore;
+import org.junit.runner.RunWith;
+
+/**
+ *
+ * @author alexis
+ */
+@RunWith(Arquillian.class)
+public class CloudbeesEjbJarTest {
+
+ @Deployment
+ public static Archive<?> deploy() {
+ return ShrinkWrap.create(JavaArchive.class)
+ .addClasses(EchoService.class);
+ }
+
+ @EJB
+ EchoService bean;
+
+ @EJB(beanName="EchoService")
+ EchoService namedBean;
+
+ @Test @Ignore // It fails :-(
+ public void shouldEjbBeInjected() {
+ assertNotNull("Anonymous bean has not bean injected", bean);
+ }
+
+ @Test
+ public void shouldNamedEjbBeInjected() {
+ assertNotNull("Named bean has not bean injected", namedBean);
+ }
+}
@@ -0,0 +1,47 @@
+/*
+ * To change this template, choose Tools | Templates and open the template in
+ * the editor.
+ */
+package org.jboss.arquillian.container.cloudbees;
+
+import javax.ejb.EJB;
+import org.jboss.arquillian.container.cloudbees.ejb.EchoService;
+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.spec.WebArchive;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import org.junit.Ignore;
+import org.junit.runner.RunWith;
+
+/**
+ *
+ * @author alexis
+ */
+@RunWith(Arquillian.class)
+public class CloudbeesEjbWarTest {
+
+ @Deployment
+ public static Archive<?> deploy() {
+ return ShrinkWrap.create(WebArchive.class)
+ .addClasses(EchoService.class);
+ }
+
+ @EJB
+ EchoService bean;
+
+ @EJB(beanName="EchoService")
+ EchoService namedBean;
+
+ @Test @Ignore // It fails :-(
+ public void shouldEjbBeInjected() {
+ assertNotNull("Anonymous bean has not bean injected", bean);
+ }
+
+ @Test
+ public void shouldNamedEjbBeInjected() {
+ assertNotNull("Named bean has not bean injected", namedBean);
+ }
+}
@@ -0,0 +1,12 @@
+package org.jboss.arquillian.container.cloudbees.cdi;
+
+/**
+ * Small example of CDI 1.0 bean
+ *
+ * @author Alexis Hassler
+ */
+public class EchoService {
+ public String repeatAfterMe(String message) {
+ return message;
+ }
+}
Oops, something went wrong.

0 comments on commit e24c40c

Please sign in to comment.