Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Appsody test is not working on spring boot 2 #821

Open
oiricaud opened this issue May 28, 2020 · 1 comment
Open

Appsody test is not working on spring boot 2 #821

oiricaud opened this issue May 28, 2020 · 1 comment
Labels
stack/java-spring-boot2 Issues related to java-spring-boot2 stack

Comments

@oiricaud
Copy link

oiricaud commented May 28, 2020

Describe the bug
Unable to run unit tests on the default MainTest class that gets generated when using
appsody test.

To Reproduce
Steps to reproduce the behavior:

brew install appsody 
mkdir plain-java-appsody
cd plain-java-appsody
appsody init kabanero/java-spring-boot2
appsody test

Step 3 generates the MainTests class

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class MainTests {

    @Autowired
    private TestRestTemplate restTemplate;

    @Test
    public void testHealthEndpoint() {
        ResponseEntity<String> entity = this.restTemplate.getForEntity("/actuator/health", String.class);
        assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
        assertThat(entity.getBody()).contains("\"status\":\"UP\"");
    }

    @Test
    public void testLivenessEndpoint() {
        ResponseEntity<String> entity = this.restTemplate.getForEntity("/actuator/liveness", String.class);
        assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
        assertThat(entity.getBody()).contains("\"status\":\"UP\"");
    }

    @Test
    @SuppressWarnings("unchecked")
    public void testMetricsEndpoint() {
        testLivenessEndpoint(); // access a page

        @SuppressWarnings("rawtypes")
        ResponseEntity<Map> entity = this.restTemplate.getForEntity("/actuator/metrics", Map.class);
        assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);

        Map<String, Object> body = entity.getBody();
        assertThat(body).containsKey("names");
        assertThat((List<String>) body.get("names")).contains("jvm.buffer.count");
    }

    @Test
    public void testPrometheusEndpoint() {
        testLivenessEndpoint(); // access a page

        ResponseEntity<String> entity = this.restTemplate.getForEntity("/actuator/prometheus", String.class);
        assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
        assertThat(entity.getBody()).contains("# TYPE jvm_buffer_count_buffers gauge");
    }
}

Expected behavior
I need to understand when using appsody test the test classes do not run. What it should do, it should run the test class that got generated by appsody.

Actual behaviour
The build is successful but I do not get any indication that the test cases passed/failed.

Running test environment
Pulling docker image docker.io/kabanero/java-spring-boot2:0.3
Running command: docker pull docker.io/kabanero/java-spring-boot2:0.3
0.3: Pulling from kabanero/java-spring-boot2
Digest: sha256:5c7154e6758d60c3a2aa855ada917aa7da02ca40740f41637166d30aed3b4733
Status: Image is up to date for kabanero/java-spring-boot2:0.3
docker.io/kabanero/java-spring-boot2:0.3
[Warning] The stack image does not contain APPSODY_DEPS
Running command: docker run --rm -p 35729:35729 -p 5005:5005 -p 8080:8080 -p 8443:8443 --name plain-java-appsody -u 501:20 -e "APPSODY_USER=501" -e "APPSODY_GROUP=20" -v "/Users/[email protected]/Documents/gse-devops/github.com/plain-java-appsody/:/project/user-app" -v "/Users/[email protected]/.m2/repository:/mvn/repository" -v appsody-controller-0.3.5:/.appsody -t --entrypoint /.appsody/appsody-controller docker.io/kabanero/java-spring-boot2:0.3 "--mode=test"
[Container] Running command:  /project/java-spring-boot2-build.sh test
[Container] Installing parent dev.appsody:spring-boot2-stack:0.3.29 and required dependencies...
[Container] > mvn install -q -f /project/appsody-boot2-snowdrop-pom.xml
[Container] Test project in the foreground
[Container] > mvn package test
[Container] [INFO] Scanning for projects...
[Container] [INFO] 
[Container] [INFO] ----------------------< dev.appsody:application >-----------------------
[Container] [INFO] Building application 0.0.1-SNAPSHOT
[Container] [INFO] --------------------------------[ jar ]---------------------------------
[Container] [INFO] 
[Container] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ application ---
[Container] [INFO] Using 'UTF-8' encoding to copy filtered resources.
[Container] [INFO] Copying 2 resources
[Container] [INFO] 
[Container] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ application ---
[Container] [INFO] Nothing to compile - all classes are up to date
[Container] [INFO] 
[Container] [INFO] --- maven-antrun-plugin:1.1:run (trigger-spring-restart) @ application ---
[Container] [INFO] Executing tasks
[Container]      [echo] Triggering Spring app restart.
[Container] [INFO] Executed tasks
[Container] [INFO] 
[Container] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ application ---
[Container] [INFO] Using 'UTF-8' encoding to copy filtered resources.
[Container] [INFO] skip non existing resourceDirectory /project/user-app/src/test/resources
[Container] [INFO] 
[Container] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ application ---
[Container] [INFO] Nothing to compile - all classes are up to date
[Container] [INFO] 
[Container] [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ application ---
[Container] [INFO] 
[Container] [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ application ---
[Container] [INFO] 
[Container] [INFO] --- spring-boot-maven-plugin:2.1.12.RELEASE:repackage (default) @ application ---
[Container] [INFO] Replacing main artifact with repackaged archive
[Container] [INFO] 
[Container] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ application ---
[Container] [INFO] Using 'UTF-8' encoding to copy filtered resources.
[Container] [INFO] Copying 2 resources
[Container] [INFO] 
[Container] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ application ---
[Container] [INFO] Nothing to compile - all classes are up to date
[Container] [INFO] 
[Container] [INFO] --- maven-antrun-plugin:1.1:run (trigger-spring-restart) @ application ---
[Container] [INFO] Executing tasks
[Container]      [echo] Triggering Spring app restart.
[Container] [INFO] Executed tasks
[Container] [INFO] 
[Container] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ application ---
[Container] [INFO] Using 'UTF-8' encoding to copy filtered resources.
[Container] [INFO] skip non existing resourceDirectory /project/user-app/src/test/resources
[Container] [INFO] 
[Container] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ application ---
[Container] [INFO] Nothing to compile - all classes are up to date
[Container] [INFO] 
[Container] [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ application ---
[Container] [INFO] Skipping execution of surefire because it has already been run for this configuration
[Container] [INFO] ------------------------------------------------------------------------
[Container] [INFO] BUILD SUCCESS
[Container] [INFO] ------------------------------------------------------------------------
[Container] [INFO] Total time:  13.411 s
[Container] [INFO] Finished at: 2020-05-28T16:24:06Z
[Container] [INFO] ------------------------------------------------------------------------
[Container] The file watcher is not running because no APPSODY_RUN/TEST/DEBUG_ON_CHANGE action was specified or it has been disabled using the --no-watcher flag.
Closing down development environment.

Environment Details (please complete the following information):

  • OS: Mac
  • Browser Chrome

If applicable please specify:

  • CLI version: 0.6.2
  • Stack you are using (including the version): kabanero/java-spring-boot2
@oiricaud
Copy link
Author

oiricaud commented May 28, 2020

Refactoring the class that appsody generates MainTests to another class name such as TestMe resolves this bug.

[Container] 2020-05-28 16:33:06.993  INFO 186 --- [o-auto-1-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
[Container] 2020-05-28 16:33:06.993  INFO 186 --- [o-auto-1-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
[Container] 2020-05-28 16:33:07.015  INFO 186 --- [o-auto-1-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 22 ms
[Container] 2020-05-28 16:33:07.164  INFO 186 --- [           main] i.j.internal.reporters.LoggingReporter   : Span reported: f8b2380dff08f327:f8b2380dff08f327:0:1 - GET
[Container] 2020-05-28 16:33:07.269  INFO 186 --- [           main] i.j.internal.reporters.LoggingReporter   : Span reported: 70520fdbe2ef36db:70520fdbe2ef36db:0:1 - GET
[Container] 2020-05-28 16:33:07.280  INFO 186 --- [           main] i.j.internal.reporters.LoggingReporter   : Span reported: be347a2139594b08:be347a2139594b08:0:1 - GET
[Container] 2020-05-28 16:33:07.320  INFO 186 --- [           main] i.j.internal.reporters.LoggingReporter   : Span reported: f4b83cf9358b4546:f4b83cf9358b4546:0:1 - GET
[Container] 2020-05-28 16:33:07.334  INFO 186 --- [           main] i.j.internal.reporters.LoggingReporter   : Span reported: 302d20a796e5e032:302d20a796e5e032:0:1 - GET
[Container] 2020-05-28 16:33:07.367  INFO 186 --- [           main] i.j.internal.reporters.LoggingReporter   : Span reported: 2ff445a4a4084526:2ff445a4a4084526:0:1 - GET
[Container] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 8.666 sec
[Container] 2020-05-28 16:33:07.435  INFO 186 --- [      Thread-11] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
[Container] 
[Container] Results :
[Container] 
[Container] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
stack/java-spring-boot2 Issues related to java-spring-boot2 stack
Projects
None yet
Development

No branches or pull requests

2 participants