From 041f149e06204345f61b5c75b56ccbe8fa6f03ba Mon Sep 17 00:00:00 2001 From: Nikolaos Kyriakoulis Date: Tue, 30 Jan 2024 12:13:02 +0200 Subject: [PATCH 01/10] Added tests for non-implemented methods of Import Job, Export Job, Hub and Listener Api Controllers in tmf.api.scm633 --- .../scm633/ExportJobApiController633Test.java | 132 ++++++ .../api/scm633/HubApiControllerTest.java | 94 +++++ .../scm633/ImportJobApiControllerTest.java | 132 ++++++ .../api/scm633/ListenerApiControllerTest.java | 394 ++++++++++++++++++ .../resources/testEventSubscriptionInput.json | 3 + src/test/resources/testExportJob.json | 4 + ...estServiceCandidateChangeNotification.json | 3 + 7 files changed, 762 insertions(+) create mode 100644 src/test/java/org/etsi/osl/services/api/scm633/ExportJobApiController633Test.java create mode 100644 src/test/java/org/etsi/osl/services/api/scm633/HubApiControllerTest.java create mode 100644 src/test/java/org/etsi/osl/services/api/scm633/ImportJobApiControllerTest.java create mode 100644 src/test/java/org/etsi/osl/services/api/scm633/ListenerApiControllerTest.java create mode 100644 src/test/resources/testEventSubscriptionInput.json create mode 100644 src/test/resources/testExportJob.json create mode 100644 src/test/resources/testServiceCandidateChangeNotification.json 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 0000000..1fb1426 --- /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 0000000..81de42a --- /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 0000000..2b8a0f3 --- /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 0000000..013aff7 --- /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 0000000..bccdb0c --- /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 0000000..cb006da --- /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 0000000..83442e8 --- /dev/null +++ b/src/test/resources/testServiceCandidateChangeNotification.json @@ -0,0 +1,3 @@ +{ + "eventId": "testId" +} \ No newline at end of file -- GitLab From a0b1c77e982e9ff6e3c3f5cb9afca3db79692151 Mon Sep 17 00:00:00 2001 From: Nikolaos Kyriakoulis Date: Thu, 1 Feb 2024 14:20:18 +0200 Subject: [PATCH 02/10] Added tests for methods of Service Catalog, Service Category and Service Specification Api Controllers in tmf.api.scm633 --- .../ServiceCatalogApiControllerTest.java | 188 ++++++++ .../ServiceCategoryApiControllerTest.java | 87 ++++ ...ServiceSpecificationApiControllerTest.java | 428 ++++++++++++++++++ 3 files changed, 703 insertions(+) create mode 100644 src/test/java/org/etsi/osl/services/api/scm633/ServiceCatalogApiControllerTest.java create mode 100644 src/test/java/org/etsi/osl/services/api/scm633/ServiceCategoryApiControllerTest.java create mode 100644 src/test/java/org/etsi/osl/services/api/scm633/ServiceSpecificationApiControllerTest.java diff --git a/src/test/java/org/etsi/osl/services/api/scm633/ServiceCatalogApiControllerTest.java b/src/test/java/org/etsi/osl/services/api/scm633/ServiceCatalogApiControllerTest.java new file mode 100644 index 0000000..5576784 --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/scm633/ServiceCatalogApiControllerTest.java @@ -0,0 +1,188 @@ +package org.etsi.osl.services.api.scm633; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.CoreMatchers.is; +import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +import net.minidev.json.JSONObject; +import org.apache.commons.io.IOUtils; + +import org.etsi.osl.tmf.OpenAPISpringBoot; +import org.etsi.osl.tmf.rcm634.model.ResourceCatalog; +import org.etsi.osl.tmf.scm633.model.*; +import org.etsi.osl.tmf.JsonUtils; + +import org.etsi.osl.tmf.scm633.reposervices.CatalogRepoService; + +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 ServiceCatalogApiControllerTest { + + private static final int FIXED_BOOTSTRAPS_CATALOGS = 1; + + @Autowired + private MockMvc mvc; + + @Autowired + private WebApplicationContext context; + + @Autowired + CatalogRepoService catalogRepoService; + + @Before + public void setup() { + mvc = MockMvcBuilders + .webAppContextSetup(context) + .apply(springSecurity()) + .build(); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testDeleteServiceCatalog() throws Exception { + + String response = createServiceCatalog(); + + ResourceCatalog responsesCatalog = JsonUtils.toJsonObj(response, ResourceCatalog.class); + assertThat( responsesCatalog.getName() ).isEqualTo( "Test Catalog" ); + + String id = responsesCatalog.getId(); + + mvc.perform(MockMvcRequestBuilders.delete("/serviceCatalogManagement/v4/serviceCatalog/" + id ) + .with( SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk() ) + .andReturn().getResponse().getContentAsString(); + + assertThat( catalogRepoService.findAll().size() ).isEqualTo( FIXED_BOOTSTRAPS_CATALOGS ); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testListServiceCatalog() throws Exception { + + createServiceCatalog(); + + String response = mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/serviceCatalog") + .with( SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk() ) + .andReturn().getResponse().getContentAsString(); + + List serviceCatalogList = JsonUtils.toJsonObj(response, ArrayList.class); + + assertThat(serviceCatalogList.size()).isEqualTo(FIXED_BOOTSTRAPS_CATALOGS + 1); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testPatchServiceCatalog() throws Exception { + + String response = createServiceCatalog(); + + ServiceCatalog responsesServiceCatalog = JsonUtils.toJsonObj(response, ServiceCatalog.class); + String id = responsesServiceCatalog.getId(); + + JSONObject obj = JsonUtils.toJsonObj(response, JSONObject.class); + obj.remove("uuid"); + obj.remove("id"); + obj.remove("lastUpdate"); + response = JsonUtils.toJsonString(obj); + + ServiceCatalogUpdate ServiceCatalogUpdate = JsonUtils.toJsonObj(response, ServiceCatalogUpdate.class); + ServiceCatalogUpdate.setName( "Test Service Catalog new name" ); + ServiceCatalogUpdate.setVersion("2.x"); + + String response2 = mvc.perform(MockMvcRequestBuilders.patch("/serviceCatalogManagement/v4/serviceCatalog/" + id ) + .with( SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( ServiceCatalogUpdate ) )) + .andExpect(status().isOk() ) + .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("name", is("Test Service Catalog new name"))) + .andExpect(status().isOk()) + .andReturn().getResponse().getContentAsString(); + + ServiceCatalog responsesServiceCatalog2 = JsonUtils.toJsonObj(response2, ServiceCatalog.class); + assertThat( responsesServiceCatalog2.getName() ).isEqualTo( "Test Service Catalog new name" ); + assertThat( responsesServiceCatalog2.getVersion() ).isEqualTo( "2.x" ); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testRetrieveServiceCatalog() throws Exception { + + String response = createServiceCatalog(); + + ServiceCatalog responsesServiceCatalog = JsonUtils.toJsonObj(response, ServiceCatalog.class); + String id = responsesServiceCatalog.getId(); + + String response2 = mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/serviceCatalog/" + id ) + .with( SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk() ) + .andReturn().getResponse().getContentAsString(); + + ServiceCatalog responsesServiceCatalog2 = JsonUtils.toJsonObj(response2, ServiceCatalog.class); + assertThat( responsesServiceCatalog2.getName() ).isEqualTo( "Test Catalog" ); + assertThat( responsesServiceCatalog2.getVersion() ).isEqualTo( "1.8" ); + } + + private String createServiceCatalog() throws Exception{ + assertThat( catalogRepoService.findAll().size() ).isEqualTo( FIXED_BOOTSTRAPS_CATALOGS ); + + File scatalog = new File( "src/test/resources/testResourceCatalog.txt" ); + InputStream in = new FileInputStream( scatalog ); + String resvxf = IOUtils.toString(in, "UTF-8"); + + ServiceCatalogCreate scc = JsonUtils.toJsonObj( resvxf, ServiceCatalogCreate.class); + + String response = mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/serviceCatalog") + .with( SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( scc ) )) + .andExpect(status().isOk()) + .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("name", is("Test Catalog"))) + .andExpect(status().isOk()) + .andReturn().getResponse().getContentAsString(); + + assertThat( catalogRepoService.findAll().size() ).isEqualTo( FIXED_BOOTSTRAPS_CATALOGS + 1 ); + + return response; + } +} diff --git a/src/test/java/org/etsi/osl/services/api/scm633/ServiceCategoryApiControllerTest.java b/src/test/java/org/etsi/osl/services/api/scm633/ServiceCategoryApiControllerTest.java new file mode 100644 index 0000000..2dd0650 --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/scm633/ServiceCategoryApiControllerTest.java @@ -0,0 +1,87 @@ +package org.etsi.osl.services.api.scm633; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.util.List; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.etsi.osl.tmf.OpenAPISpringBoot; +import org.etsi.osl.tmf.scm633.model.*; + +import org.etsi.osl.tmf.scm633.reposervices.CategoryRepoService; +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 ServiceCategoryApiControllerTest { + + @Autowired + private MockMvc mvc; + + @Autowired + CategoryRepoService categoryRepoService; + + @Autowired + private WebApplicationContext context; + + @Autowired + private ObjectMapper objectMapper; + + @Before + public void setup() { + mvc = MockMvcBuilders + .webAppContextSetup(context) + .apply(springSecurity()) + .build(); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testListServiceCategory() throws Exception { + + String response = mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/serviceCategory") + .with( SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk() ) + .andReturn().getResponse().getContentAsString(); + + List serviceCategoryList = objectMapper.readValue(response, new TypeReference>() {}); + + assertThat(serviceCategoryList.size()).isEqualTo(categoryRepoService.findAll().size()); + String id = categoryRepoService.findAll().get(0).getId(); + + boolean idExists = false; + for (ServiceCategory ss : serviceCategoryList) { + if ( ss.getId().equals( id ) ) { + idExists= true; + } + } + assertThat( idExists ).isTrue(); + } +} diff --git a/src/test/java/org/etsi/osl/services/api/scm633/ServiceSpecificationApiControllerTest.java b/src/test/java/org/etsi/osl/services/api/scm633/ServiceSpecificationApiControllerTest.java new file mode 100644 index 0000000..410f3ad --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/scm633/ServiceSpecificationApiControllerTest.java @@ -0,0 +1,428 @@ +package org.etsi.osl.services.api.scm633; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.CoreMatchers.is; +import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +import java.io.*; +import java.util.List; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import net.minidev.json.JSONObject; +import org.apache.commons.io.IOUtils; + +import org.etsi.osl.tmf.OpenAPISpringBoot; +import org.etsi.osl.tmf.common.model.Attachment; +import org.etsi.osl.tmf.rcm634.model.*; +import org.etsi.osl.tmf.rcm634.reposervices.ResourceSpecificationRepoService; +import org.etsi.osl.tmf.scm633.model.*; +import org.etsi.osl.tmf.JsonUtils; + +import org.etsi.osl.tmf.scm633.reposervices.ServiceSpecificationRepoService; +import org.etsi.osl.tmf.stm653.model.ServiceTestSpecification; +import org.etsi.osl.tmf.stm653.model.ServiceTestSpecificationCreate; +import org.etsi.osl.tmf.stm653.reposervices.ServiceTestSpecificationRepoService; +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.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.mock.web.MockMultipartFile; +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 ServiceSpecificationApiControllerTest { + + private static final int FIXED_BOOTSTRAPS_SPECS = 1; + + @Autowired + private MockMvc mvc; + + @Autowired + ServiceTestSpecificationRepoService aServiceTestSpecRpoService; + + @Autowired + ResourceSpecificationRepoService resourceSpecificationRepoService; + + @Autowired + private WebApplicationContext context; + + @Autowired + private ObjectMapper objectMapper; + + @Autowired + ServiceSpecificationRepoService specRepoService; + + @Before + public void setup() { + mvc = MockMvcBuilders + .webAppContextSetup(context) + .apply(springSecurity()) + .build(); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testDeleteServiceSpecification() throws Exception { + + assertThat( specRepoService.findAll().size() ).isEqualTo( FIXED_BOOTSTRAPS_SPECS ); + String response = createServiceSpecification(); + + ServiceSpecification responsesSpec = JsonUtils.toJsonObj(response, ServiceSpecification.class); + String id = responsesSpec.getId(); + + mvc.perform(MockMvcRequestBuilders.delete("/serviceCatalogManagement/v4/serviceSpecification/" + id ) + .with( SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk() ) + .andReturn().getResponse().getContentAsString(); + + assertThat( specRepoService.findAll().size() ).isEqualTo( FIXED_BOOTSTRAPS_SPECS ); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testListServiceSpecification() throws Exception { + + String response = mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/serviceSpecification") + + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk() ) + .andReturn().getResponse().getContentAsString(); + + List serviceSpecificationList = objectMapper.readValue(response, new TypeReference>() {}); + + assertThat(serviceSpecificationList.size()).isEqualTo(specRepoService.findAll().size()); + String id = specRepoService.findAll().get(0).getId(); + + boolean idExists = false; + for (ServiceSpecification ss : serviceSpecificationList) { + if ( ss.getId().equals( id ) ) { + idExists= true; + } + } + assertThat( idExists ).isTrue(); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testPatchServiceSpecification() throws Exception { + + String response = createServiceSpecification(); + assertThat( specRepoService.findAll().size() ).isEqualTo( FIXED_BOOTSTRAPS_SPECS + 1); + + ServiceSpecification responsesSpec = JsonUtils.toJsonObj(response, ServiceSpecification.class); + String id = responsesSpec.getId(); + + JSONObject obj = JsonUtils.toJsonObj(response, JSONObject.class); + obj.remove("uuid"); + obj.remove("id"); + obj.remove("lastUpdate"); + response = JsonUtils.toJsonString(obj); + + ServiceSpecificationUpdate ServiceSpecUpdate = JsonUtils.toJsonObj(response, ServiceSpecificationUpdate.class); + ServiceSpecUpdate.setName( "Test Spec new name" ); + ServiceSpecUpdate.setVersion("2.x"); + + String response2 = mvc.perform(MockMvcRequestBuilders.patch("/serviceCatalogManagement/v4/serviceSpecification/" + id ) + .with( SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( ServiceSpecUpdate ) )) + .andExpect(status().isOk() ) + .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("name", is("Test Spec new name"))) + .andExpect(status().isOk()) + .andReturn().getResponse().getContentAsString(); + + ServiceSpecification responsesServiceSpec2 = JsonUtils.toJsonObj(response2, ServiceSpecification.class); + assertThat( responsesServiceSpec2.getName() ).isEqualTo( "Test Spec new name" ); + assertThat( responsesServiceSpec2.getVersion() ).isEqualTo( "2.x" ); + assertThat( specRepoService.findAll().size() ).isEqualTo( FIXED_BOOTSTRAPS_SPECS + 1); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testRetrieveServiceSpecification() throws Exception { + + String response = createServiceSpecification(); + + ServiceSpecification responsesServiceSpec = JsonUtils.toJsonObj(response, ServiceSpecification.class); + String id = responsesServiceSpec.getId(); + + String response2 = mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/serviceSpecification/" + id ) + .with( SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk() ) + .andReturn().getResponse().getContentAsString(); + + ServiceSpecification responsesServiceSpec2 = JsonUtils.toJsonObj(response2, ServiceSpecification.class); + assertThat( responsesServiceSpec2.getName() ).isEqualTo( "Test Spec" ); + assertThat( responsesServiceSpec2.getVersion() ).isEqualTo( "1.8.0" ); + } + + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testGetAttachment() throws Exception { + + // Create a Service Specification + String response = createServiceSpecification(); + ServiceSpecification responsesSpec = JsonUtils.toJsonObj(response, ServiceSpecification.class); + String specId = responsesSpec.getId(); + + // Test method for non-existing logo attachment + String attId = "logo"; + mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/serviceSpecification/" + specId + "/attachment/" + attId) + .with( SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isNotFound() ) + .andReturn().getResponse().getContentAsString(); + + // Test method for non-existing non-logo attachment + attId = "random"; + mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/serviceSpecification/" + specId + "/attachment/" + attId) + .with( SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isNotFound() ) + .andReturn().getResponse().getContentAsString(); + + + // Test method for existing attachment + + // Add a new attachment to the Service Specification + String response2 = createAttachmentAndAddToServiceSpecification(specId); + Attachment attachment = JsonUtils.toJsonObj(response2, Attachment.class); + attId = attachment.getId(); + String attName = attachment.getName(); + String attMimeType = attachment.getMimeType(); + + mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/serviceSpecification/" + specId + "/attachment/" + attId) + ) + .andExpect(content().contentTypeCompatibleWith(MediaType.ALL_VALUE)) + .andExpect(status().isOk() ) + .andExpect(header().string(HttpHeaders.CACHE_CONTROL, "no-cache")) + .andExpect(header().string(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + attName)) + .andExpect(header().string(HttpHeaders.CONTENT_TYPE, attMimeType)) + .andReturn().getResponse().getContentAsString(); + } + + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testGetAttachmentWithFilename() throws Exception { + + // Create a Service Specification + String response = createServiceSpecification(); + ServiceSpecification responsesSpec = JsonUtils.toJsonObj(response, ServiceSpecification.class); + String specId = responsesSpec.getId(); + + String response2 = createAttachmentAndAddToServiceSpecification(specId); + Attachment attachment = JsonUtils.toJsonObj(response2, Attachment.class); + String attId = attachment.getId(); + String attName = attachment.getName(); + String attMimeType = attachment.getMimeType(); + + mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/serviceSpecification/" + specId + "/attachment/" + attId + "/" + attName) + ) + .andExpect(content().contentTypeCompatibleWith(MediaType.ALL_VALUE)) + .andExpect(status().isOk() ) + .andExpect(header().string(HttpHeaders.CACHE_CONTROL, "no-cache")) + .andExpect(header().string(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + attName)) + .andExpect(header().string(HttpHeaders.CONTENT_TYPE, attMimeType)) + .andReturn().getResponse().getContentAsString(); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testRetrieveServiceSpecificationDescriptor() throws Exception { + + // Test a non-existing spec + mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/serviceSpecification/" + "fakeId" + "/sd") + ) + .andExpect(status().isNotFound()) + .andReturn().getResponse().getContentAsString(); + } + + + @WithMockUser(username = "osadmin", roles = { "ADMIN","USER" }) + @Test + public void testSpecFromTestSpec() throws Exception { + + // Creeate a Test Spec + File sspec = new File( "src/test/resources/testServiceTestSpec.json" ); + InputStream in = new FileInputStream( sspec ); + String sspectext = IOUtils.toString(in, "UTF-8"); + ServiceTestSpecificationCreate spec = JsonUtils.toJsonObj( sspectext, ServiceTestSpecificationCreate.class); + + int originalSize = aServiceTestSpecRpoService.findAll().size(); + + String response = mvc.perform(MockMvcRequestBuilders.post("/serviceTestManagement/v4/serviceTestSpecification") + .with( SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( spec ) )) + .andExpect(status().isOk()) + .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("name", is("A test name"))) + .andExpect(status().isOk()) + .andReturn().getResponse().getContentAsString(); + + + assertThat( aServiceTestSpecRpoService.findAll().size() ).isEqualTo( originalSize + 1 ); + ServiceTestSpecification sts = JsonUtils.toJsonObj(response, ServiceTestSpecification.class); + assertThat(sts.getName()).isEqualTo("A test name"); + String stsId = sts.getId(); + + assertThat( specRepoService.findAll().size() ).isEqualTo( FIXED_BOOTSTRAPS_SPECS); + + // Create a Service Spec from the Test Spec + String response2 = mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/serviceSpecification/specFromTestSpec/" + stsId) + .with( SecurityMockMvcRequestPostProcessors.csrf())) + .andExpect(status().isOk()) + .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andReturn().getResponse().getContentAsString(); + + assertThat( specRepoService.findAll().size() ).isEqualTo( FIXED_BOOTSTRAPS_SPECS + 1 ); + + ServiceSpecification responsesSpec = JsonUtils.toJsonObj(response2, ServiceSpecification.class); + assertThat( responsesSpec.getName() ).isEqualTo( "A test name" ); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testGetImageSpecificationRelationshipGraph() throws Exception { + + // Create a Service Specification + String response = createServiceSpecification(); + ServiceSpecification responsesSpec = JsonUtils.toJsonObj(response, ServiceSpecification.class); + String specId = responsesSpec.getId(); + + String response2 = mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/serviceSpecification/" + specId + "/relationship_graph") + ) + .andExpect(status().is(302) ) + .andReturn().getResponse().getRedirectedUrl(); + + assertThat( response2 ).contains("/blockdiag/svg/"); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN"}) + @Test + public void testSpecFromResourceSpec() throws Exception { + + File rspec = new File( "src/test/resources/testResourceSpec.json" ); + InputStream in = new FileInputStream( rspec ); + String rspectext = IOUtils.toString(in, "UTF-8"); + ResourceSpecificationCreate rspeccr = JsonUtils.toJsonObj( rspectext, ResourceSpecificationCreate.class); + + int originalSize = resourceSpecificationRepoService.findAll().size(); + + String responseSpec = mvc.perform(MockMvcRequestBuilders.post( "/resourceCatalogManagement/v4/resourceSpecification" ) + .with( SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( rspeccr ) )) + .andExpect(status().isOk()) + .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andReturn().getResponse().getContentAsString(); + + assertThat( resourceSpecificationRepoService.findAll().size() ).isEqualTo( originalSize + 1 ); + ResourceSpecification responsesSpec1 = JsonUtils.toJsonObj(responseSpec, PhysicalResourceSpecification.class); + assertThat(responsesSpec1.getName()).isEqualTo("Test Resource Spec"); + String rSpecId = responsesSpec1.getId(); + assertThat( specRepoService.findAll().size() ).isEqualTo( FIXED_BOOTSTRAPS_SPECS); + + String response2 = mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/serviceSpecification/specFromResourceSpec/" + rSpecId) + .with( SecurityMockMvcRequestPostProcessors.csrf())) + .andExpect(status().isOk()) + .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andReturn().getResponse().getContentAsString(); + + assertThat( specRepoService.findAll().size() ).isEqualTo( FIXED_BOOTSTRAPS_SPECS + 1 ); + + ServiceSpecification responsesSpec = JsonUtils.toJsonObj(response2, ServiceSpecification.class); + assertThat( responsesSpec.getName() ).isEqualTo( "Test Resource Spec" ); + } + + + private String createServiceSpecification() throws Exception{ + assertThat( specRepoService.findAll().size() ).isEqualTo( FIXED_BOOTSTRAPS_SPECS ); + + File sspec = new File( "src/test/resources/testServiceSpec.json" ); + InputStream in = new FileInputStream( sspec ); + String sspectext = IOUtils.toString(in, "UTF-8"); + ServiceSpecificationCreate serviceSpecificationCreate = JsonUtils.toJsonObj( sspectext, ServiceSpecificationCreate.class); + + String response = mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/serviceSpecification") + .with( SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceSpecificationCreate ) )) + .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andReturn().getResponse().getContentAsString(); + + assertThat( specRepoService.findAll().size() ).isEqualTo( FIXED_BOOTSTRAPS_SPECS + 1 ); + + ServiceSpecification responsesSpec = JsonUtils.toJsonObj(response, ServiceSpecification.class); + assertThat( responsesSpec.getName() ).isEqualTo( "Test Spec" ); + + return response; + } + + private String createAttachmentAndAddToServiceSpecification(String serviceSpecId) throws Exception { + + Attachment att = new Attachment(); + + File gz = new File( "src/test/resources/cirros_vnf.tar.gz" ); + InputStream ing = new FileInputStream( gz ); + MockMultipartFile prodFile = new MockMultipartFile("afile", "cirros_vnf.tar.gz", "application/x-gzip", IOUtils.toByteArray(ing)); + + String response = mvc.perform(MockMvcRequestBuilders + .multipart("/serviceCatalogManagement/v4/serviceSpecification/" + serviceSpecId + "/attachment" ) + .file(prodFile) + .param("attachment", JsonUtils.toJsonString(att)) + .with( SecurityMockMvcRequestPostProcessors.csrf()) + ) + .andExpect(status().isOk()) + .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("name", is("cirros_vnf.tar.gz"))) + .andExpect(status().isOk()) + .andReturn().getResponse().getContentAsString(); + + Attachment attachment = JsonUtils.toJsonObj( response, Attachment.class); + + assertThat(attachment.getName()).isEqualTo("cirros_vnf.tar.gz"); + assertThat(attachment.getUrl()).contains(serviceSpecId); + + return response; + } +} -- GitLab From 8fa06e353fca76ffef8516ed0e752c2b12bf031f Mon Sep 17 00:00:00 2001 From: Nikolaos Kyriakoulis Date: Tue, 6 Feb 2024 19:31:56 +0200 Subject: [PATCH 03/10] Added tests for methods of Service Candidate Api Controller in tmf.api.scm633 --- .../ServiceCandidateApiControllerTest.java | 203 ++++++++++++++++++ src/test/resources/testServiceCandidate.txt | 5 + 2 files changed, 208 insertions(+) create mode 100644 src/test/java/org/etsi/osl/services/api/scm633/ServiceCandidateApiControllerTest.java create mode 100644 src/test/resources/testServiceCandidate.txt diff --git a/src/test/java/org/etsi/osl/services/api/scm633/ServiceCandidateApiControllerTest.java b/src/test/java/org/etsi/osl/services/api/scm633/ServiceCandidateApiControllerTest.java new file mode 100644 index 0000000..792776a --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/scm633/ServiceCandidateApiControllerTest.java @@ -0,0 +1,203 @@ +package org.etsi.osl.services.api.scm633; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.CoreMatchers.is; +import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.List; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import net.minidev.json.JSONObject; +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.etsi.osl.tmf.scm633.reposervices.CandidateRepoService; +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 ServiceCandidateApiControllerTest { + + private static final int FIXED_BOOTSTRAPS_SPECS = 1; + + @Autowired + private MockMvc mvc; + + @Autowired + private WebApplicationContext context; + + @Autowired + private ObjectMapper objectMapper; + + @Autowired + CandidateRepoService candidateRepoService; + + @Before + public void setup() { + mvc = MockMvcBuilders + .webAppContextSetup(context) + .apply(springSecurity()) + .build(); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testCreateServiceCandidate() throws Exception { + + String response = createServiceCandidate(); + + ServiceCandidate responsesServiceCandidate = JsonUtils.toJsonObj(response, ServiceCandidate.class); + assertThat( responsesServiceCandidate.getDescription() ).isEqualTo( "A Test Service Candidate" ); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testDeleteServiceCandidate() throws Exception { + + String response = createServiceCandidate(); + + ServiceCandidate responsesServiceCandidate = JsonUtils.toJsonObj(response, ServiceCandidate.class); + String id = responsesServiceCandidate.getId(); + + mvc.perform(MockMvcRequestBuilders.delete("/serviceCatalogManagement/v4/serviceCandidate/" + id ) + .with( SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk() ) + .andReturn().getResponse().getContentAsString(); + + assertThat( candidateRepoService.findAll().size() ).isEqualTo( FIXED_BOOTSTRAPS_SPECS ); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testListServiceCandidate() throws Exception { + + String response = mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/serviceCandidate") + .with( SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk() ) + .andReturn().getResponse().getContentAsString(); + + List serviceCandidateList= objectMapper.readValue(response, new TypeReference>() {}); + + assertThat(serviceCandidateList.size()).isEqualTo(candidateRepoService.findAll().size()); + + String id = candidateRepoService.findAll().get(0).getId(); + + boolean idExists = false; + for (ServiceCandidate sc : serviceCandidateList) { + if ( sc.getId().equals( id ) ) { + idExists= true; + } + } + assertThat( idExists ).isTrue(); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testPatchServiceCandidate() throws Exception { + + String response = createServiceCandidate(); + + ServiceCandidate responsesServiceCandidate = JsonUtils.toJsonObj(response, ServiceCandidate.class); + String id = responsesServiceCandidate.getId(); + + JSONObject obj = JsonUtils.toJsonObj(response, JSONObject.class); + obj.remove("uuid"); + obj.remove("id"); + obj.remove("lastUpdate"); + response = JsonUtils.toJsonString(obj); + + ServiceCandidateUpdate serviceCandidateUpdate = JsonUtils.toJsonObj(response, ServiceCandidateUpdate.class); + serviceCandidateUpdate.setDescription("Test Service Candidate new description"); + + String response2 = mvc.perform(MockMvcRequestBuilders.patch("/serviceCatalogManagement/v4/serviceCandidate/" + id ) + .with( SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceCandidateUpdate ) )) + .andExpect(status().isOk() ) + .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("description", is("Test Service Candidate new description"))) + .andExpect(status().isOk()) + .andReturn().getResponse().getContentAsString(); + + ServiceCandidate responsesServiceCandidate2 = JsonUtils.toJsonObj(response2, ServiceCandidate.class); + assertThat( responsesServiceCandidate2.getDescription() ).isEqualTo( "Test Service Candidate new description" ); + } + + + @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) + @Test + public void testRetrieveServiceCandidate() throws Exception { + + String response = createServiceCandidate(); + + ServiceCandidate responsesServiceCandidate = JsonUtils.toJsonObj(response, ServiceCandidate.class); + String id = responsesServiceCandidate.getId(); + + String response2 = mvc.perform(MockMvcRequestBuilders.get("/serviceCatalogManagement/v4/serviceCandidate/" + id ) + .with( SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk() ) + .andReturn().getResponse().getContentAsString(); + + ServiceCandidate responsesServiceCandidate2 = JsonUtils.toJsonObj(response2, ServiceCandidate.class); + assertThat( responsesServiceCandidate2.getDescription() ).isEqualTo( "A Test Service Candidate" ); + } + + private String createServiceCandidate() throws Exception{ + File resourceSpecFile = new File("src/test/resources/testServiceCandidate.txt"); + InputStream in = new FileInputStream(resourceSpecFile); + String serviceCandidateString = IOUtils.toString(in, "UTF-8"); + ServiceCandidateCreate serviceCandidate = JsonUtils.toJsonObj(serviceCandidateString, ServiceCandidateCreate.class); + + assertThat( candidateRepoService.findAll().size() ).isEqualTo( FIXED_BOOTSTRAPS_SPECS); + + String response = mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/serviceCandidate") + .with( SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content( JsonUtils.toJson( serviceCandidate ) )) + .andExpect(status().isOk()) + .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("description", is("A Test Service Candidate"))) + .andExpect(status().isOk()) + .andReturn().getResponse().getContentAsString(); + + assertThat( candidateRepoService.findAll().size() ).isEqualTo( FIXED_BOOTSTRAPS_SPECS + 1 ); + return response; + } +} diff --git a/src/test/resources/testServiceCandidate.txt b/src/test/resources/testServiceCandidate.txt new file mode 100644 index 0000000..e499cc0 --- /dev/null +++ b/src/test/resources/testServiceCandidate.txt @@ -0,0 +1,5 @@ +{ + "description": "A Test Service Candidate", + "version": "1.8", + "name": "Test Service Candidate" +} \ No newline at end of file -- GitLab From ca5053138e54c7ac09f306e1e2143b70344f2a87 Mon Sep 17 00:00:00 2001 From: trantzas Date: Wed, 14 Feb 2024 16:56:15 +0000 Subject: [PATCH 04/10] A commit to trigger the maven install pipeline with tests --- .../api/scm633/ServiceSpecificationApiControllerTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/org/etsi/osl/services/api/scm633/ServiceSpecificationApiControllerTest.java b/src/test/java/org/etsi/osl/services/api/scm633/ServiceSpecificationApiControllerTest.java index 410f3ad..bc8beb9 100644 --- a/src/test/java/org/etsi/osl/services/api/scm633/ServiceSpecificationApiControllerTest.java +++ b/src/test/java/org/etsi/osl/services/api/scm633/ServiceSpecificationApiControllerTest.java @@ -81,7 +81,6 @@ public class ServiceSpecificationApiControllerTest { .build(); } - @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) @Test public void testDeleteServiceSpecification() throws Exception { -- GitLab From a7d283d74f46101dc1d661a660ca0dbb9a39a809 Mon Sep 17 00:00:00 2001 From: Nikolaos Kyriakoulis Date: Mon, 19 Feb 2024 20:13:34 +0200 Subject: [PATCH 05/10] Merged the current state of develop branch to current branch --- .../osl/services/api/rcm634/CommonTests.java | 187 ++++++++ .../ConnectionPointSpecificationRefTest.java | 129 ++++++ .../rcm634/ConnectionSpecificationTest.java | 118 +++++ .../api/rcm634/ConstraintRefTest.java | 80 ++++ .../rcm634/EndpointSpecificationRefTest.java | 180 ++++++++ .../services/api/rcm634/EntityRefTest.java | 143 ++++++ .../osl/services/api/rcm634/ErrorTest.java | 179 ++++++++ .../rcm634/EventSubscriptionInputTest.java | 102 +++++ .../api/rcm634/EventSubscriptionTest.java | 116 +++++ .../ExportJobCreateEventPayloadTest.java | 87 ++++ .../api/rcm634/ExportJobCreateEventTest.java | 180 ++++++++ .../api/rcm634/ExportJobCreateTest.java | 231 ++++++++++ .../rcm634/ExportJobStateChangeEventTest.java | 196 ++++++++ .../services/api/rcm634/ExportJobTest.java | 266 +++++++++++ ...esourceSpecificationApiControllerTest.java | 257 +++++++++++ ...sourceSpecificationCharacteristicTest.java | 351 +++++++++++++++ .../api/rcm634/ResourceSpecificationTest.java | 422 ++++++++++++++++++ 17 files changed, 3224 insertions(+) create mode 100644 src/test/java/org/etsi/osl/services/api/rcm634/CommonTests.java create mode 100644 src/test/java/org/etsi/osl/services/api/rcm634/ConnectionPointSpecificationRefTest.java create mode 100644 src/test/java/org/etsi/osl/services/api/rcm634/ConnectionSpecificationTest.java create mode 100644 src/test/java/org/etsi/osl/services/api/rcm634/ConstraintRefTest.java create mode 100644 src/test/java/org/etsi/osl/services/api/rcm634/EndpointSpecificationRefTest.java create mode 100644 src/test/java/org/etsi/osl/services/api/rcm634/EntityRefTest.java create mode 100644 src/test/java/org/etsi/osl/services/api/rcm634/ErrorTest.java create mode 100644 src/test/java/org/etsi/osl/services/api/rcm634/EventSubscriptionInputTest.java create mode 100644 src/test/java/org/etsi/osl/services/api/rcm634/EventSubscriptionTest.java create mode 100644 src/test/java/org/etsi/osl/services/api/rcm634/ExportJobCreateEventPayloadTest.java create mode 100644 src/test/java/org/etsi/osl/services/api/rcm634/ExportJobCreateEventTest.java create mode 100644 src/test/java/org/etsi/osl/services/api/rcm634/ExportJobCreateTest.java create mode 100644 src/test/java/org/etsi/osl/services/api/rcm634/ExportJobStateChangeEventTest.java create mode 100644 src/test/java/org/etsi/osl/services/api/rcm634/ExportJobTest.java create mode 100644 src/test/java/org/etsi/osl/services/api/rcm634/ResourceSpecificationApiControllerTest.java create mode 100644 src/test/java/org/etsi/osl/services/api/rcm634/ResourceSpecificationCharacteristicTest.java create mode 100644 src/test/java/org/etsi/osl/services/api/rcm634/ResourceSpecificationTest.java diff --git a/src/test/java/org/etsi/osl/services/api/rcm634/CommonTests.java b/src/test/java/org/etsi/osl/services/api/rcm634/CommonTests.java new file mode 100644 index 0000000..94440f8 --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/rcm634/CommonTests.java @@ -0,0 +1,187 @@ +/*- + * ========================LICENSE_START================================= + * org.etsi.osl.tmf.api + * %% + * Copyright (C) 2019 - 2024 openslice.io + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * =========================LICENSE_END================================== + */ + +package org.etsi.osl.services.api.rcm634; + +import com.fasterxml.jackson.databind.ObjectMapper; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +import org.etsi.osl.tmf.rcm634.api.ApiException; +import org.etsi.osl.tmf.rcm634.api.ApiOriginFilter; +import org.etsi.osl.tmf.rcm634.api.ApiResponseMessage; +import org.etsi.osl.tmf.rcm634.api.ImportJobApiController; +import org.etsi.osl.tmf.rcm634.api.ExportJobApiController; +import org.etsi.osl.tmf.rcm634.api.ListenerApiController; +import org.etsi.osl.tmf.rcm634.api.HubApiController; +import org.etsi.osl.tmf.rcm634.api.NotFoundException; + +import org.junit.jupiter.api.Test; + +import org.springframework.mock.web.MockHttpServletRequest; + +import java.io.IOException; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.*; + +public class CommonTests { + + @Test + public void testApiException() { + int errorCode = 404; + String errorMessage = "Not Found"; + + ApiException exception = new ApiException(errorCode, errorMessage); + + assertEquals(errorMessage, exception.getMessage()); + assertEquals(errorCode, exception.getCode()); + } + + @Test + public void testApiOriginFilter() throws IOException, ServletException { + HttpServletRequest request = mock(HttpServletRequest.class); + HttpServletResponse response = mock(HttpServletResponse.class); + FilterChain chain = mock(FilterChain.class); + + ApiOriginFilter filter = new ApiOriginFilter(); + filter.doFilter(request, response, chain); + + verify(response).addHeader("Access-Control-Allow-Origin", "*"); + verify(response).addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT"); + verify(response).addHeader("Access-Control-Allow-Headers", "Content-Type"); + verify(chain).doFilter(request, response); + } + + @Test + public void testApiResponseMessage() { + int[] codes = {ApiResponseMessage.ERROR, ApiResponseMessage.WARNING, ApiResponseMessage.INFO, ApiResponseMessage.OK, ApiResponseMessage.TOO_BUSY, 6}; + + String[] types = {"error", "warning", "info", "ok", "too busy", "unknown"}; + + String[] messages = {"An error occured", "This is a warning", "Given info", "ok", "System is too busy", "unknown code"}; + + for (int i = 0; i < codes.length; i++) { + int code = codes[i]; + String type = types[i]; + String message = messages[i]; + + ApiResponseMessage responseMessage = new ApiResponseMessage(code, message); + + assertEquals(message, responseMessage.getMessage()); + assertEquals(code, responseMessage.getCode()); + assertEquals(type, responseMessage.getType()); + + } + + ApiResponseMessage responseMessage = new ApiResponseMessage(); + responseMessage.setMessage("Error"); + assertEquals("Error", responseMessage.getMessage()); + responseMessage.setType("ok"); + assertEquals("ok", responseMessage.getType()); + responseMessage.setCode(ApiResponseMessage.OK); + assertEquals(ApiResponseMessage.OK, responseMessage.getCode()); + } + + @Test + public void testExportJobApiController() { + ObjectMapper objectMapper = new ObjectMapper(); + HttpServletRequest request = new MockHttpServletRequest(); + + ExportJobApiController controller = new ExportJobApiController(objectMapper, request); + + Optional returnedObjectMapper = controller.getObjectMapper(); + Optional returnedRequest = controller.getRequest(); + + assertTrue(returnedObjectMapper.isPresent()); + assertTrue(returnedRequest.isPresent()); + + assertEquals(objectMapper, returnedObjectMapper.get()); + assertEquals(request, returnedRequest.get()); + } + + @Test + public void testHubApiController() { + ObjectMapper objectMapper = new ObjectMapper(); + HttpServletRequest request = new MockHttpServletRequest(); + + HubApiController controller = new HubApiController(objectMapper, request); + + Optional returnedObjectMapper = controller.getObjectMapper(); + Optional returnedRequest = controller.getRequest(); + + assertTrue(returnedObjectMapper.isPresent()); + assertTrue(returnedRequest.isPresent()); + + assertEquals(objectMapper, returnedObjectMapper.get()); + assertEquals(request, returnedRequest.get()); + } + + @Test + public void testImportJobApiController() { + ObjectMapper objectMapper = new ObjectMapper(); + HttpServletRequest request = new MockHttpServletRequest(); + + ImportJobApiController controller = new ImportJobApiController(objectMapper, request); + + Optional returnedObjectMapper = controller.getObjectMapper(); + Optional returnedRequest = controller.getRequest(); + + assertTrue(returnedObjectMapper.isPresent()); + assertTrue(returnedRequest.isPresent()); + + assertEquals(objectMapper, returnedObjectMapper.get()); + assertEquals(request, returnedRequest.get()); + } + + @Test + public void testListenerApiController() { + ObjectMapper objectMapper = new ObjectMapper(); + HttpServletRequest request = new MockHttpServletRequest(); + + ListenerApiController controller = new ListenerApiController(objectMapper, request); + + Optional returnedObjectMapper = controller.getObjectMapper(); + Optional returnedRequest = controller.getRequest(); + + assertTrue(returnedObjectMapper.isPresent()); + assertTrue(returnedRequest.isPresent()); + + assertEquals(objectMapper, returnedObjectMapper.get()); + assertEquals(request, returnedRequest.get()); + } + + @Test + public void testNotFoundException() { + int errorCode = 404; + String errorMessage = "Not Found"; + + NotFoundException exception = new NotFoundException(errorCode, errorMessage); + + assertEquals(errorMessage, exception.getMessage()); + assertEquals(errorCode, exception.getCode()); + } + +} + diff --git a/src/test/java/org/etsi/osl/services/api/rcm634/ConnectionPointSpecificationRefTest.java b/src/test/java/org/etsi/osl/services/api/rcm634/ConnectionPointSpecificationRefTest.java new file mode 100644 index 0000000..c899aef --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/rcm634/ConnectionPointSpecificationRefTest.java @@ -0,0 +1,129 @@ +package org.etsi.osl.services.api.rcm634; + +import org.etsi.osl.tmf.rcm634.model.ConnectionPointSpecificationRef; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; +import java.lang.reflect.Method; + +public class ConnectionPointSpecificationRefTest { + + @Test + void testConnectionPointSpecificationRef() { + ConnectionPointSpecificationRef ref = new ConnectionPointSpecificationRef(); + String id = "testId"; + String href = "testHref"; + String name = "testName"; + String version = "testVersion"; + String referredType = "testReferredType"; + + ref.id(id); + ref.setUuid(id); + ref.href(href); + ref.name(name); + ref.version(version); + ref._atReferredType(referredType); + + assertEquals(id, ref.getId()); + assertEquals(href, ref.getHref()); + assertEquals(name, ref.getName()); + assertEquals(version, ref.getVersion()); + assertEquals(referredType, ref.getAtReferredType()); + + ref = new ConnectionPointSpecificationRef(); + ref.setUuid(id); + ref.setHref(href); + ref.setName(name); + ref.setVersion(version); + ref.setAtReferredType(referredType); + + assertEquals(id, ref.getId()); + assertEquals(href, ref.getHref()); + assertEquals(name, ref.getName()); + assertEquals(version, ref.getVersion()); + assertEquals(referredType, ref.getAtReferredType()); + } + + @Test + void testEquals() { + String id = "testId"; + String href = "testHref"; + String name = "testName"; + String version = "testVersion"; + String referredType = "testReferredType"; + + ConnectionPointSpecificationRef ref1 = new ConnectionPointSpecificationRef(); + ref1.setUuid(id); + ref1.setHref(href); + ref1.setName(name); + ref1.setVersion(version); + ref1.setAtReferredType(referredType); + + ConnectionPointSpecificationRef ref2 = new ConnectionPointSpecificationRef(); + ref2.setUuid(id); + ref2.setHref(href); + ref2.setName(name); + ref2.setVersion(version); + ref2.setAtReferredType(referredType); + + + assertTrue(ref1.equals(ref2)); + assertEquals(ref1.hashCode(), ref2.hashCode()); + + ref1.id("differentId"); + + assertFalse(ref1.equals(ref2)); + assertNotEquals(ref1.hashCode(), ref2.hashCode()); + } + + @Test + void testToString() { + ConnectionPointSpecificationRef ref = new ConnectionPointSpecificationRef(); + + String id = "testId"; + String href = "testHref"; + String name = "testName"; + String version = "testVersion"; + String baseType = "testBaseType"; + String schemaLocation = "testSchemaLocation"; + String type = "testType"; + String referredType = "testReferredType"; + + ref.id(id); + ref.setUuid(id); + ref.setHref(href); + ref.setName(name); + ref.setVersion(version); + ref.setBaseType(baseType); + ref.setSchemaLocation(schemaLocation); + ref.setType(type); + ref.setAtReferredType(referredType); + + String expectedString = "class ConnectionPointSpecificationRef {\n" + + " id: " + id + "\n" + + " href: " + href + "\n" + + " name: " + name + "\n" + + " version: " + version + "\n" + + " _atBaseType: " + baseType + "\n" + + " _atSchemaLocation: " + schemaLocation + "\n" + + " _atType: " + type + "\n" + + " _atReferredType: " + referredType + "\n" + + "}"; + + assertEquals(expectedString, ref.toString()); + } + + @Test + void testToIndentedString() throws Exception { + ConnectionPointSpecificationRef ref = new ConnectionPointSpecificationRef(); + + Method method = ConnectionPointSpecificationRef.class.getDeclaredMethod("toIndentedString", Object.class); + method.setAccessible(true); + + String input = "Hello\nWorld"; + String expectedOutput = "Hello\n World"; + + String output = (String) method.invoke(ref, input); + + assertEquals(expectedOutput, output); + } +} diff --git a/src/test/java/org/etsi/osl/services/api/rcm634/ConnectionSpecificationTest.java b/src/test/java/org/etsi/osl/services/api/rcm634/ConnectionSpecificationTest.java new file mode 100644 index 0000000..527d5df --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/rcm634/ConnectionSpecificationTest.java @@ -0,0 +1,118 @@ +package org.etsi.osl.services.api.rcm634; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.etsi.osl.tmf.rcm634.model.ConnectionSpecification; +import org.etsi.osl.tmf.rcm634.model.EndpointSpecificationRef; + +import java.util.HashSet; +import java.util.Set; + +public class ConnectionSpecificationTest { + + @Test + void testConnectionSpecification() { + ConnectionSpecification spec = new ConnectionSpecification(); + String id = "testId"; + String href = "testHref"; + String associationType = "testAssociationType"; + String name = "testName"; + Set endpointSpecification = new HashSet<>(); + String baseType = "testBaseType"; + String schemaLocation = "testSchemaLocation"; + String type = "testType"; + + spec.id(id); + spec.setUuid(id); + spec.href(href); + spec.associationType(associationType); + spec.name(name); + spec.endpointSpecification(endpointSpecification); + spec._atBaseType(baseType); + spec._atSchemaLocation(schemaLocation); + spec._atType(type); + + assertEquals(id, spec.getId()); + assertEquals(href, spec.getHref()); + assertEquals(associationType, spec.getAssociationType()); + assertEquals(name, spec.getName()); + assertEquals(endpointSpecification, spec.getEndpointSpecification()); + assertEquals(baseType, spec.getAtBaseType()); + assertEquals(schemaLocation, spec.getAtSchemaLocation()); + assertEquals(type, spec.getAtType()); + + String expectedString = "class ConnectionSpecification {\n" + + " id: " + id + "\n" + + " href: " + href + "\n" + + " associationType: " + associationType + "\n" + + " name: " + name + "\n" + + " endpointSpecification: " + endpointSpecification.toString().replace("\n", "\n ") + "\n" + + " _atBaseType: " + baseType + "\n" + + " _atSchemaLocation: " + schemaLocation + "\n" + + " _atType: " + type + "\n" + + "}"; + + assertEquals(expectedString, spec.toString()); + + ConnectionSpecification spec2 = new ConnectionSpecification(); + spec2.id(id); + spec2.href(href); + spec2.associationType(associationType); + spec2.name(name); + spec2.endpointSpecification(endpointSpecification); + spec2._atBaseType(baseType); + spec2._atSchemaLocation(schemaLocation); + spec2._atType(type); + + assertTrue(spec.equals(spec2)); + assertEquals(spec.hashCode(), spec2.hashCode()); + + spec.id("differentId"); + + assertFalse(spec.equals(spec2)); + assertNotEquals(spec.hashCode(), spec2.hashCode()); + } + + @Test + void testSetters() { + ConnectionSpecification spec = new ConnectionSpecification(); + String id = "testId"; + String href = "testHref"; + String associationType = "testAssociationType"; + String name = "testName"; + Set endpointSpecification = new HashSet<>(); + String baseType = "testBaseType"; + String schemaLocation = "testSchemaLocation"; + String type = "testType"; + + spec.setUuid(id); + spec.id(id); + spec.setHref(href); + spec.setAssociationType(associationType); + spec.setName(name); + spec.setEndpointSpecification(endpointSpecification); + spec.setAtBaseType(baseType); + spec.setAtSchemaLocation(schemaLocation); + spec.setAtType(type); + + assertEquals(id, spec.getId()); + assertEquals(href, spec.getHref()); + assertEquals(associationType, spec.getAssociationType()); + assertEquals(name, spec.getName()); + assertEquals(endpointSpecification, spec.getEndpointSpecification()); + assertEquals(baseType, spec.getAtBaseType()); + assertEquals(schemaLocation, spec.getAtSchemaLocation()); + assertEquals(type, spec.getAtType()); + } + + @Test + void testAddEndpointSpecificationItem() { + ConnectionSpecification spec = new ConnectionSpecification(); + EndpointSpecificationRef endpointSpecRef = new EndpointSpecificationRef(); + endpointSpecRef.id("testId"); + + spec.addEndpointSpecificationItem(endpointSpecRef); + + assertTrue(spec.getEndpointSpecification().contains(endpointSpecRef)); + } +} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/rcm634/ConstraintRefTest.java b/src/test/java/org/etsi/osl/services/api/rcm634/ConstraintRefTest.java new file mode 100644 index 0000000..17dc9e3 --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/rcm634/ConstraintRefTest.java @@ -0,0 +1,80 @@ +package org.etsi.osl.services.api.rcm634; + +import org.etsi.osl.tmf.rcm634.model.ConstraintRef; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +public class ConstraintRefTest { + + @Test + void testConstraintRef() { + ConstraintRef ref = new ConstraintRef(); + String id = "testId"; + String href = "testHref"; + String name = "testName"; + String version = "testVersion"; + String referredType = "testReferredType"; + + String baseType = "BaseEntity"; + String schemaLocation = "null"; + String type = "null"; + + ref.id(id); + ref.setUuid(id); + ref.href(href); + ref.name(name); + ref.version(version); + ref._atReferredType(referredType); + + assertEquals(id, ref.getId()); + assertEquals(href, ref.getHref()); + assertEquals(name, ref.getName()); + assertEquals(version, ref.getVersion()); + assertEquals(referredType, ref.getAtReferredType()); + + String expectedString = "class ConstraintRef {\n" + + " id: " + id + "\n" + + " href: " + href + "\n" + + " name: " + name + "\n" + + " version: " + version + "\n" + + " baseType: " + baseType + "\n" + + " schemaLocation: " + schemaLocation + "\n" + + " type: " + type + "\n" + + " _atReferredType: " + referredType + "\n" + + "}"; + + assertEquals(expectedString, ref.toString()); + + ConstraintRef ref2 = new ConstraintRef(); + ref2.id(id); + ref2.setUuid(id); + ref2.href(href); + ref2.name(name); + ref2.version(version); + ref2._atReferredType(referredType); + + assertTrue(ref.equals(ref2)); + assertEquals(ref.hashCode(), ref2.hashCode()); + + ref.id("differentId"); + ref.setUuid("differentId"); + + assertFalse(ref.equals(ref2)); + assertNotEquals(ref.hashCode(), ref2.hashCode()); + + ref = new ConstraintRef(); + + ref.setId(id); + ref.setUuid(id); + ref.setHref(href); + ref.setName(name); + ref.setVersion(version); + ref.setAtReferredType(referredType); + + assertEquals(id, ref.getId()); + assertEquals(href, ref.getHref()); + assertEquals(name, ref.getName()); + assertEquals(version, ref.getVersion()); + assertEquals(referredType, ref.getAtReferredType()); + } +} diff --git a/src/test/java/org/etsi/osl/services/api/rcm634/EndpointSpecificationRefTest.java b/src/test/java/org/etsi/osl/services/api/rcm634/EndpointSpecificationRefTest.java new file mode 100644 index 0000000..2618021 --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/rcm634/EndpointSpecificationRefTest.java @@ -0,0 +1,180 @@ +package org.etsi.osl.services.api.rcm634; + +import org.etsi.osl.tmf.rcm634.model.ConnectionPointSpecificationRef; +import org.etsi.osl.tmf.rcm634.model.EndpointSpecificationRef; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; +import java.lang.reflect.Method; + +public class EndpointSpecificationRefTest { + @Test + void testName() { + EndpointSpecificationRef ref = new EndpointSpecificationRef(); + String name = "testName"; + ref.setName(name); + assertEquals(name, ref.getName()); + + EndpointSpecificationRef newRef = ref.name("newTestName"); + assertEquals(ref, newRef); + } + + @Test + void testConnectionPointSpecification() { + EndpointSpecificationRef ref = new EndpointSpecificationRef(); + ConnectionPointSpecificationRef connectionPointSpecificationRef = new ConnectionPointSpecificationRef(); + ref.setConnectionPointSpecification(connectionPointSpecificationRef); + assertEquals(connectionPointSpecificationRef, ref.getConnectionPointSpecification()); + + EndpointSpecificationRef newRef = ref.connectionPointSpecification(connectionPointSpecificationRef.name("newRef")); + assertEquals(ref, newRef); + } + + @Test + void testEndpointSpecificationRef() { + EndpointSpecificationRef ref = new EndpointSpecificationRef(); + String id = "testId"; + String href = "testHref"; + Boolean isRoot = true; + String role = "testRole"; + String referredType = "testReferredType"; + + ref.id(id); + ref.setUuid(id); + ref.href(href); + ref.isRoot(isRoot); + ref.role(role); + ref._atReferredType(referredType); + + assertEquals(id, ref.getId()); + assertEquals(href, ref.getHref()); + assertEquals(isRoot, ref.isIsRoot()); + assertEquals(role, ref.getRole()); + assertEquals(referredType, ref.getAtReferredType()); + + ref = new EndpointSpecificationRef(); + ref.setUuid(id); + ref.setHref(href); + ref.setIsRoot(isRoot); + ref.setRole(role); + ref.setAtReferredType(referredType); + + assertEquals(id, ref.getId()); + assertEquals(href, ref.getHref()); + assertEquals(isRoot, ref.isIsRoot()); + assertEquals(role, ref.getRole()); + assertEquals(referredType, ref.getAtReferredType()); + } + + @Test + void testEquals() { + String id = "testId"; + String href = "testHref"; + Boolean isRoot = true; + String role = "testRole"; + String referredType = "testReferredType"; + + EndpointSpecificationRef ref1 = new EndpointSpecificationRef(); + ref1.setUuid(id); + ref1.setHref(href); + ref1.setIsRoot(isRoot); + ref1.setRole(role); + ref1.setAtReferredType(referredType); + + EndpointSpecificationRef ref2 = new EndpointSpecificationRef(); + ref2.setUuid(id); + ref2.setHref(href); + ref2.setIsRoot(isRoot); + ref2.setRole(role); + ref2.setAtReferredType(referredType); + + assertTrue(ref1.equals(ref2)); + + ref1.id("differentId"); + + assertFalse(ref1.equals(ref2)); + } + + @Test + void testHashCode() { + String id = "testId"; + String href = "testHref"; + Boolean isRoot = true; + String role = "testRole"; + String referredType = "testReferredType"; + + EndpointSpecificationRef ref1 = new EndpointSpecificationRef(); + ref1.setUuid(id); + ref1.setHref(href); + ref1.setIsRoot(isRoot); + ref1.setRole(role); + ref1.setAtReferredType(referredType); + + EndpointSpecificationRef ref2 = new EndpointSpecificationRef(); + ref2.setUuid(id); + ref2.setHref(href); + ref2.setIsRoot(isRoot); + ref2.setRole(role); + ref2.setAtReferredType(referredType); + + assertEquals(ref1.hashCode(), ref2.hashCode()); + + ref1.id("differentId"); + + assertNotEquals(ref1.hashCode(), ref2.hashCode()); + } + + @Test + void testToString() { + EndpointSpecificationRef ref = new EndpointSpecificationRef(); + + String id = "testId"; + String href = "testHref"; + Boolean isRoot = true; + String role = "testRole"; + String baseType = "testBaseType"; + String schemaLocation = "testSchemaLocation"; + String type = "testType"; + String referredType = "testReferredType"; + + ref.id(id); + ref.setUuid(id); + ref.setHref(href); + ref.isRoot(isRoot); + ref.role(role); + ref.setBaseType(baseType); + ref.setSchemaLocation(schemaLocation); + ref.setType(type); + ref.setAtReferredType(referredType); + + + String expectedString = "class EndpointSpecificationRef {\n" + + " id: testId\n" + + " href: testHref\n" + + " isRoot: true\n" + + " name: null\n" + + " role: testRole\n" + + " connectionPointSpecification: null\n" + + " _atBaseType: testBaseType\n" + + " _atSchemaLocation: testSchemaLocation\n" + + " _atType: testType\n" + + " _atReferredType: testReferredType\n" + + "}"; + + assertEquals(expectedString, ref.toString()); + } + + @Test + void testToIndentedString() throws Exception { + EndpointSpecificationRef ref = new EndpointSpecificationRef(); + + Method method = EndpointSpecificationRef.class.getDeclaredMethod("toIndentedString", Object.class); + method.setAccessible(true); + + String input = "Hello\nWorld"; + String expectedOutput = "Hello\n World"; + + String output = (String) method.invoke(ref, input); + + assertEquals(expectedOutput, output); + } +} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/rcm634/EntityRefTest.java b/src/test/java/org/etsi/osl/services/api/rcm634/EntityRefTest.java new file mode 100644 index 0000000..156d8c9 --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/rcm634/EntityRefTest.java @@ -0,0 +1,143 @@ +package org.etsi.osl.services.api.rcm634; + +import org.etsi.osl.tmf.rcm634.model.EntityRef; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; +import java.lang.reflect.Method; + +public class EntityRefTest { + + @Test + void testEntityRef() { + EntityRef ref = new EntityRef(); + String id = "testId"; + String href = "testHref"; + String name = "testName"; + String referredType = "testReferredType"; + + ref.id(id); + ref.setUuid(id); + ref.href(href); + ref.name(name); + ref._atReferredType(referredType); + + assertEquals(id, ref.getId()); + assertEquals(href, ref.getHref()); + assertEquals(name, ref.getName()); + assertEquals(referredType, ref.getAtReferredType()); + + ref = new EntityRef(); + ref.setId(id); + ref.setUuid(id); + ref.setHref(href); + ref.setName(name); + ref.setAtReferredType(referredType); + + assertEquals(id, ref.getId()); + assertEquals(href, ref.getHref()); + assertEquals(name, ref.getName()); + assertEquals(referredType, ref.getAtReferredType()); + } + + @Test + void testEquals() { + String id = "testId"; + String href = "testHref"; + String name = "testName"; + String referredType = "testReferredType"; + + EntityRef ref1 = new EntityRef(); + ref1.setUuid(id); + ref1.setHref(href); + ref1.setName(name); + ref1.setAtReferredType(referredType); + + EntityRef ref2 = new EntityRef(); + ref2.setUuid(id); + ref2.setHref(href); + ref2.setName(name); + ref2.setAtReferredType(referredType); + + assertTrue(ref1.equals(ref2)); + + ref1.id("differentId"); + + assertFalse(ref1.equals(ref2)); + } + + @Test + void testHashCode() { + String id = "testId"; + String href = "testHref"; + String name = "testName"; + String referredType = "testReferredType"; + + EntityRef ref1 = new EntityRef(); + ref1.setUuid(id); + ref1.setHref(href); + ref1.setName(name); + ref1.setAtReferredType(referredType); + + EntityRef ref2 = new EntityRef(); + ref2.setUuid(id); + ref2.setHref(href); + ref2.setName(name); + ref2.setAtReferredType(referredType); + + assertEquals(ref1.hashCode(), ref2.hashCode()); + + ref1.id("differentId"); + ref1.setUuid("differentId"); + + assertNotEquals(ref1.hashCode(), ref2.hashCode()); + } + + @Test + void testToString() { + EntityRef ref = new EntityRef(); + + String id = "testId"; + String href = "testHref"; + String name = "testName"; + String baseType = "testBaseType"; + String schemaLocation = "testSchemaLocation"; + String type = "testType"; + String referredType = "testReferredType"; + + ref.id(id); + ref.setUuid(id); + ref.setHref(href); + ref.name(name); + ref.setBaseType(baseType); + ref.setSchemaLocation(schemaLocation); + ref.setType(type); + ref.setAtReferredType(referredType); + + String expectedString = "class EntityRef {\n" + + " id: testId\n" + + " href: testHref\n" + + " name: testName\n" + + " baseType: testBaseType\n" + + " schemaLocation: testSchemaLocation\n" + + " type: testType\n" + + " _atReferredType: testReferredType\n" + + "}"; + + assertEquals(expectedString, ref.toString()); + } + + @Test + void testToIndentedString() throws Exception { + EntityRef ref = new EntityRef(); + + Method method = EntityRef.class.getDeclaredMethod("toIndentedString", Object.class); + method.setAccessible(true); + + String input = "Hello\nWorld"; + String expectedOutput = "Hello\n World"; + + String output = (String) method.invoke(ref, input); + + assertEquals(expectedOutput, output); + } +} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/rcm634/ErrorTest.java b/src/test/java/org/etsi/osl/services/api/rcm634/ErrorTest.java new file mode 100644 index 0000000..d567d60 --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/rcm634/ErrorTest.java @@ -0,0 +1,179 @@ +package org.etsi.osl.services.api.rcm634; + +import org.etsi.osl.tmf.rcm634.model.Error; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; +import java.lang.reflect.Method; + +public class ErrorTest { + + @Test + void testError() { + Error error = new Error(); + String code = "testCode"; + String reason = "testReason"; + String message = "testMessage"; + String status = "testStatus"; + String referenceError = "testReferenceError"; + + error.code(code); + error.reason(reason); + error.message(message); + error.status(status); + error.referenceError(referenceError); + + assertEquals(code, error.getCode()); + assertEquals(reason, error.getReason()); + assertEquals(message, error.getMessage()); + assertEquals(status, error.getStatus()); + assertEquals(referenceError, error.getReferenceError()); + + error = new Error(); + error.setCode(code); + error.setReason(reason); + error.setMessage(message); + error.setStatus(status); + error.setReferenceError(referenceError); + + assertEquals(code, error.getCode()); + assertEquals(reason, error.getReason()); + assertEquals(message, error.getMessage()); + assertEquals(status, error.getStatus()); + assertEquals(referenceError, error.getReferenceError()); + } + + @Test + void testEquals() { + String code = "testCode"; + String reason = "testReason"; + String message = "testMessage"; + String status = "testStatus"; + String referenceError = "testReferenceError"; + + Error error1 = new Error(); + error1.setReason(reason); + error1.setMessage(message); + error1.setStatus(status); + error1.setReferenceError(referenceError); + + Error error2 = new Error(); + error2.setReason(reason); + error2.setMessage(message); + error2.setStatus(status); + error2.setReferenceError(referenceError); + + assertTrue(error1.equals(error2)); + + error1.code("differentCode"); + + assertFalse(error1.equals(error2)); + } + + @Test + void testHashCode() { + String code = "testCode"; + String reason = "testReason"; + String message = "testMessage"; + String status = "testStatus"; + String referenceError = "testReferenceError"; + + Error error1 = new Error(); + error1.setReason(reason); + error1.setMessage(message); + error1.setStatus(status); + error1.setReferenceError(referenceError); + + Error error2 = new Error(); + error2.setReason(reason); + error2.setMessage(message); + error2.setStatus(status); + error2.setReferenceError(referenceError); + + assertEquals(error1.hashCode(), error2.hashCode()); + + error1.code("differentCode"); + + assertNotEquals(error1.hashCode(), error2.hashCode()); + } + + @Test + void testToString() { + Error error = new Error(); + + String code = "testCode"; + String reason = "testReason"; + String message = "testMessage"; + String status = "testStatus"; + String referenceError = "testReferenceError"; + String baseType = "testBaseType"; + String schemaLocation = "testSchemaLocation"; + String type = "testType"; + + error.code(code); + error.reason(reason); + error.message(message); + error.status(status); + error.referenceError(referenceError); + + String expectedString = "class Error {\n" + + " code: testCode\n" + + " reason: testReason\n" + + " message: testMessage\n" + + " status: testStatus\n" + + " referenceError: testReferenceError\n" + + " _atBaseType: null\n" + + " _atSchemaLocation: null\n" + + " _atType: null\n" + + "}"; + + assertEquals(expectedString, error.toString()); + } + + @Test + void testToIndentedString() throws Exception { + Error error = new Error(); + + Method method = Error.class.getDeclaredMethod("toIndentedString", Object.class); + method.setAccessible(true); + + String input = "Hello\nWorld"; + String expectedOutput = "Hello\n World"; + + String output = (String) method.invoke(error, input); + + assertEquals(expectedOutput, output); + } + + @Test + void testAtBaseType() { + Error error = new Error(); + String baseType = "testBaseType"; + error.setAtBaseType(baseType); + assertEquals(baseType, error.getAtBaseType()); + + Error newError = error._atBaseType("newTestBaseType"); + assertEquals(error, newError); + } + + @Test + void testAtSchemaLocation() { + Error error = new Error(); + String schemaLocation = "testSchemaLocation"; + error.setAtSchemaLocation(schemaLocation); + assertEquals(schemaLocation, error.getAtSchemaLocation()); + + Error newError = error._atSchemaLocation("newTestSchemaLocation"); + assertEquals(error, newError); + } + + @Test + void testAtType() { + Error error = new Error(); + String type = "testType"; + error.setAtType(type); + assertEquals(type, error.getAtType()); + + Error newError = error._atType("newTestType"); + assertEquals(error, newError); + } +} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/rcm634/EventSubscriptionInputTest.java b/src/test/java/org/etsi/osl/services/api/rcm634/EventSubscriptionInputTest.java new file mode 100644 index 0000000..b585830 --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/rcm634/EventSubscriptionInputTest.java @@ -0,0 +1,102 @@ +package org.etsi.osl.services.api.rcm634; + +import org.etsi.osl.tmf.rcm634.model.EventSubscriptionInput; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; +import java.lang.reflect.Method; + +public class EventSubscriptionInputTest { + + @Test + void testEventSubscriptionInput() { + EventSubscriptionInput input = new EventSubscriptionInput(); + String callback = "testCallback"; + String query = "testQuery"; + + input.callback(callback); + input.query(query); + + assertEquals(callback, input.getCallback()); + assertEquals(query, input.getQuery()); + + input = new EventSubscriptionInput(); + input.setCallback(callback); + input.setQuery(query); + + assertEquals(callback, input.getCallback()); + assertEquals(query, input.getQuery()); + } + + @Test + void testEquals() { + String callback = "testCallback"; + String query = "testQuery"; + + EventSubscriptionInput input1 = new EventSubscriptionInput(); + input1.setCallback(callback); + input1.setQuery(query); + + EventSubscriptionInput input2 = new EventSubscriptionInput(); + input2.setCallback(callback); + input2.setQuery(query); + + assertTrue(input1.equals(input2)); + + input1.callback("differentCallback"); + + assertFalse(input1.equals(input2)); + } + + @Test + void testHashCode() { + String callback = "testCallback"; + String query = "testQuery"; + + EventSubscriptionInput input1 = new EventSubscriptionInput(); + input1.setCallback(callback); + input1.setQuery(query); + + EventSubscriptionInput input2 = new EventSubscriptionInput(); + input2.setCallback(callback); + input2.setQuery(query); + + assertEquals(input1.hashCode(), input2.hashCode()); + + input1.callback("differentCallback"); + + assertNotEquals(input1.hashCode(), input2.hashCode()); + } + + @Test + void testToString() { + EventSubscriptionInput input = new EventSubscriptionInput(); + + String callback = "testCallback"; + String query = "testQuery"; + + input.callback(callback); + input.query(query); + + String expectedString = "class EventSubscriptionInput {\n" + + " callback: testCallback\n" + + " query: testQuery\n" + + "}"; + + assertEquals(expectedString, input.toString()); + } + + @Test + void testToIndentedString() throws Exception { + EventSubscriptionInput input = new EventSubscriptionInput(); + + Method method = EventSubscriptionInput.class.getDeclaredMethod("toIndentedString", Object.class); + method.setAccessible(true); + + String inputString = "Hello\nWorld"; + String expectedOutput = "Hello\n World"; + + String output = (String) method.invoke(input, inputString); + + assertEquals(expectedOutput, output); + } +} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/rcm634/EventSubscriptionTest.java b/src/test/java/org/etsi/osl/services/api/rcm634/EventSubscriptionTest.java new file mode 100644 index 0000000..b28f7a8 --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/rcm634/EventSubscriptionTest.java @@ -0,0 +1,116 @@ +package org.etsi.osl.services.api.rcm634; + +import org.etsi.osl.tmf.rcm634.model.EventSubscription; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; +import java.lang.reflect.Method; + +public class EventSubscriptionTest { + + @Test + void testEventSubscription() { + EventSubscription subscription = new EventSubscription(); + String id = "testId"; + String callback = "testCallback"; + String query = "testQuery"; + + subscription.id(id); + subscription.callback(callback); + subscription.query(query); + + assertEquals(id, subscription.getId()); + assertEquals(callback, subscription.getCallback()); + assertEquals(query, subscription.getQuery()); + + subscription = new EventSubscription(); + subscription.setId(id); + subscription.setCallback(callback); + subscription.setQuery(query); + + assertEquals(id, subscription.getId()); + assertEquals(callback, subscription.getCallback()); + assertEquals(query, subscription.getQuery()); + } + + @Test + void testEquals() { + String id = "testId"; + String callback = "testCallback"; + String query = "testQuery"; + + EventSubscription subscription1 = new EventSubscription(); + subscription1.setId(id); + subscription1.setCallback(callback); + subscription1.setQuery(query); + + EventSubscription subscription2 = new EventSubscription(); + subscription2.setId(id); + subscription2.setCallback(callback); + subscription2.setQuery(query); + + assertTrue(subscription1.equals(subscription2)); + + subscription1.id("differentId"); + + assertFalse(subscription1.equals(subscription2)); + } + + @Test + void testHashCode() { + String id = "testId"; + String callback = "testCallback"; + String query = "testQuery"; + + EventSubscription subscription1 = new EventSubscription(); + subscription1.setId(id); + subscription1.setCallback(callback); + subscription1.setQuery(query); + + EventSubscription subscription2 = new EventSubscription(); + subscription2.setId(id); + subscription2.setCallback(callback); + subscription2.setQuery(query); + + assertEquals(subscription1.hashCode(), subscription2.hashCode()); + + subscription1.id("differentId"); + + assertNotEquals(subscription1.hashCode(), subscription2.hashCode()); + } + + @Test + void testToString() { + EventSubscription subscription = new EventSubscription(); + + String id = "testId"; + String callback = "testCallback"; + String query = "testQuery"; + + subscription.id(id); + subscription.callback(callback); + subscription.query(query); + + String expectedString = "class EventSubscription {\n" + + " id: testId\n" + + " callback: testCallback\n" + + " query: testQuery\n" + + "}"; + + assertEquals(expectedString, subscription.toString()); + } + + @Test + void testToIndentedString() throws Exception { + EventSubscription subscription = new EventSubscription(); + + Method method = EventSubscription.class.getDeclaredMethod("toIndentedString", Object.class); + method.setAccessible(true); + + String input = "Hello\nWorld"; + String expectedOutput = "Hello\n World"; + + String output = (String) method.invoke(subscription, input); + + assertEquals(expectedOutput, output); + } +} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobCreateEventPayloadTest.java b/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobCreateEventPayloadTest.java new file mode 100644 index 0000000..87641b1 --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobCreateEventPayloadTest.java @@ -0,0 +1,87 @@ +package org.etsi.osl.services.api.rcm634; + +import org.etsi.osl.tmf.rcm634.model.ExportJob; +import org.etsi.osl.tmf.rcm634.model.ExportJobCreateEventPayload; +import org.junit.jupiter.api.Test; + +import java.lang.reflect.Method; +import static org.junit.jupiter.api.Assertions.*; + +public class ExportJobCreateEventPayloadTest { + + @Test + void testExportJobCreateEventPayload() { + ExportJobCreateEventPayload payload = new ExportJobCreateEventPayload(); + ExportJob job = new ExportJob(); + job.setId("testId"); + + payload.exportJob(job); + assertEquals(job, payload.getExportJob()); + + payload = new ExportJobCreateEventPayload(); + payload.setExportJob(job); + assertEquals(job, payload.getExportJob()); + } + + @Test + void testEquals() { + ExportJobCreateEventPayload payload1 = new ExportJobCreateEventPayload(); + ExportJob job = new ExportJob(); + job.setId("testId"); + payload1.setExportJob(job); + + ExportJobCreateEventPayload payload2 = new ExportJobCreateEventPayload(); + payload2.setExportJob(job); + + assertTrue(payload1.equals(payload2)); + + payload1.setExportJob(new ExportJob()); + + assertFalse(payload1.equals(payload2)); + } + + @Test + void testHashCode() { + ExportJobCreateEventPayload payload1 = new ExportJobCreateEventPayload(); + ExportJob job = new ExportJob(); + job.setId("testId"); + payload1.setExportJob(job); + + ExportJobCreateEventPayload payload2 = new ExportJobCreateEventPayload(); + payload2.setExportJob(job); + + assertEquals(payload1.hashCode(), payload2.hashCode()); + + payload1.setExportJob(new ExportJob()); + + assertNotEquals(payload1.hashCode(), payload2.hashCode()); + } + + @Test + void testToString() { + ExportJobCreateEventPayload payload = new ExportJobCreateEventPayload(); + ExportJob job = new ExportJob(); + job.setId("testId"); + payload.setExportJob(job); + + String expectedString = "class ExportJobCreateEventPayload {\n" + + " exportJob: class ExportJob {\n" + + " id: testId\n" + + " href: null\n" + + " completionDate: null\n" + + " contentType: null\n" + + " creationDate: null\n" + + " errorLog: null\n" + + " path: null\n" + + " query: null\n" + + " url: null\n" + + " status: null\n" + + " _atBaseType: null\n" + + " _atSchemaLocation: null\n" + + " _atType: null\n" + + " }\n" + + "}"; + + assertEquals(expectedString, payload.toString()); + } +} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobCreateEventTest.java b/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobCreateEventTest.java new file mode 100644 index 0000000..1c6eb60 --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobCreateEventTest.java @@ -0,0 +1,180 @@ +package org.etsi.osl.services.api.rcm634; + +import org.etsi.osl.tmf.rcm634.model.ExportJobCreateEvent; +import org.etsi.osl.tmf.rcm634.model.ExportJobCreateEventPayload; +import org.junit.jupiter.api.Test; + +import java.lang.reflect.Method; +import java.time.OffsetDateTime; +import static org.junit.jupiter.api.Assertions.*; + +public class ExportJobCreateEventTest { + + @Test + void testExportJobCreateEvent() { + ExportJobCreateEvent event = new ExportJobCreateEvent(); + String id = "testId"; + String href = "testHref"; + String eventId = "testEventId"; + OffsetDateTime eventTime = OffsetDateTime.now(); + String eventType = "testEventType"; + String correlationId = "testCorrelationId"; + String domain = "testDomain"; + String title = "testTitle"; + String description = "testDescription"; + String priority = "testPriority"; + OffsetDateTime timeOccurred = OffsetDateTime.now(); + ExportJobCreateEventPayload eventPayload = new ExportJobCreateEventPayload(); + + event.id(id); + event.href(href); + event.eventId(eventId); + event.eventTime(eventTime); + event.eventType(eventType); + event.correlationId(correlationId); + event.domain(domain); + event.title(title); + event.description(description); + event.priority(priority); + event.timeOcurred(timeOccurred); + event.event(eventPayload); + + assertEquals(id, event.getId()); + assertEquals(href, event.getHref()); + assertEquals(eventId, event.getEventId()); + assertEquals(eventTime, event.getEventTime()); + assertEquals(eventType, event.getEventType()); + assertEquals(correlationId, event.getCorrelationId()); + assertEquals(domain, event.getDomain()); + assertEquals(title, event.getTitle()); + assertEquals(description, event.getDescription()); + assertEquals(priority, event.getPriority()); + assertEquals(timeOccurred, event.getTimeOcurred()); + assertEquals(eventPayload, event.getEvent()); + } + + @Test + void testEquals() { + ExportJobCreateEvent event1 = new ExportJobCreateEvent(); + event1.setId("testId"); + event1.setHref("testHref"); + event1.setEventId("testEventId"); + event1.setEventTime(OffsetDateTime.now()); + event1.setEventType("testEventType"); + event1.setCorrelationId("testCorrelationId"); + event1.setDomain("testDomain"); + event1.setTitle("testTitle"); + event1.setDescription("testDescription"); + event1.setPriority("testPriority"); + event1.setTimeOcurred(OffsetDateTime.now()); + event1.setEvent(new ExportJobCreateEventPayload()); + + ExportJobCreateEvent event2 = new ExportJobCreateEvent(); + event2.setId("testId"); + event2.setHref("testHref"); + event2.setEventId("testEventId"); + event2.setEventTime(event1.getEventTime()); + event2.setEventType("testEventType"); + event2.setCorrelationId("testCorrelationId"); + event2.setDomain("testDomain"); + event2.setTitle("testTitle"); + event2.setDescription("testDescription"); + event2.setPriority("testPriority"); + event2.setTimeOcurred(event1.getTimeOcurred()); + event2.setEvent(new ExportJobCreateEventPayload()); + + assertTrue(event1.equals(event2)); + + event1.setId("differentId"); + + assertFalse(event1.equals(event2)); + } + + @Test + void testHashCode() { + ExportJobCreateEvent event1 = new ExportJobCreateEvent(); + event1.setId("testId"); + event1.setHref("testHref"); + event1.setEventId("testEventId"); + event1.setEventTime(OffsetDateTime.now()); + event1.setEventType("testEventType"); + event1.setCorrelationId("testCorrelationId"); + event1.setDomain("testDomain"); + event1.setTitle("testTitle"); + event1.setDescription("testDescription"); + event1.setPriority("testPriority"); + event1.setTimeOcurred(OffsetDateTime.now()); + event1.setEvent(new ExportJobCreateEventPayload()); + + ExportJobCreateEvent event2 = new ExportJobCreateEvent(); + event2.setId("testId"); + event2.setHref("testHref"); + event2.setEventId("testEventId"); + event2.setEventTime(event1.getEventTime()); + event2.setEventType("testEventType"); + event2.setCorrelationId("testCorrelationId"); + event2.setDomain("testDomain"); + event2.setTitle("testTitle"); + event2.setDescription("testDescription"); + event2.setPriority("testPriority"); + event2.setTimeOcurred(event1.getTimeOcurred()); + event2.setEvent(new ExportJobCreateEventPayload()); + + assertEquals(event1.hashCode(), event2.hashCode()); + + event1.setId("differentId"); + + assertNotEquals(event1.hashCode(), event2.hashCode()); + } + + @Test + void testToString() { + ExportJobCreateEvent event = new ExportJobCreateEvent(); + event.setId("testId"); + event.setHref("testHref"); + event.setEventId("testEventId"); + event.setEventTime(OffsetDateTime.parse("2024-01-19T17:02:03.289504717+02:00")); + event.setEventType("testEventType"); + event.setCorrelationId("testCorrelationId"); + event.setDomain("testDomain"); + event.setTitle("testTitle"); + event.setDescription("testDescription"); + event.setPriority("testPriority"); + event.setTimeOcurred(OffsetDateTime.parse("2024-01-19T17:02:03.289527665+02:00")); + event.setEvent(new ExportJobCreateEventPayload()); + + String expectedString = "class ExportJobCreateEvent {\n" + + " id: testId\n" + + " href: testHref\n" + + " eventId: testEventId\n" + + " eventTime: 2024-01-19T17:02:03.289504717+02:00\n" + + " eventType: testEventType\n" + + " correlationId: testCorrelationId\n" + + " domain: testDomain\n" + + " title: testTitle\n" + + " description: testDescription\n" + + " priority: testPriority\n" + + " timeOcurred: 2024-01-19T17:02:03.289527665+02:00\n" + + " event: class ExportJobCreateEventPayload {\n" + + " exportJob: null\n" + + " }\n" + + "}"; + + assertEquals(expectedString, event.toString()); + } + + @Test + void testToIndentedString() throws Exception { + ExportJobCreateEvent event = new ExportJobCreateEvent(); + + Method method = ExportJobCreateEvent.class.getDeclaredMethod("toIndentedString", Object.class); + method.setAccessible(true); + + String input = "Hello\nWorld"; + String expectedOutput = "Hello\n World"; + + String output = (String) method.invoke(event, input); + + assertEquals(expectedOutput, output); + } +} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobCreateTest.java b/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobCreateTest.java new file mode 100644 index 0000000..8333fe9 --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobCreateTest.java @@ -0,0 +1,231 @@ +package org.etsi.osl.services.api.rcm634; + +import org.etsi.osl.tmf.rcm634.model.ExportJobCreate; +import org.etsi.osl.tmf.rcm634.model.JobStateType; +import org.junit.jupiter.api.Test; + +import java.lang.reflect.Method; +import java.time.OffsetDateTime; +import static org.junit.jupiter.api.Assertions.*; + +public class ExportJobCreateTest { + + @Test + void testExportJobCreate() { + ExportJobCreate jobCreate = new ExportJobCreate(); + String query = "testQuery"; + OffsetDateTime completionDate = OffsetDateTime.now(); + OffsetDateTime creationDate = OffsetDateTime.now(); + String contentType = "testContentType"; + String errorLog = "testErrorLog"; + String path = "testPath"; + String url = "testUrl"; + + jobCreate.query(query); + jobCreate.setCompletionDate(completionDate); + jobCreate.setCreationDate(creationDate); + jobCreate.setContentType(contentType); + jobCreate.setErrorLog(errorLog); + jobCreate.setPath(path); + jobCreate.setUrl(url); + + assertEquals(query, jobCreate.getQuery()); + assertEquals(completionDate, jobCreate.getCompletionDate()); + assertEquals(creationDate, jobCreate.getCreationDate()); + assertEquals(contentType, jobCreate.getContentType()); + assertEquals(errorLog, jobCreate.getErrorLog()); + assertEquals(path, jobCreate.getPath()); + assertEquals(url, jobCreate.getUrl()); + + jobCreate = new ExportJobCreate(); + jobCreate.setQuery(query); + jobCreate.setCompletionDate(completionDate); + jobCreate.setCreationDate(creationDate); + jobCreate.setContentType(contentType); + jobCreate.setErrorLog(errorLog); + jobCreate.setPath(path); + jobCreate.setUrl(url); + + assertEquals(query, jobCreate.getQuery()); + assertEquals(completionDate, jobCreate.getCompletionDate()); + assertEquals(creationDate, jobCreate.getCreationDate()); + assertEquals(contentType, jobCreate.getContentType()); + assertEquals(errorLog, jobCreate.getErrorLog()); + assertEquals(path, jobCreate.getPath()); + assertEquals(url, jobCreate.getUrl()); + } + + @Test + void testStatus() { + ExportJobCreate jobCreate = new ExportJobCreate(); + JobStateType status = JobStateType.RUNNING; + jobCreate.setStatus(status); + assertEquals(status, jobCreate.getStatus()); + + ExportJobCreate newJobCreate = jobCreate.status(JobStateType.FAILED); + assertEquals(jobCreate, newJobCreate); + } + + @Test + void testAtBaseType() { + ExportJobCreate jobCreate = new ExportJobCreate(); + String baseType = "testBaseType"; + jobCreate.setAtBaseType(baseType); + assertEquals(baseType, jobCreate.getAtBaseType()); + + ExportJobCreate newJobCreate = jobCreate._atBaseType("newTestBaseType"); + assertEquals(jobCreate, newJobCreate); + } + + @Test + void testAtSchemaLocation() { + ExportJobCreate jobCreate = new ExportJobCreate(); + String schemaLocation = "testSchemaLocation"; + jobCreate.setAtSchemaLocation(schemaLocation); + assertEquals(schemaLocation, jobCreate.getAtSchemaLocation()); + + ExportJobCreate newJobCreate = jobCreate._atSchemaLocation("newTestSchemaLocation"); + assertEquals(jobCreate, newJobCreate); + } + + @Test + void testAtType() { + ExportJobCreate jobCreate = new ExportJobCreate(); + String type = "testType"; + jobCreate.setAtType(type); + assertEquals(type, jobCreate.getAtType()); + + ExportJobCreate newJobCreate = jobCreate._atType("newTestType"); + assertEquals(jobCreate, newJobCreate); + } + + @Test + void testErrorLog() { + ExportJobCreate jobCreate = new ExportJobCreate(); + String errorLog = "testErrorLog"; + jobCreate.setErrorLog(errorLog); + assertEquals(errorLog, jobCreate.getErrorLog()); + + ExportJobCreate newJobCreate = jobCreate.errorLog("newTestErrorLog"); + assertEquals(jobCreate, newJobCreate); + } + + @Test + void testPath() { + ExportJobCreate jobCreate = new ExportJobCreate(); + String path = "testPath"; + jobCreate.setPath(path); + assertEquals(path, jobCreate.getPath()); + + ExportJobCreate newJobCreate = jobCreate.path("newTestPath"); + assertEquals(jobCreate, newJobCreate); + } + + @Test + void testUrl() { + ExportJobCreate jobCreate = new ExportJobCreate(); + String url = "testUrl"; + jobCreate.setUrl(url); + assertEquals(url, jobCreate.getUrl()); + + ExportJobCreate newJobCreate = jobCreate.url("newTestUrl"); + assertEquals(jobCreate, newJobCreate); + } + + @Test + void testEquals() { + ExportJobCreate jobCreate1 = new ExportJobCreate(); + jobCreate1.setQuery("testQuery"); + jobCreate1.setCompletionDate(OffsetDateTime.now()); + jobCreate1.setCreationDate(OffsetDateTime.now()); + jobCreate1.setContentType("testContentType"); + jobCreate1.setErrorLog("testErrorLog"); + jobCreate1.setPath("testPath"); + jobCreate1.setUrl("testUrl"); + + ExportJobCreate jobCreate2 = new ExportJobCreate(); + jobCreate2.setQuery("testQuery"); + jobCreate2.setCompletionDate(jobCreate1.getCompletionDate()); + jobCreate2.setCreationDate(jobCreate1.getCreationDate()); + jobCreate2.setContentType("testContentType"); + jobCreate2.setErrorLog("testErrorLog"); + jobCreate2.setPath("testPath"); + jobCreate2.setUrl("testUrl"); + + assertTrue(jobCreate1.equals(jobCreate2)); + + jobCreate1.setQuery("differentQuery"); + + assertFalse(jobCreate1.equals(jobCreate2)); + } + + @Test + void testHashCode() { + ExportJobCreate jobCreate1 = new ExportJobCreate(); + jobCreate1.setQuery("testQuery"); + jobCreate1.setCompletionDate(OffsetDateTime.now()); + jobCreate1.setCreationDate(OffsetDateTime.now()); + jobCreate1.setContentType("testContentType"); + jobCreate1.setErrorLog("testErrorLog"); + jobCreate1.setPath("testPath"); + jobCreate1.setUrl("testUrl"); + + ExportJobCreate jobCreate2 = new ExportJobCreate(); + jobCreate2.setQuery("testQuery"); + jobCreate2.setCompletionDate(jobCreate1.getCompletionDate()); + jobCreate2.setCreationDate(jobCreate1.getCreationDate()); + jobCreate2.setContentType("testContentType"); + jobCreate2.setErrorLog("testErrorLog"); + jobCreate2.setPath("testPath"); + jobCreate2.setUrl("testUrl"); + + assertEquals(jobCreate1.hashCode(), jobCreate2.hashCode()); + + jobCreate1.setQuery("differentQuery"); + + assertNotEquals(jobCreate1.hashCode(), jobCreate2.hashCode()); + } + + @Test + void testToString() { + ExportJobCreate jobCreate = new ExportJobCreate(); + jobCreate.setQuery("testQuery"); + jobCreate.setCompletionDate(OffsetDateTime.parse("2024-01-19T17:02:03.289504717+02:00")); + jobCreate.setCreationDate(OffsetDateTime.parse("2024-01-19T17:02:03.289527665+02:00")); + jobCreate.setContentType("testContentType"); + jobCreate.setErrorLog("testErrorLog"); + jobCreate.setPath("testPath"); + jobCreate.setUrl("testUrl"); + + String expectedString = "class ExportJobCreate {\n" + + " completionDate: 2024-01-19T17:02:03.289504717+02:00\n" + + " contentType: testContentType\n" + + " creationDate: 2024-01-19T17:02:03.289527665+02:00\n" + + " errorLog: testErrorLog\n" + + " path: testPath\n" + + " query: testQuery\n" + + " url: testUrl\n" + + " status: null\n" + + " _atBaseType: null\n" + + " _atSchemaLocation: null\n" + + " _atType: null\n" + + "}"; + + assertEquals(expectedString, jobCreate.toString()); + } + + @Test + void testToIndentedString() throws Exception { + ExportJobCreate jobCreate = new ExportJobCreate(); + + Method method = ExportJobCreate.class.getDeclaredMethod("toIndentedString", Object.class); + method.setAccessible(true); + + String input = "Hello\nWorld"; + String expectedOutput = "Hello\n World"; + + String output = (String) method.invoke(jobCreate, input); + + assertEquals(expectedOutput, output); + } +} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobStateChangeEventTest.java b/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobStateChangeEventTest.java new file mode 100644 index 0000000..d8bb2bb --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobStateChangeEventTest.java @@ -0,0 +1,196 @@ +package org.etsi.osl.services.api.rcm634; + +import org.etsi.osl.tmf.rcm634.model.ExportJob; +import org.etsi.osl.tmf.rcm634.model.ExportJobStateChangeEvent; +import org.etsi.osl.tmf.rcm634.model.ExportJobStateChangeEventPayload; +import org.junit.jupiter.api.Test; + +import java.lang.reflect.Method; +import java.time.OffsetDateTime; +import static org.junit.jupiter.api.Assertions.*; + +public class ExportJobStateChangeEventTest { + + @Test + void testExportJobStateChangeEvent() { + ExportJobStateChangeEvent event = new ExportJobStateChangeEvent(); + String id = "testId"; + String href = "testHref"; + String eventId = "testEventId"; + OffsetDateTime eventTime = OffsetDateTime.now(); + String eventType = "testEventType"; + String correlationId = "testCorrelationId"; + String domain = "testDomain"; + String title = "testTitle"; + String description = "testDescription"; + String priority = "testPriority"; + OffsetDateTime timeOccurred = OffsetDateTime.now(); + ExportJobStateChangeEventPayload eventPayload = new ExportJobStateChangeEventPayload(); + + event.id(id); + event.href(href); + event.eventId(eventId); + event.eventTime(eventTime); + event.eventType(eventType); + event.correlationId(correlationId); + event.domain(domain); + event.title(title); + event.description(description); + event.priority(priority); + event.timeOcurred(timeOccurred); + event.event(eventPayload); + + assertEquals(id, event.getId()); + assertEquals(href, event.getHref()); + assertEquals(eventId, event.getEventId()); + assertEquals(eventTime, event.getEventTime()); + assertEquals(eventType, event.getEventType()); + assertEquals(correlationId, event.getCorrelationId()); + assertEquals(domain, event.getDomain()); + assertEquals(title, event.getTitle()); + assertEquals(description, event.getDescription()); + assertEquals(priority, event.getPriority()); + assertEquals(timeOccurred, event.getTimeOcurred()); + assertEquals(eventPayload, event.getEvent()); + } + + @Test + void testEquals() { + ExportJobStateChangeEvent event1 = new ExportJobStateChangeEvent(); + event1.setId("testId"); + event1.setHref("testHref"); + event1.setEventId("testEventId"); + event1.setEventTime(OffsetDateTime.now()); + event1.setEventType("testEventType"); + event1.setCorrelationId("testCorrelationId"); + event1.setDomain("testDomain"); + event1.setTitle("testTitle"); + event1.setDescription("testDescription"); + event1.setPriority("testPriority"); + event1.setTimeOcurred(OffsetDateTime.now()); + event1.setEvent(new ExportJobStateChangeEventPayload()); + + ExportJobStateChangeEvent event2 = new ExportJobStateChangeEvent(); + event2.setId("testId"); + event2.setHref("testHref"); + event2.setEventId("testEventId"); + event2.setEventTime(event1.getEventTime()); + event2.setEventType("testEventType"); + event2.setCorrelationId("testCorrelationId"); + event2.setDomain("testDomain"); + event2.setTitle("testTitle"); + event2.setDescription("testDescription"); + event2.setPriority("testPriority"); + event2.setTimeOcurred(event1.getTimeOcurred()); + event2.setEvent(new ExportJobStateChangeEventPayload()); + + assertTrue(event1.equals(event2)); + + event1.setId("differentId"); + + assertFalse(event1.equals(event2)); + } + + @Test + void testHashCode() { + ExportJobStateChangeEvent event1 = new ExportJobStateChangeEvent(); + event1.setId("testId"); + event1.setHref("testHref"); + event1.setEventId("testEventId"); + event1.setEventTime(OffsetDateTime.now()); + event1.setEventType("testEventType"); + event1.setCorrelationId("testCorrelationId"); + event1.setDomain("testDomain"); + event1.setTitle("testTitle"); + event1.setDescription("testDescription"); + event1.setPriority("testPriority"); + event1.setTimeOcurred(OffsetDateTime.now()); + event1.setEvent(new ExportJobStateChangeEventPayload()); + + ExportJobStateChangeEvent event2 = new ExportJobStateChangeEvent(); + event2.setId("testId"); + event2.setHref("testHref"); + event2.setEventId("testEventId"); + event2.setEventTime(event1.getEventTime()); + event2.setEventType("testEventType"); + event2.setCorrelationId("testCorrelationId"); + event2.setDomain("testDomain"); + event2.setTitle("testTitle"); + event2.setDescription("testDescription"); + event2.setPriority("testPriority"); + event2.setTimeOcurred(event1.getTimeOcurred()); + event2.setEvent(new ExportJobStateChangeEventPayload()); + + assertEquals(event1.hashCode(), event2.hashCode()); + + event1.setId("differentId"); + + assertNotEquals(event1.hashCode(), event2.hashCode()); + } + + @Test + void testToString() { + ExportJobStateChangeEvent event = new ExportJobStateChangeEvent(); + event.setId("testId"); + event.setHref("testHref"); + event.setEventId("testEventId"); + event.setEventTime(OffsetDateTime.parse("2024-01-19T17:02:03.289504717+02:00")); + event.setEventType("testEventType"); + event.setCorrelationId("testCorrelationId"); + event.setDomain("testDomain"); + event.setTitle("testTitle"); + event.setDescription("testDescription"); + event.setPriority("testPriority"); + event.setTimeOcurred(OffsetDateTime.parse("2024-01-19T17:02:03.289527665+02:00")); + event.setEvent(new ExportJobStateChangeEventPayload()); + + String expectedString = "class ExportJobStateChangeEvent {\n" + + " id: testId\n" + + " href: testHref\n" + + " eventId: testEventId\n" + + " eventTime: 2024-01-19T17:02:03.289504717+02:00\n" + + " eventType: testEventType\n" + + " correlationId: testCorrelationId\n" + + " domain: testDomain\n" + + " title: testTitle\n" + + " description: testDescription\n" + + " priority: testPriority\n" + + " timeOcurred: 2024-01-19T17:02:03.289527665+02:00\n" + + " event: class ExportJobStateChangeEventPayload {\n" + + " exportJob: null\n" + + " }\n" + + "}"; + + assertEquals(expectedString, event.toString()); + } + + @Test + void testToIndentedString() throws Exception { + ExportJobStateChangeEvent event = new ExportJobStateChangeEvent(); + + Method method = ExportJobStateChangeEvent.class.getDeclaredMethod("toIndentedString", Object.class); + method.setAccessible(true); + + String input = "Hello\nWorld"; + String expectedOutput = "Hello\n World"; + + String output = (String) method.invoke(event, input); + + assertEquals(expectedOutput, output); + } + + @Test + void testExportJob() { + ExportJobStateChangeEventPayload payload = new ExportJobStateChangeEventPayload(); + ExportJob job = new ExportJob(); + job.setId("testId"); + payload.setExportJob(job); + assertEquals(job, payload.getExportJob()); + + ExportJob newJob = new ExportJob(); + newJob.setId("newTestId"); + ExportJobStateChangeEventPayload newPayload = payload.exportJob(newJob); + assertEquals(payload, newPayload); + assertEquals(newJob, payload.getExportJob()); + } +} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobTest.java b/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobTest.java new file mode 100644 index 0000000..07567d6 --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/rcm634/ExportJobTest.java @@ -0,0 +1,266 @@ +package org.etsi.osl.services.api.rcm634; + +import org.etsi.osl.tmf.rcm634.model.ExportJob; +import org.etsi.osl.tmf.rcm634.model.JobStateType; +import org.junit.jupiter.api.Test; +import java.time.OffsetDateTime; +import static org.junit.jupiter.api.Assertions.*; + +public class ExportJobTest { + + @Test + void testExportJob() { + ExportJob job = new ExportJob(); + String id = "testId"; + String query = "testQuery"; + OffsetDateTime completionDate = OffsetDateTime.now(); + OffsetDateTime creationDate = OffsetDateTime.now(); + String contentType = "testContentType"; + String errorLog = "testErrorLog"; + String path = "testPath"; + String url = "testUrl"; + + job.id(id); + job.query(query); + job.setCompletionDate(completionDate); + job.setCreationDate(creationDate); + job.setContentType(contentType); + job.setErrorLog(errorLog); + job.setPath(path); + job.setUrl(url); + + assertEquals(id, job.getId()); + assertEquals(query, job.getQuery()); + assertEquals(completionDate, job.getCompletionDate()); + assertEquals(creationDate, job.getCreationDate()); + assertEquals(contentType, job.getContentType()); + assertEquals(errorLog, job.getErrorLog()); + assertEquals(path, job.getPath()); + assertEquals(url, job.getUrl()); + + job = new ExportJob(); + job.setId(id); + job.setQuery(query); + job.setCompletionDate(completionDate); + job.setCreationDate(creationDate); + job.setContentType(contentType); + job.setErrorLog(errorLog); + job.setPath(path); + job.setUrl(url); + + assertEquals(id, job.getId()); + assertEquals(query, job.getQuery()); + assertEquals(completionDate, job.getCompletionDate()); + assertEquals(creationDate, job.getCreationDate()); + assertEquals(contentType, job.getContentType()); + assertEquals(errorLog, job.getErrorLog()); + assertEquals(path, job.getPath()); + assertEquals(url, job.getUrl()); + } + + @Test + void testEquals() { + String id = "testId"; + String callback = "testCallback"; + String query = "testQuery"; + OffsetDateTime completionDate = OffsetDateTime.now(); + OffsetDateTime creationDate = OffsetDateTime.now(); + String contentType = "testContentType"; + String errorLog = "testErrorLog"; + String path = "testPath"; + String url = "testUrl"; + + ExportJob job1 = new ExportJob(); + job1.setId(id); + job1.setQuery(query); + job1.setCompletionDate(completionDate); + job1.setCreationDate(creationDate); + job1.setContentType(contentType); + job1.setErrorLog(errorLog); + job1.setPath(path); + job1.setUrl(url); + + ExportJob job2 = new ExportJob(); + job2.setId(id); + job2.setQuery(query); + job2.setCompletionDate(completionDate); + job2.setCreationDate(creationDate); + job2.setContentType(contentType); + job2.setErrorLog(errorLog); + job2.setPath(path); + job2.setUrl(url); + + assertTrue(job1.equals(job2)); + + job1.id("differentId"); + + assertFalse(job1.equals(job2)); + } + + @Test + void testHashCode() { + String id = "testId"; + String callback = "testCallback"; + String query = "testQuery"; + OffsetDateTime completionDate = OffsetDateTime.now(); + OffsetDateTime creationDate = OffsetDateTime.now(); + String contentType = "testContentType"; + String errorLog = "testErrorLog"; + String path = "testPath"; + String url = "testUrl"; + + ExportJob job1 = new ExportJob(); + job1.setId(id); + job1.setQuery(query); + job1.setCompletionDate(completionDate); + job1.setCreationDate(creationDate); + job1.setContentType(contentType); + job1.setErrorLog(errorLog); + job1.setPath(path); + job1.setUrl(url); + + ExportJob job2 = new ExportJob(); + job2.setId(id); + job2.setQuery(query); + job2.setCompletionDate(completionDate); + job2.setCreationDate(creationDate); + job2.setContentType(contentType); + job2.setErrorLog(errorLog); + job2.setPath(path); + job2.setUrl(url); + + assertEquals(job1.hashCode(), job2.hashCode()); + + job1.id("differentId"); + + assertNotEquals(job1.hashCode(), job2.hashCode()); + } + + @Test + void testToString() { + ExportJob job = new ExportJob(); + + String id = "testId"; + String callback = "testCallback"; + String query = "testQuery"; + OffsetDateTime completionDate = OffsetDateTime.parse("2024-01-19T16:35:07.730526064+02:00"); + OffsetDateTime creationDate = OffsetDateTime.parse("2024-01-19T16:35:07.731493435+02:00"); + String contentType = "testContentType"; + String errorLog = "testErrorLog"; + String path = "testPath"; + String url = "testUrl"; + + job.id(id); + job.query(query); + job.setCompletionDate(completionDate); + job.setCreationDate(creationDate); + job.setContentType(contentType); + job.setErrorLog(errorLog); + job.setPath(path); + job.setUrl(url); + + String expectedString = "class ExportJob {\n" + + " id: testId\n" + + " href: null\n" + + " completionDate: 2024-01-19T16:35:07.730526064+02:00\n" + + " contentType: testContentType\n" + + " creationDate: 2024-01-19T16:35:07.731493435+02:00\n" + + " errorLog: testErrorLog\n" + + " path: testPath\n" + + " query: testQuery\n" + + " url: testUrl\n" + + " status: null\n" + + " _atBaseType: null\n" + + " _atSchemaLocation: null\n" + + " _atType: null\n" + + "}"; + + assertEquals(expectedString, job.toString()); + } + + @Test + void testHref() { + ExportJob job = new ExportJob(); + String href = "testHref"; + job.setHref(href); + assertEquals(href, job.getHref()); + + ExportJob newJob = job.href("newTestHref"); + assertEquals(job, newJob); + } + + @Test + void testCompletionDate() { + ExportJob job = new ExportJob(); + OffsetDateTime completionDate = OffsetDateTime.now(); + job.setCompletionDate(completionDate); + assertEquals(completionDate, job.getCompletionDate()); + + ExportJob newJob = job.completionDate(OffsetDateTime.now()); + assertEquals(job, newJob); + } + + @Test + void testContentType() { + ExportJob job = new ExportJob(); + String contentType = "testContentType"; + job.setContentType(contentType); + assertEquals(contentType, job.getContentType()); + + ExportJob newJob = job.contentType("newTestContentType"); + assertEquals(job, newJob); + } + + @Test + void testCreationDate() { + ExportJob job = new ExportJob(); + OffsetDateTime creationDate = OffsetDateTime.now(); + job.setCreationDate(creationDate); + assertEquals(creationDate, job.getCreationDate()); + } + + @Test + void testStatus() { + ExportJob job = new ExportJob(); + JobStateType status = JobStateType.RUNNING; + job.setStatus(status); + assertEquals(status, job.getStatus()); + + ExportJob newJob = job.status(JobStateType.FAILED); + assertEquals(job, newJob); + } + + @Test + void testAtBaseType() { + ExportJob job = new ExportJob(); + String baseType = "testBaseType"; + job.setAtBaseType(baseType); + assertEquals(baseType, job.getAtBaseType()); + + ExportJob newJob = job._atBaseType("newTestBaseType"); + assertEquals(job, newJob); + } + + @Test + void testAtSchemaLocation() { + ExportJob job = new ExportJob(); + String schemaLocation = "testSchemaLocation"; + job.setAtSchemaLocation(schemaLocation); + assertEquals(schemaLocation, job.getAtSchemaLocation()); + + ExportJob newJob = job._atSchemaLocation("newTestSchemaLocation"); + assertEquals(job, newJob); + } + + @Test + void testAtType() { + ExportJob job = new ExportJob(); + String type = "testType"; + job.setAtType(type); + assertEquals(type, job.getAtType()); + + ExportJob newJob = job._atType("newTestType"); + assertEquals(job, newJob); + } + +} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/rcm634/ResourceSpecificationApiControllerTest.java b/src/test/java/org/etsi/osl/services/api/rcm634/ResourceSpecificationApiControllerTest.java new file mode 100644 index 0000000..1aa8d1a --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/rcm634/ResourceSpecificationApiControllerTest.java @@ -0,0 +1,257 @@ +package org.etsi.osl.services.api.rcm634; + +import com.fasterxml.jackson.databind.ObjectMapper; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.transaction.Transactional; +import org.apache.commons.io.IOUtils; +import org.etsi.osl.tmf.JsonUtils; +import org.etsi.osl.tmf.OpenAPISpringBoot; +import org.etsi.osl.tmf.rcm634.api.ResourceSpecificationApiController; +import org.etsi.osl.tmf.rcm634.model.*; +import org.etsi.osl.tmf.rcm634.reposervices.ResourceSpecificationRepoService; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +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.mock.web.MockHttpServletRequest; +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.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.List; +import java.util.Optional; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + + +@Transactional +@SpringBootTest( webEnvironment = SpringBootTest.WebEnvironment.MOCK , classes = OpenAPISpringBoot.class) +@AutoConfigureTestDatabase +@AutoConfigureMockMvc +@ActiveProfiles("testing") +public class ResourceSpecificationApiControllerTest { + + @Autowired + private MockMvc mvc; + + @InjectMocks + ResourceSpecificationApiController resourceSpecificationApiController; + + @Mock + ResourceSpecificationRepoService resourceSpecificationRepoService; + + @Mock + ResourceSpecification resourceSpecification; + + @BeforeEach + public void init() { + MockitoAnnotations.initMocks(this); + } + + + // Test CREATE with role ADMIN + @Test + @WithMockUser(authorities = {"ROLE_ADMIN"}) + public void testCreateResourceSpecificationAdmin() throws Exception { + + // Testing a valid physical resource specification at the correct endpoint + File resourceSpecFile = new File("src/test/resources/testPhysicalResourceSpec.json"); + InputStream in = new FileInputStream(resourceSpecFile); + String resourceSpecString = IOUtils.toString(in, "UTF-8"); + PhysicalResourceSpecificationCreate physicalResourceSpecCreate = JsonUtils.toJsonObj(resourceSpecString, PhysicalResourceSpecificationCreate.class); + + mvc.perform(MockMvcRequestBuilders.post("/resourceCatalogManagement/v4/resourceSpecification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(JsonUtils.toJson(physicalResourceSpecCreate))) + .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("name", is("Test Resource Spec"))) + .andExpect(status().isOk()) + .andReturn().getResponse(); + + + LogicalResourceSpecificationCreate logicalResourceSpecificationCreate = new LogicalResourceSpecificationCreate(); + logicalResourceSpecificationCreate.setName("Test Logical Resource Spec"); + mvc.perform(MockMvcRequestBuilders.post("/resourceCatalogManagement/v4/resourceSpecification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(JsonUtils.toJson(logicalResourceSpecificationCreate))) + .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("name", is("Test Logical Resource Spec"))) + .andExpect(status().isOk()) + .andReturn().getResponse(); + + + ResourceFunctionSpecificationCreate resourceFunctionSpecificationCreate = new ResourceFunctionSpecificationCreate(); + resourceFunctionSpecificationCreate.setName("Test Resource Function Specification"); + resourceFunctionSpecificationCreate.setType("ResourceFunctionSpecification"); + mvc.perform(MockMvcRequestBuilders.post("/resourceCatalogManagement/v4/resourceSpecification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(JsonUtils.toJson(resourceFunctionSpecificationCreate))) + .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("name", is("Test Resource Function Specification"))) + .andExpect(status().isOk()) + .andReturn().getResponse(); + + // Testing a valid physical resource specification wrong endpoint + mvc.perform(MockMvcRequestBuilders.post("/resourceCatalogManagement/v4/resourceSpecificat") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(JsonUtils.toJson(physicalResourceSpecCreate))) + .andExpect(status().isNotFound()) + .andReturn().getResponse(); + + // Testing a valid physical resource specification wrong payload correct endpoint + String wrongStringPayload = "random string as payload"; + byte[] wrongPayload = wrongStringPayload.getBytes(); + + mvc.perform(MockMvcRequestBuilders.post("/resourceCatalogManagement/v4/resourceSpecification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(wrongPayload)) + .andExpect(status().isBadRequest()) + .andReturn().getResponse(); + } + + // Test CREATE with incorrect role USER + @Test + @WithMockUser(authorities = {"ROLE_USER"}) + public void testCreateResourceSpecificationUser() throws Exception { + // Testing a valid physical resource specification + File physicalResourceSpecFile = new File("src/test/resources/testResourceSpec.json"); + InputStream in = new FileInputStream(physicalResourceSpecFile); + String physicalResourceSpecString = IOUtils.toString(in, "UTF-8"); + LogicalResourceSpecificationCreate physicalResourceSpecCreate = JsonUtils.toJsonObj(physicalResourceSpecString, LogicalResourceSpecificationCreate.class); + mvc.perform(MockMvcRequestBuilders.post("/resourceCatalogManagement/v4/resourceSpecification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(JsonUtils.toJson(physicalResourceSpecCreate))) + .andExpect(status().isForbidden()) + .andReturn().getResponse(); + + } + + // Test DELETE method with role ADMIN + @Test + @WithMockUser(authorities = {"ROLE_ADMIN"}) + public void testDeleteResourceSpecificationAdmin() throws Exception { + ResourceFunctionSpecificationCreate resourceFunctionSpecificationCreate = new ResourceFunctionSpecificationCreate(); + resourceFunctionSpecificationCreate.setName("Test Resource Function Specification"); + resourceFunctionSpecificationCreate.setType("ResourceFunctionSpecification"); + String createdSpecificationString = mvc.perform(MockMvcRequestBuilders.post("/resourceCatalogManagement/v4/resourceSpecification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(JsonUtils.toJson(resourceFunctionSpecificationCreate))) + .andReturn().getResponse().getContentAsString(); + System.out.println(createdSpecificationString); + + ResourceSpecification createdSpecification = JsonUtils.toJsonObj(createdSpecificationString, ResourceFunctionSpecification.class); + String idToBeDeleted = createdSpecification.getId(); + + mvc.perform(MockMvcRequestBuilders.delete("/resourceCatalogManagement/v4/resourceSpecification/" + idToBeDeleted) + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(JsonUtils.toJson(null))) + .andExpect(status().isOk()) + .andReturn().getResponse(); + + } + + // Test DELETE method with incorrect role USER + @Test + @WithMockUser(authorities = {"ROLE_USER"}) + public void testDeleteResourceSpecificationUser() throws Exception { + mvc.perform(MockMvcRequestBuilders.delete("/resourceCatalogManagement/v4/resourceSpecification/idToBeDeleted") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(JsonUtils.toJson(null))) + .andExpect(status().isForbidden()) + .andReturn().getResponse(); + + } + + // Test GET by id method with no role + @Test + @WithMockUser(authorities = {"ROLE_ADMIN"}) + public void testRetrieveResourceSpecification() throws Exception { + ResourceFunctionSpecificationCreate resourceFunctionSpecificationCreate = new ResourceFunctionSpecificationCreate(); + resourceFunctionSpecificationCreate.setName("Test Resource Function Specification"); + resourceFunctionSpecificationCreate.setType("ResourceFunctionSpecification"); + String createdSpecificationString = mvc.perform(MockMvcRequestBuilders.post("/resourceCatalogManagement/v4/resourceSpecification") + .with(SecurityMockMvcRequestPostProcessors.csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(JsonUtils.toJson(resourceFunctionSpecificationCreate))) + .andReturn().getResponse().getContentAsString(); + + ResourceSpecification createdSpecification = JsonUtils.toJsonObj(createdSpecificationString, ResourceFunctionSpecification.class); + String id = createdSpecification.getId(); + String fields = "name"; + mvc.perform(MockMvcRequestBuilders.get("/resourceCatalogManagement/v4/resourceSpecification/" + id) + .contentType(MediaType.APPLICATION_JSON) + .content(JsonUtils.toJson(null)) + .param("fields", fields)) + .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("name", is("Test Resource Function Specification"))) + .andExpect(status().isOk()) + .andReturn().getResponse(); + } + + @Test + @WithMockUser(authorities = {"ROLE_ADMIN"}) + public void testListResourceSpecification() throws Exception { + String listResSpecsResponseString = mvc.perform(MockMvcRequestBuilders.get("/resourceCatalogManagement/v4/resourceSpecification") + .contentType(MediaType.APPLICATION_JSON) + .content(JsonUtils.toJson(null))) + .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andReturn().getResponse().getContentAsString(); + + List listResSpecsResponse = JsonUtils.toListOfJsonObj(listResSpecsResponseString, LogicalResourceSpecification.class); + assertEquals(7, listResSpecsResponse.size()); + + mvc.perform(MockMvcRequestBuilders.get("/resourceCatalogManagement/v4/resourceSpecification") + .contentType(MediaType.APPLICATION_JSON) + .content(JsonUtils.toJson(null)) + .param("fields", "lastUpdate")) + .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andReturn().getResponse().getContentAsString(); + } + + @Test + void testGetObjectMapper() { + ObjectMapper objectMapper = new ObjectMapper(); + MockHttpServletRequest request = new MockHttpServletRequest(); + ResourceSpecificationApiController controller = new ResourceSpecificationApiController(objectMapper, request); + + Optional result = controller.getObjectMapper(); + assertTrue(result.isPresent()); + assertEquals(objectMapper, result.get()); + } + + @Test + void testGetRequest() { + ObjectMapper objectMapper = new ObjectMapper(); + MockHttpServletRequest request = new MockHttpServletRequest(); + ResourceSpecificationApiController controller = new ResourceSpecificationApiController(objectMapper, request); + + Optional result = controller.getRequest(); + assertTrue(result.isPresent()); + assertEquals(request, result.get()); + } +} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/rcm634/ResourceSpecificationCharacteristicTest.java b/src/test/java/org/etsi/osl/services/api/rcm634/ResourceSpecificationCharacteristicTest.java new file mode 100644 index 0000000..4e297af --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/rcm634/ResourceSpecificationCharacteristicTest.java @@ -0,0 +1,351 @@ +package org.etsi.osl.services.api.rcm634; + +import org.etsi.osl.tmf.common.model.TimePeriod; +import org.etsi.osl.tmf.rcm634.model.ResourceSpecCharRelationship; +import org.etsi.osl.tmf.rcm634.model.ResourceSpecificationCharacteristic; +import org.etsi.osl.tmf.rcm634.model.ResourceSpecificationCharacteristicValue; +import org.junit.jupiter.api.Test; + +import java.lang.reflect.Method; +import java.util.HashSet; +import java.util.Set; + +import static org.junit.jupiter.api.Assertions.*; + +public class ResourceSpecificationCharacteristicTest { + @Test + void testResourceSpecificationCharacteristicConstructorAndAllProperties() { + // Create a new ResourceSpecificationCharacteristic object and set its properties + ResourceSpecificationCharacteristic characteristic1 = new ResourceSpecificationCharacteristic(); + characteristic1.setName("testName1"); + characteristic1.setDescription("testDescription1"); + characteristic1.setValueType("testValueType1"); + characteristic1.setConfigurable(true); + characteristic1.setValidFor(new TimePeriod()); + characteristic1.setSchemaLocation("testSchemaLocation1"); + characteristic1.setValueSchemaLocation("testValueSchemaLocation1"); + characteristic1.setMinCardinality(1); + characteristic1.setMaxCardinality(1); + characteristic1.setIsUnique(true); + characteristic1.setRegex("testRegex1"); + characteristic1.setExtensible(true); + characteristic1.setResourceSpecCharRelationship(new HashSet<>()); + characteristic1.setResourceSpecificationCharacteristicValue(new HashSet<>()); + + // Create another ResourceSpecificationCharacteristic object using the constructor that takes another ResourceSpecificationCharacteristic object as a parameter + ResourceSpecificationCharacteristic characteristic2 = new ResourceSpecificationCharacteristic(characteristic1); + characteristic2.setSchemaLocation("testSchemaLocation1"); + characteristic2.setValueSchemaLocation("testValueSchemaLocation1"); + + // Assert that the properties of the two objects are equal + assertEquals(characteristic1.getName(), characteristic2.getName()); + assertEquals(characteristic1.getDescription(), characteristic2.getDescription()); + assertEquals(characteristic1.getValueType(), characteristic2.getValueType()); + assertEquals(characteristic1.isConfigurable(), characteristic2.isConfigurable()); + assertEquals(characteristic1.getValidFor(), characteristic2.getValidFor()); + assertEquals(characteristic1.getSchemaLocation(), characteristic2.getSchemaLocation()); + assertEquals(characteristic1.getValueSchemaLocation(), characteristic2.getValueSchemaLocation()); + assertEquals(characteristic1.getMinCardinality(), characteristic2.getMinCardinality()); + assertEquals(characteristic1.getMaxCardinality(), characteristic2.getMaxCardinality()); + assertEquals(characteristic1.isIsUnique(), characteristic2.isIsUnique()); + assertEquals(characteristic1.getRegex(), characteristic2.getRegex()); + assertEquals(characteristic1.isExtensible(), characteristic2.isExtensible()); + assertEquals(characteristic1.getResourceSpecCharRelationship(), characteristic2.getResourceSpecCharRelationship()); + assertEquals(characteristic1.getResourceSpecCharacteristicValue(), characteristic2.getResourceSpecCharacteristicValue()); + } + + @Test + void testName() { + ResourceSpecificationCharacteristic characteristic = new ResourceSpecificationCharacteristic(); + String name = "Test Name"; + characteristic.name(name); + assertEquals(name, characteristic.getName()); + } + + @Test + void testDescription() { + ResourceSpecificationCharacteristic characteristic = new ResourceSpecificationCharacteristic(); + String description = "Test Description"; + characteristic.description(description); + assertEquals(description, characteristic.getDescription()); + } + + @Test + void testValueType() { + ResourceSpecificationCharacteristic characteristic = new ResourceSpecificationCharacteristic(); + String valueType = "Test ValueType"; + characteristic.valueType(valueType); + assertEquals(valueType, characteristic.getValueType()); + } + + @Test + void testConfigurable() { + ResourceSpecificationCharacteristic characteristic = new ResourceSpecificationCharacteristic(); + Boolean configurable = true; + characteristic.configurable(configurable); + assertEquals(configurable, characteristic.isConfigurable()); + } + + @Test + void testValidFor() { + ResourceSpecificationCharacteristic characteristic = new ResourceSpecificationCharacteristic(); + TimePeriod validFor = new TimePeriod(); + characteristic.validFor(validFor); + assertEquals(validFor, characteristic.getValidFor()); + } + + @Test + void testType() { + ResourceSpecificationCharacteristic characteristic = new ResourceSpecificationCharacteristic(); + String type = "Test Type"; + characteristic.type(type); + assertEquals(type, characteristic.getType()); + } + + @Test + void testSchemaLocation() { + ResourceSpecificationCharacteristic characteristic = new ResourceSpecificationCharacteristic(); + String schemaLocation = "Test SchemaLocation"; + characteristic.schemaLocation(schemaLocation); + assertEquals(schemaLocation, characteristic.getSchemaLocation()); + } + + @Test + void testValueSchemaLocation() { + ResourceSpecificationCharacteristic characteristic = new ResourceSpecificationCharacteristic(); + String valueSchemaLocation = "Test ValueSchemaLocation"; + characteristic.valueSchemaLocation(valueSchemaLocation); + assertEquals(valueSchemaLocation, characteristic.getValueSchemaLocation()); + } + + @Test + void testMinCardinality() { + ResourceSpecificationCharacteristic characteristic = new ResourceSpecificationCharacteristic(); + Integer minCardinality = 1; + characteristic.minCardinality(minCardinality); + assertEquals(minCardinality, characteristic.getMinCardinality()); + } + + @Test + void testMaxCardinality() { + ResourceSpecificationCharacteristic characteristic = new ResourceSpecificationCharacteristic(); + Integer maxCardinality = 10; + characteristic.maxCardinality(maxCardinality); + assertEquals(maxCardinality, characteristic.getMaxCardinality()); + } + + @Test + void testIsUnique() { + ResourceSpecificationCharacteristic characteristic = new ResourceSpecificationCharacteristic(); + Boolean isUnique = true; + characteristic.isUnique(isUnique); + assertEquals(isUnique, characteristic.isIsUnique()); + } + + @Test + void testRegex() { + ResourceSpecificationCharacteristic characteristic = new ResourceSpecificationCharacteristic(); + String regex = "Test Regex"; + characteristic.regex(regex); + assertEquals(regex, characteristic.getRegex()); + } + + @Test + void testExtensible() { + ResourceSpecificationCharacteristic characteristic = new ResourceSpecificationCharacteristic(); + Boolean extensible = true; + characteristic.extensible(extensible); + assertEquals(extensible, characteristic.isExtensible()); + } + + @Test + void testResourceSpecCharRelationship() { + ResourceSpecificationCharacteristic characteristic = new ResourceSpecificationCharacteristic(); + Set resourceSpecCharRelationship = new HashSet<>(); + resourceSpecCharRelationship.add(new ResourceSpecCharRelationship()); + characteristic.resourceSpecCharRelationship(resourceSpecCharRelationship); + assertEquals(resourceSpecCharRelationship, characteristic.getResourceSpecCharRelationship()); + } + + @Test + void testResourceSpecCharacteristicValue() { + ResourceSpecificationCharacteristic characteristic = new ResourceSpecificationCharacteristic(); + Set resourceSpecCharacteristicValue = new HashSet<>(); + resourceSpecCharacteristicValue.add(new ResourceSpecificationCharacteristicValue()); + characteristic.ResourceSpecCharacteristicValue(resourceSpecCharacteristicValue); + assertEquals(resourceSpecCharacteristicValue, characteristic.getResourceSpecCharacteristicValue()); + } + + @Test + void testAddResourceSpecCharacteristicValueItem() { + ResourceSpecificationCharacteristic characteristic = new ResourceSpecificationCharacteristic(); + ResourceSpecificationCharacteristicValue resourceSpecCharacteristicValueItem = new ResourceSpecificationCharacteristicValue(); + characteristic.addResourceSpecCharacteristicValueItem(resourceSpecCharacteristicValueItem); + assertTrue(characteristic.getResourceSpecCharacteristicValue().contains(resourceSpecCharacteristicValueItem)); + } + + @Test + void testEquals() { + ResourceSpecificationCharacteristic characteristic = new ResourceSpecificationCharacteristic(); + characteristic.setName("Test Name"); + characteristic.setDescription("Test Description"); + characteristic.setValueType("Test ValueType"); + characteristic.setConfigurable(true); + characteristic.setType("Test Type"); + characteristic.setSchemaLocation("Test SchemaLocation"); + characteristic.setValueSchemaLocation("Test ValueSchemaLocation"); + characteristic.setMinCardinality(1); + characteristic.setMaxCardinality(10); + characteristic.setIsUnique(true); + characteristic.setRegex("Test Regex"); + characteristic.setExtensible(true); + + ResourceSpecificationCharacteristic characteristic2 = new ResourceSpecificationCharacteristic(); + characteristic2.setName("Test Name"); + characteristic2.setDescription("Test Description"); + characteristic2.setValueType("Test ValueType"); + characteristic2.setConfigurable(true); + characteristic2.setType("Test Type"); + characteristic2.setSchemaLocation("Test SchemaLocation"); + characteristic2.setValueSchemaLocation("Test ValueSchemaLocation"); + characteristic2.setMinCardinality(1); + characteristic2.setMaxCardinality(10); + characteristic2.setIsUnique(true); + characteristic2.setRegex("Test Regex"); + characteristic2.setExtensible(true); + + assertTrue(characteristic.equals(characteristic2)); + + characteristic2.name("Test Name 2"); + assertFalse(characteristic.equals(characteristic2)); + } + + @Test + void testToString() { + ResourceSpecificationCharacteristic characteristic = new ResourceSpecificationCharacteristic(); + characteristic.setName("Test Name"); + characteristic.setDescription("Test Description"); + characteristic.setValueType("Test ValueType"); + characteristic.setConfigurable(true); + characteristic.setValidFor(new TimePeriod()); + characteristic.setType("Test Type"); + characteristic.setSchemaLocation("Test SchemaLocation"); + characteristic.setValueSchemaLocation("Test ValueSchemaLocation"); + characteristic.setMinCardinality(1); + characteristic.setMaxCardinality(10); + characteristic.setIsUnique(true); + characteristic.setRegex("Test Regex"); + characteristic.setExtensible(true); + characteristic.setResourceSpecCharRelationship(new HashSet<>()); + characteristic.setResourceSpecificationCharacteristicValue(new HashSet<>()); + + String expectedString = "class ResourceSpecificationCharacteristic {\n" + + " name: Test Name\n" + + " description: Test Description\n" + + " valueType: Test ValueType\n" + + " configurable: true\n" + + " validFor: " + characteristic.getValidFor().toString().replace("\n", "\n ") + "\n" + + " type: Test Type\n" + + " schemaLocation: Test SchemaLocation\n" + + " valueSchemaLocation: Test ValueSchemaLocation\n" + + " minCardinality: 1\n" + + " maxCardinality: 10\n" + + " isUnique: true\n" + + " regex: Test Regex\n" + + " extensible: true\n" + + " resourceSpecCharRelationship: []\n" + + " ResourceSpecificationCharacteristicValue: []\n" + + "}"; + + assertEquals(expectedString, characteristic.toString()); + } + + @Test + void testToIndentedString() throws Exception { + ResourceSpecificationCharacteristic resourceSpecificationCharacteristic = new ResourceSpecificationCharacteristic(); + + Method method = ResourceSpecificationCharacteristic.class.getDeclaredMethod("toIndentedString", Object.class); + method.setAccessible(true); + + String input = "Hello\nWorld"; + String expectedOutput = "Hello\n World"; + + String output = (String) method.invoke(resourceSpecificationCharacteristic, input); + + assertEquals(expectedOutput, output); + } + + @Test + void testUpdateWith() { + ResourceSpecificationCharacteristic characteristic = new ResourceSpecificationCharacteristic(); + characteristic.setName("Test Name"); + characteristic.setDescription("Test Description"); + characteristic.setConfigurable(true); + characteristic.setType("org.etsi.osl.tmf.rcm634.model.ResourceSpecificationCharacteristic"); + characteristic.setMinCardinality(1); + characteristic.setMaxCardinality(10); + characteristic.setIsUnique(true); + characteristic.setRegex("Test Regex"); + characteristic.setExtensible(true); + + ResourceSpecificationCharacteristic characteristic2 = new ResourceSpecificationCharacteristic(); + characteristic2.updateWith(characteristic); + + assertEquals(characteristic, characteristic2); + } + +// @Test +// void testUpdateResourceSpecificationCharacteristicValues() throws NoSuchMethodException { +// // Create a ResourceSpecificationCharacteristic instance +// ResourceSpecificationCharacteristic characteristic = new ResourceSpecificationCharacteristic(); +// +// // Create a set of ResourceSpecificationCharacteristicValue instances +// Set values = new HashSet<>(); +// ResourceSpecificationCharacteristicValue value1 = new ResourceSpecificationCharacteristicValue(); +// value1.setValue(new Any("Test value 1")); +// +// ResourceSpecificationCharacteristicValue value2 = new ResourceSpecificationCharacteristicValue(); +// value2.setValue(new Any("Test value 2")); +// values.add(value2); +// +// Method method = ResourceSpecificationCharacteristic.class.getDeclaredMethod("updateResourceSpecificationCharacteristicValues", Object.class); +// method.setAccessible(true); +// characteristic.updateResourceSpecificationCharacteristicValues(values); +// +// // Assert that the resourceSpecCharacteristicValue set has been updated correctly +// Set updatedValues = characteristic.getResourceSpecCharacteristicValue(); +// assertEquals(2, updatedValues.size()); +// assertTrue(updatedValues.contains(value1)); +// assertTrue(updatedValues.contains(value2)); +// +// // Create a new set of ResourceSpecificationCharacteristicValue instances with one new value +// Set newValues = new HashSet<>(values); +// ResourceSpecificationCharacteristicValue value3 = new ResourceSpecificationCharacteristicValue(); +// value3.setValue(new Any("Test Value 3")); +// newValues.add(value3); +// +// // Call the updateResourceSpecificationCharacteristicValues method with the new set +// characteristic.updateResourceSpecificationCharacteristicValues(newValues); +// +// // Assert that the resourceSpecCharacteristicValue set has been updated correctly +// updatedValues = characteristic.getResourceSpecCharacteristicValue(); +// assertEquals(3, updatedValues.size()); +// assertTrue(updatedValues.contains(value1)); +// assertTrue(updatedValues.contains(value2)); +// assertTrue(updatedValues.contains(value3)); +// +// // Create a new set of ResourceSpecificationCharacteristicValue instances without the first value +// newValues = new HashSet<>(values); +// newValues.remove(value1); +// +// // Call the updateResourceSpecificationCharacteristicValues method with the new set +// characteristic.updateResourceSpecificationCharacteristicValues(newValues); +// +// // Assert that the resourceSpecCharacteristicValue set has been updated correctly +// updatedValues = characteristic.getResourceSpecCharacteristicValue(); +// assertEquals(2, updatedValues.size()); +// assertFalse(updatedValues.contains(value1)); +// assertTrue(updatedValues.contains(value2)); +// assertTrue(updatedValues.contains(value3)); +// } +} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/services/api/rcm634/ResourceSpecificationTest.java b/src/test/java/org/etsi/osl/services/api/rcm634/ResourceSpecificationTest.java new file mode 100644 index 0000000..a767b11 --- /dev/null +++ b/src/test/java/org/etsi/osl/services/api/rcm634/ResourceSpecificationTest.java @@ -0,0 +1,422 @@ +package org.etsi.osl.services.api.rcm634; + +import org.etsi.osl.tmf.common.model.AttachmentRefOrValue; +import org.etsi.osl.tmf.prm669.model.RelatedParty; +import org.etsi.osl.tmf.rcm634.model.*; +import org.junit.jupiter.api.Test; + +import java.util.HashSet; +import java.util.Set; + +import static org.junit.jupiter.api.Assertions.*; + +public class ResourceSpecificationTest { + + static class TestResourceSpecification extends ResourceSpecification { + // You can add additional methods or override existing ones if needed + } + + @Test + void testResourceSpecification() { + ResourceSpecification resourceSpec = new TestResourceSpecification(); + + String id = "testId"; + Boolean isBundle = true; + String category = "testCategory"; + + resourceSpec.setUuid(id); + resourceSpec.setIsBundle(isBundle); + resourceSpec.setCategory(category); + + assertEquals(id, resourceSpec.getId()); + assertEquals(isBundle, resourceSpec.isIsBundle()); + assertEquals(category, resourceSpec.getCategory()); + } + + @Test + void testEquals() { + ResourceSpecification resourceSpec1 = new TestResourceSpecification(); + resourceSpec1.setUuid("testId"); + resourceSpec1.getId(); + resourceSpec1.setIsBundle(true); + resourceSpec1.setCategory("testCategory"); + + ResourceSpecification resourceSpec2 = new TestResourceSpecification(); + resourceSpec2.setUuid("testId"); + resourceSpec2.getId(); + resourceSpec2.setIsBundle(true); + resourceSpec2.setCategory("testCategory"); + + assertTrue(resourceSpec1.equals(resourceSpec2)); + + resourceSpec1.setUuid("differentId"); + resourceSpec1.getId(); + + assertFalse(resourceSpec1.equals(resourceSpec2)); + } + + @Test + void testHashCode() { + ResourceSpecification resourceSpec1 = new TestResourceSpecification(); + resourceSpec1.setUuid("testId"); + resourceSpec1.getId(); + resourceSpec1.setIsBundle(true); + resourceSpec1.setCategory("testCategory"); + + ResourceSpecification resourceSpec2 = new TestResourceSpecification(); + resourceSpec2.setUuid("testId"); + resourceSpec2.getId(); + resourceSpec2.setIsBundle(true); + resourceSpec2.setCategory("testCategory"); + + assertEquals(resourceSpec1.hashCode(), resourceSpec2.hashCode()); + + resourceSpec1.setUuid("differentId"); + resourceSpec1.getId(); + + assertNotEquals(resourceSpec1.hashCode(), resourceSpec2.hashCode()); + } + + @Test + void testHref() { + ResourceSpecification resourceSpec = new TestResourceSpecification(); + String href = "testHref"; + resourceSpec.setHref(href); + assertEquals(href, resourceSpec.getHref()); + + ResourceSpecification newResourceSpec = resourceSpec.href("newTestHref"); + assertEquals(resourceSpec, newResourceSpec); + } + + @Test + void testCategory() { + ResourceSpecification resourceSpec = new TestResourceSpecification(); + String category = "testCategory"; + resourceSpec.setCategory(category); + assertEquals(category, resourceSpec.getCategory()); + + ResourceSpecification newResourceSpec = resourceSpec.category("newTestCategory"); + assertEquals(resourceSpec, newResourceSpec); + } + + @Test + void testDescription() { + ResourceSpecification resourceSpec = new TestResourceSpecification(); + String description = "testDescription"; + resourceSpec.setDescription(description); + assertEquals(description, resourceSpec.getDescription()); + + ResourceSpecification newResourceSpec = resourceSpec.description("newTestDescription"); + assertEquals(resourceSpec, newResourceSpec); + } + + @Test + void testIsBundle() { + ResourceSpecification resourceSpec = new TestResourceSpecification(); + Boolean isBundle = true; + resourceSpec.setIsBundle(isBundle); + assertEquals(isBundle, resourceSpec.isIsBundle()); + + ResourceSpecification newResourceSpec = resourceSpec.isBundle(false); + assertEquals(resourceSpec, newResourceSpec); + } + + @Test + void testLifecycleStatus() { + ResourceSpecification resourceSpec = new TestResourceSpecification(); + String lifecycleStatus = "In study"; + resourceSpec.setLifecycleStatus(lifecycleStatus); + assertEquals(lifecycleStatus, resourceSpec.getLifecycleStatus()); + + ResourceSpecification newResourceSpec = resourceSpec.lifecycleStatus("In use"); + assertEquals(resourceSpec, newResourceSpec); + } + + @Test + void testName() { + ResourceSpecification resourceSpec = new TestResourceSpecification(); + String name = "testName"; + resourceSpec.setName(name); + assertEquals(name, resourceSpec.getName()); + + ResourceSpecification newResourceSpec = resourceSpec.name("newTestName"); + assertEquals(resourceSpec, newResourceSpec); + } + + @Test + void testSettersAndGetters() { + ResourceSpecification resourceSpec = new TestResourceSpecification(); + + // Test id + String id = "testId"; + resourceSpec.setUuid(id); + resourceSpec.getId(); + assertEquals(id, resourceSpec.getId()); + + // Test href + String href = "testHref"; + resourceSpec.setHref(href); + assertEquals(href, resourceSpec.getHref()); + + // Test category + String category = "testCategory"; + resourceSpec.setCategory(category); + assertEquals(category, resourceSpec.getCategory()); + + // Test description + String description = "testDescription"; + resourceSpec.setDescription(description); + assertEquals(description, resourceSpec.getDescription()); + + // Test isBundle + Boolean isBundle = true; + resourceSpec.setIsBundle(isBundle); + assertEquals(isBundle, resourceSpec.isIsBundle()); + + // Test lifecycleStatus + String lifecycleStatus = "In study"; + resourceSpec.setLifecycleStatus(lifecycleStatus); + assertEquals(lifecycleStatus, resourceSpec.getLifecycleStatus()); + + // Test name + String name = "testName"; + resourceSpec.setName(name); + assertEquals(name, resourceSpec.getName()); + + // Test version + String version = "testVersion"; + resourceSpec.setVersion(version); + assertEquals(version, resourceSpec.getVersion()); + + // Test baseType + String baseType = "BaseRootEntity"; + resourceSpec.setBaseType(baseType); + assertEquals(baseType, resourceSpec.getBaseType()); + + // Test schemaLocation + String schemaLocation = "testSchemaLocation"; + resourceSpec.setAtSchemaLocation(schemaLocation); + assertEquals(schemaLocation, resourceSpec.getAtSchemaLocation()); + + // Test type + String type = "BaseEntity"; + resourceSpec.setType(type); + assertEquals(type, resourceSpec.getType()); + } + @Test + void testToString() { + ResourceSpecification resourceSpec = new TestResourceSpecification(); + resourceSpec.setUuid("testId"); + resourceSpec.getId(); + resourceSpec.setIsBundle(true); + resourceSpec.setCategory("testCategory"); + resourceSpec.setHref("testHref"); + resourceSpec.setLifecycleStatus("In study"); + resourceSpec.setName("testName"); + resourceSpec.setVersion("testVersion"); + resourceSpec.setBaseType("BaseRootEntity"); + resourceSpec.setAtSchemaLocation("testSchemaLocation"); + resourceSpec.setType("BaseEntity"); + + String expectedString = "class ResourceSpecification {\n" + + " id: testId\n" + + " href: testHref\n" + + " category: testCategory\n" + + " description: null\n" + + " isBundle: true\n" + + " lastUpdate: null\n" + + " lifecycleStatus: In study\n" + + " name: testName\n" + + " version: testVersion\n" + + " attachment: []\n" + + " featureSpecification: []\n" + + " relatedParty: []\n" + + " resourceSpecCharacteristic: []\n" + + " resourceSpecRelationship: []\n" + + " targetResourceSchema: null\n" + + " validFor: null\n" + + " baseType: BaseRootEntity\n" + + " schemaLocation: testSchemaLocation\n" + + " type: BaseEntity\n" + + "}"; + + assertEquals(expectedString, resourceSpec.toString()); + } + + @Test + void testFixResourceCharRelationhsipIDs() { + ResourceSpecification resourceSpec = new TestResourceSpecification(); + resourceSpec.setName("testResourceSpec"); + + ResourceSpecificationCharacteristic schar1 = new ResourceSpecificationCharacteristic(); + schar1.setName("schar1"); + schar1.setUuid("uuid1"); + + ResourceSpecificationCharacteristic schar2 = new ResourceSpecificationCharacteristic(); + schar2.setName("schar2"); + + ResourceSpecCharRelationship charRel1 = new ResourceSpecCharRelationship(); + charRel1.setName("schar1"); // same name as schar1 + + ResourceSpecCharRelationship charRel2 = new ResourceSpecCharRelationship(); + charRel2.setName("schar2"); // same name as schar2 + + schar1.addResourceSpecCharRelationshipItem(charRel1); + schar2.addResourceSpecCharRelationshipItem(charRel2); + + resourceSpec.addResourceSpecCharacteristicItem(schar1); + resourceSpec.addResourceSpecCharacteristicItem(schar2); + + resourceSpec.fixResourceCharRelationhsipIDs(); + + assertEquals("uuid1", charRel1.getId()); // id should be set to the uuid of schar1 + assertEquals("testResourceSpec-schar2", charRel2.getId()); // id should be set to "resourceSpecName-scharName" + } + + @Test + void testRelatedParty() { + ResourceSpecification resourceSpec = new TestResourceSpecification(); + Set relatedPartySet = new HashSet<>(); + relatedPartySet.add(new RelatedParty()); + resourceSpec.setRelatedParty(relatedPartySet); + assertEquals(relatedPartySet, resourceSpec.getRelatedParty()); + + relatedPartySet.add(new RelatedParty()); + resourceSpec.setRelatedParty(relatedPartySet); + assertEquals(relatedPartySet, resourceSpec.getRelatedParty()); + } + + @Test + void testFindSpecCharacteristicByName() { + ResourceSpecification resourceSpec = new TestResourceSpecification(); + ResourceSpecificationCharacteristic characteristic1 = new ResourceSpecificationCharacteristic(); + characteristic1.setName("testName1"); + resourceSpec.getResourceSpecCharacteristic().add(characteristic1); + + ResourceSpecificationCharacteristic characteristic2 = new ResourceSpecificationCharacteristic(); + characteristic2.setName("testName2"); + resourceSpec.getResourceSpecCharacteristic().add(characteristic2); + + assertEquals(characteristic1, resourceSpec.findSpecCharacteristicByName("testName1")); + assertEquals(characteristic2, resourceSpec.findSpecCharacteristicByName("testName2")); + assertNull(resourceSpec.findSpecCharacteristicByName("nonexistentName")); + } + + + + @Test + void testResourceSpecRelationship() { + ResourceSpecification resourceSpec = new TestResourceSpecification(); + Set relationships = new HashSet<>(); + relationships.add(new ResourceSpecificationRelationship()); + resourceSpec.setResourceSpecRelationship(relationships); + assertEquals(relationships, resourceSpec.getResourceSpecRelationship()); + + ResourceSpecificationRelationship newRelationship = new ResourceSpecificationRelationship(); + resourceSpec.addResourceSpecRelationshipItem(newRelationship); + assertTrue(resourceSpec.getResourceSpecRelationship().contains(newRelationship)); + } + + @Test + void testResourceCandidateObjId() { + ResourceSpecification resourceSpec = new TestResourceSpecification(); + String resourceCandidateObjId = "testResourceCandidateObjId"; + resourceSpec.setResourceCandidateObjId(resourceCandidateObjId); + assertEquals(resourceCandidateObjId, resourceSpec.getResourceCandidateObjId()); + } + + + @Test + void testBaseType() { + ResourceSpecification resourceSpec = new TestResourceSpecification(); + String baseType = "testBaseType"; + resourceSpec.setBaseType(baseType); + assertEquals(baseType, resourceSpec.getBaseType()); + + ResourceSpecification newResourceSpec = resourceSpec.baseType("newTestBaseType"); + assertEquals(resourceSpec, newResourceSpec); + } + + @Test + void testSchemaLocation() { + ResourceSpecification resourceSpec = new TestResourceSpecification(); + String schemaLocation = "testSchemaLocation"; + resourceSpec.setAtSchemaLocation(schemaLocation); + assertEquals(schemaLocation, resourceSpec.getAtSchemaLocation()); + + ResourceSpecification newResourceSpec = resourceSpec.schemaLocation("newTestSchemaLocation"); + assertEquals(resourceSpec, newResourceSpec); + } + + @Test + void testVersion() { + ResourceSpecification resourceSpec = new TestResourceSpecification(); + String version = "testVersion"; + resourceSpec.setVersion(version); + assertEquals(version, resourceSpec.getVersion()); + + ResourceSpecification newResourceSpec = resourceSpec.version("newTestVersion"); + assertEquals(resourceSpec, newResourceSpec); + } + + @Test + void testAttachment() { + ResourceSpecification resourceSpec = new TestResourceSpecification(); + Set attachments = new HashSet<>(); + attachments.add(new AttachmentRefOrValue()); + resourceSpec.setAttachment(attachments); + assertEquals(attachments, resourceSpec.getAttachment()); + + AttachmentRefOrValue newAttachment = new AttachmentRefOrValue(); + resourceSpec.addAttachmentItem(newAttachment); + assertTrue(resourceSpec.getAttachment().contains(newAttachment)); + } + + @Test + void testFeatureSpecification() { + ResourceSpecification resourceSpec = new TestResourceSpecification(); + Set featureSpecifications = new HashSet<>(); + featureSpecifications.add(new FeatureSpecification()); + resourceSpec.setFeatureSpecification(featureSpecifications); + assertEquals(featureSpecifications, resourceSpec.getFeatureSpecification()); + + FeatureSpecification newFeatureSpecification = new FeatureSpecification(); + resourceSpec.addFeatureSpecificationItem(newFeatureSpecification); + assertTrue(resourceSpec.getFeatureSpecification().contains(newFeatureSpecification)); + } + + @Test + void testResourceSpecCharacteristic() { + ResourceSpecification resourceSpec = new TestResourceSpecification(); + Set characteristics = new HashSet<>(); + characteristics.add(new ResourceSpecificationCharacteristic()); + resourceSpec.setResourceSpecCharacteristic(characteristics); + assertEquals(characteristics, resourceSpec.getResourceSpecCharacteristic()); + + ResourceSpecification newResourceSpec = resourceSpec.resourceSpecCharacteristic(characteristics); + assertEquals(resourceSpec, newResourceSpec); + } + + + @Test + void testTargetResourceSchema() { + ResourceSpecification resourceSpec = new TestResourceSpecification(); + TargetResourceSchema targetResourceSchema = new TargetResourceSchema(); + resourceSpec.setTargetResourceSchema(targetResourceSchema); + assertEquals(targetResourceSchema, resourceSpec.getTargetResourceSchema()); + + ResourceSpecification newResourceSpec = resourceSpec.targetResourceSchema(targetResourceSchema); + assertEquals(resourceSpec, newResourceSpec); + } + + @Test + void testType() { + ResourceSpecification resourceSpec = new TestResourceSpecification(); + String type = "testType"; + resourceSpec.setType(type); + assertEquals(type, resourceSpec.getType()); + + ResourceSpecification newResourceSpec = resourceSpec.type("newTestType"); + assertEquals(resourceSpec, newResourceSpec); + } +} \ No newline at end of file -- GitLab From a908e002cb58a55c2cad00443ffd83d73949ad1f Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Sun, 21 Jan 2024 20:13:36 +0000 Subject: [PATCH 06/10] version per osl component from parent --- pom.xml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 7614473..5115e64 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,8 @@ org.etsi.osl org.etsi.osl.main - 1.2.0-SNAPSHOT + 1.0.0-SNAPSHOT + ../org.etsi.osl.main @@ -206,22 +207,22 @@ org.etsi.osl org.etsi.osl.model.nfv - ${project.version} + ${org.etsi.osl.model.nfv.version} org.etsi.osl org.etsi.osl.model.tmf - ${project.version} + ${org.etsi.osl.model.tmf.version} org.etsi.osl org.etsi.osl.model.k8s - ${project.version} + ${org.etsi.osl.model.k8s.version} org.etsi.osl org.etsi.osl.centrallog.client - ${project.version} + ${org.etsi.osl.centrallog.client.version} -- GitLab From 7b0036226c993bd2c48882dc32c5d6f3ab96a043 Mon Sep 17 00:00:00 2001 From: trantzas Date: Mon, 22 Jan 2024 10:52:55 +0000 Subject: [PATCH 07/10] fix for #9 --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0d36beb..c5f3989 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM ibm-semeru-runtimes:open-17.0.7_7-jdk # RUN mkdir /opt/shareclasses RUN mkdir -p /opt/openslice/lib/ -COPY target/org.etsi.osl.tmf.api-1.2.0-SNAPSHOT-exec.jar /opt/openslice/lib/ -CMD ["java", "-Xshareclasses:cacheDir=/opt/shareclasses", "-jar", "/opt/openslice/lib/org.etsi.osl.tmf.api-1.2.0-SNAPSHOT-exec.jar"] +COPY target/org.etsi.osl.tmf.api-1.0.0-SNAPSHOT-exec.jar /opt/openslice/lib/ +CMD ["java", "-Xshareclasses:cacheDir=/opt/shareclasses", "-jar", "/opt/openslice/lib/org.etsi.osl.tmf.api-1.0.0-SNAPSHOT-exec.jar"] EXPOSE 13082 \ No newline at end of file -- GitLab From be31ee97f2672533c93a60b4f48038da7188a7b2 Mon Sep 17 00:00:00 2001 From: George Tziavas Date: Fri, 2 Feb 2024 07:22:55 +0000 Subject: [PATCH 08/10] Resolve "Increase coverage in TMF634" --- .gitignore | 1 + src/main/java/org/etsi/osl/tmf/JsonUtils.java | 11 +++++++++++ .../org/etsi/osl/tmf/rcm634/api/ApiException.java | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/.gitignore b/.gitignore index 59419d5..f91fa93 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /.project /.classpath /.settings +/org.etsi.osl.tmf.api.iml diff --git a/src/main/java/org/etsi/osl/tmf/JsonUtils.java b/src/main/java/org/etsi/osl/tmf/JsonUtils.java index ff2221e..b28edd6 100644 --- a/src/main/java/org/etsi/osl/tmf/JsonUtils.java +++ b/src/main/java/org/etsi/osl/tmf/JsonUtils.java @@ -2,6 +2,7 @@ package org.etsi.osl.tmf; import java.io.IOException; import java.io.InputStream; +import java.util.List; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.ObjectMapper; @@ -41,4 +42,14 @@ public class JsonUtils { return mapper.readValue(content, valueType); } + public static List toListOfJsonObj(String content, Class valueType) throws IOException { + ObjectMapper mapper = new ObjectMapper(); + mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + List listOfJsonObj = mapper.readValue( + content, + mapper.getTypeFactory().constructCollectionType( + List.class, valueType)); + return listOfJsonObj; + } + } diff --git a/src/main/java/org/etsi/osl/tmf/rcm634/api/ApiException.java b/src/main/java/org/etsi/osl/tmf/rcm634/api/ApiException.java index 5371ea0..b979eef 100644 --- a/src/main/java/org/etsi/osl/tmf/rcm634/api/ApiException.java +++ b/src/main/java/org/etsi/osl/tmf/rcm634/api/ApiException.java @@ -19,6 +19,9 @@ */ package org.etsi.osl.tmf.rcm634.api; +import lombok.Getter; + +@Getter @jakarta.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2021-05-29T22:34:44.143740800+03:00[Europe/Athens]") public class ApiException extends Exception{ private int code; @@ -26,4 +29,5 @@ public class ApiException extends Exception{ super(msg); this.code = code; } + } -- GitLab From eca96ad082f65e4999bd7b2a68d25bf62612e28c Mon Sep 17 00:00:00 2001 From: George Tziavas Date: Mon, 19 Feb 2024 23:49:30 +0200 Subject: [PATCH 09/10] Added a check to make sure all ServiceSpecCharRelationships are not null --- .../api/ServiceCatalogIntegrationTest.java | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/etsi/osl/services/api/ServiceCatalogIntegrationTest.java b/src/test/java/org/etsi/osl/services/api/ServiceCatalogIntegrationTest.java index 56f3a73..511e46c 100644 --- a/src/test/java/org/etsi/osl/services/api/ServiceCatalogIntegrationTest.java +++ b/src/test/java/org/etsi/osl/services/api/ServiceCatalogIntegrationTest.java @@ -521,17 +521,31 @@ public class ServiceCatalogIntegrationTest { ServiceSpecCharacteristicValue val = new ServiceSpecCharacteristicValue(); val.setValueType( EValueType.ARRAY.toString()); val.setValue( new Any("1" ,"a second value") ); - responsesSpecUpd.getServiceSpecCharacteristic().get(0).getServiceSpecCharacteristicValue().add(val); - ServiceSpecCharRelationship scrObj = responsesSpecUpd.getServiceSpecCharacteristic().get(0).getServiceSpecCharRelationship().toArray( new ServiceSpecCharRelationship[3])[0]; - ServiceSpecCharRelationship scrObj2 = responsesSpecUpd.getServiceSpecCharacteristic().get(0).getServiceSpecCharRelationship().toArray( new ServiceSpecCharRelationship[3])[1]; - ServiceSpecCharRelationship scrObj3 = responsesSpecUpd.getServiceSpecCharacteristic().get(0).getServiceSpecCharRelationship().toArray( new ServiceSpecCharRelationship[3])[2]; + + // Following code related to 'notNullRelationshipIndex' is to fix random test failures due to getServiceSpecCharacteristic + // not having 3 ServiceSpecCharRelationships + int notNullRelationshipIndex = 0; + for (int i=0; i Date: Wed, 21 Feb 2024 12:32:03 +0200 Subject: [PATCH 10/10] Resolved issue that caused broken pipeline on GitLab --- .../osl/services/api/scm633/ExportJobApiController633Test.java | 2 -- .../org/etsi/osl/services/api/scm633/HubApiControllerTest.java | 2 -- .../osl/services/api/scm633/ImportJobApiControllerTest.java | 2 -- .../etsi/osl/services/api/scm633/ListenerApiControllerTest.java | 2 -- .../services/api/scm633/ServiceCandidateApiControllerTest.java | 2 -- .../services/api/scm633/ServiceCatalogApiControllerTest.java | 2 -- .../services/api/scm633/ServiceCategoryApiControllerTest.java | 2 -- .../api/scm633/ServiceSpecificationApiControllerTest.java | 2 -- 8 files changed, 16 deletions(-) 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 index 1fb1426..14a8a40 100644 --- a/src/test/java/org/etsi/osl/services/api/scm633/ExportJobApiController633Test.java +++ b/src/test/java/org/etsi/osl/services/api/scm633/ExportJobApiController633Test.java @@ -17,7 +17,6 @@ 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; @@ -35,7 +34,6 @@ 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 { 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 index 81de42a..048ad19 100644 --- a/src/test/java/org/etsi/osl/services/api/scm633/HubApiControllerTest.java +++ b/src/test/java/org/etsi/osl/services/api/scm633/HubApiControllerTest.java @@ -17,7 +17,6 @@ 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; @@ -35,7 +34,6 @@ 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 { 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 index 2b8a0f3..0d37698 100644 --- a/src/test/java/org/etsi/osl/services/api/scm633/ImportJobApiControllerTest.java +++ b/src/test/java/org/etsi/osl/services/api/scm633/ImportJobApiControllerTest.java @@ -17,7 +17,6 @@ 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; @@ -35,7 +34,6 @@ 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 { 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 index 013aff7..9ed631a 100644 --- a/src/test/java/org/etsi/osl/services/api/scm633/ListenerApiControllerTest.java +++ b/src/test/java/org/etsi/osl/services/api/scm633/ListenerApiControllerTest.java @@ -17,7 +17,6 @@ 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; @@ -35,7 +34,6 @@ 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 { diff --git a/src/test/java/org/etsi/osl/services/api/scm633/ServiceCandidateApiControllerTest.java b/src/test/java/org/etsi/osl/services/api/scm633/ServiceCandidateApiControllerTest.java index 792776a..c8ed3f4 100644 --- a/src/test/java/org/etsi/osl/services/api/scm633/ServiceCandidateApiControllerTest.java +++ b/src/test/java/org/etsi/osl/services/api/scm633/ServiceCandidateApiControllerTest.java @@ -25,7 +25,6 @@ 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; @@ -43,7 +42,6 @@ import org.springframework.web.context.WebApplicationContext; @RunWith(SpringRunner.class) @Transactional @SpringBootTest( webEnvironment = SpringBootTest.WebEnvironment.MOCK , classes = OpenAPISpringBoot.class) -@AutoConfigureTestDatabase @AutoConfigureMockMvc @ActiveProfiles("testing") public class ServiceCandidateApiControllerTest { diff --git a/src/test/java/org/etsi/osl/services/api/scm633/ServiceCatalogApiControllerTest.java b/src/test/java/org/etsi/osl/services/api/scm633/ServiceCatalogApiControllerTest.java index 5576784..92b48d5 100644 --- a/src/test/java/org/etsi/osl/services/api/scm633/ServiceCatalogApiControllerTest.java +++ b/src/test/java/org/etsi/osl/services/api/scm633/ServiceCatalogApiControllerTest.java @@ -25,7 +25,6 @@ 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; @@ -43,7 +42,6 @@ import org.springframework.web.context.WebApplicationContext; @RunWith(SpringRunner.class) @Transactional @SpringBootTest( webEnvironment = SpringBootTest.WebEnvironment.MOCK , classes = OpenAPISpringBoot.class) -@AutoConfigureTestDatabase @AutoConfigureMockMvc @ActiveProfiles("testing") public class ServiceCatalogApiControllerTest { diff --git a/src/test/java/org/etsi/osl/services/api/scm633/ServiceCategoryApiControllerTest.java b/src/test/java/org/etsi/osl/services/api/scm633/ServiceCategoryApiControllerTest.java index 2dd0650..865ca45 100644 --- a/src/test/java/org/etsi/osl/services/api/scm633/ServiceCategoryApiControllerTest.java +++ b/src/test/java/org/etsi/osl/services/api/scm633/ServiceCategoryApiControllerTest.java @@ -16,7 +16,6 @@ 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; @@ -34,7 +33,6 @@ import org.springframework.web.context.WebApplicationContext; @RunWith(SpringRunner.class) @Transactional @SpringBootTest( webEnvironment = SpringBootTest.WebEnvironment.MOCK , classes = OpenAPISpringBoot.class) -@AutoConfigureTestDatabase @AutoConfigureMockMvc @ActiveProfiles("testing") diff --git a/src/test/java/org/etsi/osl/services/api/scm633/ServiceSpecificationApiControllerTest.java b/src/test/java/org/etsi/osl/services/api/scm633/ServiceSpecificationApiControllerTest.java index bc8beb9..e5aa51e 100644 --- a/src/test/java/org/etsi/osl/services/api/scm633/ServiceSpecificationApiControllerTest.java +++ b/src/test/java/org/etsi/osl/services/api/scm633/ServiceSpecificationApiControllerTest.java @@ -28,7 +28,6 @@ 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.HttpHeaders; @@ -48,7 +47,6 @@ import org.springframework.web.context.WebApplicationContext; @RunWith(SpringRunner.class) @Transactional @SpringBootTest( webEnvironment = SpringBootTest.WebEnvironment.MOCK , classes = OpenAPISpringBoot.class) -@AutoConfigureTestDatabase @AutoConfigureMockMvc @ActiveProfiles("testing") public class ServiceSpecificationApiControllerTest { -- GitLab