Skip to content
Snippets Groups Projects
Commit 6e12a06f authored by Žofia Tunová's avatar Žofia Tunová
Browse files

Merge branch 'resources-test' into 'development'

Resources test

See merge request !18
parents 95b2056a 1980d38b
No related branches found
No related tags found
2 merge requests!20Milestone 2,!18Resources test
Pipeline #
Showing
with 107 additions and 7 deletions
......@@ -13,7 +13,7 @@
<modules>
<module>resources-management</module>
<module>flight-management</module>
<module>steward-management</module>
<module>steward-management</module>
</modules>
<parent>
......
......@@ -59,6 +59,17 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<argLine>-Dspring.profiles.active=test</argLine>
</configuration>
</plugin>
</plugins>
</build>
......@@ -141,6 +152,12 @@
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package cz.muni.fi.pa165.controller;
package cz.muni.fi.pa165.resources.controller;
import cz.muni.fi.pa165.generated.model.AirplaneDTO;
import cz.muni.fi.pa165.resources.controller.AirplanesController;
......
package cz.muni.fi.pa165.resources.controller;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import cz.muni.fi.pa165.generated.model.AirplaneDTO;
import cz.muni.fi.pa165.resources.data.repository.AirplaneRepository;
import cz.muni.fi.pa165.resources.model.Airplane;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
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.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
import java.util.List;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@ActiveProfiles("test")
@SpringBootTest
@AutoConfigureMockMvc
public class AirplanesControllerIT {
private final Airplane TEST_AIRPLANE1 = new Airplane();
private final Airplane TEST_AIRPLANE2 = new Airplane();
private final ObjectMapper objectMapper = new ObjectMapper();
@Autowired
private AirplaneRepository airplaneRepository;
@Autowired
private MockMvc mockMvc;
@BeforeEach
public void setup() {
TEST_AIRPLANE1.setId(1L);
TEST_AIRPLANE1.setName("Airplane 1");
TEST_AIRPLANE1.setType("Boeing 747");
TEST_AIRPLANE1.setCapacity(100);
TEST_AIRPLANE2.setId(2L);
TEST_AIRPLANE2.setName("Airplane 2");
TEST_AIRPLANE2.setType("Airbus A380");
TEST_AIRPLANE2.setCapacity(200);
}
@Test
void listAirplanes_returnsAirplanes() throws Exception {
airplaneRepository.save(TEST_AIRPLANE1);
airplaneRepository.save(TEST_AIRPLANE2);
String response = mockMvc.perform(get("/airplanes"))
.andExpect(status().isOk())
.andReturn().getResponse().getContentAsString();
List<AirplaneDTO> entities = objectMapper.readValue(response, new TypeReference<>() {});
assertThat(entities.size()).isEqualTo(2);
assertThat(entities.get(0).getId()).isEqualTo(TEST_AIRPLANE1.getId());
assertThat(entities.get(0).getName()).isEqualTo(TEST_AIRPLANE1.getName());
assertThat(entities.get(0).getType()).isEqualTo(TEST_AIRPLANE1.getType());
assertThat(entities.get(0).getCapacity()).isEqualTo(TEST_AIRPLANE1.getCapacity());
assertThat(entities.get(1).getId()).isEqualTo(TEST_AIRPLANE2.getId());
assertThat(entities.get(1).getName()).isEqualTo(TEST_AIRPLANE2.getName());
assertThat(entities.get(1).getType()).isEqualTo(TEST_AIRPLANE2.getType());
assertThat(entities.get(1).getCapacity()).isEqualTo(TEST_AIRPLANE2.getCapacity());
}
}
package cz.muni.fi.pa165.controller;
package cz.muni.fi.pa165.resources.controller;
import cz.muni.fi.pa165.generated.model.DestinationDTO;
import cz.muni.fi.pa165.resources.controller.DestinationsController;
......
package cz.muni.fi.pa165.facade;
package cz.muni.fi.pa165.resources.facade;
import cz.muni.fi.pa165.generated.model.AirplaneDTO;
import cz.muni.fi.pa165.resources.exceptions.ResourceNotFoundException;
......
package cz.muni.fi.pa165.facade;
package cz.muni.fi.pa165.resources.facade;
import cz.muni.fi.pa165.generated.model.DestinationDTO;
import cz.muni.fi.pa165.resources.exceptions.ResourceNotFoundException;
......
package cz.muni.fi.pa165.service;
package cz.muni.fi.pa165.resources.service;
import cz.muni.fi.pa165.generated.model.AirplaneDTO;
import cz.muni.fi.pa165.resources.data.repository.AirplaneRepository;
......
package cz.muni.fi.pa165.service;
package cz.muni.fi.pa165.resources.service;
import cz.muni.fi.pa165.generated.model.DestinationDTO;
import cz.muni.fi.pa165.resources.data.repository.DestinationRepository;
......
spring.datasource.url=jdbc:h2:mem:testdb;MODE=PostgreSQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username=resources-management-test
spring.datasource.password=
spring.datasource.driverClassName=org.h2.Driver
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.show_sql=false
spring.h2.console.enabled=true
\ No newline at end of file
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