1

My project is on an isolated computer, so I can't do massive dumps of files, but I will try to provide the necessary information.

I have a Spring-Boot MVC project. I can get it to run fine from the command line. I can get the ApplicationContext to fun fine as long as I am using the Spring-Boot-Test starter:

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
@TestPropertySource(locations = { "classpath:application-test-h2.properties" })
@DirtiesContext(classMode = ClassMod.AFTER_EACH_TEST_METHOD)

I have recently added some HTMLUnit tests to go do some integration testing. The tests run fine when I have the application already running (which means it can't be done automatically on the corporate Bamboo). So, after stumbling around the web, I added the cargo plugin:

<plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <version>1.4.16</version>
    <configuration>
        <wait>false</wait>
        <container>
            <containerId>tomcat8x</containerId>
            <type>embedded</type>
            <logLevel>info</logLevel>
        <container>
        <configuration>
            <properties>
                <cargo.servlet.port>8443</cargo.servlet.port>
                <cargo.protocol>https</cargo.protocol>
                <cargo.tomcat.connector.clientAuth>false</cargo.tomcat.connector.clientAuth>
                <cargo key and password stuff censored>
                <cargo.tomcat.httpSecure>true</cargo.tomcat.httpSecure>
            </properties>
       </configuration>
       <executions>
            <execution>
                 <id>start-server</id>
                 <phase>pre-integration-test</phase>
                 <goals><goal>start</goal></goals>
            </execution>
            <execution>
                 <id>stop-server</id>
                 <phase>post-integration-test</phase>
                 <goals><goal>stop</goal></goals>
            </execution>
         </executions>
  </plugin>

I also went to the maven failsafe plugin and did:

<execution>
   <id>integration-test</id>
   <goals><goal>integration-test</goal></goals>
</execution>
<execution>
   <id>verify</id>
   <goals><goal>verify</goal></goals>
</execution>

Finally I edited the spring-boot-maven-plugin and added:

<execution>
   <id>pre-integration-test</id>
   <goals><goal>start</goal></goals>
</execution>
<execution>
   <id>post-integration-test</id>
   <goals><goal>stop</goal></goals>
</execution>

So, I can finally see my application context start up when I do a "mvn verify". All is well and good, right up until it tries to connect to the database. I have 2 application.properties files and a application-test-h2.properties.

They are:

    |--- ProjectDirectory
        \--- src/main/resources
             \--- application.properties (1)
        \--- src/test/resources
             \--- application-test-h2.properties  (2)
     \--- application.properties  (3)

It appears from the error message that it is only picking up the application.properties noted by (1). The cargo startup does not appear to be getting (2) or (3) or using the precedence Spring projects use.

The integration tests are simple:

@RunWith(Theories.class)
public void HTMLUnitIT {
  @Datapoints
  private static MyTestObject[] datapoints;

  @Theory
  public void testSearches(MyTestObject obj) throws Exception {
     //..... stuff ... This stuff runs if I just run the class and have the application running
  }
}

So the $64,000 question is, how do I get the properties to all resolve in the cargo plugin?

Thank you in advance.

4

0 回答 0