diff options
Diffstat (limited to 'so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test')
3 files changed, 92 insertions, 18 deletions
diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLcmOperationOccurrencesControllerTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLcmOperationOccurrencesControllerTest.java index 9eace927d6..c5862569f2 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLcmOperationOccurrencesControllerTest.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLcmOperationOccurrencesControllerTest.java @@ -20,13 +20,26 @@ package org.onap.so.etsi.nfvo.ns.lcm.rest; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import java.time.LocalDateTime; +import java.util.Optional; import java.util.UUID; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.so.etsi.nfvo.ns.lcm.Constants; -import org.onap.so.etsi.nfvo.ns.lcm.JSON; import org.onap.so.etsi.nfvo.ns.lcm.TestApplication; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.GsonProvider; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NsLcmOpOcc; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NsLcmOpType; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.OperationStateEnum; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.State; +import org.onap.so.etsi.nfvo.ns.lcm.database.service.DatabaseServiceProvider; +import org.onap.so.etsi.nfvo.ns.lcm.model.InlineResponse400; +import org.onap.so.etsi.nfvo.ns.lcm.model.NsLcmOpOccsNsLcmOpOcc; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.web.client.RestTemplateBuilder; @@ -42,32 +55,75 @@ import org.springframework.test.context.junit4.SpringRunner; import com.google.gson.Gson; /** - * * @author Waqas Ikram (waqas.ikram@est.tech) + * @author Andrew Lamb (andrew.a.lamb@est.tech) + * */ @RunWith(SpringRunner.class) @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @ActiveProfiles("test") public class NsLcmOperationOccurrencesControllerTest { + + private static final String NS_LCM_OP_OCCS = "/ns_lcm_op_occs/"; + @LocalServerPort private int port; + + @Autowired + private DatabaseServiceProvider databaseServiceProvider; + + @Autowired + private GsonProvider gsonProvider; + private TestRestTemplate testRestTemplate; @Before public void setUp() { - final Gson gson = JSON.createGson().create(); + final Gson gson = gsonProvider.getGson(); testRestTemplate = new TestRestTemplate( new RestTemplateBuilder().additionalMessageConverters(new GsonHttpMessageConverter(gson))); } @Test - public void testGetOperationStatusS_ValidNsLcmOpOccId() { - final String baseUrl = getNsLcmBaseUrl() + "/ns_lcm_op_occs/" + UUID.randomUUID().toString(); + public void testGetOperationStatus_validNsLcmOpOccId_returnsNsLcmOpOcc() { + final String nsLcmOpOccId = addDummyNsLcmOpOccToDatabase(); + final String baseUrl = getNsLcmBaseUrl() + NS_LCM_OP_OCCS + nsLcmOpOccId; final HttpEntity<?> request = new HttpEntity<>(new HttpHeaders()); - final ResponseEntity<Void> responseEntity = - testRestTemplate.exchange(baseUrl, HttpMethod.GET, request, Void.class); - assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode()); + final ResponseEntity<NsLcmOpOccsNsLcmOpOcc> responseEntity = + testRestTemplate.exchange(baseUrl, HttpMethod.GET, request, NsLcmOpOccsNsLcmOpOcc.class); + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); + assertTrue(responseEntity.hasBody()); + assertNotNull(responseEntity.getBody()); + } + + @Test + public void testGetOperationStatus_nsLcmOpOccIdNotFound_returnsInlineResponse400() { + final String nsLcmOpOccId = UUID.randomUUID().toString(); + final Optional<NsLcmOpOcc> optionalNsLcmOpOcc = databaseServiceProvider.getNsLcmOpOcc(nsLcmOpOccId); + assertTrue(optionalNsLcmOpOcc.isEmpty()); + final String baseUrl = getNsLcmBaseUrl() + NS_LCM_OP_OCCS + nsLcmOpOccId; + final HttpEntity<?> request = new HttpEntity<>(new HttpHeaders()); + final ResponseEntity<InlineResponse400> responseEntity = + testRestTemplate.exchange(baseUrl, HttpMethod.GET, request, InlineResponse400.class); + assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode()); + assertTrue(responseEntity.hasBody()); + assertNotNull(responseEntity.getBody()); + } + + private String addDummyNsLcmOpOccToDatabase() { + final LocalDateTime currentDateTime = LocalDateTime.now(); + + final NfvoNsInst nsInst = new NfvoNsInst().name("name").nsdId("id").status(State.NOT_INSTANTIATED) + .nsdInvariantId("id").statusUpdatedTime(currentDateTime); + databaseServiceProvider.saveNfvoNsInst(nsInst); + + final NsLcmOpOcc nsLcmOpOcc = new NsLcmOpOcc().nfvoNsInst(nsInst).operationState(OperationStateEnum.PROCESSING) + .isCancelPending(false).isAutoInvocation(false).operation(NsLcmOpType.INSTANTIATE) + .startTime(currentDateTime).stateEnteredTime(currentDateTime).operationParams(""); + databaseServiceProvider.addNSLcmOpOcc(nsLcmOpOcc); + + return nsLcmOpOcc.getId(); } private String getNsLcmBaseUrl() { diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementControllerTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementControllerTest.java index 4b1195244c..585b0e1811 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementControllerTest.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementControllerTest.java @@ -19,17 +19,14 @@ */ package org.onap.so.etsi.nfvo.ns.lcm.rest; -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.when; import java.net.URISyntaxException; -import java.time.LocalDateTime; import java.util.List; import java.util.UUID; import org.junit.Before; @@ -173,11 +170,30 @@ public class NsLifecycleManagementControllerTest { } @Test - public void testCreateNs_ValidDeleteNsRequest() { - final String baseUrl = getNsLcmBaseUrl() + "/ns_instances/" + UUID.randomUUID().toString(); + public void testDeleteNs_SuccessfulCase() { + final String nsInstId = UUID.randomUUID().toString(); + doNothing().when(mockedJobExecutorService).runDeleteNsJob(eq(nsInstId)); + + final String baseUrl = getNsLcmBaseUrl() + "/ns_instances/" + nsInstId; final ResponseEntity<Void> responseEntity = testRestTemplate.exchange(baseUrl, HttpMethod.DELETE, null, Void.class); - assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode()); + assertEquals(HttpStatus.NO_CONTENT, responseEntity.getStatusCode()); + } + + @Test + public void testDeleteNs_nsRequestProcessingExceptionThrown_returnInlineResponse400() { + final String nsInstId = UUID.randomUUID().toString(); + final String message = "Unable to process request"; + doThrow(new NsRequestProcessingException(message, new InlineResponse400().detail(message))) + .when(mockedJobExecutorService).runDeleteNsJob(eq(nsInstId)); + + final String baseUrl = getNsLcmBaseUrl() + "/ns_instances/" + nsInstId; + final ResponseEntity<InlineResponse400> responseEntity = + testRestTemplate.exchange(baseUrl, HttpMethod.DELETE, null, InlineResponse400.class); + + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode()); + assertTrue(responseEntity.hasBody()); + assertNotNull(responseEntity.getBody()); } @Test diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/resources/application.yaml b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/resources/application.yaml index 44acda20a4..6f2b4d26c5 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/resources/application.yaml +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/resources/application.yaml @@ -29,11 +29,13 @@ spring: pool-name: ns-lcm-nfvo-pool registerMbeans: true jpa: + generate-ddl: true hibernate: - ddl-auto: none + ddl-auto: create logging: level: org.reflections.Reflections: ERROR + etsi-catalog-manager: base: - endpoint: http://modeling-etsicatalog.onap:8806/api
\ No newline at end of file + endpoint: http://modeling-etsicatalog.onap:8806/api |