Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
Import controller advice to integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
jillurquddus committed Aug 17, 2022
1 parent fe0dac6 commit bc02be3
Showing 1 changed file with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.mock.web.MockMultipartFile;
Expand All @@ -21,11 +22,10 @@
import org.springframework.web.context.WebApplicationContext;

import ai.hyperlearning.ontopop.api.ontology.mapping.OntologyMappingController;
import ai.hyperlearning.ontopop.exceptions.webprotege.WebProtegeInvalidProjectId;
import ai.hyperlearning.ontopop.exceptions.OntoPopExceptionHandler;
import ai.hyperlearning.ontopop.webprotege.WebProtegeDownloader;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

/**
Expand All @@ -37,6 +37,7 @@

@ContextConfiguration(classes = { OntologyMappingController.class })
@WebMvcTest(controllers = OntologyMappingController.class)
@ImportAutoConfiguration(OntoPopExceptionHandler.class)
@ActiveProfiles("integration-test-mapping-api")
class TestOntologyMappingControllerIT {

Expand Down Expand Up @@ -134,8 +135,9 @@ void whenSourceInvalid_thenReturns400() throws Exception {
.file(testSmallOntologyFile)
.param(REQUEST_PARAMETER_SOURCE_NAME, "json")
.param(REQUEST_PARAMETER_TARGET_NAME, "graphson");
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(
webApplicationContext).build();
MockMvc mockMvc = MockMvcBuilders
.webAppContextSetup(webApplicationContext)
.build();
mockMvc.perform(requestBuilder)
.andExpect(status().isBadRequest());
}
Expand All @@ -147,8 +149,9 @@ void whenTargetInvalid_thenReturns400() throws Exception {
.file(testSmallOntologyFile)
.param(REQUEST_PARAMETER_SOURCE_NAME, "rdf-xml")
.param(REQUEST_PARAMETER_TARGET_NAME, "json");
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(
webApplicationContext).build();
MockMvc mockMvc = MockMvcBuilders
.webAppContextSetup(webApplicationContext)
.build();
mockMvc.perform(requestBuilder)
.andExpect(status().isBadRequest());
}
Expand All @@ -160,8 +163,9 @@ void whenFileBlank_thenReturns400() throws Exception {
.file(testBlankOntologyFile)
.param(REQUEST_PARAMETER_SOURCE_NAME, "rdf-xml")
.param(REQUEST_PARAMETER_TARGET_NAME, "graphson");
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(
webApplicationContext).build();
MockMvc mockMvc = MockMvcBuilders
.webAppContextSetup(webApplicationContext)
.build();
mockMvc.perform(requestBuilder)
.andExpect(status().isBadRequest());
}
Expand All @@ -173,8 +177,9 @@ void whenFileExtensionInvalid_thenReturns400() throws Exception {
.file(testInvalidFileExtensionOntologyFile)
.param(REQUEST_PARAMETER_SOURCE_NAME, "rdf-xml")
.param(REQUEST_PARAMETER_TARGET_NAME, "graphson");
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(
webApplicationContext).build();
MockMvc mockMvc = MockMvcBuilders
.webAppContextSetup(webApplicationContext)
.build();
mockMvc.perform(requestBuilder)
.andExpect(status().isBadRequest());
}
Expand All @@ -188,11 +193,9 @@ void whenWebProtegeIdInvalidTooShort_thenReturns400() throws Exception {
.param(REQUEST_PARAMETER_TARGET_NAME, "graphson")
.param(REQUEST_PARAMETER_WEBPROTEGEID_NAME,
invalidWebProtegeProjectId);
given(webProtegeDownloader.run(
invalidWebProtegeProjectId, null, null))
.willThrow(WebProtegeInvalidProjectId.class);
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(
webApplicationContext).build();
MockMvc mockMvc = MockMvcBuilders
.webAppContextSetup(webApplicationContext)
.build();
mockMvc.perform(requestBuilder)
.andExpect(status().isBadRequest());
}
Expand All @@ -207,11 +210,9 @@ void whenWebProtegeIdInvalidNonAlphaNumeric_thenReturns400()
.param(REQUEST_PARAMETER_TARGET_NAME, "graphson")
.param(REQUEST_PARAMETER_WEBPROTEGEID_NAME,
invalidWebProtegeProjectId);
given(webProtegeDownloader.run(
invalidWebProtegeProjectId, null, null))
.willThrow(WebProtegeInvalidProjectId.class);
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(
webApplicationContext).build();
MockMvc mockMvc = MockMvcBuilders
.webAppContextSetup(webApplicationContext)
.build();
mockMvc.perform(requestBuilder)
.andExpect(status().isBadRequest());
}
Expand All @@ -229,8 +230,9 @@ void whenFullOntologyFileValid_thenReturns200AndGraphSon()
.file(testFullOntologyFile)
.param(REQUEST_PARAMETER_SOURCE_NAME, "rdf-xml")
.param(REQUEST_PARAMETER_TARGET_NAME, "graphson");
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(
webApplicationContext).build();
MockMvc mockMvc = MockMvcBuilders
.webAppContextSetup(webApplicationContext)
.build();
MvcResult result = mockMvc.perform(requestBuilder)
.andExpect(status().isOk())
.andReturn();
Expand All @@ -251,8 +253,9 @@ void whenFullOntologyFileValid_thenReturns200AndVisDataset()
.file(testFullOntologyFile)
.param(REQUEST_PARAMETER_SOURCE_NAME, "rdf-xml")
.param(REQUEST_PARAMETER_TARGET_NAME, "vis");
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(
webApplicationContext).build();
MockMvc mockMvc = MockMvcBuilders
.webAppContextSetup(webApplicationContext)
.build();
MvcResult result = mockMvc.perform(requestBuilder)
.andExpect(status().isOk())
.andReturn();
Expand Down

0 comments on commit bc02be3

Please sign in to comment.