org.jboss.arquillian.testcontainers.api.Testcontainer Maven / Gradle / Ivy
/*
* Copyright The Arquillian Authors
* SPDX-License-Identifier: Apache-2.0
*/
package org.jboss.arquillian.testcontainers.api;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Field;
import org.testcontainers.containers.GenericContainer;
/**
* Used to annotate a field which must be an instance of a {@link GenericContainer}. A
* {@link DockerRequired} annotation must be present on the type to use Testcontainer injection.
*
*
* @ExtendWith(ArquillianExtension.class)
* @RunAsClient
* // By throwing the TestAbortedException, the test will be skipped if docker is not available
* @DockerRequired(TestAbortedException.class)
* public class ContainerTest {
*
* @Testcontainer
* private CustomTestContainer container;
*
* @Deployment
* public static JavaArchive createDeployment() {
* return ShrinkWrap.create(JavaArchive.class)
* .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
* }
*
* @Test
* public void testContainerInjected() {
* Assertions.assertNotNull(container, "Expected the container to be injected.");
* Assertions.assertTrue(container.isRunning(), "Expected the container to be running");
* }
* }
*
*/
@Inherited
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Testcontainer {
/**
* Indicates whether Arquillian should manage the starting of the Testcontainer. With a value of {@code false},
* Arquillian will not start the server. It will still attempt to stop the server.
*
* @return {@code true} to have Arquillian manage the lifecycle of the Testcontainer
*/
boolean value() default true;
/**
* The type used to create the value for the field. The type must have a no-arg constructor.
*
* If left as the default value, {@link GenericContainer}, the type to construct is derived from the
* {@linkplain Field#getType() field}.
*
*
* @return the type to construct
*/
Class extends GenericContainer> type() default GenericContainer.class;
}