Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, 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.junit;
- import static org.jboss.arquillian.api.RunModeType.AS_CLIENT;
- import java.net.URL;
- import javax.naming.InitialContext;
- import org.jboss.arquillian.api.ArquillianResource;
- import org.jboss.arquillian.api.Deployer;
- import org.jboss.arquillian.api.Deployment;
- import org.jboss.arquillian.api.DeploymentTarget;
- import org.jboss.arquillian.api.Protocol;
- import org.jboss.arquillian.api.Run;
- import org.jboss.arquillian.api.Target;
- import org.jboss.arquillian.spi.core.annotation.Inject;
- import org.jboss.shrinkwrap.api.Archive;
- import org.jboss.shrinkwrap.api.ShrinkWrap;
- import org.jboss.shrinkwrap.api.spec.JavaArchive;
- import org.jboss.shrinkwrap.descriptor.api.Descriptor;
- import org.jboss.shrinkwrap.descriptor.api.Descriptors;
- import org.junit.Before;
- import org.junit.BeforeClass;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- /**
- * SuperAdvancedExampleTestCase
- *
- * @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a>
- * @version $Revision: $
- */
- @RunWith(Arquillian.class)
- public class SuperAdvancedExampleTestCase
- {
- // auto deployed on startup based on order
- @Deployment(order = 1) @Target("server-1")
- public static Descriptor startupEnvironmentServer1()
- {
- return Descriptors.create(JMSDescriptor.class);
- }
- /*
- * auto deployed on startup (multiple startup deployments defined for same server, sorted by order),
- * enriched for in_container testing using HTTP Servlet 3.0 as test execution protocol
- */
- @Deployment(order = 2) @Target("server-1") @Protocol("Servlet 3.0")
- public static Archive<?> startupTestableServer1()
- {
- return ShrinkWrap.create(JavaArchive.class);
- }
- // needs to be manually deployed, enriched for in_container testing using EJB 3.0 as test execution protocol
- @Deployment(name = "dep-1-server-2", startup = false) @Target("server-2") @Protocol("EJB 3.0")
- public static Archive<?> manualTestableServer2()
- {
- return ShrinkWrap.create(JavaArchive.class);
- }
- // needs to be manually deployed
- @Deployment(name = "dep-1-server-3", startup = false, testable = false) @Target("server-3")
- public static Archive<?> manualNonTestableServer3()
- {
- return ShrinkWrap.create(JavaArchive.class);
- }
- /*
- * Follow same default as @Test if no @DeploymentTarget defined. Target deployment is testable so it will only be executed when
- * running against default deployment on server-1 and @Test is running in mode IN_CONTAINER.
- * (AS_CLIENT mode never hit the server, so we can't just execute a Before IN_CONTAINER)
- */
- @Before // @DeploymentTarget("DEFAULT")
- public void beforeOnServer1(MyCDIBean bean) // support for method argument injection in Before/After on same level as @Test
- {
- // do some setup ..
- }
- // Follows default rules, but can always be executed even when @Test runs in mode AS_CLIENT.
- @Before @Run(AS_CLIENT) // @DeploymentTarget("DEFAULT")
- public void beforeOnServer1(@ArquillianResource(MyServlet.class) URL servletUrl)
- {
- // do some setup ..
- }
- // Only runs when @Test targets the "dep-1-server-3" deployment, will run with Run mode AS_CLIENT since deployment is not testable
- @BeforeClass @DeploymentTarget("dep-1-server-3")
- public void beforeAgainstServere3()
- {
- // do something..
- }
- /*
- * Will always be attempted injected in all run modes and on all servers
- * (could support @Optional or use method argument injection when mixing run modes / multi containers)
- */
- @Inject
- private MyCommonResource resource;
- // defaults to Deployment with no defined name
- @Test // @DeploymentTarget("DEFAULT")
- public void executeOnServer1(@ArquillianResource Deployer deployer)
- {
- // do something, then manual deploy archives via callback to client
- deployer.deploy("dep-1-server-2");
- deployer.deploy("dep-1-server-3");
- }
- /*
- * default run mode for a testable targeted deployment is IN_CONTIANER, override to run on client side.
- * communicates with container using Http Servlet 3.0 protocol.
- */
- @Test @Run(AS_CLIENT) // @DeploymentTarget("DEFAULT")
- public void executeWithContextSetAgainstServer1(@ArquillianResource InitialContext context)
- {
- // do something..
- }
- /*
- * defined target deployment, will execute on the deployments @Target server.
- * communicates with container using RMI EJB 3.0 protocol.
- */
- @Test @DeploymentTarget("dep-1-server-2")
- public void executeOnServer2(MyCDIBean bean)
- {
- // do something..
- }
- // since DeploymentTarget is defined as testable = false, IN_CONTAINER is not possible. Run mode becomes AS_CLIENT
- @Test @DeploymentTarget("dep-1-server-3")
- public void executeWithContextSetAgainstServer3(@ArquillianResource(MyOtherSerlvet.class) URL servletUrl, @ArquillianResource Deployer deployer)
- {
- /*
- * deployer API is available in both AS_CLIENT and IN_CONTIANER,
- * deployments are registered for auto undeploy on AfterClass if not undeployed manually.
- */
- deployer.undeploy("dep-1-server-2");
- // do something..
- }
- }
Add Comment
Please, Sign In to add comment