aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controller/WorkflowsController.java7
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/model/SOWorkflows.kt10
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/mso/rest/MockedWorkflowsRestClient.java19
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsService.java3
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsServiceImpl.java24
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/ExtWorkflowServiceImplTest.java44
-rw-r--r--vid-ext-services-simulator/src/main/resources/preset_registration/changeManagement/workflow_parameters.json41
-rw-r--r--vid-ext-services-simulator/src/main/resources/preset_registration/changeManagement/workflow_parameters_1.json20
-rw-r--r--vid-ext-services-simulator/src/main/resources/preset_registration/changeManagement/workflow_parameters_2.json27
-rw-r--r--vid-ext-services-simulator/src/main/resources/preset_registration/changeManagement/workflow_parameters_3.json34
10 files changed, 219 insertions, 10 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/WorkflowsController.java b/vid-app-common/src/main/java/org/onap/vid/controller/WorkflowsController.java
index be1976a48..b693805d1 100644
--- a/vid-app-common/src/main/java/org/onap/vid/controller/WorkflowsController.java
+++ b/vid-app-common/src/main/java/org/onap/vid/controller/WorkflowsController.java
@@ -3,8 +3,10 @@ package org.onap.vid.controller;
import java.util.List;
import org.onap.portalsdk.core.controller.RestrictedBaseController;
import org.onap.vid.model.SOWorkflow;
+import org.onap.vid.model.SOWorkflowParameterDefinitions;
import org.onap.vid.services.ExtWorkflowsService;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
@@ -27,5 +29,10 @@ public class WorkflowsController extends RestrictedBaseController {
return extWorkflowsService.getWorkflows(vnfName);
}
+ @RequestMapping(value = "workflow-parameters/{id}", method = RequestMethod.GET)
+ SOWorkflowParameterDefinitions getParameters(@PathVariable Long id) {
+ return extWorkflowsService.getWorkflowParameterDefinitions(id);
+ }
+
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/model/SOWorkflows.kt b/vid-app-common/src/main/java/org/onap/vid/model/SOWorkflows.kt
index c85bfd7d4..25125cea6 100644
--- a/vid-app-common/src/main/java/org/onap/vid/model/SOWorkflows.kt
+++ b/vid-app-common/src/main/java/org/onap/vid/model/SOWorkflows.kt
@@ -10,4 +10,12 @@ data class SOWorkflows @JvmOverloads constructor(var workflows: List<SOWorkflow>
fun clone(): SOWorkflows {
return copy(workflows?.toMutableList())
}
-} \ No newline at end of file
+}
+
+
+enum class SOWorkflowType(var type: String? = "STRING") {
+ STRING("STRING")
+}
+
+data class SOWorkflowParameterDefinition(var id: Long? = null, var name: String? = null, var pattern: String? = null, var type: SOWorkflowType? = null, val required: Boolean? = null)
+data class SOWorkflowParameterDefinitions(var parameterDefinitions: List<SOWorkflowParameterDefinition>? = null) \ No newline at end of file
diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/rest/MockedWorkflowsRestClient.java b/vid-app-common/src/main/java/org/onap/vid/mso/rest/MockedWorkflowsRestClient.java
index 313710ebd..f2d1b7c42 100644
--- a/vid-app-common/src/main/java/org/onap/vid/mso/rest/MockedWorkflowsRestClient.java
+++ b/vid-app-common/src/main/java/org/onap/vid/mso/rest/MockedWorkflowsRestClient.java
@@ -3,6 +3,7 @@ package org.onap.vid.mso.rest;
import java.util.Collections;
import org.jetbrains.annotations.NotNull;
import org.onap.vid.client.SyncRestClient;
+import org.onap.vid.model.SOWorkflowParameterDefinitions;
import org.onap.vid.model.SOWorkflows;
import org.onap.vid.mso.MsoResponseWrapper2;
@@ -25,9 +26,27 @@ public class MockedWorkflowsRestClient {
SOWorkflows.class));
}
+ public MsoResponseWrapper2<SOWorkflowParameterDefinitions> getWorkflowParameterDefinitions(Long workflowId) {
+ return new MsoResponseWrapper2<>(syncRestClient
+ .get((workflowId <= 3 && workflowId > 0) ? getParametersUrl(workflowId) : getParametersUrl(),
+ Collections.emptyMap(),
+ Collections.emptyMap(),
+ SOWorkflowParameterDefinitions.class));
+ }
+
@NotNull
private String getWorkflowsUrl() {
return baseUrl + "so/workflows";
}
+
+ @NotNull
+ private String getParametersUrl() {
+ return baseUrl + "so/workflow-parameters";
+ }
+
+ @NotNull
+ private String getParametersUrl(Long workflowId) {
+ return baseUrl + "so/workflow-parameters/" + workflowId;
+ }
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsService.java b/vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsService.java
index 4ed26a14a..a62837c35 100644
--- a/vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsService.java
+++ b/vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsService.java
@@ -2,7 +2,10 @@ package org.onap.vid.services;
import java.util.List;
import org.onap.vid.model.SOWorkflow;
+import org.onap.vid.model.SOWorkflowParameterDefinitions;
public interface ExtWorkflowsService {
List<SOWorkflow> getWorkflows(String vnfName);
+
+ SOWorkflowParameterDefinitions getWorkflowParameterDefinitions(Long workflowId);
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsServiceImpl.java
index d5170b6e5..a06e0b587 100644
--- a/vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsServiceImpl.java
+++ b/vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsServiceImpl.java
@@ -2,6 +2,7 @@ package org.onap.vid.services;
import java.util.List;
import org.onap.vid.model.SOWorkflow;
+import org.onap.vid.model.SOWorkflowParameterDefinitions;
import org.onap.vid.model.SOWorkflows;
import org.onap.vid.mso.MsoResponseWrapper2;
import org.onap.vid.mso.rest.MockedWorkflowsRestClient;
@@ -21,25 +22,36 @@ public class ExtWorkflowsServiceImpl implements ExtWorkflowsService {
@Override
public List<SOWorkflow> getWorkflows(String vnfName) {
MsoResponseWrapper2<SOWorkflows> msoResponse = mockedWorkflowsRestClient.getWorkflows(vnfName);
- if (msoResponse.getStatus() >= 400 || msoResponse.getEntity() == null) {
- throw new BadResponseFromMso(msoResponse);
- }
+ validateSOResponse(msoResponse, SOWorkflows.class);
return convertMsoResponseToWorkflowList(msoResponse);
}
+ @Override
+ public SOWorkflowParameterDefinitions getWorkflowParameterDefinitions(Long workflowId) {
+ MsoResponseWrapper2<SOWorkflowParameterDefinitions> msoResponse = mockedWorkflowsRestClient.getWorkflowParameterDefinitions(workflowId);
+ validateSOResponse(msoResponse, SOWorkflowParameterDefinitions.class);
+ return (SOWorkflowParameterDefinitions) msoResponse.getEntity();
+ }
+
private List<SOWorkflow> convertMsoResponseToWorkflowList(MsoResponseWrapper2<SOWorkflows> msoResponse) {
SOWorkflows soWorkflows = (SOWorkflows) msoResponse.getEntity();
return soWorkflows.getWorkflows();
}
+ private void validateSOResponse(MsoResponseWrapper2 response, Class<?> expectedResponseClass){
+ if (response.getStatus() >= 400 || !expectedResponseClass.isInstance(response.getEntity())) {
+ throw new BadResponseFromMso(response);
+ }
+ }
+
public static class BadResponseFromMso extends RuntimeException {
- private final MsoResponseWrapper2<SOWorkflows> msoResponse;
+ private final MsoResponseWrapper2<?> msoResponse;
- public BadResponseFromMso(MsoResponseWrapper2<SOWorkflows> msoResponse) {
+ BadResponseFromMso(MsoResponseWrapper2<?> msoResponse) {
this.msoResponse = msoResponse;
}
- public MsoResponseWrapper2<SOWorkflows> getMsoResponse() {
+ public MsoResponseWrapper2<?> getMsoResponse() {
return msoResponse;
}
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/ExtWorkflowServiceImplTest.java b/vid-app-common/src/test/java/org/onap/vid/services/ExtWorkflowServiceImplTest.java
index 1509637bb..4d0d983e9 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/ExtWorkflowServiceImplTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/services/ExtWorkflowServiceImplTest.java
@@ -1,15 +1,20 @@
package org.onap.vid.services;
-import static org.hamcrest.CoreMatchers.*;
-import static org.hamcrest.MatcherAssert.assertThat;
+
+import com.google.common.collect.Lists;
import io.joshworks.restclient.http.HttpResponse;
import java.util.Collections;
import java.util.List;
+
+import org.assertj.core.api.Assertions;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.onap.vid.model.SOWorkflow;
+import org.onap.vid.model.SOWorkflowParameterDefinition;
+import org.onap.vid.model.SOWorkflowParameterDefinitions;
+import org.onap.vid.model.SOWorkflowType;
import org.onap.vid.model.SOWorkflows;
import org.onap.vid.mso.MsoResponseWrapper2;
import org.onap.vid.mso.rest.MockedWorkflowsRestClient;
@@ -17,6 +22,8 @@ import org.onap.vid.services.ExtWorkflowsServiceImpl.BadResponseFromMso;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+
+
public class ExtWorkflowServiceImplTest {
@Mock
@@ -24,6 +31,10 @@ public class ExtWorkflowServiceImplTest {
@Mock
private HttpResponse<SOWorkflows> response;
+ @Mock
+ private HttpResponse<SOWorkflowParameterDefinitions> parameterDefinitionsHttpResponse;
+
+
@BeforeMethod
public void init(){
MockitoAnnotations.initMocks(this);
@@ -41,7 +52,7 @@ public class ExtWorkflowServiceImplTest {
List<SOWorkflow> workflows = extWorkflowsService.getWorkflows("test");
// then
Mockito.verify(client).getWorkflows("test");
- assertThat(workflows.get(0).getName(), is("xyz"));
+ Assertions.assertThat(workflows.get(0).getName()).isEqualTo("xyz");
}
@Test(expectedExceptions = BadResponseFromMso.class)
@@ -56,5 +67,32 @@ public class ExtWorkflowServiceImplTest {
extWorkflowsService.getWorkflows("test");
// then throw exception
}
+ @Test
+ public void shouldReturnWorkflowParametersOnValidResponse() {
+ SOWorkflowParameterDefinitions parameters = new SOWorkflowParameterDefinitions(Collections.singletonList(new SOWorkflowParameterDefinition(1L, "sample", "[0-9]", SOWorkflowType.STRING, true)));
+ ExtWorkflowsService extWorkflowsService = new ExtWorkflowsServiceImpl(client);
+ Mockito.when(parameterDefinitionsHttpResponse.getStatus()).thenReturn(200);
+ Mockito.when(parameterDefinitionsHttpResponse.getBody()).thenReturn(parameters);
+ MsoResponseWrapper2<SOWorkflowParameterDefinitions> msoResponseWrapper = new MsoResponseWrapper2<>(parameterDefinitionsHttpResponse);
+ Mockito.when(client.getWorkflowParameterDefinitions(1L)).thenReturn(msoResponseWrapper);
+
+ SOWorkflowParameterDefinitions workflowParameterDefinitions = extWorkflowsService.getWorkflowParameterDefinitions(1L);
+
+ Assertions.assertThat(workflowParameterDefinitions).isEqualTo(parameters);
+ }
+
+ @Test
+ public void shouldProperlyHandleEmptyParametersList(){
+ ExtWorkflowsService extWorkflowsService = new ExtWorkflowsServiceImpl(client);
+ Mockito.when(parameterDefinitionsHttpResponse.getStatus()).thenReturn(200);
+ Mockito.when(parameterDefinitionsHttpResponse.getBody()).thenReturn(new SOWorkflowParameterDefinitions(Lists.newArrayList()));
+
+ MsoResponseWrapper2<SOWorkflowParameterDefinitions> msoResponseWrapper = new MsoResponseWrapper2<>(parameterDefinitionsHttpResponse);
+ Mockito.when(client.getWorkflowParameterDefinitions(1L)).thenReturn(msoResponseWrapper);
+
+
+ SOWorkflowParameterDefinitions workflowParameterDefinitions = extWorkflowsService.getWorkflowParameterDefinitions(1L);
+ Assertions.assertThat(workflowParameterDefinitions.getParameterDefinitions()).isEmpty();
+ }
}
diff --git a/vid-ext-services-simulator/src/main/resources/preset_registration/changeManagement/workflow_parameters.json b/vid-ext-services-simulator/src/main/resources/preset_registration/changeManagement/workflow_parameters.json
new file mode 100644
index 000000000..0bc683c41
--- /dev/null
+++ b/vid-ext-services-simulator/src/main/resources/preset_registration/changeManagement/workflow_parameters.json
@@ -0,0 +1,41 @@
+{
+ "simulatorRequest": {
+ "method": "GET",
+ "path": "/so/workflow-parameters"
+ },
+ "simulatorResponse": {
+ "responseCode": 200,
+ "body": {
+ "parameterDefinitions": [
+ {
+ "id": 1,
+ "name": "general param 1",
+ "required": true,
+ "type": "STRING",
+ "pattern": "[0-9]*"
+ },
+ {
+ "id": 2,
+ "name": "general param 2",
+ "required": false,
+ "type": "STRING",
+ "pattern": "[-+]?[0-9]*\\.?[0-9]*"
+ },
+ {
+ "id": 3,
+ "name": "general param 3",
+ "required": true,
+ "type": "STRING",
+ "pattern": "[a-zA-Z0-9]{7}"
+ },
+ {
+ "id": 4,
+ "name": "general param 4",
+ "required": true,
+ "type": "STRING",
+ "pattern": "[0-9]{3}"
+ }
+ ]
+ }
+ }
+} \ No newline at end of file
diff --git a/vid-ext-services-simulator/src/main/resources/preset_registration/changeManagement/workflow_parameters_1.json b/vid-ext-services-simulator/src/main/resources/preset_registration/changeManagement/workflow_parameters_1.json
new file mode 100644
index 000000000..8dd5ad8f4
--- /dev/null
+++ b/vid-ext-services-simulator/src/main/resources/preset_registration/changeManagement/workflow_parameters_1.json
@@ -0,0 +1,20 @@
+{
+ "simulatorRequest": {
+ "method": "GET",
+ "path": "/so/workflow-parameters/1"
+ },
+ "simulatorResponse": {
+ "responseCode": 200,
+ "body": {
+ "parameterDefinitions": [
+ {
+ "id": 1,
+ "name": "[FIRST]parameter 1",
+ "required": true,
+ "type": "STRING",
+ "pattern": "[0-9]*"
+ }
+ ]
+ }
+ }
+} \ No newline at end of file
diff --git a/vid-ext-services-simulator/src/main/resources/preset_registration/changeManagement/workflow_parameters_2.json b/vid-ext-services-simulator/src/main/resources/preset_registration/changeManagement/workflow_parameters_2.json
new file mode 100644
index 000000000..8ce37bc04
--- /dev/null
+++ b/vid-ext-services-simulator/src/main/resources/preset_registration/changeManagement/workflow_parameters_2.json
@@ -0,0 +1,27 @@
+{
+ "simulatorRequest": {
+ "method": "GET",
+ "path": "/so/workflow-parameters/2"
+ },
+ "simulatorResponse": {
+ "responseCode": 200,
+ "body": {
+ "parameterDefinitions": [
+ {
+ "id": 1,
+ "name": "[SECOND] parameter 1",
+ "required": true,
+ "type": "STRING",
+ "pattern": "[0-9]*"
+ },
+ {
+ "id": 2,
+ "name": "[SECOND] parameter 2",
+ "required": false,
+ "type": "STRING",
+ "pattern": "[a-zA-Z0-9]*"
+ }
+ ]
+ }
+ }
+} \ No newline at end of file
diff --git a/vid-ext-services-simulator/src/main/resources/preset_registration/changeManagement/workflow_parameters_3.json b/vid-ext-services-simulator/src/main/resources/preset_registration/changeManagement/workflow_parameters_3.json
new file mode 100644
index 000000000..6815d5b58
--- /dev/null
+++ b/vid-ext-services-simulator/src/main/resources/preset_registration/changeManagement/workflow_parameters_3.json
@@ -0,0 +1,34 @@
+{
+ "simulatorRequest": {
+ "method": "GET",
+ "path": "/so/workflow-parameters/3"
+ },
+ "simulatorResponse": {
+ "responseCode": 200,
+ "body": {
+ "parameterDefinitions": [
+ {
+ "id": 1,
+ "name": "[THIRD] parameter 1",
+ "required": true,
+ "type": "STRING",
+ "pattern": "[0-9]*"
+ },
+ {
+ "id": 2,
+ "name": "[THIRD] parameter 2",
+ "required": false,
+ "type": "STRING",
+ "pattern": "[a-zA-Z]*"
+ },
+ {
+ "id": 3,
+ "name": "[THIRD] parameter 3",
+ "required": true,
+ "type": "STRING",
+ "pattern": "[0-9]{3}"
+ }
+ ]
+ }
+ }
+} \ No newline at end of file