summaryrefslogtreecommitdiff
path: root/src/test/java/com/stileeducation/markr/controller/TestResultsControllerTest.java
blob: 4db90088b7add1f069db415f35d91dde9d0677a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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);
  }

}