From aec0dff5477cafce865410381a722fedbac04ac1 Mon Sep 17 00:00:00 2001 From: Szymon Szukalski Date: Tue, 23 Jul 2024 15:25:17 +1000 Subject: Implement simple /import endpoint and test --- .../markr/config/XmlMapperConfig.java | 14 ++++++++ .../controller/TestResultsControllerTest.java | 41 ++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/test/java/com/stileeducation/markr/config/XmlMapperConfig.java create mode 100644 src/test/java/com/stileeducation/markr/controller/TestResultsControllerTest.java (limited to 'src/test') diff --git a/src/test/java/com/stileeducation/markr/config/XmlMapperConfig.java b/src/test/java/com/stileeducation/markr/config/XmlMapperConfig.java new file mode 100644 index 0000000..470c1f9 --- /dev/null +++ b/src/test/java/com/stileeducation/markr/config/XmlMapperConfig.java @@ -0,0 +1,14 @@ +package com.stileeducation.markr.config; + +import com.fasterxml.jackson.dataformat.xml.XmlMapper; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class XmlMapperConfig { + + @Bean + public XmlMapper xmlMapper() { + return new XmlMapper(); + } +} diff --git a/src/test/java/com/stileeducation/markr/controller/TestResultsControllerTest.java b/src/test/java/com/stileeducation/markr/controller/TestResultsControllerTest.java new file mode 100644 index 0000000..4db9008 --- /dev/null +++ b/src/test/java/com/stileeducation/markr/controller/TestResultsControllerTest.java @@ -0,0 +1,41 @@ +package com.stileeducation.markr.controller; + +import com.fasterxml.jackson.dataformat.xml.XmlMapper; +import com.stileeducation.markr.dto.MCQTestResultsDTO; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.test.web.server.LocalServerPort; +import org.springframework.http.*; + +import static com.stileeducation.markr.controller.TestResultsController.IMPORT_ENDPOINT; +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class TestResultsControllerTest { + + @LocalServerPort + private int port; + + @Autowired + private XmlMapper xmlMapper; + + @Autowired + private TestRestTemplate restTemplate; + + @Test + public void testImport() throws Exception { + MCQTestResultsDTO request = new MCQTestResultsDTO(); + String requestXml = xmlMapper.writeValueAsString(request); + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_XML); + + HttpEntity entity = new HttpEntity<>(requestXml, headers); + ResponseEntity response = restTemplate.postForEntity(IMPORT_ENDPOINT, entity, String.class); + + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); + } + +} -- cgit v1.2.3