me.bazhenov.docker.AfterContainerStart Maven / Gradle / Ivy
package me.bazhenov.docker;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* Methods annotated with {@link AfterContainerStart} are called by {@link DockerTestNgListener} after
* all containers are started.
*
* All parameters of those methids should be of type {@code int} and annotated with {@link ContainerPort} annotation.
*
* Typical usage:
*
* @Container(name="mysql", publish=@Port(3306), image=...)
* @Listeners(DockerTestNgListener.class)
* @Listeners(DockerTestNgListener.class)
* class SampleTest {
*
* private int mysqlPort;
*
* @AfterContainerStart
* public void initDocker(@ContainerPort(name="mysql", port=3306) int mysqlPort) {
* this.mysqlPort = mysqlPort;
* }
*
* @Test
* public void testMysql() {
* String url = "jdbc:mysql://localhost:" + mysqlPort;
* ...
* }
* }
*
*/
@SuppressWarnings("WeakerAccess")
@Retention(RUNTIME)
@Target(METHOD)
public @interface AfterContainerStart {
}