diff options
| author | Szymon Szukalski <szymon@skas.io> | 2024-07-23 15:25:17 +1000 |
|---|---|---|
| committer | Szymon Szukalski <szymon@skas.io> | 2024-07-23 15:25:17 +1000 |
| commit | aec0dff5477cafce865410381a722fedbac04ac1 (patch) | |
| tree | 532bd7a41e9c97e1df53cf122888a77a2f7a9f00 /src/test/java/com/stileeducation/markr/controller | |
| parent | fc96ec673822d9f1cbe0e5eb004c12b7f8f2db9b (diff) | |
Implement simple /import endpoint and test
Diffstat (limited to 'src/test/java/com/stileeducation/markr/controller')
| -rw-r--r-- | src/test/java/com/stileeducation/markr/controller/TestResultsControllerTest.java | 41 |
1 files changed, 41 insertions, 0 deletions
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<String> entity = new HttpEntity<>(requestXml, headers); + ResponseEntity<String> response = restTemplate.postForEntity(IMPORT_ENDPOINT, entity, String.class); + + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); + } + +} |
