Skip to content
Snippets Groups Projects
Commit 199ae1d4 authored by Andrej Zabka's avatar Andrej Zabka
Browse files

added integration test for other modules aswell

parent c29f50f8
No related branches found
No related tags found
2 merge requests!54Merge develop into main,!15Final milestone1 cleanup
......@@ -98,12 +98,12 @@ paths:
birthday:
type: string
description: Date of birth
example: 09-30-1997
example: 1977-09-30
format: date
fillingOutDate:
type: string
description: Date of filling out the application
example: 09-30-1997
example: 2023-01-01
format: date
required:
- name
......
package cz.muni.pa165.rest;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
/**
* Integration tests. Run by "mvn verify / mvn test / mvn clean install".
* No need to test all the rest controllers logic here, just test that the endpoints are working
*/
@SpringBootTest
@AutoConfigureMockMvc
class IntegrationTests {
private static final Logger log = LoggerFactory.getLogger(IntegrationTests.class);
@Autowired
private MockMvc mockMvc;
@Test
void testApplicationModuleResponse() throws Exception {
log.info("testApplicationModuleResponse() running");
String testRequestContent = "{\"name\":\"John\",\"surname\":\"Doe\",\"fillingOutDate\":\"2023-01-01\"}";
String response = mockMvc.perform(
post("/application")
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)
.content(testRequestContent))
.andExpect(status().isOk())
.andReturn().getResponse().getContentAsString();
log.info("response: {}", response);
String expectedResponse = "{\"id\":1,\"name\":\"John\",\"surname\":\"Doe\",\"birthday\":null,\"fillingOutDate\":\"2023-01-01\",\"status\":null}";
assertEquals(expectedResponse, response);
}
}
\ No newline at end of file
......@@ -30,7 +30,7 @@ class IntegrationTests {
@Test
void testCarControllerResponse() throws Exception {
log.debug("testCarControllerResponse() running");
log.info("testCarControllerResponse() running");
String testRequestContent = "{ \"components\": [] }";
......@@ -41,7 +41,7 @@ class IntegrationTests {
.content(testRequestContent))
.andExpect(status().isOk())
.andReturn().getResponse().getContentAsString();
log.debug("response: {}", response);
log.info("response: {}", response);
String expectedResponse = "{\"id\":1,\"components\":[],\"driver\":null}";
......@@ -50,7 +50,7 @@ class IntegrationTests {
@Test
void testComponentControllerResponse() throws Exception {
log.debug("testComponentControllerResponse() running");
log.info("testComponentControllerResponse() running");
String testRequestContent = "{ \"componentType\": \"chassis\"," +
" \"weight\": 50.5," +
......@@ -63,7 +63,7 @@ class IntegrationTests {
.content(testRequestContent))
.andExpect(status().isOk())
.andReturn().getResponse().getContentAsString();
log.debug("response: {}", response);
log.info("response: {}", response);
String expectedResponse = "{\"id\":1,\"componentType\":\"chassis\",\"weight\":50.5," +
"\"information\":\"lightweight front wing v2 (black)\"}";
......@@ -73,7 +73,7 @@ class IntegrationTests {
@Test
void testCreateDriverResponse() throws Exception {
log.debug("testCreateDriverResponse() running");
log.info("testCreateDriverResponse() running");
String testRequestContent = "{ \"name\": \"John\"," +
"\"surname\": \"Doe\"," +
......@@ -89,7 +89,7 @@ class IntegrationTests {
.content(testRequestContent))
.andExpect(status().isOk())
.andReturn().getResponse().getContentAsString();
log.debug("response: {}", response);
log.info("response: {}", response);
String expectedResponse = "{\"id\":1," +
"\"name\":\"John\"," +
......@@ -104,7 +104,7 @@ class IntegrationTests {
@Test
void testDepartmentControllerResponse() throws Exception {
log.debug("testDepartmentControllerResponse() running");
log.info("testDepartmentControllerResponse() running");
String testRequestContent = "{ \"specialization\": \"aero\" }";
......@@ -115,7 +115,7 @@ class IntegrationTests {
.content(testRequestContent))
.andExpect(status().isOk())
.andReturn().getResponse().getContentAsString();
log.debug("response: {}", response);
log.info("response: {}", response);
String expectedResponse = "{\"id\":0,\"engineers\":null,\"specialization\":\"aero\"}";
......
package cz.muni.pa165.rest;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
/**
* Integration tests. Run by "mvn verify / mvn test / mvn clean install".
* No need to test all the rest controllers logic here, just test that the endpoints are working
*/
@SpringBootTest
@AutoConfigureMockMvc
class IntegrationTests {
private static final Logger log = LoggerFactory.getLogger(IntegrationTests.class);
@Autowired
private MockMvc mockMvc;
@Test
void testNotificationModuleResponse() throws Exception {
log.info("testNotificationModuleResponse() running");
String testRequestContent = "{\"message\":\"Hello\",\"receivers\":[]}";
String response = mockMvc.perform(
post("/notification")
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)
.content(testRequestContent))
.andExpect(status().isOk())
.andReturn().getResponse().getContentAsString();
log.info("response: {}", response);
String expectedResponse = "{\"message\":\"Hello\",\"subject\":null,\"receivers\":[],\"sender\":{\"emailAddress\":\"noreply@formula1.com\"}}";
assertEquals(expectedResponse, response);
}
}
\ No newline at end of file
......@@ -20,14 +20,31 @@ components:
message:
type: string
description: short message
VisualizationRequestSchema:
type: object
title: VisualizationRequest
description: data to visualize
required:
- data
properties:
data:
type: string
description: data about cars
paths:
/visualization/get:
get:
/visualization:
post:
tags:
- Visualization
summary: Creates a visualization of given JSON
operationId: getVisualization
requestBody:
required: true
description: Request body with receiver and message for new notification
content:
application/json:
schema:
$ref: '#/components/schemas/VisualizationRequestSchema'
responses:
"200":
description: OK
......
package cz.muni.pa165.rest;
import cz.muni.pa165.generated.api.VisualizationApiDelegate;
import cz.muni.pa165.generated.model.VisualizationRequestSchema;
import cz.muni.pa165.generated.model.VisualizationSchema;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
......@@ -13,7 +14,7 @@ public class VisualizationController implements VisualizationApiDelegate {
private static final Logger log = LoggerFactory.getLogger(VisualizationController.class);
@Override
public ResponseEntity<VisualizationSchema> getVisualization() {
public ResponseEntity<VisualizationSchema> getVisualization(VisualizationRequestSchema visualizationRequestSchema) {
log.debug("getVisualization() called");
return new ResponseEntity<>(new VisualizationSchema().message("--VISUALIZATION--"), HttpStatus.OK);
......
package cz.muni.pa165.rest;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
/**
* Integration tests. Run by "mvn verify / mvn test / mvn clean install".
* No need to test all the rest controllers logic here, just test that the endpoints are working
*/
@SpringBootTest
@AutoConfigureMockMvc
class IntegrationTests {
private static final Logger log = LoggerFactory.getLogger(IntegrationTests.class);
@Autowired
private MockMvc mockMvc;
@Test
void testVisualizationModuleResponse() throws Exception {
log.info("testVisualizationModuleResponse() running");
String testRequestContent = "{\"data\":\"Hello\"}";
String response = mockMvc.perform(
post("/visualization")
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)
.content(testRequestContent))
.andExpect(status().isOk())
.andReturn().getResponse().getContentAsString();
log.info("response: {}", response);
String expectedResponse = "{\"message\":\"--VISUALIZATION--\"}";
assertEquals(expectedResponse, response);
}
}
\ No newline at end of file
package cz.muni.pa165.rest;
import cz.muni.pa165.generated.model.VisualizationRequestSchema;
import cz.muni.pa165.generated.model.VisualizationSchema;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
......@@ -21,7 +22,7 @@ class VisualizationControllerTest {
void testGetVisualization() {
log.debug("testGetVisualization() running");
ResponseEntity<VisualizationSchema> responseEntity = visualizationController.getVisualization();
ResponseEntity<VisualizationSchema> responseEntity = visualizationController.getVisualization(new VisualizationRequestSchema().data("test"));
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
assertNotNull(responseEntity.getBody());
assertEquals("--VISUALIZATION--", responseEntity.getBody().getMessage());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment