summaryrefslogtreecommitdiffstats
path: root/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test
diff options
context:
space:
mode:
authorAndrewLamb <andrew.a.lamb@est.tech>2020-10-07 14:12:44 +0100
committerAndrewLamb <andrew.a.lamb@est.tech>2020-10-13 16:38:58 +0100
commit1d12326d47c541934fd0ee3376844a159941a9ef (patch)
tree7fa730f6e793229ead98068f65993d7e1ccf586d /so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test
parent33fb2c6e36d763fd9d24f55debc55c458dab6780 (diff)
SO-ETSI-NFVO Get NS Operation Status Backend Service
Issue-ID: SO-2871 Change-Id: I1b17bbc5750abb38bf017df4088c4b40db3552ab Signed-off-by: AndrewLamb <andrew.a.lamb@est.tech>
Diffstat (limited to 'so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test')
-rw-r--r--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.java72
-rw-r--r--so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/resources/application.yaml6
2 files changed, 68 insertions, 10 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/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