summaryrefslogtreecommitdiffstats
path: root/vid-app-common
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common')
-rwxr-xr-xvid-app-common/pom.xml2
-rw-r--r--vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.js13
-rw-r--r--vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.test.js51
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controller/MsoControllerTest.java189
4 files changed, 161 insertions, 94 deletions
diff --git a/vid-app-common/pom.xml b/vid-app-common/pom.xml
index d3c6fbeeb..333181d9d 100755
--- a/vid-app-common/pom.xml
+++ b/vid-app-common/pom.xml
@@ -822,7 +822,7 @@
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.10.0</version>
- <scope>compile</scope>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.js b/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.js
index c6a5b31af..02242cb37 100644
--- a/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.js
+++ b/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.js
@@ -433,7 +433,6 @@
} else {
let source = vm.getRemoteWorkflowSource(vm.changeManagement.workflow);
if( source === "NATIVE"){
- vm.localWorkflowsParameters = vm.remoteWorkflowsParameters;
vm.triggerLocalWorkflow();
}else {
vm.triggerRemoteWorkflow();
@@ -687,7 +686,9 @@
};
vm.loadWorkFlows = function () {
- if (featureFlags.isOn(COMPONENT.FEATURE_FLAGS.FLAG_HANDLE_SO_WORKFLOWS)) {
+ vm.localWorkflowsParameters = new Map();
+ vm.remoteWorkflowsParameters = new Map();
+ if (featureFlags.isOn(COMPONENT.FEATURE_FLAGS.FLAG_HANDLE_SO_WORKFLOWS)) {
return vm.loadRemoteWorkFlows()
.then(function () {
vm.workflows = vm.remoteWorkflows.map(item => item.name);
@@ -723,7 +724,6 @@
};
vm.loadLocalWorkFlowsParameters = function () {
- vm.localWorkflowsParameters = new Map();
vm.localWorkflows.forEach(function(workflow) {
vm.loadLocalWorkFlowParameters(workflow);
});
@@ -740,9 +740,12 @@
};
vm.loadRemoteWorkFlowsParameters = function () {
- vm.remoteWorkflowsParameters = new Map();
vm.remoteWorkflows.forEach(function(workflow) {
- vm.loadRemoteWorkFlowParameters(workflow);
+ if (workflow.source ==='SDC' || workflow.source === 'sdc' ){
+ vm.loadRemoteWorkFlowParameters(workflow);
+ } else {
+ vm.loadLocalWorkFlowParameters(workflow.name);
+ }
});
};
diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.test.js b/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.test.js
index afc643993..b11070a9f 100644
--- a/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.test.js
+++ b/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.test.js
@@ -127,7 +127,7 @@ describe('Testing workFlows from SO', () => {
// when
return $controller.loadWorkFlows().then(() => {
expect($controller.workflows).toContain('inPlaceSoftwareUpdate');
- expect($controller.localWorkflowsParameters).toBeUndefined();
+ expect($controller.localWorkflowsParameters).toEqual(new Map());
});
});
@@ -196,7 +196,7 @@ describe('Testing workFlows from SO', () => {
return $controller.loadWorkFlows()
.then(() => {
expect($controller.workflows).toEqual(["workflow 0"]);
- expect($controller.remoteWorkflowsParameters).toEqual(undefined);
+ expect($controller.remoteWorkflowsParameters).toEqual(new Map());
});
});
@@ -357,4 +357,51 @@ describe('Testing workFlows from SO', () => {
expect(internalWorkFlowParameters).toEqual(result);
});
});
+
+ test('Verify get remote workflow should call internal service for params when workflow is native', () =>{
+ let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["workflow 0"]}})
+ let getLocalWorkflowsParametersStub = Promise.resolve({"data":{
+ "parameterDefinitions": [
+ {
+ "id": 1,
+ "name": "Configuration Parameters",
+ "required": true,
+ "type": "text",
+ "pattern": ".*",
+ "msgOnPatternError": null,
+ "msgOnContentError": null,
+ "acceptableFileType": null
+ }
+ ],
+ }});
+ let getSOWorkflowsPromiseStub = Promise.resolve({"data":[{
+
+ "id": "ab6478e4-ea33-3346-ac12-ab121484a333",
+ "workflowName": "inPlaceSoftwareUpdate",
+ "name": "inPlaceSoftwareUpdate",
+ "source": "native",
+ "workflowInputParameters": [
+ ]
+ }]
+ });
+
+ $controller.changeManagement.vnfNames = [{modelVersionId: 'test1', name:'test'}];
+ $changeManagementService.getWorkflows = () => getWorkflowsStub;
+ $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub;
+ $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub;
+
+ return $controller.loadWorkFlows().then(() => {
+ expect($controller.workflows).toContain('inPlaceSoftwareUpdate');
+ expect($controller.localWorkflowsParameters.get('inPlaceSoftwareUpdate')).toEqual([{
+ "id": 1,
+ "name": "Configuration Parameters",
+ "required": true,
+ "type": "text",
+ "pattern": ".*",
+ "msgOnPatternError": null,
+ "msgOnContentError": null,
+ "acceptableFileType": null
+ }]);
+ });
+});
});
diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/MsoControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/MsoControllerTest.java
index 9b0c32028..b0378b054 100644
--- a/vid-app-common/src/test/java/org/onap/vid/controller/MsoControllerTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/controller/MsoControllerTest.java
@@ -20,107 +20,124 @@
package org.onap.vid.controller;
-import org.apache.commons.lang.StringEscapeUtils;
-import org.onap.portalsdk.core.util.SystemProperties;
-import org.onap.vid.factories.MsoRequestFactory;
-import org.onap.vid.mso.model.RequestInfo;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.argThat;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.BDDMockito.then;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.only;
+import static org.springframework.http.MediaType.APPLICATION_JSON;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.jeasy.random.EasyRandom;
+import org.jeasy.random.EasyRandomParameters;
+import org.jeasy.random.randomizers.misc.BooleanRandomizer;
+import org.jeasy.random.randomizers.text.StringRandomizer;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.onap.vid.mso.MsoBusinessLogic;
+import org.onap.vid.mso.MsoResponseWrapper;
import org.onap.vid.mso.rest.Request;
import org.onap.vid.mso.rest.RequestDetails;
import org.onap.vid.mso.rest.Task;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.ResponseEntity;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
-import org.springframework.test.context.web.WebAppConfiguration;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-import java.util.List;
-
-
-@WebAppConfiguration
-@ContextConfiguration(classes = {SystemProperties.class, MsoConfig.class})
-public class MsoControllerTest extends AbstractTestNGSpringContextTests {
-
- @Autowired
- MsoRequestFactory msoRequestFactory;
-
- @Test(enabled = false)
- public void testInstanceCreationNew() throws Exception {
-
- RequestDetails requestDetails = msoRequestFactory.createMsoRequest("msoRequest.json");
- MsoController msoController = new MsoController(null, null);
- //TODO: make ths test to really test something
- //ResponseEntity<String> responseEntityNew = msoController.createSvcInstanceNew(null, requestDetails);
- ResponseEntity<String> responseEntity = msoController.createSvcInstance(null, requestDetails);
- //Assert.assertEquals(responseEntityNew, responseEntity);
-
+import org.onap.vid.services.CloudOwnerService;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+
+public class MsoControllerTest {
+
+ private static final long STATIC_SEED = 5336L;
+ private EasyRandomParameters parameters = new EasyRandomParameters()
+ .randomize(Boolean.class, new BooleanRandomizer(STATIC_SEED))
+ .randomize(String.class, new StringRandomizer(4, 4, STATIC_SEED))
+ .collectionSizeRange(2, 3);
+ private EasyRandom modelGenerator = new EasyRandom(parameters);
+ private ObjectMapper objectMapper = new ObjectMapper();
+
+ private MockMvc mockMvc;
+ private MsoBusinessLogic msoBusinessLogic;
+ private CloudOwnerService cloudService;
+
+ @Before
+ public void setUp() {
+ msoBusinessLogic = mock(MsoBusinessLogic.class);
+ cloudService = mock(CloudOwnerService.class);
+ MsoController msoController = new MsoController(msoBusinessLogic, cloudService);
+
+ mockMvc = MockMvcBuilders.standaloneSetup(msoController).build();
}
- @Test(enabled = false)
- public void testInstanceCreationLocalWithRest() throws Exception {
-
- RequestDetails requestDetails = msoRequestFactory.createMsoRequest("msoRequest.json");
- MsoController msoController = new MsoController(null, null);
- ResponseEntity<String> responseEntityNew = msoController.createSvcInstance(null, requestDetails);
- //TODO: make ths test to really test something
-// ResponseEntity<String> responseEntityRest = msoController.createSvcInstanceNewRest(null, requestDetails);
-//
-// Assert.assertEquals(responseEntityNew.getBody(), responseEntityRest.getBody());
-
+ @Test
+ public void shouldDelegateNewInstanceCreation() throws Exception {
+ // given
+ RequestDetails given = modelGenerator.nextObject(RequestDetails.class);
+ String payload = objectMapper.writeValueAsString(given);
+
+ MsoResponseWrapper expectedResponse = new MsoResponseWrapper(200, "test");
+ given(msoBusinessLogic
+ .createSvcInstance(argThat(request -> asJson(request).equals(payload))))
+ .willReturn(expectedResponse);
+
+ // when & then
+ mockMvc.perform(post("/mso/mso_create_svc_instance")
+ .content(payload)
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().json(asJson(expectedResponse)));
+
+ ArgumentCaptor<RequestDetails> captor = ArgumentCaptor.forClass(RequestDetails.class);
+ then(cloudService).should(only()).enrichRequestWithCloudOwner(captor.capture());
+ assertThat(captor.getValue()).matches(request -> asJson(request).equals(payload));
}
- @Test(enabled = false)
- public void testInstanceCreation() throws Exception {
-
- RequestDetails requestDetails = msoRequestFactory.createMsoRequest("msoRequest.json");
- MsoController msoController = new MsoController(null, null);
- ResponseEntity<String> responseEntity = msoController.createSvcInstance(null, requestDetails);
+ @Test
+ public void shouldReturnOrchestrationRequestsForDashboard() throws Exception {
+ // given
+ List<Request> orchestrationRequests = modelGenerator
+ .objects(Request.class, 2)
+ .collect(Collectors.toList());
+ given(msoBusinessLogic.getOrchestrationRequestsForDashboard()).willReturn(orchestrationRequests);
- Assert.assertEquals(responseEntity.getBody(), "{ \"status\": 200, \"entity\": {\n" +
- " \"requestReferences\": {\n" +
- " \"instanceId\": \"ba00de9b-3c3e-4b0a-a1ad-0c5489e711fb\",\n" +
- " \"requestId\": \"311cc766-b673-4a50-b9c5-471f68914586\"\n" +
- " }\n" +
- "}}");
+ // when & then
+ mockMvc.perform(get("/mso/mso_get_orch_reqs/dashboard"))
+ .andExpect(status().isOk())
+ .andExpect(content().json(objectMapper.writeValueAsString(orchestrationRequests)));
+ then(cloudService).shouldHaveZeroInteractions();
}
- @Test(enabled = false)
- public void testGetOrchestrationRequestsForDashboard() throws Exception {
- MsoController msoController = new MsoController(null, null);
- List<Request> orchestrationRequestsForDashboard = msoController.getOrchestrationRequestsForDashboard();
+ @Test
+ public void shouldReturnManualTasksById() throws Exception {
+ // given
+ List<Task> manualTasks = modelGenerator
+ .objects(Task.class, 2)
+ .collect(Collectors.toList());
- Assert.assertEquals(orchestrationRequestsForDashboard.size(), 2);
- }
+ String originalRequestId = "za1234d1-5a33-55df-13ab-12abad84e335";
+ given(msoBusinessLogic.getManualTasksByRequestId(originalRequestId)).willReturn(manualTasks);
- @Test(enabled = false)
- public void testGetManualTasksByRequestId() throws Exception {
- MsoController msoController = new MsoController(null, null);
- List<Task> orchestrationRequestsForDashboard = msoController.getManualTasksByRequestId("za1234d1-5a33-55df-13ab-12abad84e335");
+ // when & then
+ mockMvc.perform(get("/mso/mso_get_man_task/{id}", originalRequestId))
+ .andExpect(status().isOk())
+ .andExpect(content().json(objectMapper.writeValueAsString(manualTasks)));
- Assert. assertEquals(orchestrationRequestsForDashboard.get(0).getTaskId(), "daf4dd84-b77a-42da-a051-3239b7a9392c");
+ then(cloudService).shouldHaveZeroInteractions();
}
-
- public void testCompleteManualTask() throws Exception { // TODO not done yet
- RequestInfo requestInfo = new RequestInfo();
- requestInfo.setResponseValue("rollback");
- requestInfo.setRequestorId("abc");
- requestInfo.setSource("VID");
- RequestDetails requestDetails = new RequestDetails();
- requestDetails.setRequestInfo(requestInfo);
- MsoController msoController = new MsoController(null, null);
- ResponseEntity<String> responseEntity = msoController.manualTaskComplete("daf4dd84-b77a-42da-a051-3239b7a9392c", requestDetails);
- String assertString = "{ \\\"status\\\": 200, \\\"entity\\\": {\\n\" +\n" +
- " \" \\\"taskRequestReference\\\": {\\n\" +\n" +
- " \" \\\"taskId\\\": \\\"daf4dd84-b77a-42da-a051-3239b7a9392c\\\"\\n\" +\n" +
- " \" }\\n\" +\n" +
- " \"}\\n\" +\n" +
- " \"}";
- Assert.assertEquals(responseEntity.getBody(), StringEscapeUtils.unescapeJava(assertString));
+ private <T> String asJson(T value) {
+ try {
+ return objectMapper.writeValueAsString(value);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
}
-
-
-}
+} \ No newline at end of file