package de.digitalcollections.blueprints.rest.server;

import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;

import static org.assertj.core.api.BDDAssertions.then;

/**
 * Basic integration tests for service application.
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class,
        webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestPropertySource(properties = {
  "management.port=0",
  "pathToUserProperties=classpath:///users.properties"
})
public class ApplicationTest {

  @LocalServerPort
  private int port;

  @Value("${local.management.port}")
  private int mgt;

  @Autowired
  private TestRestTemplate testRestTemplate;

  @Test
  public void shouldReturn200WhenSendingRequestToController() throws Exception {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = this.testRestTemplate.getForEntity(
            "http://localhost:" + this.port + "/hello", Map.class);

    then(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
  }

  @Test
  public void shouldReturn200WhenSendingRequestToManagementEndpoint() throws Exception {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = this.testRestTemplate.getForEntity(
            "http://localhost:" + this.mgt + "/info", Map.class);

    then(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
  }

}

@@ -87,16 +87,28 @@
 g.junit.
+jupiter.api.
 Test;%0Aim
@@ -126,18 +126,36 @@
 nit.
-runner.Run
+jupiter.api.extension.Extend
 With
@@ -251,37 +251,64 @@
 rk.b
-eans.factory.annotation.Value
+oot.actuate.autoconfigure.web.server.LocalManagementPort
 ;%0Aim
@@ -337,24 +337,29 @@
 rk.boot.
+test.
 context.
 embedded
@@ -354,31 +354,21 @@
 ext.
-embedded.LocalServerPor
+SpringBootTes
 t;%0Ai
@@ -417,32 +417,47 @@
 t.SpringBootTest
+.WebEnvironment
 ;%0Aimport org.spr
@@ -508,16 +508,76 @@
 mplate;%0A
+import org.springframework.boot.web.server.LocalServerPort;%0A
 import o
@@ -769,22 +769,32 @@
 unit
-4.SpringRunner
+.jupiter.SpringExtension
 ;%0A%0Ai
@@ -909,19 +909,22 @@
 n.%0A */%0A@
-Run
+Extend
 With(Spr
@@ -930,14 +930,17 @@
 ring
-Runner
+Extension
 .cla
@@ -988,20 +988,16 @@
 .class,%0A
-    
     webE
@@ -1009,31 +1009,16 @@
 nment = 
-SpringBootTest.
 WebEnvir
@@ -1072,16 +1072,18 @@
 ies = %7B%0A
+  
   %22manag
@@ -1097,16 +1097,39 @@
 ort=0%22,%0A
+    %22server.port=0%22,%0A  
   %22pathT
@@ -1257,24 +1257,14 @@
 %0A  @
-Value(%22$%7Bl
+L
 ocal
-.m
+M
 anag
@@ -1272,16 +1272,12 @@
 ment
-.p
+P
 ort
-%7D%22)
 %0A  p
@@ -1544,36 +1544,32 @@
 Entity(%0A        
-    
 %22http://localhos
@@ -1877,28 +1877,24 @@
 ty(%0A        
-    
 %22http://loca
@@ -1916,16 +1916,27 @@
 mgt + %22/
+monitoring/
 info%22, M

refactor unit tests (JUnit5). Fix monitoring endpoint url (Spring Boot 2.x)