package de.digitalcollections.blueprints.rest.integration.tests;

import de.digitalcollections.blueprints.rest.client.HelloClient;
import de.digitalcollections.blueprints.rest.common.model.impl.Greeting;
import feign.Feign;
import feign.gson.GsonDecoder;
import java.io.File;
import org.junit.ClassRule;
import org.junit.Test;
import org.testcontainers.containers.DockerComposeContainer;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.from;

public class HelloClientTest {

  private static final String DOCKER_COMPOSE_FILE = "src/test/resources/docker-compose.yml";

  private static final String REST_SERVICE_NAME = "rest_1";

  private static final int REST_SERVICE_PORT = 9000;

  @ClassRule
  public static final DockerComposeContainer ENVIRONMENT = new DockerComposeContainer(new File(DOCKER_COMPOSE_FILE))
          .withLocalCompose(true)
          .withExposedService(REST_SERVICE_NAME, REST_SERVICE_PORT)
          .withTailChildContainers(true); // append all outputs of applications in the container to the main log

  @Test
  public void greetingShouldReturnGreetingForTheExpectedName() {
    final String targetUrl = String.format("http://%s:%d",
                                           ENVIRONMENT.getServiceHost(REST_SERVICE_NAME, REST_SERVICE_PORT),
                                           ENVIRONMENT.getServicePort(REST_SERVICE_NAME, REST_SERVICE_PORT));

    final HelloClient client = Feign.builder()
            .decoder(new GsonDecoder())
            .target(HelloClient.class, targetUrl);

    assertThat(client.greeting("Captain")).returns("Hello, Captain!", from(Greeting::getContent));
  }

}

@@ -290,35 +290,19 @@
 nit.
-ClassRule;%0Aimport org.junit
+jupiter.api
 .Tes
@@ -365,16 +365,124 @@
 tainer;%0A
+import org.testcontainers.junit.jupiter.Container;%0Aimport org.testcontainers.junit.jupiter.Testcontainers;%0A%0A
 %0Aimport 
@@ -585,16 +585,32 @@
 .from;%0A%0A
+@Testcontainers%0A
 public c
@@ -846,20 +846,61 @@
 0;%0A%0A
-  @ClassRule
+//  //@ExtendWith(SpringExtension.class)%0A  @Container
 %0A  p
@@ -1015,28 +1015,24 @@
 ILE))%0A      
-    
 .withLocalCo
@@ -1043,20 +1043,16 @@
 e(true)%0A
-    
       .w
@@ -1107,20 +1107,16 @@
 E_PORT)%0A
-    
       .w
@@ -1353,43 +1353,8 @@
 d%22,%0A
-                                   
     
@@ -1427,43 +1427,8 @@
 T),%0A
-                                   
     
@@ -1554,20 +1554,16 @@
         
-    
 .decoder
@@ -1582,20 +1582,16 @@
 oder())%0A
-    
         
@@ -1733,11 +1733,10 @@
 ));%0A  %7D%0A
-%0A
 %7D%0A

update unit tests to JUnit5: org.testcontainers needs special junit-jupiter package and @Testcontainers and @Container annotation to work properly, see also: https://github.com/testcontainers/testcontainers-java/pull/887/files