package no.cantara.dwsample;

import io.dropwizard.testing.ResourceHelpers;
import io.dropwizard.testing.junit.DropwizardAppRule;
import no.cantara.dwsample.api.Planet;
import no.cantara.dwsample.api.Saying;
import org.glassfish.jersey.client.JerseyClientBuilder;
import org.junit.ClassRule;
import org.junit.Test;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Response;

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

public class HelloWorldFullStackIntegrationTest {

    @ClassRule
    public static final DropwizardAppRule<HelloWorldDropwizardConfiguration> RULE =
            new DropwizardAppRule<>(HelloWorldApplication.class, ResourceHelpers.resourceFilePath("hello-world-test.yml"));

    @Test
    public void getHelloWorld() {
        Client client = JerseyClientBuilder.createClient();

        Response response = client.target(
                String.format("http://localhost:%d/hello-world", RULE.getLocalPort()))
                .request()
                .get();

        assertThat(response.getStatus()).isEqualTo(200);
    }

    @Test
    public void postHelloWorld() {
        Client client = JerseyClientBuilder.createClient();

        Response response = client.target(
                String.format("http://localhost:%d/hello-world", RULE.getLocalPort()))
                .request()
                .post(Entity.json(new Planet("Neptune", "Bad Santa")));

        assertThat(response.getStatus()).isEqualTo(200);
        Saying saying = response.readEntity(Saying.class);
        assertThat(saying.getContent()).isEqualTo("Hello Bad Santa on planet Neptune");
    }

}

@@ -119,24 +119,75 @@
 ardAppRule;%0A
+import no.cantara.dwsample.api.HelloWorldResource;%0A
 import no.ca
@@ -991,37 +991,51 @@
 localhost:%25d
-/h
+%22 + H
 ello
--w
+W
 orld
-%22
+Resource.PATH
 , RULE.getLo
@@ -1365,21 +1365,35 @@
 t:%25d
-/h
+%22 + H
 ello
--w
+W
 orld
-%22
+Resource.PATH
 , RU

Use path constants in HelloWorldResource from api module instead of hardcoded values.