[jboss-svn-commits] JBoss Common SVN: r4269 - in arquillian/trunk: impl-base and 13 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Apr 20 11:02:46 EDT 2010
Author: aslak
Date: 2010-04-20 11:02:38 -0400 (Tue, 20 Apr 2010)
New Revision: 4269
Added:
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/EventTestRunnerAdaptor.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/AbstractEventContext.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/ClassContext.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/ClientProfileBuilder.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/ContainerProfileBuilder.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/Context.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/ContextLifecycleManager.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/ProfileBuilder.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/StandaloneProfileBuilder.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/SuiteContext.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/TestContext.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/Event.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/EventHandler.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/EventManager.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/FiredEventException.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/MapEventManager.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/After.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/AfterClass.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/AfterSuite.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/Before.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/BeforeClass.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/BeforeSuite.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/ClassEvent.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/SuiteEvent.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/Test.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/TestEvent.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ArchiveGenerator.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ContainerCreator.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ContainerDeployer.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ContainerRestarter.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ContainerStarter.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ContainerStopper.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ContainerTestExecuter.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ContainerUndeployer.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ExecutionTimer.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/TestCaseEnricher.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/TestEventExecuter.java
arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/DeploymentAnnotationArchiveGeneratorTestCase.java
arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/EventTestRunnerAdaptorTestCase.java
arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/event/
arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/event/ContextLifecycleManagerTestCase.java
arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/event/EventManagerTestCase.java
arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/
arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ArchiveGeneratorTestCase.java
arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ContainerCreatorTestCase.java
arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ContainerDeployerTestCase.java
arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ContainerRestarterTestCase.java
arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ContainerStarterTestCase.java
arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ContainerStopperTestCase.java
arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ContainerTestExecuterTestCase.java
arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ContainerUndeployerTestCase.java
arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/TestCaseEnricherTestCase.java
arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/TestEventExecuterTestCase.java
arquillian/trunk/impl-base/src/test/resources/arquillian.xml
arquillian/trunk/impl-base/src/test/resources/broken_arquillian.xml
arquillian/trunk/spi/src/main/java/org/jboss/arquillian/spi/TestRunnerAdaptor.java
Removed:
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/DeployableTest.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/Deployer.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/NullDeploymentGenerator.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/container/
Modified:
arquillian/trunk/build/pom.xml
arquillian/trunk/impl-base/pom.xml
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/ClientDeploymentGenerator.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/DeployableTestBuilder.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/DeploymentAnnotationArchiveGenerator.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/DynamicServiceLoader.java
arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/Validate.java
arquillian/trunk/junit/src/main/java/org/jboss/arquillian/junit/Arquillian.java
arquillian/trunk/junit/src/main/java/org/jboss/arquillian/junit/JUnitTestRunner.java
arquillian/trunk/spi/src/main/java/org/jboss/arquillian/spi/DeployableContainer.java
arquillian/trunk/spi/src/main/java/org/jboss/arquillian/spi/ServiceLoader.java
arquillian/trunk/spi/src/main/java/org/jboss/arquillian/spi/TestRunner.java
arquillian/trunk/testng/pom.xml
arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/Arquillian.java
arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/TestNGTestRunner.java
Log:
ARQ-69 ARQ-104 New multi context event based core with new Test framework integration
Modified: arquillian/trunk/build/pom.xml
===================================================================
--- arquillian/trunk/build/pom.xml 2010-04-20 14:53:59 UTC (rev 4268)
+++ arquillian/trunk/build/pom.xml 2010-04-20 15:02:38 UTC (rev 4269)
@@ -251,7 +251,12 @@
<artifactId>jetty-embedded</artifactId>
<version>${version.jetty_jetty}</version>
</dependency>
-
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.8.3</version>
+ </dependency>
+
</dependencies>
</dependencyManagement>
Modified: arquillian/trunk/impl-base/pom.xml
===================================================================
--- arquillian/trunk/impl-base/pom.xml 2010-04-20 14:53:59 UTC (rev 4268)
+++ arquillian/trunk/impl-base/pom.xml 2010-04-20 15:02:38 UTC (rev 4269)
@@ -58,6 +58,12 @@
External Projects
-->
<dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
Modified: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/ClientDeploymentGenerator.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/ClientDeploymentGenerator.java 2010-04-20 14:53:59 UTC (rev 4268)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/ClientDeploymentGenerator.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -16,17 +16,19 @@
*/
package org.jboss.arquillian.impl;
+import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.jboss.arquillian.spi.ApplicationArchiveGenerator;
+import org.jboss.arquillian.spi.ApplicationArchiveProcessor;
import org.jboss.arquillian.spi.AuxiliaryArchiveAppender;
+import org.jboss.arquillian.spi.AuxiliaryArchiveProcessor;
import org.jboss.arquillian.spi.DeploymentPackager;
import org.jboss.arquillian.spi.ServiceLoader;
-import org.jboss.arquillian.spi.AuxiliaryArchiveProcessor;
-import org.jboss.arquillian.spi.ApplicationArchiveProcessor;
import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.exporter.ZipExporter;
/**
* Responsible for
@@ -61,7 +63,11 @@
List<Archive<?>> auxiliaryArchives = loadAuxiliaryArchives();
applyAuxiliaryProcessors(auxiliaryArchives);
- return packager.generateDeployment(applicationArchive, auxiliaryArchives);
+ Archive<?> deployment = packager.generateDeployment(applicationArchive, auxiliaryArchives);
+
+ deployment.as(ZipExporter.class).exportZip(new File("test.ear"), true);
+
+ return deployment;
}
private List<Archive<?>> loadAuxiliaryArchives()
Deleted: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/DeployableTest.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/DeployableTest.java 2010-04-20 14:53:59 UTC (rev 4268)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/DeployableTest.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -1,84 +0,0 @@
-/*
- * 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;
-
-import org.jboss.arquillian.impl.container.Controlable;
-import org.jboss.arquillian.spi.ServiceLoader;
-import org.jboss.shrinkwrap.api.Archive;
-
-/**
- * DeployableTest
- *
- * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
- * @version $Revision: $
- */
-public class DeployableTest
-{
- // TODO: move to DeploybleTestBuilder
- private static boolean inContainer = false;
-
- public static boolean isInContainer()
- {
- return inContainer;
- }
-
- public static void setInContainer(boolean inContainer)
- {
- DeployableTest.inContainer = inContainer;
- }
-
- private Controlable containerController;
- private Deployer containerDeployer;
- private ServiceLoader serviceLoader;
-
-
- DeployableTest(Controlable containerController, Deployer containerDeployer, ServiceLoader serviceLoader)
- {
- Validate.notNull(containerController, "ContainerController must bespecified");
- Validate.notNull(containerDeployer, "ContainerDeployer must bespecified");
- Validate.notNull(serviceLoader, "ServiceLoader must bespecified");
-
- this.containerController = containerController;
- this.containerDeployer = containerDeployer;
- this.serviceLoader = serviceLoader;
- }
-
- public Controlable getContainerController()
- {
- return containerController;
- }
-
- public Deployer getDeployer()
- {
- return containerDeployer;
- }
-
- public Archive<?> generateArchive(Class<?> testCase)
- {
- return getArchiveGenerator().generate(testCase);
- }
-
- // TODO: move DeploymentGenerator injection to DeployableTestBuilder
- private DeploymentGenerator getArchiveGenerator()
- {
- if(DeployableTest.isInContainer())
- {
- return new NullDeploymentGenerator();
- }
- return new ClientDeploymentGenerator(serviceLoader);
- }
-}
Modified: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/DeployableTestBuilder.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/DeployableTestBuilder.java 2010-04-20 14:53:59 UTC (rev 4268)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/DeployableTestBuilder.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -16,19 +16,16 @@
*/
package org.jboss.arquillian.impl;
-import org.jboss.arquillian.impl.container.ContainerController;
-import org.jboss.arquillian.impl.container.ContainerDeployer;
-import org.jboss.arquillian.impl.container.Controlable;
-import org.jboss.arquillian.spi.ContainerMethodExecutor;
-import org.jboss.arquillian.spi.DeployableContainer;
-import org.jboss.arquillian.spi.DeploymentException;
-import org.jboss.arquillian.spi.LifecycleException;
+import org.jboss.arquillian.impl.context.ClientProfileBuilder;
+import org.jboss.arquillian.impl.context.ContainerProfileBuilder;
+import org.jboss.arquillian.impl.context.ContextLifecycleManager;
+import org.jboss.arquillian.impl.context.ProfileBuilder;
+import org.jboss.arquillian.impl.context.StandaloneProfileBuilder;
+import org.jboss.arquillian.spi.Configuration;
+import org.jboss.arquillian.spi.ContainerConfiguration;
+import org.jboss.arquillian.spi.ContainerProfile;
import org.jboss.arquillian.spi.ServiceLoader;
-import org.jboss.arquillian.spi.TestMethodExecutor;
-import org.jboss.arquillian.spi.TestResult;
-import org.jboss.arquillian.spi.TestResult.Status;
-import org.jboss.arquillian.spi.util.TestEnrichers;
-import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.arquillian.spi.TestRunnerAdaptor;
/**
* DeployableTestBuilder
@@ -39,71 +36,80 @@
public class DeployableTestBuilder
{
private DeployableTestBuilder() {}
+
+ private static ContainerProfile profile = null;
+
+ public static void setProfile(ContainerProfile profile)
+ {
+ Validate.notNull(profile, "Profile must be specified");
+
+ DeployableTestBuilder.profile = profile;
+ }
- public static DeployableTest build(Object config)
+ public static ContainerProfile getProfile()
{
- Controlable controller = null;
- Deployer deployer = null;
-
- // TODO: lookup service loader impl from configuration
- ServiceLoader serviceLoader = new DynamicServiceLoader();
-
- if(DeployableTest.isInContainer())
- {
- controller = new InContainerContainer();
- deployer = new InContainerContainer();
- }
- else
- {
- DeployableContainer container = serviceLoader.onlyOne(DeployableContainer.class);
- // TODO: lookup controller / deployer from configuration
- controller = new ContainerController(container);
- deployer = new ContainerDeployer(container);
- }
+ return DeployableTestBuilder.profile;
+ }
- return new DeployableTest(
- controller,
- deployer,
- serviceLoader);
+ /**
+ * @return
+ */
+ public static TestRunnerAdaptor build()
+ {
+ return build(DeployableTestBuilder.profile);
}
- private static class InContainerContainer implements Controlable, Deployer
+ // TODO: fix the ContainerProfile loading/selecting
+ public static TestRunnerAdaptor build(Configuration configuration)
{
- @Override
- public void start() throws LifecycleException
+ ContainerProfile profile = DeployableTestBuilder.profile;
+ ContainerConfiguration activeConfiguration = configuration.getActiveContainerConfiguration();
+ if(activeConfiguration != null && profile == null)
{
+ profile = activeConfiguration.getContainerProfile();
}
-
- @Override
- public void stop() throws LifecycleException
+ return build(profile, configuration);
+ }
+
+ public static TestRunnerAdaptor build(ContainerProfile profile)
+ {
+ return build(profile, new XmlConfigurationBuilder().build());
+ }
+
+ public static TestRunnerAdaptor build(ContainerProfile profile, Configuration configuration)
+ {
+ ProfileBuilder profileBuilder = null;
+ switch(profile)
{
+ case STANDALONE:
+ profileBuilder = new StandaloneProfileBuilder();
+ break;
+ case CONTAINER:
+ profileBuilder = new ContainerProfileBuilder();
+ break;
+ case CLIENT:
+ profileBuilder = new ClientProfileBuilder();
+ break;
+ default: // TODO: create profile builders dynamic
+ throw new IllegalArgumentException("Unknon profile " + profile);
}
+ return build(profileBuilder, configuration);
+ }
+
+ /**
+ * @param profileBuilder
+ * @return
+ */
+ public static TestRunnerAdaptor build(ProfileBuilder profileBuilder, Configuration configuration)
+ {
+ ServiceLoader serviceLoader = new DynamicServiceLoader();
- @Override
- public ContainerMethodExecutor deploy(Archive<?> archive) throws DeploymentException
- {
- return new ContainerMethodExecutor()
- {
- @Override
- public TestResult invoke(TestMethodExecutor testMethodExecutor)
- {
- try
- {
- TestEnrichers.enrich(testMethodExecutor.getInstance());
- testMethodExecutor.invoke();
- return new TestResultImpl(Status.PASSED);
- }
- catch (Throwable e)
- {
- return new TestResultImpl(Status.FAILED, e);
- }
- }
- };
- }
+ ContextLifecycleManager eventManager = new ContextLifecycleManager(
+ configuration,
+ profileBuilder,
+ serviceLoader
+ );
- @Override
- public void undeploy(Archive<?> archive) throws DeploymentException
- {
- }
+ return new EventTestRunnerAdaptor(eventManager);
}
}
Deleted: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/Deployer.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/Deployer.java 2010-04-20 14:53:59 UTC (rev 4268)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/Deployer.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -1,35 +0,0 @@
-/*
- * 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;
-
-import org.jboss.arquillian.spi.ContainerMethodExecutor;
-import org.jboss.arquillian.spi.DeploymentException;
-import org.jboss.shrinkwrap.api.Archive;
-
-/**
- * Deployer
- *
- * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
- * @version $Revision: $
- */
-public interface Deployer
-{
-
- ContainerMethodExecutor deploy(Archive<?> archive) throws DeploymentException;
- void undeploy(Archive<?> archive) throws DeploymentException;
-
-}
Modified: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/DeploymentAnnotationArchiveGenerator.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/DeploymentAnnotationArchiveGenerator.java 2010-04-20 14:53:59 UTC (rev 4268)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/DeploymentAnnotationArchiveGenerator.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -17,6 +17,7 @@
package org.jboss.arquillian.impl;
import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.spi.ApplicationArchiveGenerator;
@@ -39,8 +40,16 @@
Method deploymentMethod = findDeploymentMethod(testCase);
if(deploymentMethod == null)
{
- throw new RuntimeException("No static method annotated with " + Deployment.class.getName() + " found");
+ throw new IllegalArgumentException("No method annotated with " + Deployment.class.getName() + " found");
}
+ if(!Modifier.isStatic(deploymentMethod.getModifiers()))
+ {
+ throw new IllegalArgumentException("Method annotated with " + Deployment.class.getName() + " is not static");
+ }
+ if(!Archive.class.isAssignableFrom(deploymentMethod.getReturnType()))
+ {
+ throw new IllegalArgumentException("Method annotated with " + Deployment.class.getName() + " must have return type " + Archive.class.getName());
+ }
try
{
Archive<?> archive = (Archive<?>)deploymentMethod.invoke(null);
Modified: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/DynamicServiceLoader.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/DynamicServiceLoader.java 2010-04-20 14:53:59 UTC (rev 4268)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/DynamicServiceLoader.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -48,11 +48,11 @@
Collection<T> providers = DefaultServiceLoader.load(serviceClass).getProviders();
if(providers == null || providers.size() == 0)
{
- throw new RuntimeException("No implementation found for: " + serviceClass.getName() + ", check classpath");
+ throw new IllegalStateException("No implementation found for: " + serviceClass.getName() + ", check classpath");
}
if(providers.size() > 1)
{
- throw new RuntimeException("Mutiple implementations found for: " + serviceClass.getName() + ", check classpath");
+ throw new IllegalStateException("Mutiple implementations found for: " + serviceClass.getName() + ", check classpath");
}
return providers.iterator().next();
}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/EventTestRunnerAdaptor.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/EventTestRunnerAdaptor.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/EventTestRunnerAdaptor.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,128 @@
+/*
+ * 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;
+
+import java.lang.reflect.Method;
+
+import org.jboss.arquillian.impl.context.ContextLifecycleManager;
+import org.jboss.arquillian.impl.event.type.After;
+import org.jboss.arquillian.impl.event.type.AfterClass;
+import org.jboss.arquillian.impl.event.type.AfterSuite;
+import org.jboss.arquillian.impl.event.type.Before;
+import org.jboss.arquillian.impl.event.type.BeforeClass;
+import org.jboss.arquillian.impl.event.type.BeforeSuite;
+import org.jboss.arquillian.impl.event.type.Test;
+import org.jboss.arquillian.spi.TestMethodExecutor;
+import org.jboss.arquillian.spi.TestResult;
+import org.jboss.arquillian.spi.TestRunnerAdaptor;
+
+/**
+ * EventTestRunnerAdaptor
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class EventTestRunnerAdaptor implements TestRunnerAdaptor
+{
+ private ContextLifecycleManager contextLifecycle;
+
+ public EventTestRunnerAdaptor(ContextLifecycleManager contextLifecycle)
+ {
+ Validate.notNull(contextLifecycle, "ContextLifecycle must be specified");
+
+ this.contextLifecycle = contextLifecycle;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.spi.TestRunnerAdaptor#beforeSuite()
+ */
+ @Override
+ public void beforeSuite() throws Exception
+ {
+ contextLifecycle.createRestoreSuiteContext().fire(new BeforeSuite());
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.spi.TestRunnerAdaptor#afterSuite()
+ */
+ @Override
+ public void afterSuite() throws Exception
+ {
+ contextLifecycle.createRestoreSuiteContext().fire(new AfterSuite());
+ contextLifecycle.destroySuiteContext();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.spi.TestRunnerAdaptor#beforeClass(java.lang.Class)
+ */
+ @Override
+ public void beforeClass(Class<?> testClass) throws Exception
+ {
+ Validate.notNull(testClass, "TestClass must be specified");
+
+ contextLifecycle.createRestoreClassContext(testClass).fire(new BeforeClass(testClass));
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.spi.TestRunnerAdaptor#afterClasss(java.lang.Class)
+ */
+ @Override
+ public void afterClass(Class<?> testClass) throws Exception
+ {
+ Validate.notNull(testClass, "TestClass must be specified");
+
+ contextLifecycle.createRestoreClassContext(testClass).fire(new AfterClass(testClass));
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.spi.TestRunnerAdaptor#before(java.lang.Object, java.lang.reflect.Method)
+ */
+ @Override
+ public void before(Object testInstance, Method testMethod) throws Exception
+ {
+ Validate.notNull(testInstance, "TestInstance must be specified");
+ Validate.notNull(testMethod, "TestMethod must be specified");
+
+ contextLifecycle.createRestoreTestContext(testInstance).fire(new Before(testInstance, testMethod));
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.spi.TestRunnerAdaptor#after(java.lang.Object, java.lang.reflect.Method)
+ */
+ @Override
+ public void after(Object testInstance, Method testMethod) throws Exception
+ {
+ Validate.notNull(testInstance, "TestInstance must be specified");
+ Validate.notNull(testMethod, "TestMethod must be specified");
+
+ contextLifecycle.createRestoreTestContext(testInstance).fire(new After(testInstance, testMethod));
+ contextLifecycle.destroyTestContext(testInstance);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.spi.TestRunnerAdaptor#test(org.jboss.arquillian.spi.TestMethodExecutor)
+ */
+ @Override
+ public TestResult test(TestMethodExecutor testMethodExecutor) throws Exception
+ {
+ Validate.notNull(testMethodExecutor, "TestMethodExecutor must be specified");
+
+ Test test = new Test(testMethodExecutor);
+ contextLifecycle.createRestoreTestContext(testMethodExecutor.getInstance()).fire(test);
+ return test.getTestResult();
+ }
+}
Deleted: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/NullDeploymentGenerator.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/NullDeploymentGenerator.java 2010-04-20 14:53:59 UTC (rev 4268)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/NullDeploymentGenerator.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -1,38 +0,0 @@
-/*
- * 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;
-
-import org.jboss.shrinkwrap.api.Archive;
-
-/**
- * NullDeploymentGenerator
- *
- * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
- * @version $Revision: $
- */
-public class NullDeploymentGenerator implements DeploymentGenerator
-{
-
- /* (non-Javadoc)
- * @see org.jboss.arquillian.impl.DeploymentGenerator#generate(java.lang.Class)
- */
- @Override
- public Archive<?> generate(Class<?> testCase)
- {
- return null;
- }
-}
Modified: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/Validate.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/Validate.java 2010-04-20 14:53:59 UTC (rev 4268)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/Validate.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -60,4 +60,19 @@
throw new IllegalArgumentException(message);
}
}
+
+ /**
+ * Checks that obj is not null, throws exception if it is.
+ *
+ * @param obj The object to check
+ * @param message The exception message
+ * @throws IllegalStateException Thrown if obj is null
+ */
+ public static void stateNotNull(final Object obj, final String message) throws IllegalStateException
+ {
+ if(obj == null)
+ {
+ throw new IllegalStateException(message);
+ }
+ }
}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/AbstractEventContext.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/AbstractEventContext.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/AbstractEventContext.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,91 @@
+/*
+ * 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.context;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.arquillian.impl.Validate;
+import org.jboss.arquillian.impl.event.Event;
+import org.jboss.arquillian.impl.event.EventHandler;
+import org.jboss.arquillian.impl.event.MapEventManager;
+import org.jboss.arquillian.impl.event.EventManager;
+import org.jboss.arquillian.spi.ServiceLoader;
+
+
+/**
+ * AbstractEventContext
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public abstract class AbstractEventContext<X extends Context<X, T>, T extends Event> implements Context<X, T>
+{
+ private EventManager<X, T> eventManager;
+
+ // TODO: create ObjectStore
+ private Map<Class<?>, Object> objectStore;
+
+ public AbstractEventContext()
+ {
+ this.eventManager = new MapEventManager<X, T>();
+ this.objectStore = new HashMap<Class<?>, Object>();
+ }
+
+ @Override
+ public <K extends T> void register(Class<? extends K> eventType, EventHandler<X, ? super K> handler)
+ {
+ eventManager.register(eventType, handler);
+ }
+
+ protected EventManager<X, T> getEventManager()
+ {
+ return eventManager;
+ }
+
+ public <B> void add(Class<B> type, B instance)
+ {
+ Validate.notNull(type, "Type must be specified");
+ Validate.notNull(instance, "Instance must be specified");
+
+ objectStore.put(type, instance);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <B> B get(Class<B> type)
+ {
+ Validate.notNull(type, "Type must be specified");
+
+ Object instance = objectStore.get(type);
+ if(instance == null)
+ {
+ Context<?, ?> parentContext = getParentContext();
+ if(parentContext != null)
+ {
+ instance = parentContext.get(type);
+ }
+ }
+ return (B) instance;
+ }
+
+ @Override
+ public ServiceLoader getServiceLoader()
+ {
+ return get(ServiceLoader.class);
+ }
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/ClassContext.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/ClassContext.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/ClassContext.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,79 @@
+/*
+ * 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.context;
+
+import org.jboss.arquillian.impl.Validate;
+import org.jboss.arquillian.impl.event.type.ClassEvent;
+
+/**
+ * A ClassContext is alive in the following life cycles: <br/>
+ * <ul>
+ * <li>BeforeClass</li>
+ * <li>Before</li>
+ * <li>Test</li>
+ * <li>After</li>
+ * <li>AfterClass</li>
+ * </ul>
+ * Used for firing events and storing of object that live in the Class Scope.
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class ClassContext extends AbstractEventContext<ClassContext, ClassEvent>
+{
+ private SuiteContext suiteContext;
+
+ /**
+ * Create a new ClassContext for a given {@link SuiteContext}.
+ *
+ * @param suiteContext The parent SuiteContext
+ * @throws IllegalArgumentException if suiteContext is null
+ */
+ public ClassContext(final SuiteContext suiteContext)
+ {
+ Validate.notNull(suiteContext, "SuiteContext must be specified");
+
+ this.suiteContext = suiteContext;
+ }
+
+ /**
+ * @return The parent SuiteContext
+ */
+ public SuiteContext getSuiteContext()
+ {
+ return suiteContext;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.impl.context.Context#getParentContext()
+ */
+ @Override
+ public Context<?, ?> getParentContext()
+ {
+ return getSuiteContext();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.impl.context.Context#fire(org.jboss.arquillian.impl.event.Event)
+ */
+ @Override
+ public void fire(ClassEvent event)
+ {
+ getEventManager().fire(this, event);
+ getSuiteContext().fire(event);
+ }
+}
\ No newline at end of file
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/ClientProfileBuilder.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/ClientProfileBuilder.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/ClientProfileBuilder.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,99 @@
+/*
+ * 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.context;
+
+import org.jboss.arquillian.impl.ClientDeploymentGenerator;
+import org.jboss.arquillian.impl.DeploymentGenerator;
+import org.jboss.arquillian.impl.event.EventHandler;
+import org.jboss.arquillian.impl.event.type.After;
+import org.jboss.arquillian.impl.event.type.AfterClass;
+import org.jboss.arquillian.impl.event.type.AfterSuite;
+import org.jboss.arquillian.impl.event.type.Before;
+import org.jboss.arquillian.impl.event.type.BeforeClass;
+import org.jboss.arquillian.impl.event.type.BeforeSuite;
+import org.jboss.arquillian.impl.event.type.SuiteEvent;
+import org.jboss.arquillian.impl.event.type.Test;
+import org.jboss.arquillian.impl.handler.ArchiveGenerator;
+import org.jboss.arquillian.impl.handler.ContainerCreator;
+import org.jboss.arquillian.impl.handler.ContainerDeployer;
+import org.jboss.arquillian.impl.handler.ContainerStarter;
+import org.jboss.arquillian.impl.handler.ContainerStopper;
+import org.jboss.arquillian.impl.handler.ContainerTestExecuter;
+import org.jboss.arquillian.impl.handler.ContainerUndeployer;
+import org.jboss.arquillian.impl.handler.ExecutionTimer;
+
+/**
+ * ClientContextCreator
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class ClientProfileBuilder implements ProfileBuilder
+{
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.impl.context.ContextBuilder#buildSuiteContext(org.jboss.arquillian.impl.context.SuiteContext)
+ */
+ @Override
+ public void buildSuiteContext(SuiteContext context)
+ {
+ context.register(BeforeSuite.class, new ContainerCreator());
+ context.register(BeforeSuite.class, new ContainerStarter());
+ context.register(AfterSuite.class, new ContainerStopper());
+
+ EventHandler<SuiteContext, SuiteEvent> timer = new ExecutionTimer();
+ context.register(BeforeSuite.class, timer);
+ context.register(AfterSuite.class, timer);
+ context.register(BeforeClass.class, timer);
+ context.register(AfterClass.class, timer);
+ context.register(Before.class, timer);
+ context.register(Test.class, timer);
+ context.register(After.class, timer);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.impl.context.ContextBuilder#buildClassContext(org.jboss.arquillian.impl.context.ClassContext)
+ */
+ @Override
+ public void buildClassContext(ClassContext context)
+ {
+ // TODO: move out to SerivceLoader
+ context.add(DeploymentGenerator.class, new ClientDeploymentGenerator(context.getServiceLoader()));
+
+ context.register(BeforeClass.class, new ArchiveGenerator());
+ context.register(BeforeClass.class, new ContainerDeployer());
+ context.register(AfterClass.class, new ContainerUndeployer());
+
+// if(runLocally)
+// {
+// context.register(Before.class, new TestCaseEnricher());
+// context.register(Test.class, new TestEventExecuter());
+// }
+// else
+// {
+// context.register(Test.class, new ContainerTestExecuter());
+// }
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.impl.context.ContextBuilder#buildTestContext(org.jboss.arquillian.impl.context.TestContext)
+ */
+ @Override
+ public void buildTestContext(TestContext context)
+ {
+ context.register(Test.class, new ContainerTestExecuter());
+ }
+}
\ No newline at end of file
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/ContainerProfileBuilder.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/ContainerProfileBuilder.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/ContainerProfileBuilder.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,57 @@
+/*
+ * 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.context;
+
+import org.jboss.arquillian.impl.event.type.Before;
+import org.jboss.arquillian.impl.event.type.Test;
+import org.jboss.arquillian.impl.handler.TestEventExecuter;
+import org.jboss.arquillian.impl.handler.TestCaseEnricher;
+
+/**
+ * ClientContextCreator
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class ContainerProfileBuilder implements ProfileBuilder
+{
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.impl.context.ContextBuilder#buildSuiteContext(org.jboss.arquillian.impl.context.SuiteContext)
+ */
+ @Override
+ public void buildSuiteContext(SuiteContext context)
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.impl.context.ContextBuilder#buildClassContext(org.jboss.arquillian.impl.context.ClassContext)
+ */
+ @Override
+ public void buildClassContext(ClassContext context)
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.impl.context.ContextBuilder#buildTestContext(org.jboss.arquillian.impl.context.TestContext)
+ */
+ @Override
+ public void buildTestContext(TestContext context)
+ {
+ context.register(Before.class, new TestCaseEnricher());
+ context.register(Test.class, new TestEventExecuter());
+ }
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/Context.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/Context.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/Context.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,81 @@
+/*
+ * 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.context;
+
+import org.jboss.arquillian.impl.event.Event;
+import org.jboss.arquillian.impl.event.EventHandler;
+import org.jboss.arquillian.spi.ServiceLoader;
+
+/**
+ *
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ * @param <X>
+ * @param <T>
+ */
+public interface Context<X, T extends Event>
+{
+ /**
+ * Fire a new {@link Event}.
+ *
+ * @param event The {@link Event} instance to fire
+ */
+ void fire(T event);
+
+ /**
+ * Register a {@link EventHandler} for a specific {@link Event}.
+ *
+ * @param <K>
+ * @param eventType The Type of {@link Event} to listen to
+ * @param handler The receiver of the {@link Event}
+ */
+ <K extends T> void register(Class<? extends K> eventType, EventHandler<X, ? super K> handler);
+
+ /**
+ * Get the defined {@link ServiceLoader}
+ *
+ * @return A instance of {@link ServiceLoader}
+ * @see #get(Class)
+ */
+ ServiceLoader getServiceLoader();
+
+ /**
+ * Get this contexts parent context.
+ *
+ * @return The parent context if any, null if this is the top context.
+ */
+ Context<?, ?> getParentContext();
+
+ /**
+ * Add a instance of B to the context.
+ *
+ * @param <B>
+ * @param type The Type of the instance to add
+ * @param instance The instance to add
+ */
+ <B> void add(Class<B> type, B instance);
+
+ /**
+ * Get a instance of B from the context.
+ *
+ * @param <B>
+ * @param type Type to lookup
+ * @return A instance of B or null if not found
+ */
+ <B> B get(Class<B> type);
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/ContextLifecycleManager.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/ContextLifecycleManager.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/ContextLifecycleManager.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,191 @@
+/*
+ * 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.context;
+
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.jboss.arquillian.impl.Validate;
+import org.jboss.arquillian.spi.Configuration;
+import org.jboss.arquillian.spi.ServiceLoader;
+
+
+/**
+ * Handles creation and destruction of the scopes; Suite, Class, Test <br/>
+ * There can only be one SuiteContext pr run. A SuiteContext can be associated with multiple ClassContexts that
+ * again can be associated with multiple TestContexts.<br/>
+ * <br/>
+ * Normal Lifecycle:<br/>
+ * {@link #createRestoreSuiteContext()}<br/>
+ * <br/>
+ * {@link #createRestoreClassContext(Class)}<br/>
+ * ...<br/>
+ * {@link #createRestoreTestContext(Object)}<br/>
+ * {@link #destroyTestContext(Object)}<br/>
+ * ...<br/>
+ * {@link #destroyClassContext(Class)}<br/>
+ * <br/>
+ * {@link #destroySuiteContext()}<br/>
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class ContextLifecycleManager
+{
+ private Configuration configuration;
+ private ProfileBuilder profileBuilder;
+ private ServiceLoader serviceLoader;
+
+ private SuiteContext suiteContext;
+
+ // TODO: move out into a ContextStore IF
+ private ConcurrentHashMap<Class<?>, ClassContext> classContextStore;
+ private ConcurrentHashMap<Object, TestContext> testContextStore;
+
+ public ContextLifecycleManager(ProfileBuilder profileBuilder, ServiceLoader serviceLoader)
+ {
+ this(new Configuration(), profileBuilder, serviceLoader);
+ }
+
+ public ContextLifecycleManager(Configuration configuration, ProfileBuilder profileBuilder, ServiceLoader serviceLoader)
+ {
+ Validate.notNull(configuration, "Configuration must be specified");
+ Validate.notNull(profileBuilder, "ProfileBuilder must be specified");
+ Validate.notNull(serviceLoader, "ServiceLoader must be specified");
+
+ this.configuration = configuration;
+ this.profileBuilder = profileBuilder;
+ this.serviceLoader = serviceLoader;
+
+ classContextStore = new ConcurrentHashMap<Class<?>, ClassContext>();
+ testContextStore = new ConcurrentHashMap<Object, TestContext>();
+ }
+
+ /**
+ * Creates or restores the SuiteContext.<br/>
+ *
+ * If the Context has previously been created, the same instance will be returned.
+ *
+ * @return A SuiteContext instance
+ */
+ public SuiteContext createRestoreSuiteContext()
+ {
+ if(suiteContext == null)
+ {
+ suiteContext = new SuiteContext(serviceLoader);
+ suiteContext.add(Configuration.class, configuration);
+ profileBuilder.buildSuiteContext(suiteContext);
+ }
+ return suiteContext;
+ }
+
+ /**
+ * Destroy the Context.<br/>
+ *
+ * A new Context instance will be returned on next {@link #createRestoreSuiteContext()} call.
+ *
+ * @param testClass Context association
+ */
+ public void destroySuiteContext()
+ {
+ suiteContext = null;
+ }
+
+ /**
+ * Creates or restores the ClassContext.<br/>
+ *
+ * If the Context has previously been created, the same instance will be returned.
+ *
+ * @param testClass The TestClass this Context belongs to
+ * @return A ClassContext instance
+ * @throws IllegalArgumentException if testClass is null
+ * @throws IllegalStateException if {@link #createRestoreSuiteContext()} has not been called
+ */
+ public ClassContext createRestoreClassContext(Class<?> testClass)
+ {
+ Validate.notNull(testClass, "TestClass must be specified");
+
+ if(suiteContext == null)
+ {
+ throw new IllegalStateException(
+ "No " +
+ SuiteContext.class.getSimpleName() +
+ " found, please create one before creating a " +
+ ClassContext.class.getSimpleName());
+ }
+
+ if(!classContextStore.contains(testClass))
+ {
+ ClassContext classContext = new ClassContext(createRestoreSuiteContext());
+ profileBuilder.buildClassContext(classContext);
+
+ classContextStore.putIfAbsent(
+ testClass,
+ classContext);
+ }
+ return classContextStore.get(testClass);
+ }
+
+ /**
+ * Destroy the Context associated with given test class.<br/>
+ *
+ * A new Context instance will be returned on next {@link #createRestoreClassContext(Class)} call.
+ *
+ * @param testClass Context association
+ */
+ public void destroyClassContext(Class<?> testClass)
+ {
+ classContextStore.remove(testClass);
+ }
+
+ /**
+ * Creates or restores the TestContext.<br/>
+ *
+ * If the Context has previously been created, the same instance will be returned.
+ *
+ * @param testInstance The TestObject this Context belongs to
+ * @return A TestContext instance
+ * @throws IllegalArgumentException if testInstance is null
+ */
+ // TODO: split create and restore in two private methods so we can verify if previous context was created.
+ // Expose the createRestore v.
+ public TestContext createRestoreTestContext(Object testInstance)
+ {
+ Validate.notNull(testInstance, "TestInstance must be specified");
+
+ if(!testContextStore.contains(testInstance))
+ {
+ TestContext testContext = new TestContext(createRestoreClassContext(testInstance.getClass()));
+ profileBuilder.buildTestContext(testContext);
+ testContextStore.putIfAbsent(
+ testInstance,
+ testContext);
+ }
+ return testContextStore.get(testInstance);
+ }
+
+ /**
+ * Destroy the Context associated with given test instance.<br/>
+ *
+ * A new Context instance will be returned on next {@link #createRestoreTestContext(Object)} call.
+ *
+ * @param testInstance Context association
+ */
+ public void destroyTestContext(Object testInstance)
+ {
+ testContextStore.remove(testInstance);
+ }
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/ProfileBuilder.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/ProfileBuilder.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/ProfileBuilder.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,41 @@
+/*
+ * 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.context;
+
+/**
+ *
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public interface ProfileBuilder
+{
+ /**
+ * @param context
+ */
+ void buildSuiteContext(SuiteContext context);
+
+ /**
+ * @param context
+ */
+ void buildClassContext(ClassContext context);
+
+ /**
+ * @param context
+ */
+ void buildTestContext(TestContext context);
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/StandaloneProfileBuilder.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/StandaloneProfileBuilder.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/StandaloneProfileBuilder.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,41 @@
+/*
+ * 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.context;
+
+import org.jboss.arquillian.impl.event.type.Before;
+import org.jboss.arquillian.impl.event.type.Test;
+import org.jboss.arquillian.impl.handler.TestEventExecuter;
+import org.jboss.arquillian.impl.handler.TestCaseEnricher;
+
+/**
+ * StandaloneProfileBuilder
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class StandaloneProfileBuilder extends ClientProfileBuilder
+{
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.impl.context.ProfileBuilder#buildTestContext(org.jboss.arquillian.impl.context.TestContext)
+ */
+ @Override
+ public void buildTestContext(TestContext context)
+ {
+ context.register(Before.class, new TestCaseEnricher());
+ context.register(Test.class, new TestEventExecuter());
+ }
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/SuiteContext.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/SuiteContext.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/SuiteContext.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,74 @@
+/*
+ * 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.context;
+
+import org.jboss.arquillian.impl.Validate;
+import org.jboss.arquillian.impl.event.type.SuiteEvent;
+import org.jboss.arquillian.spi.ServiceLoader;
+
+/**
+ * A SuiteContext is alive in the following life cycles: <br/>
+ * <ul>
+ * <li>BeforeSuite</li>
+ * <li>BeforeClass</li>
+ * <li>Before</li>
+ * <li>Test</li>
+ * <li>After</li>
+ * <li>AfterClass</li>
+ * <li>AfterSuite</li>
+ * </ul>
+ * Used for firing events and storing of object that live in the Suite Scope.
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class SuiteContext extends AbstractEventContext<SuiteContext, SuiteEvent>
+{
+ /**
+ * Create a new SuiteContext.
+ *
+ * @param serviceLoader The ServiceLoader to use
+ * @throws IllegalArgumentException if serviceLoader is null
+ */
+ public SuiteContext(final ServiceLoader serviceLoader)
+ {
+ Validate.notNull(serviceLoader, "ServiceLoader must be specified");
+
+ add(ServiceLoader.class, serviceLoader);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.impl.context.Context#fire(org.jboss.arquillian.impl.event.Event)
+ */
+ @Override
+ public void fire(SuiteEvent event)
+ {
+ getEventManager().fire(this, event);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.impl.context.Context#getParentContext()
+ */
+ /**
+ * @return Always null, SuiteContext is the root context.
+ */
+ @Override
+ public Context<?, ?> getParentContext()
+ {
+ return null;
+ }
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/TestContext.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/TestContext.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/context/TestContext.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,77 @@
+/*
+ * 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.context;
+
+import org.jboss.arquillian.impl.Validate;
+import org.jboss.arquillian.impl.event.type.TestEvent;
+
+/**
+ * A TestContext is alive in the following life cycles: <br/>
+ * <ul>
+ * <li>Before</li>
+ * <li>Test</li>
+ * <li>After</li>
+ * </ul>
+ * Used for firing events and storing of object that live in the Test Scope.
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class TestContext extends AbstractEventContext<TestContext, TestEvent>
+{
+ private ClassContext classContext;
+
+ /**
+ * Create a new TestContext for a given {@link ClassContext}.
+ *
+ * @param classContext The parent ClassContext
+ * @throws IllegalArgumentException if classContext is null
+ */
+ public TestContext(final ClassContext classContext)
+ {
+ Validate.notNull(classContext, "ClassContext must be specified");
+
+ this.classContext = classContext;
+ }
+
+ /**
+ * @return The parent ClassContext
+ */
+ public ClassContext getClassContext()
+ {
+ return classContext;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.impl.context.Context#getParentContext()
+ */
+ @Override
+ public Context<?, ?> getParentContext()
+ {
+ return getClassContext();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.impl.context.Context#fire(org.jboss.arquillian.impl.event.Event)
+ */
+ @Override
+ public void fire(TestEvent event)
+ {
+ getEventManager().fire(this, event);
+ getClassContext().fire(event);
+ }
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/Event.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/Event.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/Event.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,27 @@
+/*
+ * 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.event;
+
+/**
+ * Event
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public interface Event
+{
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/EventHandler.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/EventHandler.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/EventHandler.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,37 @@
+/*
+ * 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.event;
+
+/**
+ * EventHandler
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ * @param <X> The Context
+ * @param <T> The Event
+ */
+public interface EventHandler<X, T>
+{
+
+ /**
+ * @param context
+ * @param event
+ * @throws Exception
+ */
+ void callback(X context, T event) throws Exception;
+
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/EventManager.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/EventManager.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/EventManager.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,41 @@
+/*
+ * 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.event;
+
+/**
+ * EventManagerIF
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ * @param <X>
+ * @param <T>
+ */
+public interface EventManager<X, T extends Event>
+{
+ /**
+ * @param context
+ * @param event
+ */
+ void fire(X context, T event);
+
+ /**
+ * @param <K>
+ * @param eventType
+ * @param handler
+ */
+ <K extends T> void register(Class<? extends K> eventType, EventHandler<X, ? super K> handler);
+}
\ No newline at end of file
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/FiredEventException.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/FiredEventException.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/FiredEventException.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -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.event;
+
+import org.jboss.arquillian.impl.context.Context;
+
+/**
+ * FiredEventException
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class FiredEventException extends RuntimeException
+{
+ private static final long serialVersionUID = 1L;
+
+ private transient Event source;
+ private transient Context<?, ?> context;
+
+ public FiredEventException(Context<?, ?> context, Event source, Exception cause)
+ {
+ super(cause);
+ this.source = source;
+ this.context = context;
+ }
+
+ public Event getSource()
+ {
+ return source;
+ }
+
+ public Context<?, ?> getContext()
+ {
+ return context;
+ }
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/MapEventManager.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/MapEventManager.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/MapEventManager.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,79 @@
+/*
+ * 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.event;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.jboss.arquillian.impl.Validate;
+import org.jboss.arquillian.impl.context.Context;
+
+/**
+ * EventManager
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ at SuppressWarnings("unchecked")
+public class MapEventManager<X extends Context<X, T>, T extends Event> implements EventManager<X, T>
+{
+ private Map<Class<? extends T>, List<EventHandler>> handlerRegistry;
+
+ public MapEventManager()
+ {
+ this.handlerRegistry = new ConcurrentHashMap<Class<? extends T>, List<EventHandler>>();
+ }
+
+ public void fire(X context, T event)
+ {
+ Validate.notNull(context, "Context must be specified");
+ Validate.notNull(event, "Event must be specified");
+
+ List<EventHandler> handlers = handlerRegistry.get(event.getClass());
+ if(handlers != null)
+ {
+ try
+ {
+ for(EventHandler<X, T> handler : handlers)
+ {
+ handler.callback(context, event);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new FiredEventException(context, event, e);
+ }
+ }
+ }
+
+ // TODO: look at concurrency of add / list
+ public <K extends T> void register(Class<? extends K> eventType, EventHandler<X, ? super K> handler)
+ {
+ Validate.notNull(eventType, "EventType must be specified");
+ Validate.notNull(handler, "EventHandler must be specified");
+
+ List<EventHandler> handlers = handlerRegistry.get(eventType);
+ if(handlers == null)
+ {
+ handlers = new ArrayList<EventHandler>();
+ }
+ handlers.add(handler);
+ handlerRegistry.put(eventType, handlers);
+ }
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/After.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/After.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/After.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,37 @@
+/*
+ * 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.event.type;
+
+import java.lang.reflect.Method;
+
+/**
+ * Event fired After the Test method execution.
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class After extends TestEvent
+{
+ /**
+ * @param testInstance The test case instance being tested
+ * @param testMethod The test method that was executed
+ */
+ public After(Object testInstance, Method testMethod)
+ {
+ super(testInstance, testMethod);
+ }
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/AfterClass.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/AfterClass.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/AfterClass.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,34 @@
+/*
+ * 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.event.type;
+
+/**
+ * Event fired After the Class execution.
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class AfterClass extends ClassEvent
+{
+ /**
+ * @param testClass The Test case {@link Class}
+ */
+ public AfterClass(Class<?> testClass)
+ {
+ super(testClass);
+ }
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/AfterSuite.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/AfterSuite.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/AfterSuite.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,30 @@
+/*
+ * 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.event.type;
+
+/**
+ * Event fired After the Suite execution.
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class AfterSuite extends SuiteEvent
+{
+ public AfterSuite()
+ {
+ }
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/Before.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/Before.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/Before.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,37 @@
+/*
+ * 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.event.type;
+
+import java.lang.reflect.Method;
+
+/**
+ * Event fired Before the Test method execution
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class Before extends TestEvent
+{
+ /**
+ * @param testInstance The test case instance being tested
+ * @param testMethod The test method that is about to be executed
+ */
+ public Before(Object testInstance, Method testMethod)
+ {
+ super(testInstance, testMethod);
+ }
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/BeforeClass.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/BeforeClass.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/BeforeClass.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,34 @@
+/*
+ * 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.event.type;
+
+/**
+ * Event fired Before the Class execution.
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class BeforeClass extends ClassEvent
+{
+ /**
+ * @param testClass The Test case {@link Class}
+ */
+ public BeforeClass(Class<?> testClass)
+ {
+ super(testClass);
+ }
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/BeforeSuite.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/BeforeSuite.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/BeforeSuite.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,30 @@
+/*
+ * 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.event.type;
+
+/**
+ * Event fired Before the Suite execution.
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class BeforeSuite extends SuiteEvent
+{
+ public BeforeSuite()
+ {
+ }
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/ClassEvent.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/ClassEvent.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/ClassEvent.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,46 @@
+/*
+ * 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.event.type;
+
+import org.jboss.arquillian.impl.Validate;
+
+/**
+ * Base for events fired in the Test Class execution face.
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class ClassEvent extends SuiteEvent
+{
+ private Class<?> testClass;
+
+ /**
+ * @param testClass The Test case {@link Class}
+ * @throws IllegalArgumentException if testCase is null
+ */
+ public ClassEvent(Class<?> testClass)
+ {
+ Validate.notNull(testClass, "TestClass must be specified");
+
+ this.testClass = testClass;
+ }
+
+ public Class<?> getTestClass()
+ {
+ return testClass;
+ }
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/SuiteEvent.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/SuiteEvent.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/SuiteEvent.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,32 @@
+/*
+ * 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.event.type;
+
+import org.jboss.arquillian.impl.event.Event;
+
+/**
+ * Base for events fired in the Suite execution cycle.
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class SuiteEvent implements Event
+{
+ public SuiteEvent()
+ {
+ }
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/Test.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/Test.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/Test.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,60 @@
+/*
+ * 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.event.type;
+
+import org.jboss.arquillian.spi.TestMethodExecutor;
+import org.jboss.arquillian.spi.TestResult;
+
+/**
+ * Event fired to execute the Test method
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class Test extends TestEvent
+{
+ private TestMethodExecutor testMethodExecutor;
+ private TestResult testResult;
+
+ /**
+ * @param testMethodExecutor The executor responsible for executing the test method
+ */
+ public Test(TestMethodExecutor testMethodExecutor)
+ {
+ // TODO: how to validate testMethodExecutor
+ super(testMethodExecutor.getInstance(), testMethodExecutor.getMethod());
+
+ //Validate.notNull(testMethodExecutor, "TestMethodExecutor must be specified");
+
+ this.testMethodExecutor = testMethodExecutor;
+ }
+
+ public TestMethodExecutor getTestMethodExecutor()
+ {
+ return testMethodExecutor;
+ }
+
+ public TestResult getTestResult()
+ {
+ return testResult;
+ }
+
+ public void setTestResult(TestResult testResult)
+ {
+ this.testResult = testResult;
+ }
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/TestEvent.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/TestEvent.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/event/type/TestEvent.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,66 @@
+/*
+ * 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.event.type;
+
+import java.lang.reflect.Method;
+
+import org.jboss.arquillian.impl.Validate;
+
+/**
+ * Base for events fired in the Test execution cycle.
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class TestEvent extends ClassEvent
+{
+ private Object testInstance;
+ private Method testMethod;
+
+ /**
+ * @param testInstance The test case instance
+ * @param testMethod The test method
+ * @throws IllegalArgumentException if testInstance is null
+ * @throws IllegalArgumentException if testMethod is null
+ */
+ public TestEvent(Object testInstance, Method testMethod)
+ {
+ super(validateAndExtractClass(testInstance, testMethod));
+
+ this.testInstance = testInstance;
+ this.testMethod = testMethod;
+ }
+
+ // TODO: eeehh..?
+ private static Class<?> validateAndExtractClass(Object testInstance, Method testMethod)
+ {
+ Validate.notNull(testInstance, "TestInstance must be specified");
+ Validate.notNull(testMethod, "TestMethod must be specified");
+
+ return testInstance.getClass();
+ }
+
+ public Object getTestInstance()
+ {
+ return testInstance;
+ }
+
+ public Method getTestMethod()
+ {
+ return testMethod;
+ }
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ArchiveGenerator.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ArchiveGenerator.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ArchiveGenerator.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,57 @@
+/*
+ * 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.impl.DeploymentGenerator;
+import org.jboss.arquillian.impl.Validate;
+import org.jboss.arquillian.impl.context.ClassContext;
+import org.jboss.arquillian.impl.event.EventHandler;
+import org.jboss.arquillian.impl.event.type.ClassEvent;
+import org.jboss.shrinkwrap.api.Archive;
+
+/**
+ * A Handler for generate the {@link Archive} used for deployment. <br/>
+ * <br/>
+ *
+ * <b>Imports:</b><br/>
+ * {@link DeploymentGenerator}<br/>
+ * <br/>
+ * <b>Exports:</b><br/>
+ * {@link Archive}<br/>
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ *
+ * @see DeploymentGenerator
+ * @see Archive
+ */
+public class ArchiveGenerator implements EventHandler<ClassContext, ClassEvent>
+{
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.impl.event.EventHandler#callback(java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public void callback(ClassContext context, ClassEvent event) throws Exception
+ {
+ DeploymentGenerator generator = context.get(DeploymentGenerator.class);
+ Validate.stateNotNull(generator, "No " + DeploymentGenerator.class.getName() + " found in context");
+
+ Archive<?> deployment = generator.generate(event.getTestClass());
+
+ context.add(Archive.class, deployment);
+ }
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ContainerCreator.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ContainerCreator.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ContainerCreator.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,54 @@
+/*
+ * 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.impl.context.SuiteContext;
+import org.jboss.arquillian.impl.event.EventHandler;
+import org.jboss.arquillian.impl.event.type.SuiteEvent;
+import org.jboss.arquillian.spi.Configuration;
+import org.jboss.arquillian.spi.DeployableContainer;
+
+/**
+ * A Handler for creating and setting up a {@link DeployableContainer} for use. <br/>
+ * <br/>
+ *
+ * <b>Imports:</b><br/>
+ * {@link Configuration}<br/>
+ * <br/>
+ * <b>Exports:</b><br/>
+ * {@link DeployableContainer}<br/>
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ *
+ * @see Configuration
+ * @see DeployableContainer
+ */
+public class ContainerCreator implements EventHandler<SuiteContext, SuiteEvent>
+{
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.impl.event.EventHandler#callback(java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public void callback(SuiteContext context, SuiteEvent event) throws Exception
+ {
+ DeployableContainer container = context.getServiceLoader().onlyOne(DeployableContainer.class);
+ container.setup(context.get(Configuration.class));
+
+ context.add(DeployableContainer.class, container);
+ }
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ContainerDeployer.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ContainerDeployer.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ContainerDeployer.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,62 @@
+/*
+ * 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.impl.Validate;
+import org.jboss.arquillian.impl.context.ClassContext;
+import org.jboss.arquillian.impl.event.EventHandler;
+import org.jboss.arquillian.impl.event.type.ClassEvent;
+import org.jboss.arquillian.spi.ContainerMethodExecutor;
+import org.jboss.arquillian.spi.DeployableContainer;
+import org.jboss.shrinkwrap.api.Archive;
+
+/**
+ * A Handler for creating and deploying the generated {@link Archive} to the container. <br/>
+ * <br/>
+ *
+ * <b>Imports:</b><br/>
+ * {@link DeployableContainer}<br/>
+ * {@link Archive}<br/>
+ * <br/>
+ * <b>Exports:</b><br/>
+ * {@link ContainerMethodExecutor}<br/>
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ *
+ * @see DeployableContainer
+ * @see ContainerMethodExecutor
+ * @see Archive
+ */
+public class ContainerDeployer implements EventHandler<ClassContext, ClassEvent>
+{
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.impl.event.EventHandler#callback(java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public void callback(ClassContext context, ClassEvent event) throws Exception
+ {
+ DeployableContainer container = context.get(DeployableContainer.class);
+ Validate.stateNotNull(container, "No " + DeployableContainer.class.getName() + " found in context");
+
+ Archive<?> deployment = context.get(Archive.class);
+ Validate.stateNotNull(deployment, "No " + Archive.class.getName() + " found in context");
+
+ ContainerMethodExecutor executor = container.deploy(deployment);
+ context.add(ContainerMethodExecutor.class, executor);
+ }
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ContainerRestarter.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ContainerRestarter.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ContainerRestarter.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,66 @@
+/*
+ * 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.impl.Validate;
+import org.jboss.arquillian.impl.context.ClassContext;
+import org.jboss.arquillian.impl.event.EventHandler;
+import org.jboss.arquillian.impl.event.type.SuiteEvent;
+import org.jboss.arquillian.spi.DeployableContainer;
+
+/**
+ * A Handler for restarting the {@link DeployableContainer} for every X deployments.<br/>
+ * <br/>
+ *
+ * <b>Imports:</b><br/>
+ * {@link DeployableContainer}<br/>
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ * @see DeployableContainer
+ */
+public class ContainerRestarter implements EventHandler<ClassContext, SuiteEvent>
+{
+ private static final int MAX_DEPLOYMENTS_BEFORE_RESTART = 5;
+
+ private int deploymentCount = 0;
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.impl.event.EventHandler#callback(java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public void callback(ClassContext context, SuiteEvent event) throws Exception
+ {
+ DeployableContainer container = context.get(DeployableContainer.class);
+ Validate.stateNotNull(container, "No " + DeployableContainer.class.getName() + " found in context");
+
+ if(deploymentCount == getMaxDeployments(context) -1)
+ {
+ container.stop();
+ container.start();
+
+ deploymentCount = 0;
+ }
+ deploymentCount++;
+ }
+
+ private int getMaxDeployments(ClassContext context)
+ {
+ //context.get(Configuration.class).getMaxDeploymentsBeforeRestart();
+ return MAX_DEPLOYMENTS_BEFORE_RESTART;
+ }
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ContainerStarter.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ContainerStarter.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ContainerStarter.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,49 @@
+/*
+ * 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.impl.Validate;
+import org.jboss.arquillian.impl.context.SuiteContext;
+import org.jboss.arquillian.impl.event.EventHandler;
+import org.jboss.arquillian.impl.event.type.SuiteEvent;
+import org.jboss.arquillian.spi.DeployableContainer;
+
+/**
+ * A Handler for starting the {@link DeployableContainer}.<br/>
+ * <br/>
+ *
+ * <b>Imports:</b><br/>
+ * {@link DeployableContainer}<br/>
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ * @see DeployableContainer
+ */
+public class ContainerStarter implements EventHandler<SuiteContext, SuiteEvent>
+{
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.impl.event.EventHandler#callback(java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public void callback(SuiteContext context, SuiteEvent event) throws Exception
+ {
+ DeployableContainer container = context.get(DeployableContainer.class);
+ Validate.stateNotNull(container, "No " + DeployableContainer.class.getName() + " found in context");
+
+ container.start();
+ }
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ContainerStopper.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ContainerStopper.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ContainerStopper.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,49 @@
+/*
+ * 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.impl.Validate;
+import org.jboss.arquillian.impl.context.SuiteContext;
+import org.jboss.arquillian.impl.event.EventHandler;
+import org.jboss.arquillian.impl.event.type.SuiteEvent;
+import org.jboss.arquillian.spi.DeployableContainer;
+
+/**
+ * A Handler for stopping the {@link DeployableContainer}.<br/>
+ * <br/>
+ *
+ * <b>Imports:</b><br/>
+ * {@link DeployableContainer}<br/>
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ * @see DeployableContainer
+ */
+public class ContainerStopper implements EventHandler<SuiteContext, SuiteEvent>
+{
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.impl.event.EventHandler#callback(java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public void callback(SuiteContext context, SuiteEvent event) throws Exception
+ {
+ DeployableContainer container = context.get(DeployableContainer.class);
+ Validate.stateNotNull(container, "No " + DeployableContainer.class.getName() + " found in context");
+
+ container.stop();
+ }
+}
\ No newline at end of file
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ContainerTestExecuter.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ContainerTestExecuter.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ContainerTestExecuter.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,54 @@
+/*
+ * 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.impl.Validate;
+import org.jboss.arquillian.impl.context.TestContext;
+import org.jboss.arquillian.impl.event.EventHandler;
+import org.jboss.arquillian.impl.event.type.Test;
+import org.jboss.arquillian.spi.ContainerMethodExecutor;
+import org.jboss.arquillian.spi.DeployableContainer;
+import org.jboss.arquillian.spi.TestResult;
+
+/**
+ * A Handler for executing the remote Test Method.<br/>
+ * <br/>
+ *
+ * <b>Imports:</b><br/>
+ * {@link DeployableContainer}<br/>
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ * @see DeployableContainer
+ */
+public class ContainerTestExecuter implements EventHandler<TestContext, Test>
+{
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.impl.event.EventHandler#callback(java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public void callback(TestContext context, Test event) throws Exception
+ {
+ ContainerMethodExecutor executor = context.get(ContainerMethodExecutor.class);
+ Validate.stateNotNull(executor, "No " + ContainerMethodExecutor.class.getName() + " found in context");
+
+ TestResult result = executor.invoke(event.getTestMethodExecutor());
+
+ // TODO: move to context ?
+ event.setTestResult(result);
+ }
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ContainerUndeployer.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ContainerUndeployer.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ContainerUndeployer.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,56 @@
+/*
+ * 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.impl.Validate;
+import org.jboss.arquillian.impl.context.ClassContext;
+import org.jboss.arquillian.impl.event.EventHandler;
+import org.jboss.arquillian.impl.event.type.ClassEvent;
+import org.jboss.arquillian.spi.DeployableContainer;
+import org.jboss.shrinkwrap.api.Archive;
+
+/**
+ * A Handler for undeploying the generated {@link Archive} from the container. <br/>
+ * <br/>
+ *
+ * <b>Imports:</b><br/>
+ * {@link DeployableContainer}<br/>
+ * {@link Archive}<br/>
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ *
+ * @see DeployableContainer
+ * @see Archive
+ */
+public class ContainerUndeployer implements EventHandler<ClassContext, ClassEvent>
+{
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.impl.event.EventHandler#callback(java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public void callback(ClassContext context, ClassEvent event) throws Exception
+ {
+ DeployableContainer container = context.get(DeployableContainer.class);
+ Validate.stateNotNull(container, "No " + DeployableContainer.class.getName() + " found in context");
+
+ Archive<?> deployment = context.get(Archive.class);
+ Validate.stateNotNull(deployment, "No " + Archive.class.getName() + " found in context");
+
+ container.undeploy(deployment);
+ }
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ExecutionTimer.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ExecutionTimer.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/ExecutionTimer.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,46 @@
+/*
+ * 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.impl.DeployableTestBuilder;
+import org.jboss.arquillian.impl.context.SuiteContext;
+import org.jboss.arquillian.impl.event.EventHandler;
+import org.jboss.arquillian.impl.event.type.SuiteEvent;
+
+/**
+ * A Handler for simple execution time tracking. Prints to System.out the
+ * time in milliseconds since last execution.
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class ExecutionTimer implements EventHandler<SuiteContext, SuiteEvent>
+{
+ private long start = System.currentTimeMillis();
+ private long previous = System.currentTimeMillis();
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.impl.event.EventHandler#callback(java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public void callback(SuiteContext context, SuiteEvent event) throws Exception
+ {
+ System.out.println(DeployableTestBuilder.getProfile() + "-" + event.getClass().getName() + " " + (previous - start) + " ms");
+ start = previous;
+ previous = System.currentTimeMillis();
+ }
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/TestCaseEnricher.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/TestCaseEnricher.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/TestCaseEnricher.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,46 @@
+/*
+ * 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 java.util.Collection;
+
+import org.jboss.arquillian.impl.context.TestContext;
+import org.jboss.arquillian.impl.event.EventHandler;
+import org.jboss.arquillian.impl.event.type.TestEvent;
+import org.jboss.arquillian.spi.TestEnricher;
+
+/**
+ * A Handler for enriching the Test instance.<br/>
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class TestCaseEnricher implements EventHandler<TestContext, TestEvent>
+{
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.impl.event.EventHandler#callback(java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public void callback(TestContext context, TestEvent event) throws Exception
+ {
+ Collection<TestEnricher> testEnrichers = context.getServiceLoader().all(TestEnricher.class);
+ for(TestEnricher enricher : testEnrichers)
+ {
+ enricher.enrich(event.getTestInstance());
+ }
+ }
+}
Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/TestEventExecuter.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/TestEventExecuter.java (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/handler/TestEventExecuter.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,49 @@
+/*
+ * 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.impl.TestResultImpl;
+import org.jboss.arquillian.impl.context.TestContext;
+import org.jboss.arquillian.impl.event.EventHandler;
+import org.jboss.arquillian.impl.event.type.Test;
+import org.jboss.arquillian.spi.TestResult.Status;
+
+/**
+ * A Handler for executing the Test Method.
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class TestEventExecuter implements EventHandler<TestContext, Test>
+{
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.impl.event.EventHandler#callback(java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public void callback(TestContext context, Test event) throws Exception
+ {
+ try
+ {
+ event.getTestMethodExecutor().invoke();
+ event.setTestResult(new TestResultImpl(Status.PASSED));
+ }
+ catch (Throwable e)
+ {
+ event.setTestResult(new TestResultImpl(Status.FAILED, e));
+ }
+ }
+}
Added: arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/DeploymentAnnotationArchiveGeneratorTestCase.java
===================================================================
--- arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/DeploymentAnnotationArchiveGeneratorTestCase.java (rev 0)
+++ arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/DeploymentAnnotationArchiveGeneratorTestCase.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,87 @@
+/*
+ * 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;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Test;
+
+
+/**
+ * DeploymentAnnotationArchiveGeneratorTestCase
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class DeploymentAnnotationArchiveGeneratorTestCase
+{
+
+ @Test(expected = IllegalArgumentException.class)
+ public void shouldThrowExceptionOnDeploymentNotPresent() throws Exception
+ {
+ new DeploymentAnnotationArchiveGenerator().generateApplicationArchive(DeploymentNotPresent.class);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void shouldThrowExceptionOnDeploymentNotStatic() throws Exception
+ {
+ new DeploymentAnnotationArchiveGenerator().generateApplicationArchive(DeploymentNotStatic.class);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void shouldThrowExceptionOnDeploymentWrongReturnType() throws Exception
+ {
+ new DeploymentAnnotationArchiveGenerator().generateApplicationArchive(DeploymentWrongReturnType.class);
+ }
+
+ @Test
+ public void shouldThrowExceptionOnDeploymentOk() throws Exception
+ {
+ new DeploymentAnnotationArchiveGenerator().generateApplicationArchive(DeploymentOK.class);
+ }
+
+ private static class DeploymentNotPresent {}
+
+ private static class DeploymentNotStatic
+ {
+ @SuppressWarnings("unused")
+ @Deployment
+ public Archive<?> test() {
+ return Archives.create("test.jar", JavaArchive.class);
+ }
+ }
+
+ private static class DeploymentWrongReturnType
+ {
+ @SuppressWarnings("unused")
+ @Deployment
+ public Object test() {
+ return Archives.create("test.jar", JavaArchive.class);
+ }
+ }
+
+ private static class DeploymentOK
+ {
+ @SuppressWarnings("unused")
+ @Deployment
+ public static JavaArchive test() {
+ return Archives.create("test.jar", JavaArchive.class);
+ }
+ }
+}
Added: arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/EventTestRunnerAdaptorTestCase.java
===================================================================
--- arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/EventTestRunnerAdaptorTestCase.java (rev 0)
+++ arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/EventTestRunnerAdaptorTestCase.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,137 @@
+/*
+ * 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;
+
+import java.lang.reflect.Method;
+
+import org.jboss.arquillian.impl.context.ClassContext;
+import org.jboss.arquillian.impl.context.ContextLifecycleManager;
+import org.jboss.arquillian.impl.context.ProfileBuilder;
+import org.jboss.arquillian.impl.context.SuiteContext;
+import org.jboss.arquillian.impl.context.TestContext;
+import org.jboss.arquillian.impl.event.EventHandler;
+import org.jboss.arquillian.impl.event.type.ClassEvent;
+import org.jboss.arquillian.impl.event.type.SuiteEvent;
+import org.jboss.arquillian.impl.event.type.TestEvent;
+import org.jboss.arquillian.spi.ServiceLoader;
+import org.jboss.arquillian.spi.TestMethodExecutor;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.stubbing.Answer;
+
+
+/**
+ * Verifies that the {@link EventTestRunnerAdaptor} creates and fires the proper events.
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ at RunWith(MockitoJUnitRunner.class)
+public class EventTestRunnerAdaptorTestCase
+{
+ @Mock
+ public ServiceLoader serviceLoader;
+
+ @Mock
+ public ProfileBuilder profileBuilder;
+
+ @Mock
+ private EventHandler<SuiteContext, SuiteEvent> suiteEventHandler;
+
+ @Mock
+ private EventHandler<ClassContext, ClassEvent> classEventHandler;
+
+ @Mock
+ private EventHandler<TestContext, TestEvent> testEventHandler;
+
+ @Before
+ public void createContexts() throws Exception
+ {
+ // Add mock EventHandlers to the contexts so we can verify that the events are fired
+ Mockito.doAnswer(new Answer<Void>()
+ {
+ @Override
+ public Void answer(InvocationOnMock invocation) throws Throwable
+ {
+ SuiteContext context = (SuiteContext)invocation.getArguments()[0];
+ context.register(org.jboss.arquillian.impl.event.type.BeforeSuite.class, suiteEventHandler);
+ context.register(org.jboss.arquillian.impl.event.type.AfterSuite.class, suiteEventHandler);
+ return null;
+ }
+ }).when(profileBuilder).buildSuiteContext(Mockito.any(SuiteContext.class));
+ Mockito.doAnswer(new Answer<Void>()
+ {
+ @Override
+ public Void answer(InvocationOnMock invocation) throws Throwable
+ {
+ ClassContext context = (ClassContext)invocation.getArguments()[0];
+ context.register(org.jboss.arquillian.impl.event.type.BeforeClass.class, classEventHandler);
+ context.register(org.jboss.arquillian.impl.event.type.AfterClass.class, classEventHandler);
+ return null;
+ }
+ }).when(profileBuilder).buildClassContext(Mockito.any(ClassContext.class));
+ Mockito.doAnswer(new Answer<Void>()
+ {
+ @Override
+ public Void answer(InvocationOnMock invocation) throws Throwable
+ {
+ TestContext context = (TestContext)invocation.getArguments()[0];
+ context.register(org.jboss.arquillian.impl.event.type.Before.class, testEventHandler);
+ context.register(org.jboss.arquillian.impl.event.type.Test.class, testEventHandler);
+ context.register(org.jboss.arquillian.impl.event.type.After.class, testEventHandler);
+ return null;
+ }
+ }).when(profileBuilder).buildTestContext(Mockito.any(TestContext.class));
+ }
+
+ @Test
+ public void shouldHandleLifeCycleEvents() throws Exception
+ {
+ EventTestRunnerAdaptor adaptor = new EventTestRunnerAdaptor(
+ new ContextLifecycleManager(profileBuilder, serviceLoader));
+
+ Class<?> testClass = getClass();
+ Method testMetod = testClass.getMethod("shouldHandleLifeCycleEvents");
+ Object testInstance = this;
+
+ TestMethodExecutor testExecutor = Mockito.mock(TestMethodExecutor.class);
+ Mockito.when(testExecutor.getInstance()).thenReturn(testInstance);
+ Mockito.when(testExecutor.getMethod()).thenReturn(testMetod);
+
+ adaptor.beforeSuite();
+ adaptor.beforeClass(testClass);
+ adaptor.before(testInstance, testMetod);
+ adaptor.test(testExecutor);
+ adaptor.after(testInstance, testMetod);
+ adaptor.afterClass(testClass);
+ adaptor.afterSuite();
+
+ Mockito.verify(suiteEventHandler, Mockito.times(2))
+ .callback(Mockito.any(SuiteContext.class), Mockito.any(SuiteEvent.class));
+
+ Mockito.verify(classEventHandler, Mockito.times(2))
+ .callback(Mockito.any(ClassContext.class), Mockito.any(ClassEvent.class));
+
+ Mockito.verify(testEventHandler, Mockito.times(3))
+ .callback(Mockito.any(TestContext.class), Mockito.any(TestEvent.class));
+ }
+}
Added: arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/event/ContextLifecycleManagerTestCase.java
===================================================================
--- arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/event/ContextLifecycleManagerTestCase.java (rev 0)
+++ arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/event/ContextLifecycleManagerTestCase.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,154 @@
+/*
+ * 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.event;
+
+import junit.framework.Assert;
+
+import org.jboss.arquillian.impl.context.ClassContext;
+import org.jboss.arquillian.impl.context.ContextLifecycleManager;
+import org.jboss.arquillian.impl.context.ProfileBuilder;
+import org.jboss.arquillian.impl.context.SuiteContext;
+import org.jboss.arquillian.impl.context.TestContext;
+import org.jboss.arquillian.impl.event.type.Before;
+import org.jboss.arquillian.impl.event.type.ClassEvent;
+import org.jboss.arquillian.impl.event.type.SuiteEvent;
+import org.jboss.arquillian.impl.event.type.TestEvent;
+import org.jboss.arquillian.spi.ServiceLoader;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+
+/**
+ * Test Case to verify context create/restore and event propagation model.
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ at RunWith(MockitoJUnitRunner.class)
+public class ContextLifecycleManagerTestCase
+{
+ @Mock
+ private ServiceLoader serviceLoader;
+
+ @Mock
+ private ProfileBuilder profileBuilder;
+
+ @Mock
+ private EventHandler<SuiteContext, SuiteEvent> suiteEventHandler;
+
+ @Mock
+ private EventHandler<ClassContext, ClassEvent> classEventHandler;
+
+ @Mock
+ private EventHandler<TestContext, TestEvent> testEventHandler;
+
+ @Test
+ public void shouldBeAbleToCreateRestoreSuiteContext() throws Exception
+ {
+ ContextLifecycleManager manager = new ContextLifecycleManager(profileBuilder, serviceLoader);
+
+ // Create a new
+ SuiteContext context = manager.createRestoreSuiteContext();
+
+ Assert.assertNotNull("Context should have been created", context);
+
+ // Restore
+ SuiteContext context2 = manager.createRestoreSuiteContext();
+
+ Assert.assertNotNull("Context should have been created", context2);
+ Assert.assertTrue("Restore of context should return same instance", context.equals(context2));
+
+ // Destroy and create a new
+ manager.destroySuiteContext();
+ context2 = manager.createRestoreSuiteContext();
+
+ Assert.assertNotNull("Context should have been created", context2);
+ Assert.assertFalse("Restore of context should return same instance", context.equals(context2));
+ }
+
+ @Test
+ public void shouldBeAbleToCreateRestoreClassContext() throws Exception
+ {
+ ContextLifecycleManager manager = new ContextLifecycleManager(profileBuilder, serviceLoader);
+
+ // Create a new
+ manager.createRestoreSuiteContext();
+
+ ClassContext context = manager.createRestoreClassContext(getClass());
+ Assert.assertNotNull("Context should have been created", context);
+
+ ClassContext context2 = manager.createRestoreClassContext(getClass());
+ Assert.assertNotNull("Context should have been created", context2);
+ Assert.assertTrue("Restore of context should return same instance", context.equals(context2));
+
+ manager.destroyClassContext(getClass());
+
+ context2 = manager.createRestoreClassContext(getClass());
+
+ Assert.assertNotNull("Context should have been created", context2);
+ Assert.assertFalse("Restore of context should return same instance", context.equals(context2));
+ }
+
+ @Test
+ public void shouldBeAbleToCreateRestoreTestContext() throws Exception
+ {
+ ContextLifecycleManager manager = new ContextLifecycleManager(profileBuilder, serviceLoader);
+
+ // Create a new
+ manager.createRestoreSuiteContext();
+ manager.createRestoreClassContext(getClass());
+
+ TestContext context = manager.createRestoreTestContext(this);
+ Assert.assertNotNull("Context should have been created", context);
+
+ TestContext context2 = manager.createRestoreTestContext(this);
+ Assert.assertNotNull("Context should have been created", context2);
+ Assert.assertTrue("Restore of context should return same instance", context.equals(context2));
+
+ manager.destroyTestContext(this);
+
+ context2 = manager.createRestoreTestContext(this);
+
+ Assert.assertNotNull("Context should have been created", context2);
+ Assert.assertFalse("Restore of context should return same instance", context.equals(context2));
+ }
+
+ @Test
+ public void shouldBeAbleToFireUpwards() throws Exception
+ {
+ Before event = new Before(getClass(), getClass().getMethod("shouldBeAbleToFireUpwards"));
+ ContextLifecycleManager manager = new ContextLifecycleManager(profileBuilder, serviceLoader);
+
+ SuiteContext suiteContext = manager.createRestoreSuiteContext();
+ suiteContext.register(Before.class, suiteEventHandler);
+
+ ClassContext classContext = manager.createRestoreClassContext(getClass());
+ classContext.register(Before.class, classEventHandler);
+
+ TestContext testContext = manager.createRestoreTestContext(this);
+ testContext.register(Before.class, testEventHandler);
+
+ testContext.fire(event);
+
+ Mockito.verify(suiteEventHandler, Mockito.times(1)).callback(suiteContext, event);
+ Mockito.verify(classEventHandler, Mockito.times(1)).callback(classContext, event);
+ Mockito.verify(testEventHandler, Mockito.times(1)).callback(testContext, event);
+ }
+}
Added: arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/event/EventManagerTestCase.java
===================================================================
--- arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/event/EventManagerTestCase.java (rev 0)
+++ arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/event/EventManagerTestCase.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,78 @@
+/*
+ * 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.event;
+
+import org.jboss.arquillian.impl.context.SuiteContext;
+import org.jboss.arquillian.impl.event.type.SuiteEvent;
+import org.jboss.arquillian.spi.ServiceLoader;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+
+/**
+ * EventManagerTestCase
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ at RunWith(MockitoJUnitRunner.class)
+public class EventManagerTestCase
+{
+ @Mock
+ private ServiceLoader serviceLoader;
+
+ @Mock
+ private EventHandler<SuiteContext, SuiteEvent> handler;
+
+ @Test(expected = FiredEventException.class)
+ public void shouldWrapException() throws Exception
+ {
+ Mockito.doThrow(new Exception())
+ .when(handler).callback(
+ Mockito.any(SuiteContext.class), Mockito.any(SuiteEvent.class));
+
+ SuiteContext context = new SuiteContext(serviceLoader);
+ SuiteEvent event = new SuiteEvent();
+
+ EventManager<SuiteContext, SuiteEvent> manager = new MapEventManager<SuiteContext, SuiteEvent>();
+ manager.register(SuiteEvent.class, handler);
+
+ manager.fire(context, event);
+ }
+
+ @Test
+ public void shouldBeAbleToRegisterAndFireToMultipleHandlersOnSameEvent() throws Exception
+ {
+ int handlerCount = 2;
+
+ SuiteContext context = new SuiteContext(serviceLoader);
+ SuiteEvent event = new SuiteEvent();
+
+ EventManager<SuiteContext, SuiteEvent> manager = new MapEventManager<SuiteContext, SuiteEvent>();
+ for(int i = 0; i < handlerCount; i++)
+ {
+ manager.register(SuiteEvent.class, handler);
+ }
+ manager.fire(context, event);
+
+ Mockito.verify(handler, Mockito.times(handlerCount)).callback(context, event);
+ }
+
+}
Added: arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ArchiveGeneratorTestCase.java
===================================================================
--- arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ArchiveGeneratorTestCase.java (rev 0)
+++ arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ArchiveGeneratorTestCase.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,83 @@
+/*
+ * 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.impl.DeploymentGenerator;
+import org.jboss.arquillian.impl.context.ClassContext;
+import org.jboss.arquillian.impl.context.SuiteContext;
+import org.jboss.arquillian.impl.event.type.ClassEvent;
+import org.jboss.arquillian.impl.handler.ArchiveGenerator;
+import org.jboss.arquillian.spi.ServiceLoader;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.stubbing.Answer;
+
+/**
+ * ArchiveGeneratorHandlerTestCase
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ at RunWith(MockitoJUnitRunner.class)
+public class ArchiveGeneratorTestCase
+{
+ @Mock
+ private ServiceLoader serviceLoader;
+
+ @Mock
+ private DeploymentGenerator generator;
+
+ @Test(expected = IllegalStateException.class)
+ public void shouldThrowIllegalStateExceptionOnMissingDeploymentGenerator() throws Exception
+ {
+ ClassContext context = new ClassContext(new SuiteContext(serviceLoader));
+
+ ArchiveGenerator handler = new ArchiveGenerator();
+ handler.callback(context, new ClassEvent(getClass()));
+ }
+
+ @Test
+ public void shouldGenerateArchive() throws Exception
+ {
+ final Archive<?> deployment = Archives.create("test.jar", JavaArchive.class);
+
+ Mockito.when(generator.generate(getClass())).thenAnswer(new Answer<Archive<?>>()
+ {
+ public Archive<?> answer(org.mockito.invocation.InvocationOnMock invocation) throws Throwable {
+ return deployment;
+ }
+ });
+
+ ClassContext context = new ClassContext(new SuiteContext(serviceLoader));
+ context.add(DeploymentGenerator.class, generator);
+
+ ArchiveGenerator handler = new ArchiveGenerator();
+ handler.callback(context, new ClassEvent(getClass()));
+
+ Assert.assertNotNull(
+ "Should have exported " + Archive.class.getSimpleName(),
+ context.get(Archive.class));
+ }
+}
Added: arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ContainerCreatorTestCase.java
===================================================================
--- arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ContainerCreatorTestCase.java (rev 0)
+++ arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ContainerCreatorTestCase.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,67 @@
+/*
+ * 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.impl.context.SuiteContext;
+import org.jboss.arquillian.impl.event.type.SuiteEvent;
+import org.jboss.arquillian.spi.Configuration;
+import org.jboss.arquillian.spi.DeployableContainer;
+import org.jboss.arquillian.spi.ServiceLoader;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+
+/**
+ * Verify that the {@link DeployableContainer} is setup and exported.
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ at RunWith(MockitoJUnitRunner.class)
+public class ContainerCreatorTestCase
+{
+ @Mock
+ private ServiceLoader serviceLoader;
+
+ @Mock
+ private DeployableContainer container;
+
+ @Test
+ public void shouldLoadAndSetupTheContainer() throws Exception
+ {
+ Mockito.when(serviceLoader.onlyOne(DeployableContainer.class)).thenReturn(container);
+
+ Configuration configuration = new Configuration();
+
+ SuiteContext context = new SuiteContext(serviceLoader);
+ context.add(Configuration.class, configuration);
+
+ ContainerCreator handler = new ContainerCreator();
+ handler.callback(context, new SuiteEvent());
+
+ Mockito.verify(container).setup(configuration);
+
+ Assert.assertNotNull(
+ "Should have exported " + DeployableContainer.class,
+ context.get(DeployableContainer.class));
+ }
+}
Added: arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ContainerDeployerTestCase.java
===================================================================
--- arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ContainerDeployerTestCase.java (rev 0)
+++ arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ContainerDeployerTestCase.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,92 @@
+/*
+ * 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.impl.context.ClassContext;
+import org.jboss.arquillian.impl.context.SuiteContext;
+import org.jboss.arquillian.impl.event.type.ClassEvent;
+import org.jboss.arquillian.impl.handler.ContainerDeployer;
+import org.jboss.arquillian.spi.ContainerMethodExecutor;
+import org.jboss.arquillian.spi.DeployableContainer;
+import org.jboss.arquillian.spi.ServiceLoader;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+/**
+ * DeploymentHandlerTestCase
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ at RunWith(MockitoJUnitRunner.class)
+public class ContainerDeployerTestCase
+{
+ @Mock
+ private ServiceLoader serviceLoader;
+
+ @Mock
+ private DeployableContainer container;
+
+ @Mock
+ private ContainerMethodExecutor executor;
+
+ @Test(expected = IllegalStateException.class)
+ public void shouldThrowIllegalStateOnMissingDeployableContainer() throws Exception
+ {
+ ClassContext context = new ClassContext(new SuiteContext(serviceLoader));
+
+ ContainerDeployer handler = new ContainerDeployer();
+ handler.callback(context, new ClassEvent(getClass()));
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void shouldThrowIllegalStateOnMissingArchive() throws Exception
+ {
+ ClassContext context = new ClassContext(new SuiteContext(serviceLoader));
+ context.add(DeployableContainer.class, container);
+
+ ContainerDeployer handler = new ContainerDeployer();
+ handler.callback(context, new ClassEvent(getClass()));
+ }
+
+ @Test
+ public void shouldExportContainerMethodExecutor() throws Exception
+ {
+ Archive<?> deployment = Archives.create("test.jar", JavaArchive.class);
+
+ Mockito.when(container.deploy(deployment)).thenReturn(executor);
+
+ ClassContext context = new ClassContext(new SuiteContext(serviceLoader));
+ context.add(DeployableContainer.class, container);
+ context.add(Archive.class, deployment);
+
+ ContainerDeployer handler = new ContainerDeployer();
+ handler.callback(context, new ClassEvent(getClass()));
+
+ Assert.assertNotNull(
+ "Should have exported " + ContainerMethodExecutor.class.getSimpleName(),
+ context.get(ContainerMethodExecutor.class));
+ }
+}
Added: arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ContainerRestarterTestCase.java
===================================================================
--- arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ContainerRestarterTestCase.java (rev 0)
+++ arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ContainerRestarterTestCase.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,63 @@
+/*
+ * 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.impl.context.ClassContext;
+import org.jboss.arquillian.impl.context.SuiteContext;
+import org.jboss.arquillian.impl.event.type.SuiteEvent;
+import org.jboss.arquillian.spi.DeployableContainer;
+import org.jboss.arquillian.spi.ServiceLoader;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+
+/**
+ * ContainerRestarterTestCase
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ at RunWith(MockitoJUnitRunner.class)
+public class ContainerRestarterTestCase
+{
+
+ @Mock
+ private ServiceLoader serviceLoader;
+
+ @Mock
+ private DeployableContainer container;
+
+ @Test
+ public void shouldRestartContainerForEveryX() throws Exception
+ {
+ ClassContext context = new ClassContext(new SuiteContext(serviceLoader));
+ context.add(DeployableContainer.class, container);
+
+ ContainerRestarter handler = new ContainerRestarter();
+
+ for(int i = 0; i < 10; i++)
+ {
+ handler.callback(context, new SuiteEvent());
+ }
+
+ Mockito.verify(container, Mockito.times(2)).stop();
+ Mockito.verify(container, Mockito.times(2)).start();
+ }
+}
Added: arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ContainerStarterTestCase.java
===================================================================
--- arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ContainerStarterTestCase.java (rev 0)
+++ arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ContainerStarterTestCase.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,65 @@
+/*
+ * 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.impl.context.SuiteContext;
+import org.jboss.arquillian.impl.event.type.SuiteEvent;
+import org.jboss.arquillian.impl.handler.ContainerStarter;
+import org.jboss.arquillian.spi.DeployableContainer;
+import org.jboss.arquillian.spi.ServiceLoader;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+/**
+ * StartContainerTestCase
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ at RunWith(MockitoJUnitRunner.class)
+public class ContainerStarterTestCase
+{
+ @Mock
+ private ServiceLoader serviceLoader;
+
+ @Mock
+ private DeployableContainer container;
+
+ @Test(expected = IllegalStateException.class)
+ public void shouldThrowIllegalStateOnMissingDeployableContainer() throws Exception
+ {
+ SuiteContext context = new SuiteContext(serviceLoader);
+
+ ContainerStarter handler = new ContainerStarter();
+ handler.callback(context, new SuiteEvent());
+ }
+
+ @Test
+ public void shouldStartTheDeployableContainer() throws Exception
+ {
+ SuiteContext context = new SuiteContext(serviceLoader);
+ context.add(DeployableContainer.class, container);
+
+ ContainerStarter handler = new ContainerStarter();
+ handler.callback(context, new SuiteEvent());
+
+ Mockito.verify(container).start();
+ }
+}
Added: arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ContainerStopperTestCase.java
===================================================================
--- arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ContainerStopperTestCase.java (rev 0)
+++ arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ContainerStopperTestCase.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,68 @@
+/*
+ * 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.impl.context.SuiteContext;
+import org.jboss.arquillian.impl.event.type.SuiteEvent;
+import org.jboss.arquillian.impl.handler.ContainerStopper;
+import org.jboss.arquillian.spi.DeployableContainer;
+import org.jboss.arquillian.spi.ServiceLoader;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+
+/**
+ * StopContainerTestCase
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ at RunWith(MockitoJUnitRunner.class)
+public class ContainerStopperTestCase
+{
+ @Mock
+ private ServiceLoader serviceLoader;
+
+ @Mock
+ private DeployableContainer container;
+
+ @Test(expected = IllegalStateException.class)
+ public void shouldThrowIllegalStateOnMissingDeployableContainer() throws Exception
+ {
+ SuiteContext context = new SuiteContext(serviceLoader);
+
+ ContainerStopper handler = new ContainerStopper();
+ handler.callback(context, new SuiteEvent());
+ }
+
+ @Test
+ public void shouldStartTheDeployableContainer() throws Exception
+ {
+ SuiteContext context = new SuiteContext(serviceLoader);
+ context.add(DeployableContainer.class, container);
+
+ ContainerStopper handler = new ContainerStopper();
+ handler.callback(context, new SuiteEvent());
+
+ Mockito.verify(container).stop();
+ }
+
+
+}
Added: arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ContainerTestExecuterTestCase.java
===================================================================
--- arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ContainerTestExecuterTestCase.java (rev 0)
+++ arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ContainerTestExecuterTestCase.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,114 @@
+/*
+ * 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 java.lang.reflect.Method;
+
+import junit.framework.Assert;
+
+import org.jboss.arquillian.impl.TestResultImpl;
+import org.jboss.arquillian.impl.context.ClassContext;
+import org.jboss.arquillian.impl.context.SuiteContext;
+import org.jboss.arquillian.impl.context.TestContext;
+import org.jboss.arquillian.impl.handler.ContainerTestExecuter;
+import org.jboss.arquillian.spi.ContainerMethodExecutor;
+import org.jboss.arquillian.spi.ServiceLoader;
+import org.jboss.arquillian.spi.TestMethodExecutor;
+import org.jboss.arquillian.spi.TestResult;
+import org.jboss.arquillian.spi.TestResult.Status;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+/**
+ * TestExecutorHandlerTestCase
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ at RunWith(MockitoJUnitRunner.class)
+public class ContainerTestExecuterTestCase
+{
+ @Mock
+ private ServiceLoader serviceLoader;
+
+ @Mock
+ private ContainerMethodExecutor executor;
+
+ @Mock
+ private TestMethodExecutor testExecutor;
+
+ @Test(expected = IllegalStateException.class)
+ public void shouldThrowIllegalStateOnMissingContainerMethodExecutor() throws Exception
+ {
+ TestContext context = new TestContext(new ClassContext(new SuiteContext(serviceLoader)));
+
+ Mockito.when(testExecutor.getInstance()).thenReturn(this);
+ Mockito.when(testExecutor.getMethod()).thenReturn(
+ getTestMethod("shouldThrowIllegalStateOnMissingContainerMethodExecutor"));
+
+ ContainerTestExecuter handler = new ContainerTestExecuter();
+ handler.callback(context,
+ new org.jboss.arquillian.impl.event.type.Test(testExecutor));
+ }
+
+ @Test
+ public void shouldInvokeContainerMethodExecutor() throws Exception
+ {
+ TestResult result = new TestResultImpl(Status.PASSED);
+ Mockito.when(executor.invoke(testExecutor)).thenReturn(result);
+ Mockito.when(testExecutor.getInstance()).thenReturn(this);
+ Mockito.when(testExecutor.getMethod()).thenReturn(
+ getTestMethod("shouldInvokeContainerMethodExecutor"));
+
+ TestContext context = new TestContext(new ClassContext(new SuiteContext(serviceLoader)));
+ context.add(ContainerMethodExecutor.class, executor);
+
+ ContainerTestExecuter handler = new ContainerTestExecuter();
+ handler.callback(context,
+ new org.jboss.arquillian.impl.event.type.Test(testExecutor));
+ }
+
+ @Test
+ public void shouldSetTestResult() throws Exception
+ {
+ TestResult result = new TestResultImpl(Status.PASSED);
+ Mockito.when(executor.invoke(testExecutor)).thenReturn(result);
+ Mockito.when(testExecutor.getInstance()).thenReturn(this);
+ Mockito.when(testExecutor.getMethod()).thenReturn(
+ getTestMethod("shouldSetTestResult"));
+
+ TestContext context = new TestContext(new ClassContext(new SuiteContext(serviceLoader)));
+ context.add(ContainerMethodExecutor.class, executor);
+
+ org.jboss.arquillian.impl.event.type.Test event = new org.jboss.arquillian.impl.event.type.Test(testExecutor);
+ ContainerTestExecuter handler = new ContainerTestExecuter();
+ handler.callback(context, event);
+
+ Assert.assertEquals(
+ "Should set result on event",
+ result,
+ event.getTestResult());
+ }
+
+ private Method getTestMethod(String name) throws Exception
+ {
+ return this.getClass().getMethod(name);
+ }
+}
Added: arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ContainerUndeployerTestCase.java
===================================================================
--- arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ContainerUndeployerTestCase.java (rev 0)
+++ arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/ContainerUndeployerTestCase.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,83 @@
+/*
+ * 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.impl.context.ClassContext;
+import org.jboss.arquillian.impl.context.SuiteContext;
+import org.jboss.arquillian.impl.event.type.ClassEvent;
+import org.jboss.arquillian.impl.handler.ContainerUndeployer;
+import org.jboss.arquillian.spi.DeployableContainer;
+import org.jboss.arquillian.spi.ServiceLoader;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+
+/**
+ * UnDeploymentHandlerTestCase
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ at RunWith(MockitoJUnitRunner.class)
+public class ContainerUndeployerTestCase
+{
+ @Mock
+ private ServiceLoader serviceLoader;
+
+ @Mock
+ private DeployableContainer container;
+
+ @Test(expected = IllegalStateException.class)
+ public void shouldThrowIllegalStateOnMissingDeployableContainer() throws Exception
+ {
+ ClassContext context = new ClassContext(new SuiteContext(serviceLoader));
+
+ ContainerUndeployer handler = new ContainerUndeployer();
+ handler.callback(context, new ClassEvent(getClass()));
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void shouldThrowIllegalStateOnMissingArchive() throws Exception
+ {
+ ClassContext context = new ClassContext(new SuiteContext(serviceLoader));
+ context.add(DeployableContainer.class, container);
+
+ ContainerUndeployer handler = new ContainerUndeployer();
+ handler.callback(context, new ClassEvent(getClass()));
+ }
+
+ @Test
+ public void shouldUndeployArchive() throws Exception
+ {
+ Archive<?> deployment = Archives.create("test.jar", JavaArchive.class);
+
+ ClassContext context = new ClassContext(new SuiteContext(serviceLoader));
+ context.add(DeployableContainer.class, container);
+ context.add(Archive.class, deployment);
+
+ ContainerUndeployer handler = new ContainerUndeployer();
+ handler.callback(context, new ClassEvent(getClass()));
+
+ Mockito.verify(container).undeploy(deployment);
+ }
+}
Added: arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/TestCaseEnricherTestCase.java
===================================================================
--- arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/TestCaseEnricherTestCase.java (rev 0)
+++ arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/TestCaseEnricherTestCase.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -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 java.util.Arrays;
+
+import org.jboss.arquillian.impl.context.ClassContext;
+import org.jboss.arquillian.impl.context.SuiteContext;
+import org.jboss.arquillian.impl.context.TestContext;
+import org.jboss.arquillian.impl.event.type.TestEvent;
+import org.jboss.arquillian.spi.ServiceLoader;
+import org.jboss.arquillian.spi.TestEnricher;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+/**
+ * Verifies that the TestEnricher SPI is called.
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ at RunWith(MockitoJUnitRunner.class)
+public class TestCaseEnricherTestCase
+{
+ @Mock
+ private ServiceLoader serviceLoader;
+
+ @Mock
+ private TestEnricher enricher;
+
+ @Test
+ public void shouldCallAllEnrichers() throws Exception
+ {
+ Mockito.when(serviceLoader.all(TestEnricher.class)).thenReturn(Arrays.asList(enricher, enricher));
+
+ TestContext context = new TestContext(new ClassContext(new SuiteContext(serviceLoader)));
+ TestEvent event = new TestEvent(this, getClass().getMethod("shouldCallAllEnrichers"));
+
+ TestCaseEnricher handler = new TestCaseEnricher();
+ handler.callback(context, event);
+
+ Mockito.verify(enricher, Mockito.times(2)).enrich(this);
+ }
+}
Added: arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/TestEventExecuterTestCase.java
===================================================================
--- arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/TestEventExecuterTestCase.java (rev 0)
+++ arquillian/trunk/impl-base/src/test/java/org/jboss/arquillian/impl/handler/TestEventExecuterTestCase.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,114 @@
+/*
+ * 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 java.lang.reflect.Method;
+
+import junit.framework.Assert;
+
+import org.jboss.arquillian.impl.context.ClassContext;
+import org.jboss.arquillian.impl.context.SuiteContext;
+import org.jboss.arquillian.impl.context.TestContext;
+import org.jboss.arquillian.impl.handler.TestEventExecuter;
+import org.jboss.arquillian.spi.ServiceLoader;
+import org.jboss.arquillian.spi.TestMethodExecutor;
+import org.jboss.arquillian.spi.TestResult;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+
+/**
+ * InContainerExecuterTestCase
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ at RunWith(MockitoJUnitRunner.class)
+public class TestEventExecuterTestCase
+{
+ @Mock
+ private ServiceLoader serviceLoader;
+
+ @Mock
+ private TestMethodExecutor testExecutor;
+
+ @Test
+ public void shouldReturnPassed() throws Throwable
+ {
+ Mockito.when(testExecutor.getInstance()).thenReturn(this);
+ Mockito.when(testExecutor.getMethod()).thenReturn(
+ getTestMethod("shouldReturnPassed"));
+
+ TestContext context = new TestContext(new ClassContext(new SuiteContext(serviceLoader)));
+
+ org.jboss.arquillian.impl.event.type.Test event = new org.jboss.arquillian.impl.event.type.Test(testExecutor);
+ TestEventExecuter handler = new TestEventExecuter();
+ handler.callback(context, event);
+
+ Assert.assertNotNull(
+ "Should have set result",
+ event.getTestResult());
+
+ Assert.assertEquals(
+ "Should have passed test",
+ TestResult.Status.PASSED,
+ event.getTestResult().getStatus());
+
+ Assert.assertNull(
+ "Should not have set cause",
+ event.getTestResult().getThrowable());
+ }
+
+ @Test
+ public void shouldReturnFailedOnException() throws Throwable
+ {
+ Exception exception = new Exception();
+
+ Mockito.when(testExecutor.getInstance()).thenReturn(this);
+ Mockito.when(testExecutor.getMethod()).thenReturn(
+ getTestMethod("shouldReturnFailedOnException"));
+ Mockito.doThrow(exception).when(testExecutor).invoke();
+
+ TestContext context = new TestContext(new ClassContext(new SuiteContext(serviceLoader)));
+
+ org.jboss.arquillian.impl.event.type.Test event = new org.jboss.arquillian.impl.event.type.Test(testExecutor);
+ TestEventExecuter handler = new TestEventExecuter();
+ handler.callback(context, event);
+
+ Assert.assertNotNull(
+ "Should have set result",
+ event.getTestResult());
+
+ Assert.assertEquals(
+ "Should have failed test",
+ TestResult.Status.FAILED,
+ event.getTestResult().getStatus());
+
+ Assert.assertEquals(
+ "Should have set failed cause",
+ exception,
+ event.getTestResult().getThrowable());
+ }
+
+ private Method getTestMethod(String name) throws Exception
+ {
+ return this.getClass().getMethod(name);
+ }
+}
Added: arquillian/trunk/impl-base/src/test/resources/arquillian.xml
===================================================================
--- arquillian/trunk/impl-base/src/test/resources/arquillian.xml (rev 0)
+++ arquillian/trunk/impl-base/src/test/resources/arquillian.xml 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,14 @@
+<?xml version="1.0"?>
+
+<arquillian xmlns="http://jboss.com/arquillian"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:mock="urn:arq:org.jboss.arquillian.impl">
+
+ <mock:container>
+ <mock:property string="hola" long="2" />
+ <mock:propertyInt>1</mock:propertyInt>
+ <mock:propertyDouble>3</mock:propertyDouble>
+ <mock:propertyBoolean>true</mock:propertyBoolean>
+ </mock:container>
+
+</arquillian>
\ No newline at end of file
Added: arquillian/trunk/impl-base/src/test/resources/broken_arquillian.xml
===================================================================
--- arquillian/trunk/impl-base/src/test/resources/broken_arquillian.xml (rev 0)
+++ arquillian/trunk/impl-base/src/test/resources/broken_arquillian.xml 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+
+<arquillian xmlns="http://jboss.com/arquillian"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <mock:container />
+
+</arquillian>
\ No newline at end of file
Modified: arquillian/trunk/junit/src/main/java/org/jboss/arquillian/junit/Arquillian.java
===================================================================
--- arquillian/trunk/junit/src/main/java/org/jboss/arquillian/junit/Arquillian.java 2010-04-20 14:53:59 UTC (rev 4268)
+++ arquillian/trunk/junit/src/main/java/org/jboss/arquillian/junit/Arquillian.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -20,12 +20,12 @@
import java.util.Arrays;
import java.util.List;
-import org.jboss.arquillian.impl.DeployableTest;
import org.jboss.arquillian.impl.DeployableTestBuilder;
-import org.jboss.arquillian.spi.ContainerMethodExecutor;
+import org.jboss.arquillian.impl.XmlConfigurationBuilder;
+import org.jboss.arquillian.spi.Configuration;
import org.jboss.arquillian.spi.TestMethodExecutor;
import org.jboss.arquillian.spi.TestResult;
-import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.arquillian.spi.TestRunnerAdaptor;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
@@ -39,26 +39,25 @@
*/
public class Arquillian extends BlockJUnit4ClassRunner
{
- private static ThreadLocal<DeployableTest> deployableTest = new ThreadLocal<DeployableTest>();
+ private static ThreadLocal<TestRunnerAdaptor> deployableTest = new ThreadLocal<TestRunnerAdaptor>();
- private Archive<?> archive = null;
- private ContainerMethodExecutor methodExecutor;
-
public Arquillian(Class<?> klass) throws InitializationError
{
super(klass);
if(deployableTest.get() == null)
{
- deployableTest.set(DeployableTestBuilder.build(null));
+ Configuration configuration = new XmlConfigurationBuilder().build();
+ deployableTest.set(DeployableTestBuilder.build(configuration));
try
{
- deployableTest.get().getContainerController().start();
+ deployableTest.get().beforeSuite();
}
catch (Exception e)
{
throw new InitializationError(Arrays.asList((Throwable)e));
}
- Runtime.getRuntime().addShutdownHook(new Thread() {
+ Runtime.getRuntime().addShutdownHook(new Thread()
+ {
@Override
public void run()
{
@@ -66,7 +65,7 @@
{
if(deployableTest.get() != null)
{
- deployableTest.get().getContainerController().stop();
+ deployableTest.get().beforeSuite();
}
}
catch (Exception e)
@@ -85,40 +84,68 @@
return super.computeTestMethods();
}
+
@Override
- protected Statement withBeforeClasses(Statement statement)
+ protected Statement withBeforeClasses(final Statement originalStatement)
{
- final Statement originalStatement = super.withBeforeClasses(statement);
+ final Statement statementWithBefores = super.withBeforeClasses(originalStatement);
return new Statement()
{
@Override
public void evaluate() throws Throwable
{
- archive = deployableTest.get().generateArchive(
- Arquillian.this.getTestClass().getJavaClass());
-
- methodExecutor = deployableTest.get().getDeployer().deploy(archive);
- originalStatement.evaluate();
+ deployableTest.get().beforeClass(Arquillian.this.getTestClass().getJavaClass());
+ statementWithBefores.evaluate();
}
};
}
@Override
- protected Statement withAfterClasses(Statement statement)
+ protected Statement withAfterClasses(final Statement originalStatement)
{
- final Statement originalStatement = super.withAfterClasses(statement);
+ final Statement statementWithAfters = super.withAfterClasses(originalStatement);
return new Statement()
{
@Override
public void evaluate() throws Throwable
{
- originalStatement.evaluate();
- deployableTest.get().getDeployer().undeploy(archive);
+ statementWithAfters.evaluate();
+ deployableTest.get().afterClass(Arquillian.this.getTestClass().getJavaClass());
}
};
}
@Override
+ protected Statement withBefores(final FrameworkMethod method, final Object target, final Statement originalStatement)
+ {
+ final Statement statementWithBefores = super.withBefores(method, target, originalStatement);
+ return new Statement()
+ {
+ @Override
+ public void evaluate() throws Throwable
+ {
+ deployableTest.get().before(target, method.getMethod());
+ statementWithBefores.evaluate();
+ }
+ };
+ }
+
+ @Override
+ protected Statement withAfters(final FrameworkMethod method, final Object target, final Statement originalStatement)
+ {
+ final Statement statementWithAfters = super.withBefores(method, target, originalStatement);
+ return new Statement()
+ {
+ @Override
+ public void evaluate() throws Throwable
+ {
+ statementWithAfters.evaluate();
+ deployableTest.get().after(target, method.getMethod());
+ }
+ };
+ }
+
+ @Override
protected Statement methodInvoker(final FrameworkMethod method, final Object test)
{
return new Statement()
@@ -126,7 +153,7 @@
@Override
public void evaluate() throws Throwable
{
- TestResult result = methodExecutor.invoke(new TestMethodExecutor()
+ TestResult result = deployableTest.get().test(new TestMethodExecutor()
{
public void invoke() throws Throwable
{
Modified: arquillian/trunk/junit/src/main/java/org/jboss/arquillian/junit/JUnitTestRunner.java
===================================================================
--- arquillian/trunk/junit/src/main/java/org/jboss/arquillian/junit/JUnitTestRunner.java 2010-04-20 14:53:59 UTC (rev 4268)
+++ arquillian/trunk/junit/src/main/java/org/jboss/arquillian/junit/JUnitTestRunner.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -16,9 +16,9 @@
*/
package org.jboss.arquillian.junit;
-import org.jboss.arquillian.impl.DeployableTest;
+import org.jboss.arquillian.impl.DeployableTestBuilder;
import org.jboss.arquillian.impl.TestResultImpl;
-import org.jboss.arquillian.impl.Validate;
+import org.jboss.arquillian.spi.ContainerProfile;
import org.jboss.arquillian.spi.TestResult;
import org.jboss.arquillian.spi.TestRunner;
import org.jboss.arquillian.spi.TestResult.Status;
@@ -36,59 +36,22 @@
*/
public class JUnitTestRunner implements TestRunner
{
- private ExecutionMode executionMode = ExecutionMode.STANDALONE;
-
/* (non-Javadoc)
- * @see org.jboss.arquillian.spi.TestRunner#setExecutionMode(org.jboss.arquillian.spi.TestRunner.ExecutionMode)
- */
- @Override
- public void setExecutionMode(ExecutionMode executionMode)
- {
- Validate.notNull(executionMode, "ExecutionMode must be specified");
- this.executionMode = executionMode;
- }
-
- /* (non-Javadoc)
* @see org.jboss.arquillian.spi.TestRunner#execute(java.lang.Class, java.lang.String)
*/
@Override
public TestResult execute(Class<?> testClass, String methodName)
{
- setExecutionMode();
-
+ DeployableTestBuilder.setProfile(ContainerProfile.CONTAINER);
JUnitCore runner = new JUnitCore();
Result result = runner.run(
Request.method(
testClass,
methodName));
- TestResult testResult = convertToTestResult(result);
-
- resetExecutionMode();
-
- return testResult;
+ return convertToTestResult(result);
}
- private void setExecutionMode()
- {
- switch (executionMode)
- {
- case CONTAINER:
- DeployableTest.setInContainer(true);
- break;
- }
- }
-
- private void resetExecutionMode()
- {
- switch (executionMode)
- {
- case CONTAINER:
- DeployableTest.setInContainer(false);
- break;
- }
- }
-
/**
* Convert a JUnit Result object to Arquillian TestResult
*
Modified: arquillian/trunk/spi/src/main/java/org/jboss/arquillian/spi/DeployableContainer.java
===================================================================
--- arquillian/trunk/spi/src/main/java/org/jboss/arquillian/spi/DeployableContainer.java 2010-04-20 14:53:59 UTC (rev 4268)
+++ arquillian/trunk/spi/src/main/java/org/jboss/arquillian/spi/DeployableContainer.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -26,7 +26,8 @@
*/
public interface DeployableContainer
{
-
+ void setup(Configuration configuration);
+
void start() throws LifecycleException;
void stop() throws LifecycleException;
Modified: arquillian/trunk/spi/src/main/java/org/jboss/arquillian/spi/ServiceLoader.java
===================================================================
--- arquillian/trunk/spi/src/main/java/org/jboss/arquillian/spi/ServiceLoader.java 2010-04-20 14:53:59 UTC (rev 4268)
+++ arquillian/trunk/spi/src/main/java/org/jboss/arquillian/spi/ServiceLoader.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -26,7 +26,24 @@
*/
public interface ServiceLoader
{
+ /**
+ * Load multiple service implementations.
+ *
+ * @param <T>
+ * @param serviceClass The service interface to load a implementations for
+ * @return A {@link Collection} of all instances of serviceClass
+ */
<T> Collection<T> all(Class<T> serviceClass);
- <T> T onlyOne(Class<T> serviceClass);
+ /**
+ * Load a single service implementation.
+ *
+ * Method should throw {@link IllegalStateException} if multiple instances of serviceClass found.
+ *
+ * @param <T>
+ * @param serviceClass The service interface to load a implementation for
+ * @return A instance of serviceClass
+ * @throws IllegalStateException if more then one implementation of serviceClass found
+ */
+ <T> T onlyOne(Class<T> serviceClass);
}
Modified: arquillian/trunk/spi/src/main/java/org/jboss/arquillian/spi/TestRunner.java
===================================================================
--- arquillian/trunk/spi/src/main/java/org/jboss/arquillian/spi/TestRunner.java 2010-04-20 14:53:59 UTC (rev 4268)
+++ arquillian/trunk/spi/src/main/java/org/jboss/arquillian/spi/TestRunner.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -26,19 +26,6 @@
*/
public interface TestRunner
{
- public enum ExecutionMode
- {
- /**
- * When running deployed inside the container
- */
- CONTAINER,
-
- /**
- * When running outside the container
- */
- STANDALONE
- }
-
/**
* Run a single test method in a test class.
*
@@ -47,11 +34,4 @@
* @return The result of the test
*/
TestResult execute(Class<?> testClass, String methodName);
-
- /**
- * Instruct the TestRunner which mode to run in.
- *
- * @param executionMode
- */
- void setExecutionMode(ExecutionMode executionMode);
}
Added: arquillian/trunk/spi/src/main/java/org/jboss/arquillian/spi/TestRunnerAdaptor.java
===================================================================
--- arquillian/trunk/spi/src/main/java/org/jboss/arquillian/spi/TestRunnerAdaptor.java (rev 0)
+++ arquillian/trunk/spi/src/main/java/org/jboss/arquillian/spi/TestRunnerAdaptor.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -0,0 +1,73 @@
+/*
+ * 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.spi;
+
+import java.lang.reflect.Method;
+
+/**
+ * TestRunnerAdaptor
+ *
+ * Need to be Thread-safe
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public interface TestRunnerAdaptor
+{
+ /**
+ * @throws Exception
+ */
+ void beforeSuite() throws Exception;
+
+ /**
+ * @throws Exception
+ */
+ void afterSuite() throws Exception;
+
+ /**
+ * @param testClass
+ * @throws Exception
+ */
+ void beforeClass(Class<?> testClass) throws Exception;
+
+ /**
+ * @param testClass
+ * @throws Exception
+ */
+ void afterClass(Class<?> testClass) throws Exception;
+
+ /**
+ * @param testInstance
+ * @param testMethod
+ * @throws Exception
+ */
+ void before(Object testInstance, Method testMethod) throws Exception;
+
+ /**
+ * @param testInstance
+ * @param testMethod
+ * @throws Exception
+ */
+ void after(Object testInstance, Method testMethod) throws Exception;
+
+ /**
+ * @param testMethodExecutor
+ * @return
+ * @throws Exception
+ */
+ TestResult test(TestMethodExecutor testMethodExecutor) throws Exception;
+}
Modified: arquillian/trunk/testng/pom.xml
===================================================================
--- arquillian/trunk/testng/pom.xml 2010-04-20 14:53:59 UTC (rev 4268)
+++ arquillian/trunk/testng/pom.xml 2010-04-20 15:02:38 UTC (rev 4269)
@@ -55,6 +55,11 @@
<version>1.6.5</version>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
Modified: arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/Arquillian.java
===================================================================
--- arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/Arquillian.java 2010-04-20 14:53:59 UTC (rev 4268)
+++ arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/Arquillian.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -18,20 +18,20 @@
import java.lang.reflect.Method;
-import org.jboss.arquillian.impl.DeployableTest;
import org.jboss.arquillian.impl.DeployableTestBuilder;
-import org.jboss.arquillian.spi.ContainerMethodExecutor;
-import org.jboss.arquillian.spi.DeploymentException;
-import org.jboss.arquillian.spi.LifecycleException;
+import org.jboss.arquillian.impl.XmlConfigurationBuilder;
+import org.jboss.arquillian.spi.Configuration;
import org.jboss.arquillian.spi.TestMethodExecutor;
import org.jboss.arquillian.spi.TestResult;
-import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.arquillian.spi.TestRunnerAdaptor;
import org.testng.IHookCallBack;
import org.testng.IHookable;
import org.testng.ITestResult;
import org.testng.annotations.AfterClass;
+import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
/**
@@ -42,69 +42,86 @@
*/
public abstract class Arquillian implements IHookable
{
- private static DeployableTest deployableTest = null;
+ private static ThreadLocal<TestRunnerAdaptor> deployableTest = new ThreadLocal<TestRunnerAdaptor>();
- private Archive<?> archive = null;
- private ContainerMethodExecutor methodExecutor;
-
- @BeforeSuite
- public void createAndStartContainer() throws LifecycleException
+ @BeforeSuite(alwaysRun = true)
+ public void arquillianBeforeSuite() throws Exception
{
- if (deployableTest == null)
+ if(deployableTest.get() == null)
{
- deployableTest = DeployableTestBuilder.build(null);
+ Configuration configuration = new XmlConfigurationBuilder().build();
+ deployableTest.set(DeployableTestBuilder.build(configuration));
}
- deployableTest.getContainerController().start();
+ deployableTest.get().beforeSuite();
}
- @AfterSuite
- public void destroyAndStopContainer() throws LifecycleException
+ @AfterSuite(alwaysRun = true)
+ public void arquillianAfterSuite() throws Exception
{
- if (deployableTest == null)
+ if (deployableTest.get() == null)
{
return;
}
- deployableTest.getContainerController().stop();
+ deployableTest.get().afterSuite();
}
- @BeforeClass
- public void createAndDeployArtifact() throws DeploymentException
+ @BeforeClass(alwaysRun = true)
+ public void arquillianBeforeClass() throws Exception
{
- archive = deployableTest.generateArchive(this.getClass());
- methodExecutor = deployableTest.getDeployer().deploy(archive);
+ deployableTest.get().beforeClass(getClass());
}
- @AfterClass
- public void destroyAndUndeployArtifact() throws DeploymentException
+ @AfterClass(alwaysRun = true)
+ public void arquillianAfterClass() throws Exception
{
- deployableTest.getDeployer().undeploy(archive);
+ deployableTest.get().afterClass(getClass());
}
+
+ @BeforeMethod(alwaysRun = true)
+ public void arquillianBeforeTest(Method testMethod) throws Exception
+ {
+ deployableTest.get().before(this, testMethod);
+ }
+ @AfterMethod(alwaysRun = true)
+ public void arquillianAfterTest(Method testMethod) throws Exception
+ {
+ deployableTest.get().after(this, testMethod);
+ }
+
public void run(final IHookCallBack callback, final ITestResult testResult)
{
- TestResult result = methodExecutor.invoke(new TestMethodExecutor()
+ TestResult result;
+ try
{
- @Override
- public void invoke() throws Throwable
+ result = deployableTest.get().test(new TestMethodExecutor()
{
- callback.runTestMethod(testResult);
- }
-
- @Override
- public Method getMethod()
+ @Override
+ public void invoke() throws Throwable
+ {
+ callback.runTestMethod(testResult);
+ }
+
+ @Override
+ public Method getMethod()
+ {
+ return testResult.getMethod().getMethod();
+ }
+
+ @Override
+ public Object getInstance()
+ {
+ return Arquillian.this;
+ }
+ });
+ if(result.getThrowable() != null)
{
- return testResult.getMethod().getMethod();
+ testResult.setThrowable(result.getThrowable());
}
-
- @Override
- public Object getInstance()
- {
- return Arquillian.this;
- }
- });
- if(result.getThrowable() != null)
+ }
+ catch (Exception e)
{
- testResult.setThrowable(result.getThrowable());
+ testResult.setThrowable(e);
}
}
}
Modified: arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/TestNGTestRunner.java
===================================================================
--- arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/TestNGTestRunner.java 2010-04-20 14:53:59 UTC (rev 4268)
+++ arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/TestNGTestRunner.java 2010-04-20 15:02:38 UTC (rev 4269)
@@ -17,12 +17,11 @@
package org.jboss.arquillian.testng;
import java.util.ArrayList;
-
import java.util.Arrays;
import java.util.List;
-import org.jboss.arquillian.impl.DeployableTest;
-import org.jboss.arquillian.impl.Validate;
+import org.jboss.arquillian.impl.DeployableTestBuilder;
+import org.jboss.arquillian.spi.ContainerProfile;
import org.jboss.arquillian.spi.TestResult;
import org.jboss.arquillian.spi.TestRunner;
import org.testng.TestNG;
@@ -39,29 +38,16 @@
*/
public class TestNGTestRunner implements TestRunner
{
- private ExecutionMode executionMode = ExecutionMode.STANDALONE;
-
/* (non-Javadoc)
- * @see org.jboss.arquillian.spi.TestRunner#setExecutionMode(org.jboss.arquillian.spi.TestRunner.ExecutionMode)
- */
- @Override
- public void setExecutionMode(ExecutionMode executionMode)
- {
- Validate.notNull(executionMode, "ExecutionMode must be specified");
- this.executionMode = executionMode;
- }
-
- /* (non-Javadoc)
* @see org.jboss.arquillian.spi.TestRunner#execute(java.lang.Class, java.lang.String)
*/
@Override
public TestResult execute(Class<?> testClass, String methodName)
{
- setExecutionMode();
-
+ DeployableTestBuilder.setProfile(ContainerProfile.CONTAINER);
TestListener resultListener = new TestListener();
- TestNG runner = new TestNG(false);
+ TestNG runner = new TestNG(true);
runner.setVerbose(0);
runner.addListener(resultListener);
runner.setXmlSuites(
@@ -69,11 +55,7 @@
runner.run();
- TestResult testResult = resultListener.getTestResult();
-
- resetExecutionMode();
-
- return testResult;
+ return resultListener.getTestResult();
}
private XmlSuite createSuite(Class<?> className, String methodName)
@@ -91,24 +73,4 @@
test.setXmlClasses(testClasses);
return suite;
}
-
- private void setExecutionMode()
- {
- switch (executionMode)
- {
- case CONTAINER:
- DeployableTest.setInContainer(true);
- break;
- }
- }
-
- private void resetExecutionMode()
- {
- switch (executionMode)
- {
- case CONTAINER:
- DeployableTest.setInContainer(false);
- break;
- }
- }
}
More information about the jboss-svn-commits
mailing list