diff --git a/src/test/java/org/etsi/osl/services/api/scm633/ExportJobApiController633Test.java b/src/test/java/org/etsi/osl/services/api/scm633/ExportJobApiController633Test.java new file mode 100644 index 0000000000000000000000000000000000000000..1fb14261724e385ba12aefe1c1a4e482ec57c4ce --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/scm633/ExportJobApiController633Test.java @@ -0,0 +1,132 @@ +package org.etsi.osl.services.api.scm633; + +import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; + +import org.apache.commons.io.IOUtils; + +import org.etsi.osl.tmf.OpenAPISpringBoot; +import org.etsi.osl.tmf.scm633.model.*; +import org.etsi.osl.tmf.JsonUtils; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.MediaType; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.context.WebApplicationContext; + + +@RunWith(SpringRunner.class) +@Transactional +@SpringBootTest( webEnvironment = SpringBootTest.WebEnvironment.MOCK , classes = OpenAPISpringBoot.class) +@AutoConfigureTestDatabase +@AutoConfigureMockMvc +@ActiveProfiles("testing") +public class ExportJobApiController633Test { + + @Autowired + private MockMvc mvc; + + @Autowired + private WebApplicationContext context; + + @Before + public void setup() { + mvc = MockMvcBuilders + .webAppContextSetup(context) + .apply(springSecurity()) + .build(); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testCreateExportJob() throws Exception { + + File resourceSpecFile = new File("src/test/resources/testExportJob.json"); + InputStream in = new FileInputStream(resourceSpecFile); + String exportJobString = IOUtils.toString(in, "UTF-8"); + ExportJobCreate exportJobCreate = JsonUtils.toJsonObj(exportJobString, ExportJobCreate.class); + + // Test when providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/exportJob") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( exportJobCreate ) )) + .andExpect(status().is(501)); + + // Test when not providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/exportJob") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( exportJobCreate ) )) + .andExpect(status().is(501)); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testDeleteExportJob() throws Exception { + + mvc.perform(MockMvcRequestBuilders.delete("/serviceCatalogManagement/v4/exportJob/testId") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().is(501)); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testListExportJob() throws Exception { + + // Test when providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/exportJob") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().is(501)); + + // Test when not providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/exportJob") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().is(501)); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testRetrieveExportJob() throws Exception { + + // Test when providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/exportJob?testId") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().is(501)); + + // Test when not providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/exportJob/testId") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().is(501)); + } +} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/scm633/HubApiControllerTest.java b/src/test/java/org/etsi/osl/services/api/scm633/HubApiControllerTest.java new file mode 100644 index 0000000000000000000000000000000000000000..81de42a4ae2d98d3624a625fd899b4fe63553aa9 --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/scm633/HubApiControllerTest.java @@ -0,0 +1,94 @@ +package org.etsi.osl.services.api.scm633; + +import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; + +import org.apache.commons.io.IOUtils; + +import org.etsi.osl.tmf.OpenAPISpringBoot; +import org.etsi.osl.tmf.scm633.model.*; +import org.etsi.osl.tmf.JsonUtils; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.MediaType; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.context.WebApplicationContext; + + +@RunWith(SpringRunner.class) +@Transactional +@SpringBootTest( webEnvironment = SpringBootTest.WebEnvironment.MOCK , classes = OpenAPISpringBoot.class) +@AutoConfigureTestDatabase +@AutoConfigureMockMvc +@ActiveProfiles("testing") +public class HubApiControllerTest { + + @Autowired + private MockMvc mvc; + + @Autowired + private WebApplicationContext context; + + @Before + public void setup() { + mvc = MockMvcBuilders + .webAppContextSetup(context) + .apply(springSecurity()) + .build(); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testRegisterListener() throws Exception { + + File resourceSpecFile = new File("src/test/resources/testEventSubscriptionInput.json"); + InputStream in = new FileInputStream(resourceSpecFile); + String eventSubscriptionInputString = IOUtils.toString(in, "UTF-8"); + EventSubscriptionInput eventSubscriptionInput = JsonUtils.toJsonObj(eventSubscriptionInputString, EventSubscriptionInput.class); + + // Test when providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/hub") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( eventSubscriptionInput ) )) + .andExpect(status().is(501)); + + // Test when not providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/hub") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( eventSubscriptionInput ) )) + .andExpect(status().is(501)); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testUnregisterListener() throws Exception { + + mvc.perform(MockMvcRequestBuilders.delete("/serviceCatalogManagement/v4/hub/testId") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().is(501)); + } +} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/scm633/ImportJobApiControllerTest.java b/src/test/java/org/etsi/osl/services/api/scm633/ImportJobApiControllerTest.java new file mode 100644 index 0000000000000000000000000000000000000000..2b8a0f3d3265bb85ec0f79f308fef5830a1a5e32 --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/scm633/ImportJobApiControllerTest.java @@ -0,0 +1,132 @@ +package org.etsi.osl.services.api.scm633; + +import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; + +import org.apache.commons.io.IOUtils; + +import org.etsi.osl.tmf.OpenAPISpringBoot; +import org.etsi.osl.tmf.scm633.model.*; +import org.etsi.osl.tmf.JsonUtils; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.MediaType; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.context.WebApplicationContext; + + +@RunWith(SpringRunner.class) +@Transactional +@SpringBootTest( webEnvironment = SpringBootTest.WebEnvironment.MOCK , classes = OpenAPISpringBoot.class) +@AutoConfigureTestDatabase +@AutoConfigureMockMvc +@ActiveProfiles("testing") +public class ImportJobApiControllerTest { + + @Autowired + private MockMvc mvc; + + @Autowired + private WebApplicationContext context; + + @Before + public void setup() { + mvc = MockMvcBuilders + .webAppContextSetup(context) + .apply(springSecurity()) + .build(); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testCreateImportJob() throws Exception { + + File resourceSpecFile = new File("src/test/resources/testExportJob.json"); + InputStream in = new FileInputStream(resourceSpecFile); + String exportJobString = IOUtils.toString(in, "UTF-8"); + ExportJobCreate exportJobCreate = JsonUtils.toJsonObj(exportJobString, ExportJobCreate.class); + + // Test when providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/importJob") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( exportJobCreate ) )) + .andExpect(status().is(501)); + + // Test when not providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/importJob") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( exportJobCreate ) )) + .andExpect(status().is(501)); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testDeleteImportJob() throws Exception { + + mvc.perform(MockMvcRequestBuilders.delete("/serviceCatalogManagement/v4/importJob/testId") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().is(501)); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testListImportJob() throws Exception { + + // Test when providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/importJob") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().is(501)); + + // Test when not providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/importJob") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().is(501)); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testRetrieveImportJob() throws Exception { + + // Test when providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/importJob?testId") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().is(501)); + + // Test when not providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/importJob/testId") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().is(501)); + } +} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/scm633/ListenerApiControllerTest.java b/src/test/java/org/etsi/osl/services/api/scm633/ListenerApiControllerTest.java new file mode 100644 index 0000000000000000000000000000000000000000..013aff739c9802b8f385d68e9d4c88089b924574 --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/scm633/ListenerApiControllerTest.java @@ -0,0 +1,394 @@ +package org.etsi.osl.services.api.scm633; + +import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; + +import org.apache.commons.io.IOUtils; + +import org.etsi.osl.tmf.OpenAPISpringBoot; +import org.etsi.osl.tmf.scm633.model.*; +import org.etsi.osl.tmf.JsonUtils; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.MediaType; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.context.WebApplicationContext; + + +@RunWith(SpringRunner.class) +@Transactional +@SpringBootTest( webEnvironment = SpringBootTest.WebEnvironment.MOCK , classes = OpenAPISpringBoot.class) +@AutoConfigureTestDatabase +@AutoConfigureMockMvc +@ActiveProfiles("testing") +public class ListenerApiControllerTest { + + @Autowired + private MockMvc mvc; + + @Autowired + private WebApplicationContext context; + + @Before + public void setup() { + mvc = MockMvcBuilders + .webAppContextSetup(context) + .apply(springSecurity()) + .build(); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testListenToServiceCandidateChangeNotification() throws Exception { + + File resourceSpecFile = new File("src/test/resources/testServiceCandidateChangeNotification.json"); + InputStream in = new FileInputStream(resourceSpecFile); + String changeNotificationString = IOUtils.toString(in, "UTF-8"); + ServiceCandidateChangeNotification serviceCandidateChangeNotification = JsonUtils.toJsonObj(changeNotificationString, ServiceCandidateChangeNotification.class); + + // Test when providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCandidateChangeNotification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceCandidateChangeNotification ) )) + .andExpect(status().is(501)); + + // Test when not providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCandidateChangeNotification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceCandidateChangeNotification ) )) + .andExpect(status().is(501)); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testListenToServiceCandidateCreateNotification() throws Exception { + + File resourceSpecFile = new File("src/test/resources/testServiceCandidateChangeNotification.json"); + InputStream in = new FileInputStream(resourceSpecFile); + String createNotificationString = IOUtils.toString(in, "UTF-8"); + ServiceCandidateCreateNotification serviceCandidateCreateNotification = JsonUtils.toJsonObj(createNotificationString, ServiceCandidateCreateNotification.class); + + // Test when providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCandidateCreateNotification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceCandidateCreateNotification ) )) + .andExpect(status().is(501)); + + // Test when not providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCandidateCreateNotification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceCandidateCreateNotification ) )) + .andExpect(status().is(501)); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testListenToServiceCandidateDeleteNotification() throws Exception { + + File resourceSpecFile = new File("src/test/resources/testServiceCandidateChangeNotification.json"); + InputStream in = new FileInputStream(resourceSpecFile); + String deleteNotificationString = IOUtils.toString(in, "UTF-8"); + ServiceCandidateDeleteNotification serviceCandidateDeleteNotification = JsonUtils.toJsonObj(deleteNotificationString, ServiceCandidateDeleteNotification.class); + + // Test when providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCandidateDeleteNotification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceCandidateDeleteNotification ) )) + .andExpect(status().is(501)); + + // Test when not providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCandidateDeleteNotification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceCandidateDeleteNotification ) )) + .andExpect(status().is(501)); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testListenToServiceCatalogBatchNotification() throws Exception { + + File resourceSpecFile = new File("src/test/resources/testServiceCandidateChangeNotification.json"); + InputStream in = new FileInputStream(resourceSpecFile); + String batchNotificationString = IOUtils.toString(in, "UTF-8"); + ServiceCatalogBatchNotification serviceCatalogBatchNotification = JsonUtils.toJsonObj(batchNotificationString, ServiceCatalogBatchNotification.class); + + // Test when providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCatalogBatchNotification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceCatalogBatchNotification ) )) + .andExpect(status().is(501)); + + // Test when not providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCatalogBatchNotification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceCatalogBatchNotification ) )) + .andExpect(status().is(501)); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testListenToServiceCatalogChangeNotification() throws Exception { + + File resourceSpecFile = new File("src/test/resources/testServiceCandidateChangeNotification.json"); + InputStream in = new FileInputStream(resourceSpecFile); + String changeNotificationString = IOUtils.toString(in, "UTF-8"); + ServiceCatalogChangeNotification serviceCatalogChangeNotification = JsonUtils.toJsonObj(changeNotificationString, ServiceCatalogChangeNotification.class); + + // Test when providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCatalogChangeNotification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceCatalogChangeNotification ) )) + .andExpect(status().is(501)); + + // Test when not providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCatalogChangeNotification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceCatalogChangeNotification ) )) + .andExpect(status().is(501)); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testListenToServiceCatalogCreateNotification() throws Exception { + + File resourceSpecFile = new File("src/test/resources/testServiceCandidateChangeNotification.json"); + InputStream in = new FileInputStream(resourceSpecFile); + String createNotificationString = IOUtils.toString(in, "UTF-8"); + ServiceCatalogCreateNotification serviceCatalogCreateNotification = JsonUtils.toJsonObj(createNotificationString, ServiceCatalogCreateNotification.class); + + // Test when providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCatalogCreateNotification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceCatalogCreateNotification ) )) + .andExpect(status().is(501)); + + // Test when not providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCatalogCreateNotification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceCatalogCreateNotification ) )) + .andExpect(status().is(501)); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testListenToServiceCatalogDeleteNotification() throws Exception { + + File resourceSpecFile = new File("src/test/resources/testServiceCandidateChangeNotification.json"); + InputStream in = new FileInputStream(resourceSpecFile); + String deleteNotificationString = IOUtils.toString(in, "UTF-8"); + ServiceCatalogDeleteNotification serviceCatalogDeleteNotification = JsonUtils.toJsonObj(deleteNotificationString, ServiceCatalogDeleteNotification.class); + + // Test when providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCatalogDeleteNotification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceCatalogDeleteNotification ) )) + .andExpect(status().is(501)); + + // Test when not providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCatalogDeleteNotification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceCatalogDeleteNotification ) )) + .andExpect(status().is(501)); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testListenToServiceCategoryChangeNotification() throws Exception { + + File resourceSpecFile = new File("src/test/resources/testServiceCandidateChangeNotification.json"); + InputStream in = new FileInputStream(resourceSpecFile); + String changeNotificationString = IOUtils.toString(in, "UTF-8"); + ServiceCategoryChangeNotification serviceCategoryChangeNotification = JsonUtils.toJsonObj(changeNotificationString, ServiceCategoryChangeNotification.class); + + // Test when providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCategoryChangeNotification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceCategoryChangeNotification ) )) + .andExpect(status().is(501)); + + // Test when not providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCategoryChangeNotification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceCategoryChangeNotification ) )) + .andExpect(status().is(501)); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testListenToServiceCategoryCreateNotification() throws Exception { + + File resourceSpecFile = new File("src/test/resources/testServiceCandidateChangeNotification.json"); + InputStream in = new FileInputStream(resourceSpecFile); + String createNotificationString = IOUtils.toString(in, "UTF-8"); + ServiceCategoryCreateNotification serviceCategoryCreateNotification = JsonUtils.toJsonObj(createNotificationString, ServiceCategoryCreateNotification.class); + + // Test when providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCategoryCreateNotification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceCategoryCreateNotification ) )) + .andExpect(status().is(501)); + + // Test when not providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCategoryCreateNotification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceCategoryCreateNotification ) )) + .andExpect(status().is(501)); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testListenToServiceCategoryDeleteNotification() throws Exception { + + File resourceSpecFile = new File("src/test/resources/testServiceCandidateChangeNotification.json"); + InputStream in = new FileInputStream(resourceSpecFile); + String deleteNotificationString = IOUtils.toString(in, "UTF-8"); + ServiceCategoryDeleteNotification serviceCategoryDeleteNotification = JsonUtils.toJsonObj(deleteNotificationString, ServiceCategoryDeleteNotification.class); + + // Test when providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCategoryDeleteNotification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceCategoryDeleteNotification ) )) + .andExpect(status().is(501)); + + // Test when not providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceCategoryDeleteNotification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceCategoryDeleteNotification ) )) + .andExpect(status().is(501)); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testListenToServiceSpecificationChangeNotification() throws Exception { + + File resourceSpecFile = new File("src/test/resources/testServiceCandidateChangeNotification.json"); + InputStream in = new FileInputStream(resourceSpecFile); + String changeNotificationString = IOUtils.toString(in, "UTF-8"); + ServiceSpecificationChangeNotification serviceSpecificationChangeNotification = JsonUtils.toJsonObj(changeNotificationString, ServiceSpecificationChangeNotification.class); + + // Test when providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceSpecificationChangeNotification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceSpecificationChangeNotification ) )) + .andExpect(status().is(501)); + + // Test when not providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceSpecificationChangeNotification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceSpecificationChangeNotification ) )) + .andExpect(status().is(501)); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testListenToServiceSpecificationCreateNotification() throws Exception { + + File resourceSpecFile = new File("src/test/resources/testServiceCandidateChangeNotification.json"); + InputStream in = new FileInputStream(resourceSpecFile); + String createNotificationString = IOUtils.toString(in, "UTF-8"); + ServiceSpecificationCreateNotification serviceSpecificationCreateNotification = JsonUtils.toJsonObj(createNotificationString, ServiceSpecificationCreateNotification.class); + + // Test when providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceSpecificationCreateNotification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceSpecificationCreateNotification ) )) + .andExpect(status().is(501)); + + // Test when not providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceSpecificationCreateNotification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceSpecificationCreateNotification ) )) + .andExpect(status().is(501)); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testListenToServiceSpecificationDeleteNotification() throws Exception { + + File resourceSpecFile = new File("src/test/resources/testServiceCandidateChangeNotification.json"); + InputStream in = new FileInputStream(resourceSpecFile); + String deleteNotificationString = IOUtils.toString(in, "UTF-8"); + ServiceSpecificationDeleteNotification serviceSpecificationDeleteNotification = JsonUtils.toJsonObj(deleteNotificationString, ServiceSpecificationDeleteNotification.class); + + // Test when providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceSpecificationDeleteNotification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceSpecificationDeleteNotification ) )) + .andExpect(status().is(501)); + + // Test when not providing an "Accept" request header + mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/listener/serviceSpecificationDeleteNotification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceSpecificationDeleteNotification ) )) + .andExpect(status().is(501)); + } +} \ No newline at end of file diff --git a/src/test/resources/testEventSubscriptionInput.json b/src/test/resources/testEventSubscriptionInput.json new file mode 100644 index 0000000000000000000000000000000000000000..bccdb0cdb7f50e92a7ac57abcd18cbe28d5be28e --- /dev/null +++ b/src/test/resources/testEventSubscriptionInput.json @@ -0,0 +1,3 @@ +{ + "query": "test" +} \ No newline at end of file diff --git a/src/test/resources/testExportJob.json b/src/test/resources/testExportJob.json new file mode 100644 index 0000000000000000000000000000000000000000..cb006da88796f2874e9c144291833106c0c747ba --- /dev/null +++ b/src/test/resources/testExportJob.json @@ -0,0 +1,4 @@ +{ + "contentType": "application/json", + "url": "https://my/daily/job/NHCFD6" +} \ No newline at end of file diff --git a/src/test/resources/testServiceCandidateChangeNotification.json b/src/test/resources/testServiceCandidateChangeNotification.json new file mode 100644 index 0000000000000000000000000000000000000000..83442e8e267ea97db23f53bd0557c0845e6ce818 --- /dev/null +++ b/src/test/resources/testServiceCandidateChangeNotification.json @@ -0,0 +1,3 @@ +{ + "eventId": "testId" +} \ No newline at end of file