[jboss-svn-commits] JBoss Common SVN: r4365 - in arquillian/trunk: examples/domain/src/main/java/com/acme and 5 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri May 7 16:27:46 EDT 2010
Author: aslak
Date: 2010-05-07 16:27:45 -0400 (Fri, 07 May 2010)
New Revision: 4365
Added:
arquillian/trunk/examples/domain/src/main/java/com/acme/web/
arquillian/trunk/examples/domain/src/main/java/com/acme/web/TestServlet.java
arquillian/trunk/examples/junit/src/test/java/com/acme/web/
arquillian/trunk/examples/junit/src/test/java/com/acme/web/LocalRunServletTestCase.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/AbstractRunModeHandler.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ActivateRunModeTypeLocalDeployment.java
arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ActivateRunModeTypeLocalDeploymentTestCase.java
Modified:
arquillian/trunk/examples/domain/pom.xml
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ActivateRunModeTypeLocal.java
Log:
ARQ-134 Don't add all axuiliary archives and repackage the deployment in RunMode.LOCAL. Keep the defined Deployment
Modified: arquillian/trunk/examples/domain/pom.xml
===================================================================
--- arquillian/trunk/examples/domain/pom.xml 2010-05-07 19:39:26 UTC (rev 4364)
+++ arquillian/trunk/examples/domain/pom.xml 2010-05-07 20:27:45 UTC (rev 4365)
@@ -65,6 +65,12 @@
<version>1.4.1</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>jboss.web</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>3.0.0.alpha-25</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
Added: arquillian/trunk/examples/domain/src/main/java/com/acme/web/TestServlet.java
===================================================================
--- arquillian/trunk/examples/domain/src/main/java/com/acme/web/TestServlet.java (rev 0)
+++ arquillian/trunk/examples/domain/src/main/java/com/acme/web/TestServlet.java 2010-05-07 20:27:45 UTC (rev 4365)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. 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 com.acme.web;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * TestServlet
+ *
+ * @author <a href="mailto:aslak at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ at WebServlet(urlPatterns = "/*")
+public class TestServlet extends HttpServlet
+{
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+ {
+ response.getWriter().append("hello");
+ }
+}
Added: arquillian/trunk/examples/junit/src/test/java/com/acme/web/LocalRunServletTestCase.java
===================================================================
--- arquillian/trunk/examples/junit/src/test/java/com/acme/web/LocalRunServletTestCase.java (rev 0)
+++ arquillian/trunk/examples/junit/src/test/java/com/acme/web/LocalRunServletTestCase.java 2010-05-07 20:27:45 UTC (rev 4365)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. 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 com.acme.web;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.api.RunMode;
+import org.jboss.arquillian.api.RunModeType;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * LocalRunServletTestCase
+ *
+ * @author <a href="mailto:aslak at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ at RunWith(Arquillian.class)
+ at RunMode(RunModeType.LOCAL)
+public class LocalRunServletTestCase
+{
+ @Deployment
+ public static WebArchive createDeployment()
+ {
+ return ShrinkWrap.create("test.war", WebArchive.class)
+ .addClass(TestServlet.class);
+ }
+
+ @Test
+ public void shouldBeAbleToDeployWebArchive() throws Exception
+ {
+ String body = readAllAndClose(new URL("http://localhost:8080/test/Test").openStream());
+
+ Assert.assertEquals(
+ "Verify that the servlet was deployed and returns expected result",
+ "hello",
+ body);
+ }
+
+ private String readAllAndClose(InputStream is) throws Exception
+ {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ try
+ {
+ int read;
+ while( (read = is.read()) != -1)
+ {
+ out.write(read);
+ }
+ }
+ finally
+ {
+ try { is.close(); } catch (Exception e) { }
+ }
+ return out.toString();
+ }
+
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/AbstractRunModeHandler.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/AbstractRunModeHandler.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/AbstractRunModeHandler.java 2010-05-07 20:27:45 UTC (rev 4365)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. 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.impl.handler;
+
+import org.jboss.arquillian.api.RunMode;
+import org.jboss.arquillian.api.RunModeType;
+import org.jboss.arquillian.spi.Context;
+import org.jboss.arquillian.spi.event.suite.ClassEvent;
+import org.jboss.arquillian.spi.event.suite.EventHandler;
+
+/**
+ * Abstract RunMode Handler for checking and delegating the different run modes to
+ * sub classes.
+ *
+ * @author <a href="mailto:aslak at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public abstract class AbstractRunModeHandler<T extends ClassEvent> implements EventHandler<T>
+{
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.spi.event.suite.EventHandler#callback(org.jboss.arquillian.spi.Context, java.lang.Object)
+ */
+ public final void callback(Context context, ClassEvent event) throws Exception
+ {
+ if(event.getTestClass().isAnnotationPresent(RunMode.class))
+ {
+ RunModeType runModeType = event.getTestClass().getAnnotation(RunMode.class).value();
+ if(RunModeType.LOCAL == runModeType)
+ {
+ hasLocalRunMode(context);
+ }
+ }
+ }
+
+ protected abstract void hasLocalRunMode(Context context);
+}
\ No newline at end of file
Modified: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ActivateRunModeTypeLocal.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ActivateRunModeTypeLocal.java 2010-05-07 19:39:26 UTC (rev 4364)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ActivateRunModeTypeLocal.java 2010-05-07 20:27:45 UTC (rev 4365)
@@ -24,7 +24,6 @@
import org.jboss.arquillian.spi.TestResult;
import org.jboss.arquillian.spi.TestResult.Status;
import org.jboss.arquillian.spi.event.suite.BeforeClass;
-import org.jboss.arquillian.spi.event.suite.EventHandler;
/**
* Handler that will setup the context as defined by the {@link RunModeType#LOCAL}. <br/>
@@ -37,26 +36,17 @@
* @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
* @version $Revision: $
*/
-public class ActivateRunModeTypeLocal implements EventHandler<BeforeClass>
+public class ActivateRunModeTypeLocal extends AbstractRunModeHandler<BeforeClass>
{
- /* (non-Javadoc)
- * @see org.jboss.arquillian.impl.event.EventHandler#callback(java.lang.Object, java.lang.Object)
- */
- public void callback(Context context, BeforeClass event)
- throws Exception
+
+ @Override
+ protected void hasLocalRunMode(Context context)
{
- if(event.getTestClass().isAnnotationPresent(RunMode.class))
- {
- RunModeType runModeType = event.getTestClass().getAnnotation(RunMode.class).value();
- if(RunModeType.LOCAL == runModeType)
- {
- context.add(ContainerMethodExecutor.class, new LocalMethodExecutor());
- }
- }
+ context.add(ContainerMethodExecutor.class, new LocalMethodExecutor());
}
// TODO: this is a copy of the protocol-local Executor. Move to SPI and remove protocol local?
- private static class LocalMethodExecutor implements ContainerMethodExecutor
+ static class LocalMethodExecutor implements ContainerMethodExecutor
{
/* (non-Javadoc)
* @see org.jboss.arquillian.spi.ContainerMethodExecutor#invoke(org.jboss.arquillian.spi.TestMethodExecutor)
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ActivateRunModeTypeLocalDeployment.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ActivateRunModeTypeLocalDeployment.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ActivateRunModeTypeLocalDeployment.java 2010-05-07 20:27:45 UTC (rev 4365)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. 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.impl.handler;
+
+import org.jboss.arquillian.api.RunModeType;
+import org.jboss.arquillian.impl.DeploymentGenerator;
+import org.jboss.arquillian.spi.ApplicationArchiveGenerator;
+import org.jboss.arquillian.spi.Context;
+import org.jboss.arquillian.spi.ServiceLoader;
+import org.jboss.arquillian.spi.event.suite.BeforeClass;
+import org.jboss.shrinkwrap.api.Archive;
+
+/**
+ * Handler that will setup the context as defined by the {@link RunModeType#LOCAL}. <br/>
+ * Will override the normal DeploymentPackager with a version that ignores appenders/processors and packagers.<br/>
+ * <br/>
+ *
+ * <b>Exports:</b><br/>
+ * {@link DeploymentGenerator}<br/>
+ *
+ * @author <a href="mailto:aslak at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class ActivateRunModeTypeLocalDeployment extends AbstractRunModeHandler<BeforeClass>
+{
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.impl.handler.AbstractRunModeHandler#hasLocalRunMode(org.jboss.arquillian.spi.Context)
+ */
+ @Override
+ protected void hasLocalRunMode(Context context)
+ {
+ context.add(DeploymentGenerator.class, new ApplicationArchiveDeployment(context.getServiceLoader()));
+ }
+
+ /**
+ *
+ * @author <a href="mailto:aslak at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ private class ApplicationArchiveDeployment implements DeploymentGenerator
+ {
+ private ServiceLoader serviceLoader;
+
+ public ApplicationArchiveDeployment(ServiceLoader serviceLoader)
+ {
+ this.serviceLoader = serviceLoader;
+ }
+
+ public Archive<?> generate(Class<?> testCase)
+ {
+ return serviceLoader.onlyOne(ApplicationArchiveGenerator.class).generateApplicationArchive(testCase);
+ }
+ }
+}
Added: arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ActivateRunModeTypeLocalDeploymentTestCase.java
===================================================================
--- arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ActivateRunModeTypeLocalDeploymentTestCase.java (rev 0)
+++ arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ActivateRunModeTypeLocalDeploymentTestCase.java 2010-05-07 20:27:45 UTC (rev 4365)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. 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.impl.handler;
+
+import junit.framework.Assert;
+
+import org.jboss.arquillian.api.RunMode;
+import org.jboss.arquillian.api.RunModeType;
+import org.jboss.arquillian.impl.DeploymentGenerator;
+import org.jboss.arquillian.impl.context.ClassContext;
+import org.jboss.arquillian.impl.context.SuiteContext;
+import org.jboss.arquillian.spi.ServiceLoader;
+import org.jboss.arquillian.spi.event.suite.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+
+/**
+ * ActivateRunModeTypeLocalDeploymentTestCase
+ *
+ * @author <a href="mailto:aslak at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ at RunWith(MockitoJUnitRunner.class)
+public class ActivateRunModeTypeLocalDeploymentTestCase
+{
+ @Mock
+ private ServiceLoader serviceLoader;
+
+ @Test
+ public void shouldExportContainerMethodExecutorIfLocalMode() throws Exception
+ {
+ ClassContext context = new ClassContext(new SuiteContext(serviceLoader));
+
+ ActivateRunModeTypeLocalDeployment handler = new ActivateRunModeTypeLocalDeployment();
+ handler.callback(context, new BeforeClass(TestWithRunModeLocal.class));
+
+ Assert.assertNotNull(
+ "Should have exported a " + DeploymentGenerator.class,
+ context.get(DeploymentGenerator.class));
+ }
+
+ @RunMode(RunModeType.LOCAL)
+ private static class TestWithRunModeLocal { }
+}
More information about the jboss-svn-commits
mailing list