Testing Spring Boot applications with Archillian Cube


#1

I was wondering if anybody could help me figure out how to test a Spring Boot application using Arquillian Cube. The main problem is that the application is not able to find the application.properties file needed to start up. It starts up atThey are located within the application at this location

src/test/resources/arquillianTest/archillian-cube.properties

The application tries to start but it fails when it is not able to find properties located in the archillian-cube.properties file.

Thank you in advance for all your help

Maria Gabriela Mino

My archillian.xml looks like this:

<extension qualifier="docker">
                <property name="serverVersion">1.26</property>
                <property name="definitionFormat">COMPOSE</property>
                <property name="machineName">default</property>
                <property name="dockerContainersFile">docker-compose.yml</property>
</extension>

And my docker-compose.yml file looks like

cgwCompose:
  image: <image>
  alwaysPull: true
  await:
    strategy: polling
  env: [SPRING.CONFIG.LOCATION=src/test/resources/arquillianTest/arquillian-cube.properties, JAVA_OPTS= -Dcom.sun.management.jmxremote.port=8443 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false]
  portBindings: [5001/tcp, 8443/tcp]

My test looks like this:

@RunWith(Arquillian.class)
public class RestAssuredTest {
 
                @HostIp
                private String ip;
 
                @HostPort(containerName = "cgwCompose", value = 5001)
                int cgwPort;
                
    @Test
    public void getTransactionsTest() throws IOException {
 
                URL url = new URL("http://" + ip + ":" + cgwPort + "/rest/v2/transactions/");
                
                String responseBody = given().relaxedHTTPSValidation()
                                                .headers("accept", "application/json", "api-key", "", "Content-type", "application/json")
                .when().get(url.toString())
                .then().extract().body().asString();
 
        assertNotNull("Error: null response", responseBody);
    }
}

#2

Hi Maria, the problem you are facing here is that the environment variable points to a local directory src/test/resources but this location should be a location where the application is running, in this case inside docker container, so this variable should point to an existing location inside docker container since it is where the spring boot application is running, and not local directory.

Last note is that this is a cube format and not docker-compose format so you should change this COMPOSE to CUBE or adapt the file to a docker-compose format.

Alex.


#3

I was able to get it to pick up the spring.config.location by doing the following:

  1. I am using Docker Toolbox which contains a default Boot2Docker machine. I followed the mounting volumes steps in this post https://www.viget.com/articles/how-to-use-docker-on-os-x-the-missing-guide in order to access the c:/Users/ directory from my local computer.

  2. I followed the containerObject pattern in order to specify the host and container volumes with the following annotations:

    @Cube(value = “test”, portBinding = “5000->8433/tcp”)
    @Image("")
    @Volume(hostPath = “/c/Users/gmino”, containerPath = “/opt/properties”)
    @Environment(key = “SPRING.CONFIG.LOCATION”, value = “file:/opt/properties/arquillian-cube.properties”)
    public class TestContainerObject {
    In my test I have

     @RunWith(Arquillian.class)
     public class PingPongTest {
         @Cube
         TestContainerObject testContainer;
        @Test
        public void shouldReturnOkAsPong() throws IOException {
    

But I still not sure what would be the syntax inside the docker-compose.yml file for volumes


#4

Maybe these Spring Boot tutorials can help you.