Class WireMockContainer

  • All Implemented Interfaces:
    AutoCloseable, org.junit.rules.TestRule, org.testcontainers.containers.Container<WireMockContainer>, org.testcontainers.containers.ContainerState, org.testcontainers.containers.traits.LinkableContainer, org.testcontainers.containers.wait.strategy.WaitStrategyTarget, org.testcontainers.lifecycle.Startable

    public class WireMockContainer
    extends org.testcontainers.containers.GenericContainer<WireMockContainer>
    Provisions WireMock standalone server as a container. Designed to follow the WireMock Docker image (wiremock/wiremock) structure and configuration, but other images can be included too at your own risk.
    • Field Detail

      • WIREMOCK_2_LATEST

        public static final org.testcontainers.utility.DockerImageName WIREMOCK_2_LATEST
    • Constructor Detail

      • WireMockContainer

        public WireMockContainer​(String image)
        Create image from the specified full image name (repo, image, tag)
      • WireMockContainer

        public WireMockContainer​(org.testcontainers.utility.DockerImageName dockerImage)
    • Method Detail

      • withoutBanner

        public WireMockContainer withoutBanner()
        Disables the banner when starting the WireMock container.
        Returns:
        this instance
      • withBanner

        public WireMockContainer withBanner()
        Enable the banner when starting the WireMock container.
        Returns:
        this instance
      • withCliArg

        public WireMockContainer withCliArg​(String arg)
        Adds CLI argument to the WireMock call.
        Parameters:
        arg - Argument
        Returns:
        this instance
      • withMappingFromJSON

        public WireMockContainer withMappingFromJSON​(String json)
        Add mapping JSON file from its value
        Parameters:
        json - JSON sting
        Returns:
        This instance
      • withMappingFromJSON

        public WireMockContainer withMappingFromJSON​(String name,
                                                     String json)
        Adds a JSON mapping stub to WireMock configuration
        Parameters:
        name - Name of the mapping stub
        json - Configuration JSON
        Returns:
        this instance
      • withMappingFromResource

        public WireMockContainer withMappingFromResource​(String name,
                                                         Class<?> resource,
                                                         String resourceJson)
        Loads mapping stub from the class resource
        Parameters:
        name - Name of the mapping stub
        resource - Resource class. Name of the class will be appended to the resource path
        resourceJson - Reference to the mapping definition file, starting from the resource root (normally package)
        Returns:
        this instance
      • withMappingFromResource

        public WireMockContainer withMappingFromResource​(Class<?> resource,
                                                         String resourceJson)
        Loads mapping stub from the class resource
        Parameters:
        resource - Resource class. Name of the class will be appended to the resource path
        resourceJson - Mapping definition file
        Returns:
        this instance
      • withMappingFromResource

        public WireMockContainer withMappingFromResource​(String name,
                                                         String resourceName)
        Loads mapping stub from the resource file
        Parameters:
        name - Name of the mapping stub
        resourceName - Resource name and path
        Returns:
        this instance
      • withMappingFromResource

        public WireMockContainer withMappingFromResource​(String resourceName)
        Loads mapping stub from the resource file
        Parameters:
        resourceName - Resource name and path
        Returns:
        this instance
      • withMappingFromResource

        public WireMockContainer withMappingFromResource​(String name,
                                                         URL url)
        Loads mapping stub from the resource file
        Parameters:
        name - Name of the mapping stub
        url - Resource file URL
        Returns:
        this instance
      • withFile

        public WireMockContainer withFile​(String name,
                                          File file)
        Adds file
        Parameters:
        name - ID to be used
        file - File to add
        Returns:
        This instance
      • withFile

        public WireMockContainer withFile​(File file)
        Adds file
        Parameters:
        file - File to add
        Returns:
        This instance
      • withExtensions

        public WireMockContainer withExtensions​(Collection<String> classNames,
                                                Collection<File> jars)
        Add extension that will be loaded from the specified JAR files. In the internal engine, it will be handled as a single plugin.
        Parameters:
        classNames - Class names of the extension to be included
        jars - JARs to be included into the container
        Returns:
        this instance
      • withExtensions

        public WireMockContainer withExtensions​(String id,
                                                Collection<String> classNames,
                                                Collection<File> jars)
        Add extension that will be loaded from the specified JAR files. In the internal engine, it will be handled as a single plugin.
        Parameters:
        id - Identifier top use
        classNames - Class names of the extension to be included
        jars - JARs to be included into the container
        Returns:
        this instance
      • withExtensions

        public WireMockContainer withExtensions​(Collection<String> classNames,
                                                File jarDirectory)
        Add extension that will be loaded from the specified directory with JAR files. In the internal engine, it will be handled as a single plugin.
        Parameters:
        classNames - Class names of the extension to be included
        jarDirectory - Directory that stores all JARs
        Returns:
        this instance
      • withExtension

        public WireMockContainer withExtension​(String className)
        Add extension that will be loaded from the classpath. This method can be used if the extension is a part of the WireMock bundle, or a Jar is already added via withExtensions(Collection, Collection)}. In the internal engine, it will be handled as a single plugin.
        Parameters:
        className - Class name of the extension
        Returns:
        this instance
      • getBaseUrl

        public String getBaseUrl()
      • getPort

        public Integer getPort()
      • configure

        protected void configure()
        Overrides:
        configure in class org.testcontainers.containers.GenericContainer<WireMockContainer>