From d7c81f81fad9b31a1aff6101226537648e8a8d93 Mon Sep 17 00:00:00 2001 From: Bernard Labno Date: Wed, 25 Apr 2012 09:03:50 +0200 Subject: [PATCH] Implementation for servlet protocol. - Force undeployment before deployment if deployment is required. - Workaround to AS7-4620. --- README.md | 23 ++- impl/pom.xml | 44 +++++ .../jrebel/DeploymentInterceptor.java | 157 ++++++++++++++++++ .../extension/jrebel/JRebelExtension.java | 18 +- .../jrebel/SerializableHttpContextData.java | 70 ++++++++ .../extension/jrebel/Serializer.java | 94 ++++++----- .../extension/jrebel/ShrinkWrapUtil.java | 35 ++-- ...boss.arquillian.core.spi.LoadableExtension | 0 int-test/pom.xml | 123 ++++++++++++++ .../extension/jrebel/InjectableArtifact.java | 22 +++ .../jrebel/JRebelIntegrationTestCase.java | 55 +++--- .../jrebel/MultipleDeploymentsTestCase.java | 58 +++++++ .../arquillian/extension/jrebel/Packager.java | 29 ++++ int-test/src/test/resources/arquillian.xml | 11 ++ pom.xml | 71 ++------ .../jrebel/DeploymentInterceptor.java | 116 ------------- 16 files changed, 654 insertions(+), 272 deletions(-) create mode 100644 impl/pom.xml create mode 100644 impl/src/main/java/org/jboss/arquillian/extension/jrebel/DeploymentInterceptor.java rename {src => impl/src}/main/java/org/jboss/arquillian/extension/jrebel/JRebelExtension.java (75%) create mode 100644 impl/src/main/java/org/jboss/arquillian/extension/jrebel/SerializableHttpContextData.java rename {src => impl/src}/main/java/org/jboss/arquillian/extension/jrebel/Serializer.java (59%) rename {src => impl/src}/main/java/org/jboss/arquillian/extension/jrebel/ShrinkWrapUtil.java (64%) rename {src => impl/src}/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension (100%) create mode 100644 int-test/pom.xml create mode 100644 int-test/src/main/java/org/jboss/arquillian/extension/jrebel/InjectableArtifact.java rename {src => int-test/src}/test/java/org/jboss/arquillian/extension/jrebel/JRebelIntegrationTestCase.java (56%) create mode 100644 int-test/src/test/java/org/jboss/arquillian/extension/jrebel/MultipleDeploymentsTestCase.java create mode 100644 int-test/src/test/java/org/jboss/arquillian/extension/jrebel/Packager.java create mode 100644 int-test/src/test/resources/arquillian.xml delete mode 100644 src/main/java/org/jboss/arquillian/extension/jrebel/DeploymentInterceptor.java diff --git a/README.md b/README.md index 71e25a1..a5cfae3 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,26 @@ JRebel - The Arquillian Experience ----------------------------------- +================================== +This extension is for speeding up test development cycle. It deploys the package only once and then leverages [JRebel][jrebel] to hot deploy changed files. +Usage +----- +Just add impl module to classpath and run test either from IDE or maven. -http://zeroturnaround.com/jrebel/ + + org.jboss.arquillian.extension + arquillian-jrebel-impl + 1.0.0.Alpha1-SNAPSHOT + + +**Make sure you use servlet protocol!** To do that add following to arquillian.xml: + + + +First time you run test it will deploy the package, export the deployment to target/jrebel-temp directory and attach auto generated rebel.xml file that instructs JRebel to override deployed package with the one exported to target/jrebel-temp. Next time you run the test Arquillian will check if package exists in the temp directory and if so it will run tests without deploying the package. + +If you want to force Arquillian to deploy the package again to the container you have to delete the temp directory. + + +[jrebel]: http://zeroturnaround.com/jrebel/ diff --git a/impl/pom.xml b/impl/pom.xml new file mode 100644 index 0000000..6fa803e --- /dev/null +++ b/impl/pom.xml @@ -0,0 +1,44 @@ + + + + + + org.jboss.arquillian.extension + arquillian-jrebel-parent + 1.0.0.Alpha1-SNAPSHOT + + + + 4.0.0 + + + arquillian-jrebel-impl + 1.0.0.Alpha1-SNAPSHOT + Arquillian Extension JRebel Implementation + http://www.jboss.org + Arquillian Extension JRebel + + + + + org.jboss.arquillian.core + arquillian-core-spi + + + org.jboss.arquillian.container + arquillian-container-impl-base + + + junit + junit + test + + + org.jboss.arquillian.junit + arquillian-junit-container + test + + + + diff --git a/impl/src/main/java/org/jboss/arquillian/extension/jrebel/DeploymentInterceptor.java b/impl/src/main/java/org/jboss/arquillian/extension/jrebel/DeploymentInterceptor.java new file mode 100644 index 0000000..80a98bb --- /dev/null +++ b/impl/src/main/java/org/jboss/arquillian/extension/jrebel/DeploymentInterceptor.java @@ -0,0 +1,157 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors + * as indicated by the @authors tag. All rights reserved. + * See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed 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.jboss.arquillian.extension.jrebel; + +import org.jboss.arquillian.container.spi.client.deployment.Deployment; +import org.jboss.arquillian.container.spi.client.deployment.DeploymentDescription; +import org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext; +import org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData; +import org.jboss.arquillian.container.spi.context.annotation.DeploymentScoped; +import org.jboss.arquillian.container.spi.event.DeployDeployment; +import org.jboss.arquillian.container.spi.event.DeploymentEvent; +import org.jboss.arquillian.container.spi.event.UnDeployDeployment; +import org.jboss.arquillian.core.api.Event; +import org.jboss.arquillian.core.api.InstanceProducer; +import org.jboss.arquillian.core.api.annotation.Inject; +import org.jboss.arquillian.core.api.annotation.Observes; +import org.jboss.arquillian.core.spi.EventContext; +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.exporter.ExplodedExporter; +import org.jboss.shrinkwrap.api.formatter.Formatters; + +import java.io.File; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * DeploymentInterceptor + * + * @author Aslak Knutsen + * @version $Revision: $ + */ +public class DeploymentInterceptor { +// ------------------------------ FIELDS ------------------------------ + + private static final Logger LOGGER = Logger.getLogger(DeploymentInterceptor.class.getName()); + + @Inject + @DeploymentScoped + private InstanceProducer deploymentDescriptionProducer; + + @Inject + @DeploymentScoped + private InstanceProducer deploymentProducer; + + @Inject + private Event event; + + private boolean forcedUndeployment; + + @Inject + @DeploymentScoped + private InstanceProducer protocolMetaData; + + private final File tempDirectory; + +// --------------------------- CONSTRUCTORS --------------------------- + + public DeploymentInterceptor() + { + tempDirectory = ShrinkWrapUtil.createTempDirectory(); + } + +// -------------------------- OTHER METHODS -------------------------- + + public void onDeploy(@Observes(precedence = -1) EventContext eventContext) + { + final Deployment deployment = eventContext.getEvent().getDeployment(); + Archive archive = deployment.getDescription().getTestableArchive(); + File exportPath = new File(tempDirectory, archive.getName()); + File metaDataFile = new File(tempDirectory, archive.getName() + ".meta"); + boolean alreadyDeployed = exportPath.exists() && metaDataFile.exists(); + //noinspection ResultOfMethodCallIgnored + exportPath.mkdirs(); + archive.as(ExplodedExporter.class).exportExploded(tempDirectory); + + + if (!alreadyDeployed) { + forcedUndeployment = true; + try { + event.fire(new UnDeployDeployment(eventContext.getEvent().getContainer(), deployment)); + } catch (Exception e) { + LOGGER.log(Level.WARNING, "Cannot undeploy " + deployment.getDescription().getName(), e); + } finally { + forcedUndeployment = false; + } +// TODO if rebel.xml already exists in the archive then don't add new one and don't do exploded export + String rebelXml = createRebelXML(exportPath); + archive.add(new StringAsset(rebelXml), "WEB-INF/classes/rebel.xml"); + + System.out.println(archive.toString(Formatters.VERBOSE)); + System.out.println(); + System.out.println(rebelXml); + + eventContext.proceed(); + + HTTPContext httpContext = protocolMetaData.get().getContext(HTTPContext.class); + if (httpContext != null) { + Serializer.toStream(new SerializableHttpContextData(httpContext), metaDataFile); + } + } else { + ProtocolMetaData metaData = new ProtocolMetaData(); + SerializableHttpContextData serializableHttpContextData = Serializer.toObject(SerializableHttpContextData.class, metaDataFile); + metaData.addContext(serializableHttpContextData.toHTTPContext()); + protocolMetaData.set(metaData); + deployment.deployed(); + deploymentProducer.set(deployment); + deploymentDescriptionProducer.set(deployment.getDescription()); + } + } + + public void onUnDeploy(@Observes EventContext eventContext) + { + if (forcedUndeployment) { + eventContext.proceed(); + } + } + + private String createRebelXML(File output) + { + return "\n" + + "\n" + + " \n" + + /* + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + */ + ""; + } +} diff --git a/src/main/java/org/jboss/arquillian/extension/jrebel/JRebelExtension.java b/impl/src/main/java/org/jboss/arquillian/extension/jrebel/JRebelExtension.java similarity index 75% rename from src/main/java/org/jboss/arquillian/extension/jrebel/JRebelExtension.java rename to impl/src/main/java/org/jboss/arquillian/extension/jrebel/JRebelExtension.java index fe925e3..63f4822 100644 --- a/src/main/java/org/jboss/arquillian/extension/jrebel/JRebelExtension.java +++ b/impl/src/main/java/org/jboss/arquillian/extension/jrebel/JRebelExtension.java @@ -25,11 +25,15 @@ * @author Aslak Knutsen * @version $Revision: $ */ -public class JRebelExtension implements LoadableExtension -{ - @Override - public void register(ExtensionBuilder builder) - { - builder.observer(DeploymentInterceptor.class); - } +public class JRebelExtension implements LoadableExtension { +// ------------------------ INTERFACE METHODS ------------------------ + + +// --------------------- Interface LoadableExtension --------------------- + + @Override + public void register(ExtensionBuilder builder) + { + builder.observer(DeploymentInterceptor.class); + } } \ No newline at end of file diff --git a/impl/src/main/java/org/jboss/arquillian/extension/jrebel/SerializableHttpContextData.java b/impl/src/main/java/org/jboss/arquillian/extension/jrebel/SerializableHttpContextData.java new file mode 100644 index 0000000..9831646 --- /dev/null +++ b/impl/src/main/java/org/jboss/arquillian/extension/jrebel/SerializableHttpContextData.java @@ -0,0 +1,70 @@ +package org.jboss.arquillian.extension.jrebel; + +import org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext; + +import java.io.Serializable; +import java.util.HashSet; +import java.util.Set; + +public class SerializableHttpContextData implements Serializable { +// ------------------------------ FIELDS ------------------------------ + + private String host; + + private String name; + + private int port; + + private Set servlets; + +// --------------------------- CONSTRUCTORS --------------------------- + + public SerializableHttpContextData(HTTPContext context) + { + name = context.getName(); + host = context.getHost(); + port = context.getPort(); + for (org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet servlet : context.getServlets()) { + getServlets().add(new Servlet(servlet.getName(), servlet.getContextRoot())); + } + } + +// --------------------- GETTER / SETTER METHODS --------------------- + + private Set getServlets() + { + if (servlets == null) { + servlets = new HashSet(); + } + return servlets; + } + +// -------------------------- OTHER METHODS -------------------------- + + public HTTPContext toHTTPContext() + { + final HTTPContext httpContext = new HTTPContext(name, host, port); + for (Servlet servlet : getServlets()) { + httpContext.add(new org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet(servlet.name, servlet.contextRoot)); + } + return httpContext; + } + +// -------------------------- INNER CLASSES -------------------------- + + private class Servlet implements Serializable { +// ------------------------------ FIELDS ------------------------------ + + private String contextRoot; + + private String name; + +// --------------------------- CONSTRUCTORS --------------------------- + + public Servlet(String name, String contextRoot) + { + this.name = name; + this.contextRoot = contextRoot; + } + } +} diff --git a/src/main/java/org/jboss/arquillian/extension/jrebel/Serializer.java b/impl/src/main/java/org/jboss/arquillian/extension/jrebel/Serializer.java similarity index 59% rename from src/main/java/org/jboss/arquillian/extension/jrebel/Serializer.java rename to impl/src/main/java/org/jboss/arquillian/extension/jrebel/Serializer.java index db16dc8..a09b66f 100644 --- a/src/main/java/org/jboss/arquillian/extension/jrebel/Serializer.java +++ b/impl/src/main/java/org/jboss/arquillian/extension/jrebel/Serializer.java @@ -29,31 +29,15 @@ /** * Serializer - * + * * @author Aslak Knutsen * @version $Revision: $ */ final class Serializer { +// -------------------------- STATIC METHODS -------------------------- - public static void toStream(Object object, File out) { - try { - toStream(object, new FileOutputStream(out)); - } catch (Exception e) { - throw new RuntimeException("Could not serialize object to Stream", e); - } - } - - public static void toStream(Object object, OutputStream out) { - byte[] serialized = toByteArray(object); - try { - out.write(serialized); - out.close(); - } catch (Exception e) { - throw new RuntimeException("Could not serialize object to Stream", e); - } - } - - public static byte[] toByteArray(Object object) { + public static byte[] toByteArray(Object object) + { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); ObjectOutputStream outObj = new ObjectOutputStream(out); @@ -65,7 +49,8 @@ public static byte[] toByteArray(Object object) { } } - public static T toObject(Class type, byte[] objectArray) { + public static T toObject(Class type, byte[] objectArray) + { try { ObjectInputStream outObj = new ObjectInputStream(new ByteArrayInputStream(objectArray)); Object object = outObj.readObject(); @@ -76,29 +61,50 @@ public static T toObject(Class type, byte[] objectArray) { } } - public static T toObject(Class type, File input) { - try { - return toObject(type, new FileInputStream(input)); - } catch (Exception e) { - throw new RuntimeException("Could not deserialize object", e); - } - } + public static T toObject(Class type, File input) + { + try { + return toObject(type, new FileInputStream(input)); + } catch (Exception e) { + throw new RuntimeException("Could not deserialize object", e); + } + } - public static T toObject(Class type, InputStream input) { - try { - ObjectInputStream outObj = new ObjectInputStream(input); - Object object = outObj.readObject(); + public static T toObject(Class type, InputStream input) + { + try { + ObjectInputStream outObj = new ObjectInputStream(input); + Object object = outObj.readObject(); - return type.cast(object); - } catch (Exception e) { - throw new RuntimeException("Could not deserialize object", e); - } - finally { - try { - input.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - } + return type.cast(object); + } catch (Exception e) { + throw new RuntimeException("Could not deserialize object", e); + } finally { + try { + input.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + public static void toStream(Object object, File out) + { + try { + toStream(object, new FileOutputStream(out)); + } catch (Exception e) { + throw new RuntimeException("Could not serialize object to Stream", e); + } + } + + public static void toStream(Object object, OutputStream out) + { + byte[] serialized = toByteArray(object); + try { + out.write(serialized); + out.close(); + } catch (Exception e) { + throw new RuntimeException("Could not serialize object to Stream", e); + } + } } diff --git a/src/main/java/org/jboss/arquillian/extension/jrebel/ShrinkWrapUtil.java b/impl/src/main/java/org/jboss/arquillian/extension/jrebel/ShrinkWrapUtil.java similarity index 64% rename from src/main/java/org/jboss/arquillian/extension/jrebel/ShrinkWrapUtil.java rename to impl/src/main/java/org/jboss/arquillian/extension/jrebel/ShrinkWrapUtil.java index 358b212..1eba10f 100644 --- a/src/main/java/org/jboss/arquillian/extension/jrebel/ShrinkWrapUtil.java +++ b/impl/src/main/java/org/jboss/arquillian/extension/jrebel/ShrinkWrapUtil.java @@ -25,21 +25,24 @@ * @author Aslak Knutsen * @version $Revision: $ */ -final class ShrinkWrapUtil -{ - private ShrinkWrapUtil() { } +final class ShrinkWrapUtil { +// -------------------------- STATIC METHODS -------------------------- - public static File createTempDirectory() { - try - { - File root = new File("target/jrebel-temp/"); //File.createTempFile("arquillian", "jrebel"); - root.delete(); - root.mkdirs(); - return root; - } - catch (Exception e) - { - throw new RuntimeException(e); - } - } + public static File createTempDirectory() + { + try { + File root = new File("target/jrebel-temp/"); //File.createTempFile("arquillian", "jrebel"); + root.delete(); + root.mkdirs(); + return root; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + +// --------------------------- CONSTRUCTORS --------------------------- + + private ShrinkWrapUtil() + { + } } diff --git a/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension b/impl/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension similarity index 100% rename from src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension rename to impl/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension diff --git a/int-test/pom.xml b/int-test/pom.xml new file mode 100644 index 0000000..fac61ee --- /dev/null +++ b/int-test/pom.xml @@ -0,0 +1,123 @@ + + + + + + org.jboss.arquillian.extension + arquillian-jrebel-parent + 1.0.0.Alpha1-SNAPSHOT + + + + 4.0.0 + + + arquillian-jrebel-inttest + Arquillian Extension JRebel Integration tests + http://www.jboss.org + Arquillian Extension JRebel + + + + + org.jboss.arquillian.extension + arquillian-jrebel-impl + ${project.version} + + + junit + junit + test + + + org.jboss.arquillian.junit + arquillian-junit-container + ${version.arquillian_core} + test + + + org.jboss.arquillian.protocol + arquillian-protocol-servlet + ${version.arquillian_core} + test + + + org.jboss.spec + jboss-javaee-6.0 + ${version.jboss_javaee6_spec} + pom + test + + + javax.enterprise + cdi-api + 1.0 + provided + + + + + + arq-jbossas-remote-5 + + + org.jboss.arquillian.container + arquillian-jbossas-remote-5.1 + 1.0.0.CR3 + test + + + org.jboss.jbossas + jboss-as-client + ${version.jboss_as_5} + pom + provided + + + + + + arq-jbossas-remote-7 + + + org.jboss.as + jboss-as-arquillian-container-remote + 7.1.0.Beta1 + test + + + + + arq-jbossas-remote-7.1 + + + org.jboss.as + jboss-as-arquillian-container-remote + 7.1.1.Final + test + + + + + + + + + org.zeroturnaround + jrebel-maven-plugin + 1.1.3 + + + generate-rebel-xml + process-resources + + generate + + + + + + + + diff --git a/int-test/src/main/java/org/jboss/arquillian/extension/jrebel/InjectableArtifact.java b/int-test/src/main/java/org/jboss/arquillian/extension/jrebel/InjectableArtifact.java new file mode 100644 index 0000000..2343a6d --- /dev/null +++ b/int-test/src/main/java/org/jboss/arquillian/extension/jrebel/InjectableArtifact.java @@ -0,0 +1,22 @@ +package org.jboss.arquillian.extension.jrebel; + +import javax.enterprise.context.ApplicationScoped; + +@ApplicationScoped +public class InjectableArtifact { +// ------------------------------ FIELDS ------------------------------ + + private boolean valueSet; + +// --------------------- GETTER / SETTER METHODS --------------------- + + public boolean isValueSet() + { + return valueSet; + } + + public void setValueSet(boolean valueSet) + { + this.valueSet = valueSet; + } +} diff --git a/src/test/java/org/jboss/arquillian/extension/jrebel/JRebelIntegrationTestCase.java b/int-test/src/test/java/org/jboss/arquillian/extension/jrebel/JRebelIntegrationTestCase.java similarity index 56% rename from src/test/java/org/jboss/arquillian/extension/jrebel/JRebelIntegrationTestCase.java rename to int-test/src/test/java/org/jboss/arquillian/extension/jrebel/JRebelIntegrationTestCase.java index ccd6118..ded2f6d 100644 --- a/src/test/java/org/jboss/arquillian/extension/jrebel/JRebelIntegrationTestCase.java +++ b/int-test/src/test/java/org/jboss/arquillian/extension/jrebel/JRebelIntegrationTestCase.java @@ -17,18 +17,17 @@ */ package org.jboss.arquillian.extension.jrebel; -import javax.annotation.Resource; -import javax.jms.ConnectionFactory; -import javax.jms.Queue; - import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; 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.Test; import org.junit.runner.RunWith; +import javax.inject.Inject; + /** * JRebelIntegrationTestCase * @@ -36,26 +35,30 @@ * @version $Revision: $ */ @RunWith(Arquillian.class) -public class JRebelIntegrationTestCase -{ - @Deployment - public static WebArchive createWar() - { - return ShrinkWrap.create(WebArchive.class, "jrebel-test.war"); - } - - @Resource(mappedName = "queue/DLQ") - private Queue dlq; - - @Resource(mappedName = "ConnectionFactory") - private ConnectionFactory cf; - - @Test - public void shouldBeAbleToiChange() throws Exception - { - Assert.assertNotNull(dlq); - - - Assert.assertNotNull(cf); - } +public class JRebelIntegrationTestCase { +// ------------------------------ FIELDS ------------------------------ + + @Inject + InjectableArtifact injectableArtifact; + +// -------------------------- STATIC METHODS -------------------------- + + @Deployment + public static WebArchive createWar() + { + return ShrinkWrap.create(WebArchive.class, "jrebel-test.war").addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml").addClass(InjectableArtifact.class); + } + +// -------------------------- OTHER METHODS -------------------------- + + @Test + public void shouldBeAbleToiChange() throws Exception + { + /** + * Run tests once, then modify this method and run tests again. + * Notice that unless you run "mvn clean" the package is not redeployed between "mvn test" runs. + */ + System.out.println(injectableArtifact); + Assert.assertNotNull(injectableArtifact); + } } diff --git a/int-test/src/test/java/org/jboss/arquillian/extension/jrebel/MultipleDeploymentsTestCase.java b/int-test/src/test/java/org/jboss/arquillian/extension/jrebel/MultipleDeploymentsTestCase.java new file mode 100644 index 0000000..9087b6b --- /dev/null +++ b/int-test/src/test/java/org/jboss/arquillian/extension/jrebel/MultipleDeploymentsTestCase.java @@ -0,0 +1,58 @@ +package org.jboss.arquillian.extension.jrebel; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.OperateOnDeployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.inject.Inject; + +@RunWith(Arquillian.class) +public class MultipleDeploymentsTestCase { +// ------------------------------ FIELDS ------------------------------ + + private static final String OTHER_WAR_WITH_INJECTABLE_ARTIFACT = "OtherWarWithInjectableArtifact"; + + private static final String WAR_WITH_INJECTABLE_ARTIFACT = "WarWithInjectableArtifact"; + + @Inject + InjectableArtifact injectableArtifact; + +// -------------------------- STATIC METHODS -------------------------- + + @Deployment(name = WAR_WITH_INJECTABLE_ARTIFACT) + public static WebArchive createFirstArchive() + { + return Packager.warWithInjectableArtifact(); + } + + @Deployment(name = OTHER_WAR_WITH_INJECTABLE_ARTIFACT) + public static WebArchive createSecondArchive() + { + return Packager.otherWarWithInjectableArtifact(); + } + +// -------------------------- OTHER METHODS -------------------------- + + @Test + @OperateOnDeployment(WAR_WITH_INJECTABLE_ARTIFACT) + public void injectableArtifactAvailable() throws Exception + { + /** + * Run tests once, then modify this method and run tests again. + * Notice that unless you run "mvn clean" the package is not redeployed between "mvn test" runs. + */ + System.out.println(injectableArtifact); + Assert.assertNotNull(injectableArtifact); + } + + @Test + @OperateOnDeployment(OTHER_WAR_WITH_INJECTABLE_ARTIFACT) + public void injectableArtifactAvailable2() throws Exception + { + Assert.assertNotNull(injectableArtifact); + } +} diff --git a/int-test/src/test/java/org/jboss/arquillian/extension/jrebel/Packager.java b/int-test/src/test/java/org/jboss/arquillian/extension/jrebel/Packager.java new file mode 100644 index 0000000..8f87839 --- /dev/null +++ b/int-test/src/test/java/org/jboss/arquillian/extension/jrebel/Packager.java @@ -0,0 +1,29 @@ +package org.jboss.arquillian.extension.jrebel; + +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; + +public class Packager { +// -------------------------- STATIC METHODS -------------------------- + + public static WebArchive otherWarWithInjectableArtifact() + { + return ShrinkWrap.create(WebArchive.class, "otherWithInjectableArtifact.war") + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") + .addClass(InjectableArtifact.class); + } + + public static WebArchive warWithInjectableArtifact() + { + return ShrinkWrap.create(WebArchive.class, "withInjectableArtifact.war") + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") + .addClass(InjectableArtifact.class); + } + +// --------------------------- CONSTRUCTORS --------------------------- + + private Packager() + { + } +} diff --git a/int-test/src/test/resources/arquillian.xml b/int-test/src/test/resources/arquillian.xml new file mode 100644 index 0000000..d813d5e --- /dev/null +++ b/int-test/src/test/resources/arquillian.xml @@ -0,0 +1,11 @@ + + + + + + + target/ + + + diff --git a/pom.xml b/pom.xml index ac5c191..2682670 100644 --- a/pom.xml +++ b/pom.xml @@ -1,13 +1,13 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> org.jboss jboss-parent 8 - + @@ -15,17 +15,22 @@ org.jboss.arquillian.extension - arquillian-jrebel + arquillian-jrebel-parent 1.0.0.Alpha1-SNAPSHOT - Arquillian Extension JRebel + Arquillian Extension JRebel Parent + pom http://www.jboss.org Arquillian Extension JRebel + + impl + int-test + - 1.0.0.CR7 + 1.0.0.Final 5.1.0.GA 1.0.0.Final @@ -54,56 +59,6 @@ - - - org.jboss.arquillian.core - arquillian-core-spi - - - org.jboss.arquillian.container - arquillian-container-impl-base - - - junit - junit - test - - - org.jboss.arquillian.junit - arquillian-junit-container - test - - - org.jboss.spec - jboss-javaee-6.0 - ${version.jboss_javaee6_spec} - pom - test - - - - - - arq-jbossas-remote-5 - - - org.jboss.arquillian.container - arquillian-jbossas-remote-5.1 - 1.0.0.CR3 - test - - - org.jboss.jbossas - jboss-as-client - ${version.jboss_as_5} - pom - provided - - - - - - @@ -114,12 +69,6 @@ true - - maven-surefire-plugin - - true - - diff --git a/src/main/java/org/jboss/arquillian/extension/jrebel/DeploymentInterceptor.java b/src/main/java/org/jboss/arquillian/extension/jrebel/DeploymentInterceptor.java deleted file mode 100644 index 1afcd10..0000000 --- a/src/main/java/org/jboss/arquillian/extension/jrebel/DeploymentInterceptor.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors - * as indicated by the @authors tag. All rights reserved. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.arquillian.extension.jrebel; - -import java.io.File; - -import org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData; -import org.jboss.arquillian.container.spi.context.annotation.DeploymentScoped; -import org.jboss.arquillian.container.spi.event.DeployDeployment; -import org.jboss.arquillian.container.spi.event.UnDeployDeployment; -import org.jboss.arquillian.core.api.InstanceProducer; -import org.jboss.arquillian.core.api.annotation.Inject; -import org.jboss.arquillian.core.api.annotation.Observes; -import org.jboss.arquillian.core.spi.EventContext; -import org.jboss.shrinkwrap.api.Archive; -import org.jboss.shrinkwrap.api.asset.StringAsset; -import org.jboss.shrinkwrap.api.exporter.ExplodedExporter; -import org.jboss.shrinkwrap.api.formatter.Formatters; - - -/** - * DeploymentInterceptor - * - * @author Aslak Knutsen - * @version $Revision: $ - */ -public class DeploymentInterceptor -{ - private final File tempDirectory; - - @Inject @DeploymentScoped - private InstanceProducer protocolMetaData; - - public DeploymentInterceptor() - { - tempDirectory = ShrinkWrapUtil.createTempDirectory(); - } - - public void onDeploy(@Observes(precedence = -1) EventContext eventContext) - { - Archive deployment = eventContext.getEvent().getDeployment().getDescription().getTestableArchive(); - File exportPath = new File(tempDirectory, deployment.getName()); - boolean alreadyDeployed = exportPath.exists(); - exportPath.mkdirs(); - deployment.as(ExplodedExporter.class).exportExploded(tempDirectory); - - File metaDataFile = new File(tempDirectory, deployment.getName() + ".meta"); - - if(!alreadyDeployed) - { - String rebelXml = createRebelXML(exportPath); - deployment.add(new StringAsset(rebelXml), "WEB-INF/classes/rebel.xml"); - - System.out.println(deployment.toString(Formatters.VERBOSE)); - System.out.println(); - System.out.println(rebelXml); - - - eventContext.proceed(); - - ProtocolMetaData metaData = protocolMetaData.get(); - Serializer.toStream(metaData, metaDataFile); - } - else - { - ProtocolMetaData metaData = Serializer.toObject(ProtocolMetaData.class, metaDataFile); - protocolMetaData.set(metaData); -// eventContext.proceed(); - } - } - - public void onUnDeploy(@Observes EventContext eventContext) - { - //eventContext.proceed(); - } - - private String createRebelXML(File output) - { - return - "\n" + - "\n" + - " \n" + - /* - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - */ - ""; - } -}