package at.gv.egiz.moazs; import org.junit.Test; import org.junit.runner.RunWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.nio.file.Paths; import static java.net.http.HttpClient.*; import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) public class App2MzsServiceTest { private final String serviceUri = "http://localhost:8080/services/DeliveryRequest"; private final String basePath = "src/test/resources/at/gv/egiz/moazs/App2MzsServiceTest/"; Logger logger = LoggerFactory.getLogger(App2MzsServiceTest.class); @Test public void acceptValidDeliveryRequest() throws IOException, InterruptedException { final String payloadFile = basePath + "validDeliveryRequest.soap"; var client = HttpClient.newBuilder().version(Version.HTTP_1_1).build(); var request = HttpRequest.newBuilder() .uri(URI.create(serviceUri)) .header("Content-Type", "text/xml;charset=UTF-8") .header("SOAPAction", "\"\"") .POST(HttpRequest.BodyPublishers.ofFile(Paths.get(payloadFile))) .build(); var response = client.send(request, HttpResponse.BodyHandlers.ofString()); logger.info("response.body was " + response.body()); logger.info("response.code was " + response.statusCode()); //TODO Verify response } @Test public void rejectFormallyIncorrectDeliveryRequest() throws IOException, InterruptedException { var invalidDeliveryRequest = basePath + "formallyIncorrectDeliveryRequest.soap"; var client = HttpClient.newBuilder().version(Version.HTTP_1_1).build(); var request = HttpRequest.newBuilder() .uri(URI.create(serviceUri)) .header("Content-Type", "text/xml;charset=UTF-8") .header("SOAPAction", "\"\"") .POST(HttpRequest.BodyPublishers.ofFile(Paths.get(invalidDeliveryRequest))) .build(); var response = client.send(request, HttpResponse.BodyHandlers.ofString()); assertThat(response.statusCode()).isEqualTo(500); } }