Forked from aslakknutsen/CloseCustomContainersOnAfterSuiteExtension.java
Created
May 7, 2012 15:59
-
-
Save rhusar/2628635 to your computer and use it in GitHub Desktop.
Arquillian Custom mode containers are not stopped on AfterSuite by default, their lifecyle is left completely up to the user/extensions. Example of a little extension that will stop the custom containers on AfterSuite.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* JBoss, Home of Professional Open Source | |
* Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors | |
* as indicated by the @authors tag. All rights reserved. | |
* See the copyright.txt in the distribution for a | |
* full listing of individual contributors. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
package my.testsuite; | |
import org.jboss.arquillian.container.spi.Container; | |
import org.jboss.arquillian.container.spi.Container.State; | |
import org.jboss.arquillian.container.spi.ContainerRegistry; | |
import org.jboss.arquillian.core.api.annotation.Observes; | |
import org.jboss.arquillian.core.spi.LoadableExtension; | |
import org.jboss.arquillian.test.spi.event.suite.AfterSuite; | |
/** | |
* @author <a href="mailto:[email protected]">Aslak Knutsen</a> | |
* @version $Revision: $ | |
*/ | |
public class CloseCustomContainersOnAfterSuiteExtension implements LoadableExtension | |
{ | |
@Override | |
public void register(ExtensionBuilder builder) | |
{ | |
builder.observer(CloseCustomContainers.class); | |
} | |
public static class CloseCustomContainers | |
{ | |
public void close(@Observes AfterSuite event, ContainerRegistry registry) | |
{ | |
for(Container c : registry.getContainers()) | |
{ | |
if(c.getState() == State.STARTED && "custom".equalsIgnoreCase(c.getContainerConfiguration().getMode())) | |
{ | |
try | |
{ | |
c.stop(); | |
} | |
catch (Exception e) | |
{ | |
System.err.println("Could not stop custom container " + c.getName()); | |
e.printStackTrace(); | |
} | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my.testsuite.CloseCustomContainersOnAfterSuiteExtension |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment