lundi 8 août 2016

Spring Boot profile. How to test?

How can I test my profiles?

that's my test

    @Test
public void testDevProfile() throws Exception {
    System.setProperty("spring.profiles.active", "dev");
    Application.main(new String[0]);
    String output = this.outputCapture.toString();
    Assert.assertTrue(output.contains("The following profiles are active: dev"));
}

@Test
public void testUatProfile() throws Exception {
    System.setProperty("spring.profiles.active", "uat");
    Application.main(new String[0]);
    String output = this.outputCapture.toString();
    Assert.assertTrue(output.contains("The following profiles are active: uat"));
}

@Test
public void testPrdProfile() throws Exception {
    System.setProperty("spring.profiles.active", "prd");
    Application.main(new String[0]);
    String output = this.outputCapture.toString();
    Assert.assertFalse(output.contains("The following profiles are active: uat"));
    Assert.assertFalse(output.contains("The following profiles are active: dev"));
    Assert.assertFalse(output.contains("The following profiles are active: default"));
}

My first test executes OK but the others fail.

org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [org.springframework.boot.actuate.endpoint.jmx.DataEndpointMBean@6cbe68e9] with key 'requestMappingEndpoint'; nested exception is javax.management.InstanceAlreadyExistsException: org.springframework.boot:type=Endpoint,name=requestMappingEndpoint

How can I stop the instance before the next test start? Or which is the better approach?

thanks

Aucun commentaire:

Enregistrer un commentaire