Skip to content
develop
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Autorelease

build status Download

Docker Proxy JUnit Rule

This is a small library for executing JUnit tests that interact with Docker containers. It supports the following:

  • Hitting the docker containers according the their hostnames when using interfaces that are not backed by Java NIO
  • Auto-mapping the hostnames when using docker-compose-rule
  • Auto-mapping the hostnames when specifying the name of the network they are on

Why should I use this

This code allows you to avoid having to map internal docker ports to external ports so you don't have to map them to ports that may be in-use, or map them to random ports then have logic to construct clients based on which random port is being used.

Simple Use

Add a dependency to your project. For example, in gradle:

repositories {
    maven {
        url 'https://dl.bintray.com/palantir/releases' // docker-proxy-rule is published on bintray
    }
}
dependencies {
    compile 'com.palantir.docker.proxy:docker-proxy-rule:<latest-tag-from-bintray>'
}

For the most basic use (with docker-compose-rule), simply add an @ClassRule as follows:

public class MyIntegrationTest {
    private static DockerComposeRule docker = ...;
    private static DockerProxyRule proxy = DockerProxyRule.fromProjectName(docker.projectName());

    @ClassRule
    public static RuleChain ruleChain = RuleChain.outerRule(docker)
            .around(proxy);
}

You can then communicate with the hosts within your tests. For example:

URLConnection urlConnection = new URL("http://webserver").openConnection();
urlConnection.connect();

About

A JUnit Proxy/DNS rule for connecting to dockerised applications with standard hostnames and ports

Resources

License

You can’t perform that action at this time.