diff options
author | Arthur Martella <amartell@research.att.com> | 2017-09-08 13:27:46 -0400 |
---|---|---|
committer | Arthur Martella <amartell@research.att.com> | 2017-09-08 13:32:24 -0400 |
commit | 62cd6aaaf74aa91ee0037c0e155c8e7284f07567 (patch) | |
tree | 68c0c53c9156f5aa3c6b3599ac940770f986633d /bpmn/MSOCommonBPMN/src/test/java/org | |
parent | fa1a211d28a912892fcd888569df033900eb01ee (diff) |
1710 Rebase - Second Attempt
This commit rebases changes from openecomp-mso/internal-staging-1710 up to and including this codecloud commit:
54483fc6606ddb1591a2e9da61bff8712325f924
Wed Sep 6 18:12:56 2017 -0400
Rebasing was done on a branch on top of this commit in so/master in ONAP:
93fbdfbe46104f8859d4754040f979cb7997c157
Thu Sep 7 16:42:59 2017 +0000
Change-Id: I4ad9abf40da32bf5bdca43e868b8fa2dbcd9dc59
Issue-id: SO-107
Signed-off-by: Arthur Martella <amartell@research.att.com>
Diffstat (limited to 'bpmn/MSOCommonBPMN/src/test/java/org')
12 files changed, 811 insertions, 31 deletions
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/BPMNUtil.java b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/BPMNUtil.java index 27f2479a7b..c476c6577f 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/BPMNUtil.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/BPMNUtil.java @@ -19,7 +19,7 @@ import org.camunda.bpm.engine.variable.impl.VariableMapImpl; import org.jboss.resteasy.spi.AsynchronousResponse;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
-import org.openecomp.mso.bpmn.common.workflow.service.WorkflowAsyncCommonResource;
+import org.openecomp.mso.bpmn.common.workflow.service.WorkflowAsyncResource;
import org.openecomp.mso.bpmn.common.workflow.service.WorkflowResource;
import org.openecomp.mso.bpmn.common.workflow.service.WorkflowResponse;
@@ -166,7 +166,7 @@ public class BPMNUtil { * @param variables
*/
private static void executeAsyncFlow(ProcessEngineServices processEngineServices, String processKey, AsynchronousResponse asyncResponse, Map<String,String> variables) {
- WorkflowAsyncCommonResource workflowResource = new WorkflowAsyncCommonResource();
+ WorkflowAsyncResource workflowResource = new WorkflowAsyncResource();
VariableMapImpl variableMap = new VariableMapImpl();
Map<String, Object> variableValueType = new HashMap<String, Object>();
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/DecomposeServiceTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/DecomposeServiceTest.java new file mode 100644 index 0000000000..6ec9493557 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/DecomposeServiceTest.java @@ -0,0 +1,95 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.openecomp.mso.bpmn.common; + +import static org.openecomp.mso.bpmn.mock.StubResponseDatabase.MockGetServiceResourcesCatalogData; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.camunda.bpm.engine.test.Deployment; +import org.junit.Assert; +import org.junit.Test; +import org.openecomp.mso.bpmn.common.WorkflowTest; + +/** + * Unit Test for the DecomposeService Flow + * + */ +public class DecomposeServiceTest extends WorkflowTest { + + + public DecomposeServiceTest() throws IOException { + + } + + @Test + @Deployment(resources = {"subprocess/BuildingBlock/DecomposeService.bpmn"}) + public void testDecomposeService_success() throws Exception{ + MockGetServiceResourcesCatalogData("cmw-123-456-789", "/getCatalogServiceResourcesData.json", "1.0"); + + + String businessKey = UUID.randomUUID().toString(); + Map<String, Object> variables = new HashMap<String, Object>(); + setVariablesSuccess(variables, "testRequestId123", "ff5256d2-5a33-55df-13ab-12abad84e7ff"); + invokeSubProcess("DecomposeService", businessKey, variables); + + waitForProcessEnd(businessKey, 10000); + + Assert.assertTrue(isProcessEnded(businessKey)); + + } + + //@Test + @Deployment(resources = {"subprocess/BuildingBlock/DecomposeService.bpmn"}) + public void testDecomposeService_success_partial() throws Exception{ + MockGetServiceResourcesCatalogData("cmw-123-456-789", "/getCatalogServiceResourcesDataNoNetwork.json"); + + + String businessKey = UUID.randomUUID().toString(); + Map<String, Object> variables = new HashMap<String, Object>(); + setVariablesSuccess(variables, "testRequestId123", "ff5256d2-5a33-55df-13ab-12abad84e7ff"); + invokeSubProcess("DecomposeService", businessKey, variables); + + waitForProcessEnd(businessKey, 10000); + + Assert.assertTrue(isProcessEnded(businessKey)); + + } + + private void setVariablesSuccess(Map<String, Object> variables, String requestId, String siId) { + variables.put("isDebugLogEnabled", "true"); + variables.put("mso-request-id", requestId); + variables.put("msoRequestId", requestId); + variables.put("serviceInstanceId",siId); + + String serviceModelInfo = "{ "+ "\"modelType\": \"service\"," + + "\"modelInvariantUuid\": \"cmw-123-456-789\"," + + "\"modelVersionId\": \"ab6478e5-ea33-3346-ac12-ab121484a3fe\"," + + "\"modelName\": \"ServicevSAMP12\"," + + "\"modelVersion\": \"1.0\"," + + "}"; + variables.put("serviceModelInfo", serviceModelInfo); + + } + +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/ManualHandlingTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/ManualHandlingTest.java new file mode 100644 index 0000000000..c68c7bb184 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/ManualHandlingTest.java @@ -0,0 +1,122 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.openecomp.mso.bpmn.common; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; + +import org.camunda.bpm.engine.TaskService; +import org.camunda.bpm.ProcessEngineService; +import org.camunda.bpm.engine.task.TaskQuery; +import org.camunda.bpm.engine.task.Task; +import org.camunda.bpm.engine.delegate.BpmnError; +import org.camunda.bpm.engine.delegate.DelegateTask; +import org.camunda.bpm.engine.runtime.Execution; + +import static org.openecomp.mso.bpmn.common.BPMNUtil.executeWorkFlow; +import static org.openecomp.mso.bpmn.common.BPMNUtil.waitForWorkflowToFinish; +import static com.github.tomakehurst.wiremock.client.WireMock.containing; +import static com.github.tomakehurst.wiremock.client.WireMock.put; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; +import static org.openecomp.mso.bpmn.common.BPMNUtil.executeWorkFlow; +import static org.openecomp.mso.bpmn.common.BPMNUtil.waitForWorkflowToFinish; +import static org.openecomp.mso.bpmn.mock.StubResponsePolicy.MockPolicyAbort; + +import java.io.DataOutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import java.util.List; + +import org.camunda.bpm.engine.RuntimeService; +import org.camunda.bpm.engine.test.Deployment; +import org.junit.Assert; +import org.junit.Test; +import org.openecomp.mso.bpmn.common.workflow.service.WorkflowResponse; +import org.openecomp.mso.bpmn.core.WorkflowException; + +/** + * Unit test for RainyDayHandler.bpmn. + */ +public class ManualHandlingTest extends WorkflowTest { + + @Test + @Deployment(resources = { + "subprocess/BuildingBlock/ManualHandling.bpmn" + }) + public void TestManualHandlingSuccess() { + + RuntimeService runtimeService = processEngineRule.getRuntimeService(); + Map<String, Object> variables = new HashMap<String, Object>(); + variables.put("isDebugLogEnabled","true"); + variables.put("msoRequestId", "testRequestId"); + variables.put("serviceType", "X"); + variables.put("vnfType", "Y"); + variables.put("currentActivity", "BB1"); + variables.put("workStep", "1"); + variables.put("failedActivity", ""); + variables.put("errorCode", "123"); + variables.put("errorText", "update failed"); + variables.put("validResponses", "Rollback"); + + + String businessKey = UUID.randomUUID().toString(); + invokeSubProcess("ManualHandling", businessKey, variables); + + try { + Thread.sleep(5); + } catch (Exception e) { + + } + + TaskService taskService = processEngineRule.getTaskService(); + + TaskQuery q = taskService.createTaskQuery(); + + List<Task> tasks = q.orderByTaskCreateTime().asc().list(); + int i = 0; + + for (Task task : tasks) { + + + System.out.println("TASK ID: " + task.getId()); + System.out.println("TASK NAME: " + task.getName()); + try { + System.out.println("Completing the task"); + Map<String,Object> completeVariables = new HashMap<String,Object>(); + completeVariables.put("responseValue", "skip"); + taskService.complete(task.getId(), completeVariables); + } + catch(Exception e) { + System.out.println("GOT EXCEPTION: " + e.getMessage()); + } + } + + waitForProcessEnd(businessKey, 100000); + + Assert.assertTrue(isProcessEnded(businessKey)); + + } + + +}
\ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/RainyDayHandlerTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/RainyDayHandlerTest.java new file mode 100644 index 0000000000..86b59f9074 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/RainyDayHandlerTest.java @@ -0,0 +1,85 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.openecomp.mso.bpmn.common;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static org.openecomp.mso.bpmn.common.BPMNUtil.executeWorkFlow;
+import static org.openecomp.mso.bpmn.common.BPMNUtil.waitForWorkflowToFinish;
+import static com.github.tomakehurst.wiremock.client.WireMock.containing;
+import static com.github.tomakehurst.wiremock.client.WireMock.put;
+import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
+import static org.openecomp.mso.bpmn.common.BPMNUtil.executeWorkFlow;
+import static org.openecomp.mso.bpmn.common.BPMNUtil.waitForWorkflowToFinish;
+import static org.openecomp.mso.bpmn.mock.StubResponsePolicy.MockPolicyAbort;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.camunda.bpm.engine.RuntimeService;
+import org.camunda.bpm.engine.test.Deployment;
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.openecomp.mso.bpmn.common.workflow.service.WorkflowResponse;
+import org.openecomp.mso.bpmn.core.WorkflowException;
+
+/**
+ * Unit test for RainyDayHandler.bpmn.
+ */
+public class RainyDayHandlerTest extends WorkflowTest {
+
+ @Test
+ @Ignore // IGNORED FOR 1710 MERGE TO ONAP
+ @Deployment(resources = {
+ "subprocess/BuildingBlock/RainyDayHandler.bpmn",
+ "subprocess/BuildingBlock/ManualHandling.bpmn"
+ })
+ public void TestRainyDayHandlingSuccess() {
+
+ RuntimeService runtimeService = processEngineRule.getRuntimeService();
+ Map<String, Object> variables = new HashMap<String, Object>();
+ variables.put("isDebugLogEnabled","true");
+ variables.put("msoRequestId", "testRequestId");
+ variables.put("serviceType", "X");
+ variables.put("vnfType", "Y");
+ variables.put("currentActivity", "BB1");
+ variables.put("workStep", "1");
+ variables.put("failedActivity", "");
+ variables.put("errorCode", "123");
+ variables.put("errorText", "update failed");
+
+ MockPolicyAbort();
+
+
+ String businessKey = UUID.randomUUID().toString();
+ invokeSubProcess("RainyDayHandler", businessKey, variables);
+
+ waitForProcessEnd(businessKey, 10000);
+
+ Assert.assertTrue(isProcessEnded(businessKey));
+
+ }
+
+
+
+}
\ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/SDNCAdapterV1Test.java b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/SDNCAdapterV1Test.java index 3eb7acd91a..d1ca98ccab 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/SDNCAdapterV1Test.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/SDNCAdapterV1Test.java @@ -38,6 +38,7 @@ import org.camunda.bpm.engine.runtime.Job; import org.camunda.bpm.engine.test.Deployment;
import org.camunda.bpm.engine.variable.impl.VariableMapImpl;
import org.junit.Assert;
+import org.junit.Ignore;
import org.junit.Test;
import org.openecomp.mso.bpmn.common.adapter.sdnc.CallbackHeader;
import org.openecomp.mso.bpmn.common.adapter.sdnc.SDNCAdapterCallbackRequest;
@@ -47,6 +48,7 @@ import org.openecomp.mso.bpmn.common.workflow.service.SDNCAdapterCallbackService import org.openecomp.mso.bpmn.common.workflow.service.WorkflowResource;
import org.openecomp.mso.bpmn.common.workflow.service.WorkflowResponse;
import org.openecomp.mso.bpmn.core.PropertyConfigurationSetup;
+import org.openecomp.mso.bpmn.core.xml.XmlTool;
import org.openecomp.mso.bpmn.mock.FileUtil;
/**
@@ -173,6 +175,7 @@ public class SDNCAdapterV1Test extends WorkflowTest { checkForTimeout(pid);
assertEquals(true, (Boolean) (getVariable(pid, "continueListening")));
+ assertEquals(false, (Boolean) (getVariable(pid, "SDNCA_InterimNotify")));
//System.out.println("SDNCAdapter interim status processing flow Completed!");
@@ -215,6 +218,7 @@ public class SDNCAdapterV1Test extends WorkflowTest { assertFalse(sdncAdapterResponse instanceof SDNCAdapterErrorResponse);
assertProcessInstanceNotFinished(pid);
assertEquals(true, (Boolean) (getVariable(pid, "continueListening")));
+ assertEquals(false, (Boolean) (getVariable(pid, "SDNCA_InterimNotify")));
// Inject a "final" SDNC Adapter asynchronous callback message
sdncAdapterCallbackRequest.setRequestData(sdncAdapterCallbackRequestData);
@@ -224,11 +228,74 @@ public class SDNCAdapterV1Test extends WorkflowTest { assertFalse(sdncAdapterResponse instanceof SDNCAdapterErrorResponse);
assertProcessInstanceFinished(pid);
assertEquals(false, (Boolean) (getVariable(pid, "continueListening")));
+ assertEquals(false, (Boolean) (getVariable(pid, "SDNCA_InterimNotify")));
+
+ //System.out.println("SDNCAdapter non-final then final processing flow Completed!");
+ }
+
+
+ @Test
+ @Deployment(resources = {"subprocess/SDNCAdapterV1.bpmn",
+ "subprocess/GenericNotificationService.bpmn"
+ })
+ public void nonFinalThenFinalWithNotify() throws InterruptedException {
+
+ mockSDNCAdapter(200);
+ mockUpdateRequestDB(200, "Database/DBAdapter.xml");
+
+ //System.out.println("SDNCAdapter non-final then final processing flow Started!");
+
+ String modSdncAdapterWorkflowRequestAct = sdncAdapterWorkflowRequestAct;
+ try {
+ // only service-type "uCPE-VMS" is applicable to notification, so modify the test request
+ modSdncAdapterWorkflowRequestAct = XmlTool.modifyElement(sdncAdapterWorkflowRequestAct, "tag0:service-type", "uCPE-VMS").get();
+ System.out.println("modified request: " + modSdncAdapterWorkflowRequestAct);
+ } catch (Exception e) {
+ System.out.println("request modification failed");
+ //e.printStackTrace();
+ }
+
+ // Start the flow
+ ProcessExecutionThread thread = new ProcessExecutionThread(modSdncAdapterWorkflowRequestAct);
+ thread.start();
+ waitForExecutionToStart("sdncAdapter", 3);
+ String pid = getPid();
+
+ assertProcessInstanceNotFinished(pid);
+
+ // Inject a "non-final" SDNC Adapter asynchronous callback message
+ //System.out.println("Injecting SDNC Adapter asynchronous callback message to continue processing");
+ String generatedRequestId = (String) processEngineRule.getRuntimeService().getVariable(pid, "SDNCA_requestId");
+ CallbackHeader callbackHeader = new CallbackHeader();
+ callbackHeader.setRequestId(generatedRequestId);
+ callbackHeader.setResponseCode("200");
+ callbackHeader.setResponseMessage("OK");
+ SDNCAdapterCallbackRequest sdncAdapterCallbackRequest = new SDNCAdapterCallbackRequest();
+ sdncAdapterCallbackRequest.setCallbackHeader(callbackHeader);
+ sdncAdapterCallbackRequest.setRequestData(sdncAdapterCallbackRequestDataNonfinal);
+ SDNCAdapterCallbackServiceImpl callbackService = new SDNCAdapterCallbackServiceImpl();
+ callbackService.setProcessEngineServices4junit(processEngineRule);
+ SDNCAdapterResponse sdncAdapterResponse = callbackService.sdncAdapterCallback(sdncAdapterCallbackRequest);
+ //System.out.println("Back from executing process again");
+
+ assertFalse(sdncAdapterResponse instanceof SDNCAdapterErrorResponse);
+ assertProcessInstanceNotFinished(pid);
+ assertEquals(true, (Boolean) (getVariable(pid, "continueListening")));
+ assertEquals(true, (Boolean) (getVariable(pid, "SDNCA_InterimNotify")));
+
+ // Inject a "final" SDNC Adapter asynchronous callback message
+ sdncAdapterCallbackRequest.setRequestData(sdncAdapterCallbackRequestData);
+ sdncAdapterResponse = callbackService.sdncAdapterCallback(sdncAdapterCallbackRequest);
+ //System.out.println("Back from executing process again");
+
+ assertFalse(sdncAdapterResponse instanceof SDNCAdapterErrorResponse);
+ assertProcessInstanceFinished(pid);
+ assertEquals(false, (Boolean) (getVariable(pid, "continueListening")));
+ assertEquals(false, (Boolean) (getVariable(pid, "SDNCA_InterimNotify")));
//System.out.println("SDNCAdapter non-final then final processing flow Completed!");
}
-
private void waitForExecutionToStart(String processDefintion, int count) throws InterruptedException {
//System.out.println(processEngineRule.getRuntimeService().createExecutionQuery().processDefinitionKey(processDefintion).count());
@@ -238,6 +305,7 @@ public class SDNCAdapterV1Test extends WorkflowTest { }
@Test
+ @Ignore // Ignored because PropertyConfigurationSetup is timing out
@Deployment(resources = {"subprocess/SDNCAdapterV1.bpmn",
"subprocess/GenericNotificationService.bpmn"
})
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/WorkflowAsyncResourceTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/WorkflowAsyncResourceTest.java index 4ac885fd9d..abad6c373d 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/WorkflowAsyncResourceTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/WorkflowAsyncResourceTest.java @@ -31,7 +31,7 @@ import org.camunda.bpm.engine.test.Deployment; import org.camunda.bpm.engine.variable.impl.VariableMapImpl; import org.jboss.resteasy.spi.AsynchronousResponse; import org.junit.Test; -import org.openecomp.mso.bpmn.common.workflow.service.WorkflowAsyncCommonResource; +import org.openecomp.mso.bpmn.common.workflow.service.WorkflowAsyncResource; import org.openecomp.mso.bpmn.common.workflow.service.WorkflowResponse; public class WorkflowAsyncResourceTest extends WorkflowTest { @@ -53,7 +53,7 @@ public class WorkflowAsyncResourceTest extends WorkflowTest { } private void executeWorkflow(String request, String requestId, AsynchronousResponse asyncResponse, String processKey) { - WorkflowAsyncCommonResource workflowResource = new WorkflowAsyncCommonResource(); + WorkflowAsyncResource workflowResource = new WorkflowAsyncResource(); VariableMapImpl variableMap = new VariableMapImpl(); Map<String, Object> variableValueType = new HashMap<String, Object>(); diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/WorkflowTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/WorkflowTest.java index 49ad6d6e34..4deac221a5 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/WorkflowTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/WorkflowTest.java @@ -1,22 +1,22 @@ -/*-
- * ============LICENSE_START=======================================================
- * OPENECOMP - MSO
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * 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=========================================================
- */
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.openecomp.mso.bpmn.common;
@@ -60,6 +60,8 @@ import org.camunda.bpm.engine.variable.impl.VariableMapImpl; import org.custommonkey.xmlunit.DetailedDiff;
import org.custommonkey.xmlunit.XMLUnit;
import org.jboss.resteasy.spi.AsynchronousResponse;
+import org.json.JSONArray;
+import org.json.JSONObject;
import org.junit.Before;
import org.junit.Rule;
import org.openecomp.mso.bpmn.common.adapter.sdnc.CallbackHeader;
@@ -73,11 +75,15 @@ import org.openecomp.mso.bpmn.common.adapter.vnf.UpdateVnfNotification; import org.openecomp.mso.bpmn.common.adapter.vnf.VnfRollback;
import org.openecomp.mso.bpmn.common.workflow.service.SDNCAdapterCallbackServiceImpl;
import org.openecomp.mso.bpmn.common.workflow.service.VnfAdapterNotifyServiceImpl;
-import org.openecomp.mso.bpmn.common.workflow.service.WorkflowAsyncCommonResource;
+import org.openecomp.mso.bpmn.common.workflow.service.WorkflowAsyncResource;
import org.openecomp.mso.bpmn.common.workflow.service.WorkflowMessageResource;
import org.openecomp.mso.bpmn.common.workflow.service.WorkflowResponse;
import org.openecomp.mso.bpmn.core.CamundaDBSetup;
import org.openecomp.mso.bpmn.core.PropertyConfigurationSetup;
+import org.openecomp.mso.bpmn.core.domain.Resource;
+import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition;
+
+import static org.openecomp.mso.bpmn.core.json.JsonUtils.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -119,6 +125,7 @@ public class WorkflowTest { */
protected static final String JSON = "application/json; charset=UTF-8";
+
/**
* Constructor.
*/
@@ -265,7 +272,7 @@ public class WorkflowTest { VariableMapImpl variableMapImpl = createVariableMapImpl(variables);
System.out.println("Sending " + request + " to " + processKey + " process");
- WorkflowAsyncCommonResource workflowResource = new WorkflowAsyncCommonResource();
+ WorkflowAsyncResource workflowResource = new WorkflowAsyncResource();
workflowResource.setProcessEngineServices4junit(processEngineRule);
TestAsyncResponse asyncResponse = new TestAsyncResponse();
@@ -298,7 +305,7 @@ public class WorkflowTest { VariableMapImpl variableMapImpl = createVariableMapImpl(variables);
System.out.println("Sending " + request + " to " + processKey + " process");
- WorkflowAsyncCommonResource workflowResource = new WorkflowAsyncCommonResource();
+ WorkflowAsyncResource workflowResource = new WorkflowAsyncResource();
workflowResource.setProcessEngineServices4junit(processEngineRule);
TestAsyncResponse asyncResponse = new TestAsyncResponse();
@@ -619,6 +626,18 @@ public class WorkflowTest { content = callbackData.getContent();
respCode = 200;
respMsg = "OK";
+ } else if ("CREATED".equals(modifier)) {
+ CallbackData callbackData = callbacks.get(action);
+
+ if (callbackData == null) {
+ String msg = "No callback defined for '" + action + "' SDNC request";
+ System.out.println(msg);
+ fail(msg);
+ }
+
+ content = callbackData.getContent();
+ respCode = 201;
+ respMsg = "Created";
} else if ("ERR".equals(modifier)) {
content = "<svc-request-id>((REQUEST-ID))</svc-request-id><response-code>500</response-code><response-message>SIMULATED ERROR FROM SDNC ADAPTER</response-message>";
respCode = 500;
@@ -1386,6 +1405,127 @@ public class WorkflowTest { }
/**
+ * Runs a program to inject sniro workflow messages into the test environment.
+ * A program is essentially just a list of keys that identify event data
+ * to be injected, in sequence. For more details, see
+ * injectSNIROCallbacks(String contentType, String messageType, String content, long timeout)
+ *
+ * Errors are handled with junit assertions and will cause the test to fail.
+ * NOTE: Each callback must have a workflow message type associated with it.
+ *
+ * @param callbacks an object containing event data for the program
+ * @param program the program to execute
+ */
+ protected void injectSNIROCallbacks(CallbackSet callbacks, String program) {
+
+ String[] cmds = program.replaceAll("\\s+", "").split(",");
+
+ for (String cmd : cmds) {
+ String action = cmd;
+ String modifier = "STD";
+
+ if (cmd.contains(":")) {
+ String[] parts = cmd.split(":");
+ action = parts[0];
+ modifier = parts[1];
+ }
+
+ String messageType = null;
+ String content = null;
+ String contentType = null;
+
+ if ("STD".equals(modifier)) {
+ CallbackData callbackData = callbacks.get(action);
+
+ if (callbackData == null) {
+ String msg = "No '" + action + "' workflow message callback is defined";
+ System.out.println(msg);
+ fail(msg);
+ }
+
+ messageType = callbackData.getMessageType();
+
+ if (messageType == null || messageType.trim().equals("")) {
+ String msg = "No workflow message type is defined in the '" + action + "' callback";
+ System.out.println(msg);
+ fail(msg);
+ }
+
+ content = callbackData.getContent();
+ contentType = callbackData.getContentType();
+ } else {
+ String msg = "Invalid workflow message program modifier: '" + modifier + "'";
+ System.out.println(msg);
+ fail(msg);
+ }
+
+ if (!injectSNIROCallbacks(contentType, messageType, content, 10000)) {
+ fail("Failed to inject '" + action + "' workflow message");
+ }
+
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ fail("Interrupted after injection of '" + action + "' workflow message");
+ }
+ }
+ }
+
+ /**
+ * Injects a sniro workflow message. The specified callback response may
+ * contain the placeholder strings ((CORRELATOR)) and ((SERVICE_RESOURCE_ID))
+ * The ((CORRELATOR)) is replaced with the actual correlator value from the
+ * request. The ((SERVICE_RESOURCE_ID)) is replaced with the actual serviceResourceId
+ * value from the sniro request. Currently this only works with sniro request
+ * that contain only 1 resource.
+ *
+ * @param contentType the HTTP contentType for the message (possibly null)
+ * @param messageType the message type
+ * @param content the message content (possibly null)
+ * @param timeout the timeout in milliseconds
+ * @return true if the message could be injected, false otherwise
+ */
+ protected boolean injectSNIROCallbacks(String contentType, String messageType, String content, long timeout) {
+ String correlator = (String) getProcessVariable("ReceiveWorkflowMessage",
+ messageType + "_CORRELATOR", timeout);
+
+ if (correlator == null) {
+ return false;
+ }
+ if (content != null) {
+ content = content.replace("((CORRELATOR))", correlator);
+ if(messageType.equalsIgnoreCase("SNIROResponse")){
+ //TODO figure out a solution for when there is more than 1 resource being homed (i.e. more than 1 reason in the placement list)
+ ServiceDecomposition decomp = (ServiceDecomposition) getProcessVariable("Homing", "serviceDecomposition", timeout);
+ List<Resource> resourceList = decomp.getServiceResources();
+ if(resourceList.size() == 1){
+ String resourceId = "";
+ for(Resource resource:resourceList){
+ resourceId = resource.getResourceId();
+ }
+ String homingList = getJsonValue(content, "solutionInfo.placement");
+ JSONArray placementArr = new JSONArray(homingList);
+ if(placementArr.length() == 1){
+ content = content.replace("((SERVICE_RESOURCE_ID))", resourceId);
+ }
+ String licenseInfoList = getJsonValue(content, "solutionInfo.licenseInfo");
+ JSONArray licenseArr = new JSONArray(licenseInfoList);
+ if(licenseArr.length() == 1){
+ content = content.replace("((SERVICE_RESOURCE_ID))", resourceId);
+ }
+ }
+ }
+ }
+ System.out.println("Injecting " + messageType + " message");
+ WorkflowMessageResource workflowMessageResource = new WorkflowMessageResource();
+ workflowMessageResource.setProcessEngineServices4junit(processEngineRule);
+ Response response = workflowMessageResource.deliver(contentType, messageType, correlator, content);
+ System.out.println("Workflow response to " + messageType + " message: " + response);
+ return true;
+ }
+
+
+ /**
* Wait for the process to end.
* @param businessKey the process business key
* @param timeout the amount of time to wait, in milliseconds
@@ -1477,8 +1617,6 @@ public class WorkflowTest { }
/**
- * @author cb645j
- *
* Gets the value of a subflow variable from the specified subflow's
* historical process instance.
*
@@ -1517,8 +1655,6 @@ public class WorkflowTest { }
/**
- * @author cb645j
- *
* Gets the value of a subflow variable from the subflow's
* historical process x instance.
*
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/client/aai/AAIPServerTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/client/aai/AAIPServerTest.java new file mode 100644 index 0000000000..4011a8f7e7 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/client/aai/AAIPServerTest.java @@ -0,0 +1,45 @@ +package org.openecomp.mso.client.aai;
+
+import java.io.File;
+import java.io.IOException;
+import java.security.NoSuchAlgorithmException;
+import java.util.List;
+import java.util.UUID;
+
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.openecomp.aai.domain.yang.Pserver;
+import static org.junit.Assert.assertEquals;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+public class AAIPServerTest {
+
+ @BeforeClass
+ public static void setUp() {
+ System.setProperty("mso.config.path", "src/test/resources");
+ System.setProperty("javax.net.ssl.keyStore", "C:/etc/ecomp/mso/config/msoClientKeyStore.jks");
+ System.setProperty("javax.net.ssl.keyStorePassword", "mso4you");
+ System.setProperty("javax.net.ssl.trustStore", "C:/etc/ecomp/mso/config/msoTrustStore.jks");
+ System.setProperty("javax.net.ssl.trustStorePassword", "mso_Domain2.0_4you");
+ }
+
+ @Test
+ @Ignore // IGNORED FOR 1710 MERGE TO ONAP
+ public void pserverTest() throws JsonParseException, JsonMappingException, IOException, NoSuchAlgorithmException {
+ AAIRestClientImpl client = new AAIRestClientImpl();
+ File file = new File("src/test/resources/__files/AAI/pserver.json");
+ List<Pserver> list = client.getListOfPservers(file);
+
+ assertEquals("", list.get(0).getHostname(), "test");
+ }
+
+ @Test
+ @Ignore // IGNORED FOR 1710 MERGE TO ONAP
+ public void pserverActualTest() throws JsonParseException, JsonMappingException, IOException, NoSuchAlgorithmException {
+ AAIRestClientImpl client = new AAIRestClientImpl();
+ List<Pserver> list = client.getPhysicalServerByVnfId("d946afed-8ebe-4c5d-9665-54fcc043b8e7", UUID.randomUUID().toString());
+ assertEquals("", list.size(), 0);
+ }
+
+}
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/client/aai/AAIValidatorTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/client/aai/AAIValidatorTest.java new file mode 100644 index 0000000000..bf1cb076e3 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/client/aai/AAIValidatorTest.java @@ -0,0 +1,80 @@ + +package org.openecomp.mso.client.aai; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.openecomp.aai.domain.yang.GenericVnf; +import org.openecomp.aai.domain.yang.Pserver; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; + +@RunWith(MockitoJUnitRunner.class) +public class AAIValidatorTest { + + @Mock + protected AAIRestClient client; + String vnfName = "testVnf"; + String uuid = "UUID"; + AAIValidatorImpl validator; + + @Before + public void init(){ + validator = new AAIValidatorImpl(); + validator.setClient(client); + } + + public List<Pserver> getPservers(boolean locked){ + Pserver pserver = new Pserver(); + pserver.setInMaint(locked); + List<Pserver> pservers = new ArrayList<Pserver>(); + pservers.add(pserver); + return pservers; + } + + public GenericVnf createGenericVnfs(boolean locked){ + GenericVnf genericVnf = new GenericVnf(); + genericVnf.setInMaint(locked); + + return genericVnf; + } + + @Test + public void test_IsPhysicalServerLocked_True() throws IOException{ + when(client.getPhysicalServerByVnfId(vnfName,uuid)).thenReturn(getPservers(true)); + boolean locked = validator.isPhysicalServerLocked(vnfName, uuid); + assertEquals(true, locked); + } + + @Test + public void test_IsPhysicalServerLocked_False() throws JsonParseException, JsonMappingException, UnsupportedEncodingException, IOException { + when(client.getPhysicalServerByVnfId(vnfName,uuid)).thenReturn(getPservers(false)); + boolean locked = validator.isPhysicalServerLocked(vnfName, uuid); + assertEquals(false, locked); + } + + @Test + public void test_IsVNFLocked_False() throws Exception{ + when(client.getVnfByName(vnfName,uuid)).thenReturn(createGenericVnfs(false)); + boolean locked = validator.isVNFLocked(vnfName, uuid); + assertEquals(false, locked); + } + + @Test + public void test_IsVNFLocked_True() throws Exception{ + when(client.getVnfByName(vnfName,uuid)).thenReturn(createGenericVnfs(true)); + boolean locked = validator.isVNFLocked(vnfName, uuid); + assertEquals(true,locked ); + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/client/aai/EntitiesTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/client/aai/EntitiesTest.java new file mode 100644 index 0000000000..beb457497e --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/client/aai/EntitiesTest.java @@ -0,0 +1,21 @@ +package org.openecomp.mso.client.aai; + +import org.junit.Test; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; + +public class EntitiesTest { + + private String packageName = "org.openecomp.mso.client.aai.entities"; + + @Test + public void validate() { + Validator validator = ValidatorBuilder.create().with(new SetterMustExistRule(), new GetterMustExistRule()) + .with(new SetterTester(), new GetterTester()).build(); + validator.validate(packageName); + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/client/appc/ApplicationControllerClientTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/client/appc/ApplicationControllerClientTest.java new file mode 100644 index 0000000000..3cc6b35b3a --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/client/appc/ApplicationControllerClientTest.java @@ -0,0 +1,78 @@ +package org.openecomp.mso.client.appc;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Properties;
+import java.util.UUID;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import org.openecomp.appc.client.lcm.model.Action;
+import org.openecomp.appc.client.lcm.model.ActionIdentifiers;
+import org.openecomp.appc.client.lcm.model.CheckLockInput;
+import org.openecomp.appc.client.lcm.model.Flags;
+import org.openecomp.appc.client.lcm.model.Status;
+
+public class ApplicationControllerClientTest {
+
+ private static ApplicationControllerClient client;
+ private static ApplicationControllerSupport support;
+
+ @BeforeClass
+ public static void beforeClass() {
+ client = new ApplicationControllerClient();
+ support = new ApplicationControllerSupport();
+ client.appCSupport = support;
+ System.setProperty("mso.config.path", "src/test/resources");
+
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception {
+ client.shutdownclient();
+ }
+
+ @Test
+ @Ignore // IGNORED FOR 1710 MERGE TO ONAP
+ public void createRequest_CheckLock_RequestBuilt() throws Exception {
+
+ org.springframework.test.util.ReflectionTestUtils.setField(support, "lcmModelPackage",
+ "org.openecomp.appc.client.lcm.model");
+ Flags flags = new Flags();
+ ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
+ actionIdentifiers.setVnfId("vnfId");
+ CheckLockInput checkLockInput = (CheckLockInput) client.createRequest(Action.CheckLock, actionIdentifiers,
+ flags, null, "requestId");
+ assertEquals(checkLockInput.getAction().name(), "CheckLock");
+ }
+
+ @Test
+ @Ignore // IGNORED FOR 1710 MERGE TO ONAP
+ public void runCommand_liveAppc() throws Exception {
+ org.springframework.test.util.ReflectionTestUtils.setField(support, "lcmModelPackage",
+ "org.openecomp.appc.client.lcm.model");
+ Flags flags = new Flags();
+ ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
+ actionIdentifiers.setVnfId("ca522254-2ba4-4fbd-b15b-0ef0d9cfda5f");
+
+ // CheckLockInput checkLockInput = (CheckLockInput)
+ // client.createRequest(Action.CheckLock,actionIdentifiers,flags,null,"requestId");
+ Status status = client.runCommand(Action.Lock, actionIdentifiers, flags, null, UUID.randomUUID().toString());
+ assertEquals("Status of run command is correct", status.getCode(), 306);
+ }
+
+ @Test
+ @Ignore // IGNORED FOR 1710 MERGE TO ONAP
+ public void runCommand_CheckLock_RequestBuilt() throws Exception {
+ org.springframework.test.util.ReflectionTestUtils.setField(support, "lcmModelPackage",
+ "org.openecomp.appc.client.lcm.model");
+ Flags flags = new Flags();
+ ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
+ actionIdentifiers.setVnfId("fusion-vpp-vnf-001");
+ Status status = client.runCommand(Action.CheckLock, actionIdentifiers, flags, null, "requestId");
+ assertEquals("Status of run command is correct", status.getCode(), 400);
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/client/policy/PolicyDecisionTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/client/policy/PolicyDecisionTest.java new file mode 100644 index 0000000000..a369423ddc --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/client/policy/PolicyDecisionTest.java @@ -0,0 +1,50 @@ +package org.openecomp.mso.client.policy; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.Map; + +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +public class PolicyDecisionTest { + + @BeforeClass + public static void setUp() { + System.setProperty("mso.config.path", "src/test/resources"); + } + @Test + public void successReadProperties() throws IOException, Exception { + PolicyRestClient client = new PolicyRestClient(); + Map<String, String> headerMap = client.headerMap; + + assertEquals("Found expected Client Auth", headerMap.get("ClientAuth"), "Basic bTAzNzQzOnBvbGljeVIwY2sk"); + assertEquals("Found expected Authorization", headerMap.get("Authorization"), "Basic dGVzdHBkcDphbHBoYTEyMw=="); + assertEquals("Found expected Environment", headerMap.get("Environment"), "TEST"); + assertEquals("Has X-ECOMP-RequestID", headerMap.containsKey("X-ECOMP-RequestID"), true); + } + + @Test + @Ignore // IGNORED FOR 1710 MERGE TO ONAP + public void restEndpointCall() throws IOException, Exception { + PolicyRestClient client = new PolicyRestClient(); + PolicyDecision decision = client.getDecision("X", "Y", "BB1", "1", "123"); + assertEquals("Decision is correct", decision.getDecision(), "PERMIT"); + assertEquals("Decision details is correct", decision.getDetails(), "Abort"); + } +/* + @Test + public void failure() throws IOException, Exception { + when(dmaapConsumer.getMRConsumer()).thenReturn(mrConsumer); + when(mrConsumer.fetch()) + .thenReturn(Arrays.asList(new String[] { getJson("response.json"), getJson("output-failure.json") })); + + SDNOValidatorImpl validator = new SDNOValidatorImpl(); + thrown.expect(SDNOException.class); + thrown.expectMessage("my message"); + boolean result = validator.pollForResponse(dmaapConsumer, "xyz123"); + + }*/ +} |