package de.digitalcollections.blueprints.webapp.springboot;

import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
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 webapp endpoints.
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {Application.class},
        webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) // set random webapp/server port
@TestPropertySource(properties = {"management.server.port=0"}) // set random management port
public class ApplicationTest {

  @LocalServerPort
  private int port;

  @LocalManagementPort
  private int mgt;

  @Autowired
  private TestRestTemplate testRestTemplate;

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

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

  @Test
  public void shouldReturn200WhenSendingAuthorizedRequestToSensitiveManagementEndpoint() throws Exception {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = this.testRestTemplate.withBasicAuth("admin", "secret").getForEntity(
            "http://localhost:" + this.mgt + "/monitoring/env", Map.class);

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

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

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

}

@@ -54,16 +54,99 @@
 gboot;%0A%0A
+import de.digitalcollections.blueprints.webapp.springboot.config.SpringConfigWeb;%0A%0A
 import j
@@ -159,16 +159,17 @@
 il.Map;%0A
+%0A
 import o
@@ -177,16 +177,28 @@
 g.junit.
+jupiter.api.
 Test;%0Aim
@@ -216,24 +216,43 @@
 nit.
-runner.Run
+jupiter.api.extension.Extend
 With;%0A
+%0A
 impo
@@ -346,16 +346,8 @@
 oot.
-actuate.
 auto
@@ -360,38 +360,29 @@
 ure.
-web.server.LocalManagementPort
+SpringBootApplication
 ;%0Aim
@@ -510,68 +510,8 @@
 te;%0A
-import org.springframework.boot.web.server.LocalServerPort;%0A
 impo
@@ -707,23 +707,180 @@
 unit
-4.SpringRunner;
+.jupiter.SpringExtension;%0Aimport org.springframework.boot.web.server.LocalServerPort;%0Aimport org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort;%0A
 %0A%0Aim
@@ -933,16 +933,17 @@
 .then;%0A%0A
+%0A
 /**%0A * B
@@ -995,12 +995,16 @@
  */%0A
-@Run
+%0A@Extend
 With
@@ -1014,22 +1014,25 @@
 ring
-Runner
+Extension
 .class)%0A
 @Spr
@@ -1027,16 +1027,39 @@
 .class)%0A
+@SpringBootApplication%0A
 @SpringB
@@ -1098,15 +1098,34 @@
 lass
-%7D,%0A    
+, SpringConfigWeb.class%7D,%0A
     
@@ -1348,68 +1348,258 @@
 %0A%0A  
-@LocalServerPort%0A  private int port;%0A%0A  @LocalManagementPort
+// %22local%22 is not profile name, it is needed to use random port%0A  @LocalServerPort //(%22$%7Blocal.server.port%7D%22)%0A  private int port;%0A%0A  // %22local%22 is not profile name, it is needed to use random port%0A  @LocalManagementPort //(%22$%7Blocal.management.port%7D%22)
 %0A  p
@@ -1863,36 +1863,32 @@
 Entity(%0A        
-    
 %22http://localhos
@@ -2242,36 +2242,32 @@
 Entity(%0A        
-    
 %22http://localhos
@@ -2604,28 +2604,24 @@
 ty(%0A        
-    
 %22http://loca
@@ -2750,7 +2750,5 @@
   %7D%0A
-%0A%7D%0A
+%7D

Update application test to JUnit5