From 5a6a6de6f1a26a1897e4917a0df613e25a24eb70 Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Mon, 30 Jul 2018 15:56:09 -0400 Subject: Containerization feature of SO Change-Id: I95381232eeefcd247a66a5cec370a8ce1c288e18 Issue-ID: SO-670 Signed-off-by: Benjamin, Max (mb388a) --- .../onap/so/bpmn/common/scripts/AaiUtilTest.groovy | 471 ++++++++++ .../AbstractServiceTaskProcessorTest.groovy | 182 ++++ .../bpmn/common/scripts/CatalogDbUtilsTest.groovy | 98 +++ .../common/scripts/CompleteMsoProcessTest.groovy | 170 ++++ .../scripts/ConfirmVolumeGroupNameTest.groovy | 130 +++ .../scripts/ConfirmVolumeGroupTenantTest.groovy | 125 +++ .../common/scripts/CustomE2EGetServiceTest.groovy | 104 +++ .../common/scripts/CustomE2EPutServiceTest.groovy | 72 ++ .../common/scripts/DeleteAAIVfModuleTest.groovy | 218 +++++ .../bpmn/common/scripts/ExceptionUtilTest.groovy | 98 +++ .../bpmn/common/scripts/FalloutHandlerTest.groovy | 312 +++++++ .../common/scripts/GenerateVfModuleNameTest.groovy | 125 +++ .../common/scripts/GenericGetServiceTest.groovy | 124 +++ .../bpmn/common/scripts/GenericGetVnfTest.groovy | 180 ++++ .../common/scripts/GenericPutServiceTest.groovy | 235 +++++ .../so/bpmn/common/scripts/MsoGroovyTest.groovy | 72 ++ .../so/bpmn/common/scripts/MsoUtilsTest.groovy | 291 ++++++ .../so/bpmn/common/scripts/NetworkUtilsTest.groovy | 101 +++ .../scripts/PrepareUpdateAAIVfModuleTest.groovy | 171 ++++ .../common/scripts/SDNCAdapterRestV1Test.groovy | 151 ++++ .../common/scripts/SDNCAdapterRestV2Test.groovy | 151 ++++ .../so/bpmn/common/scripts/SDNCAdapterTest.groovy | 951 ++++++++++++++++++++ .../common/scripts/SDNCAdapterUtilsTest.groovy | 191 ++++ .../bpmn/common/scripts/SniroHomingV1Test.groovy | 196 +++++ .../common/scripts/TrinityExceptionUtilTest.groovy | 201 +++++ .../common/scripts/UpdateAAIGenericVnfTest.groovy | 172 ++++ .../common/scripts/UpdateAAIVfModuleTest.groovy | 175 ++++ .../so/bpmn/common/scripts/VidUtilsTest.groovy | 969 ++++++++++++++++++++ .../common/scripts/VnfAdapterRestV1Test.groovy | 118 +++ .../IgnoreNamedElementsDifferenceListener.groovy | 51 ++ .../bpmn/common/scripts/utils/XmlComparator.groovy | 41 + .../mso/bpmn/common/scripts/AaiUtilTest.groovy | 385 -------- .../common/scripts/CompleteMsoProcessTest.groovy | 170 ---- .../bpmn/common/scripts/ExceptionUtilTest.groovy | 66 -- .../bpmn/common/scripts/FalloutHandlerTest.groovy | 312 ------- .../common/scripts/GenericPutServiceTest.groovy | 214 ----- .../mso/bpmn/common/scripts/MsoGroovyTest.groovy | 72 -- .../mso/bpmn/common/scripts/MsoUtilsTest.groovy | 233 ----- .../bpmn/common/scripts/NetworkUtilsTest.groovy | 97 -- .../mso/bpmn/common/scripts/SDNCAdapterTest.groovy | 948 -------------------- .../common/scripts/SDNCAdapterUtilsTest.groovy | 213 ----- .../common/scripts/TrinityExceptionUtilTest.groovy | 201 ----- .../mso/bpmn/common/scripts/VidUtilsTest.groovy | 972 --------------------- .../common/scripts/VnfAdapterRestV1Test.groovy | 44 - 44 files changed, 6646 insertions(+), 3927 deletions(-) create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/AaiUtilTest.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/AbstractServiceTaskProcessorTest.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CatalogDbUtilsTest.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CompleteMsoProcessTest.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupNameTest.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupTenantTest.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CustomE2EGetServiceTest.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CustomE2EPutServiceTest.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/DeleteAAIVfModuleTest.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/ExceptionUtilTest.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/FalloutHandlerTest.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/GenerateVfModuleNameTest.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/GenericGetServiceTest.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/GenericGetVnfTest.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/GenericPutServiceTest.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/MsoGroovyTest.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/MsoUtilsTest.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/NetworkUtilsTest.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/PrepareUpdateAAIVfModuleTest.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterRestV1Test.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterRestV2Test.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterTest.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterUtilsTest.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SniroHomingV1Test.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/TrinityExceptionUtilTest.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIGenericVnfTest.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIVfModuleTest.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/VidUtilsTest.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/VnfAdapterRestV1Test.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/utils/IgnoreNamedElementsDifferenceListener.groovy create mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/utils/XmlComparator.groovy delete mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/AaiUtilTest.groovy delete mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/CompleteMsoProcessTest.groovy delete mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/ExceptionUtilTest.groovy delete mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/FalloutHandlerTest.groovy delete mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/GenericPutServiceTest.groovy delete mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/MsoGroovyTest.groovy delete mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/MsoUtilsTest.groovy delete mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/NetworkUtilsTest.groovy delete mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/SDNCAdapterTest.groovy delete mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/SDNCAdapterUtilsTest.groovy delete mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/TrinityExceptionUtilTest.groovy delete mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/VidUtilsTest.groovy delete mode 100644 bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/VnfAdapterRestV1Test.groovy (limited to 'bpmn/MSOCommonBPMN/src/test/groovy') diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/AaiUtilTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/AaiUtilTest.groovy new file mode 100644 index 0000000000..79caf5b9ac --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/AaiUtilTest.groovy @@ -0,0 +1,471 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts + +import com.github.tomakehurst.wiremock.junit.WireMockRule + +import static org.junit.Assert.*; +import static org.mockito.Mockito.* + +import org.onap.so.rest.HttpHeader +import org.mockito.MockitoAnnotations +import org.mockito.runners.MockitoJUnitRunner +import org.mockito.internal.debugging.MockitoDebuggerImpl +import org.junit.Before +import org.onap.so.bpmn.common.scripts.AaiUtil; +import org.junit.Rule; +import org.junit.Test +import org.junit.rules.ExpectedException +import org.junit.Ignore +import org.junit.runner.RunWith +import org.junit.Before; +import org.junit.Test; +import org.camunda.bpm.engine.ProcessEngineServices +import org.camunda.bpm.engine.RepositoryService +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.camunda.bpm.engine.impl.pvm.process.ProcessDefinitionImpl +import org.camunda.bpm.engine.repository.ProcessDefinition + +@RunWith(MockitoJUnitRunner.class) +@Ignore +class AaiUtilTest extends MsoGroovyTest { + + + @Rule + public WireMockRule wireMockRule = new WireMockRule(8090); + + @Rule + public ExpectedException thrown = ExpectedException.none + + + def aaiPaylod = "\n" + + "\t\t\t\tallottedResourceId\n" + + "\t\t\t\t\n" + + "\t\t\t\tallottedResourceType\n" + + "\t\t\t\tallottedResourceRole\n" + + "\t\t\t\t\n" + + "\t\t\t\t\n" + + "\t\t\t\t\n" + + "\t\t\t\t\n" + + "\t\t\t\tPendingCreate\n" + + "\t\t\t\t\n" + + "\t\t\t\t\n" + + "\t\t\t\t\t\n" + + " \t\t\tservice-instance\n" + + " \t\t\tCSI_resourceLink\n" + + "\t\t\t\t\t\n" + + "\t\t\t\t\n" + + "\t\t\t"; + + @Test + public void testGetVersionDefault() { + ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8') + + CreateAAIVfModule myproc = new CreateAAIVfModule() + AaiUtil aaiUtil = new AaiUtil(myproc) + def version = aaiUtil.getVersion(mockExecution, 'l3-network', 'CreateAAIVfModule') + assertEquals('8', version) + } + + @Test + public void testGetVersionResourceSpecific() { + ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("mso.workflow.default.aai.l3-network.version")).thenReturn('7') + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8') + CreateAAIVfModule myproc = new CreateAAIVfModule() + AaiUtil aaiUtil = new AaiUtil(myproc) + def version = aaiUtil.getVersion(mockExecution, 'l3-network', 'CreateAAIVfModule') + assertEquals('7', version) + } + + @Test + public void testGetVersionFlowSpecific() { + ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("mso.workflow.custom.CreateAAIVfModule.aai.version")).thenReturn('6') + when(mockExecution.getVariable("mso.workflow.default.aai.l3-network.version")).thenReturn('7') + + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8') + + CreateAAIVfModule myproc = new CreateAAIVfModule() + AaiUtil aaiUtil = new AaiUtil(myproc) + def version = aaiUtil.getVersion(mockExecution, 'l3-network', 'CreateAAIVfModule') + assertEquals('6', version) + } + + @Test + public void testGetVersionNotDefined() { + thrown.expect(Exception.class) + ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + CreateAAIVfModule myproc = new CreateAAIVfModule() + AaiUtil aaiUtil = new AaiUtil(myproc) + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn("") + + def version = aaiUtil.getVersion(mockExecution, 'l3-network', 'CreateAAIVfModule') + + } + + @Test + public void testGetUriDefaultVersion() { + ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("mso.workflow.default.aai.v8.l3-network.uri")).thenReturn('/aai/v8/network/l3-networks/l3-network') + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8') + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/') + + CreateAAIVfModule myproc = new CreateAAIVfModule() + AaiUtil aaiUtil = new AaiUtil(myproc) + def uri = aaiUtil.getUri(mockExecution, 'l3-network') + assertEquals('/aai/v8/network/l3-networks/l3-network', uri) + } + + @Test + public void testGetUriFlowAndResourceSpecific() { + ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("mso.workflow.CreateAAIVfModule.aai.l3-network.uri")).thenReturn('/aai/v6/network/l3-networks/l3-network') + + when(mockExecution.getVariable("mso.workflow.default.aai.v8.l3-network.uri")).thenReturn('/aai/v8/network/l3-networks/l3-network') + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8') + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/') + + CreateAAIVfModule myproc = new CreateAAIVfModule() + AaiUtil aaiUtil = new AaiUtil(myproc) + def uri = aaiUtil.getUri(mockExecution, 'l3-network') + assertEquals('/aai/v6/network/l3-networks/l3-network', uri) + } + + @Test + public void testGetNetworkGenericVnfEndpoint() { + ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8') + + when(mockExecution.getVariable("mso.workflow.default.aai.v8.generic-vnf.uri")).thenReturn('/aai/v8/network/generic-vnfs/generic-vnf') + + when(mockExecution.getVariable('aai.endpoint')).thenReturn('http://localhost:28090') + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/') + + when(mockExecution.getVariable("mso.workflow.default.aai.generic-vnf.version")).thenReturn('8') + + + CreateAAIVfModule myproc = new CreateAAIVfModule() + AaiUtil aaiUtil = new AaiUtil(myproc) + def endpoint = aaiUtil.getNetworkGenericVnfEndpoint(mockExecution) + assertEquals('http://localhost:28090/aai/v8/network/generic-vnfs/generic-vnf', endpoint) + } + + @Test + public void testGetNetworkGenericVnfUri() { + ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8') + + when(mockExecution.getVariable("mso.workflow.default.aai.v8.generic-vnf.uri")).thenReturn('/aai/v8/network/generic-vnfs/generic-vnf') + + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/') + + when(mockExecution.getVariable("mso.workflow.default.aai.generic-vnf.version")).thenReturn('8') + + CreateAAIVfModule myproc = new CreateAAIVfModule() + AaiUtil aaiUtil = new AaiUtil(myproc) + def uri = aaiUtil.getNetworkGenericVnfUri(mockExecution) + assertEquals('/aai/v8/network/generic-vnfs/generic-vnf', uri) + } + + @Test + public void testGetNetworkVpnBindingUri() { + ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8') + when(mockExecution.getVariable("mso.workflow.default.aai.v8.vpn-binding.uri")).thenReturn('/aai/v8/network/vpn-bindings/vpn-binding') + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/') + + CreateAAIVfModule myproc = new CreateAAIVfModule() + AaiUtil aaiUtil = new AaiUtil(myproc) + def uri = aaiUtil.getNetworkVpnBindingUri(mockExecution) + assertEquals('/aai/v8/network/vpn-bindings/vpn-binding', uri) + } + + @Test + public void testGetNetworkPolicyUri() { + ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8') + when(mockExecution.getVariable("mso.workflow.default.aai.v8.network-policy.uri")).thenReturn('/aai/v8/network/network-policies/network-policy') + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/') + + CreateAAIVfModule myproc = new CreateAAIVfModule() + AaiUtil aaiUtil = new AaiUtil(myproc) + def uri = aaiUtil.getNetworkPolicyUri(mockExecution) + assertEquals('/aai/v8/network/network-policies/network-policy', uri) + } + + @Test + public void testGetNetworkTableReferencesUri() { + ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8') + when(mockExecution.getVariable("mso.workflow.default.aai.v8.route-table-reference.uri")).thenReturn('/aai/v8/network/route-table-references/route-table-reference') + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/') + + CreateAAIVfModule myproc = new CreateAAIVfModule() + AaiUtil aaiUtil = new AaiUtil(myproc) + def uri = aaiUtil.getNetworkTableReferencesUri(mockExecution) + assertEquals('/aai/v8/network/route-table-references/route-table-reference', uri) + } + + @Test + public void testGetNetworkVceUri() { + ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8') + when(mockExecution.getVariable("mso.workflow.default.aai.v8.vce.uri")).thenReturn('/aai/v8/network/vces/vce') + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/') + + CreateAAIVfModule myproc = new CreateAAIVfModule() + AaiUtil aaiUtil = new AaiUtil(myproc) + def uri = aaiUtil.getNetworkVceUri(mockExecution) + assertEquals('/aai/v8/network/vces/vce', uri) + } + + @Test + public void testGetNetworkL3NetworkUri() { + ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8') + when(mockExecution.getVariable("mso.workflow.default.aai.v8.l3-network.uri")).thenReturn('/aai/v8/network/l3-networks/l3-network') + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/') + + CreateAAIVfModule myproc = new CreateAAIVfModule() + AaiUtil aaiUtil = new AaiUtil(myproc) + def uri = aaiUtil.getNetworkL3NetworkUri(mockExecution) + assertEquals('/aai/v8/network/l3-networks/l3-network', uri) + } + + @Test + public void testGetBusinessCustomerUri() { + ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8') + when(mockExecution.getVariable("mso.workflow.default.aai.v8.customer.uri")).thenReturn('/aai/v8/business/customers/customer') + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/') + + CreateAAIVfModule myproc = new CreateAAIVfModule() + AaiUtil aaiUtil = new AaiUtil(myproc) + def uri = aaiUtil.getBusinessCustomerUri(mockExecution) + assertEquals('/aai/v8/business/customers/customer', uri) + } + + @Test + public void testGetCloudInfrastructureCloudRegionEndpoint() { + ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8') + + when(mockExecution.getVariable("mso.workflow.default.aai.v8.cloud-region.uri")).thenReturn('/aai/v8/cloud-infrastructure/cloud-regions/cloud-region/att-aic') + + when(mockExecution.getVariable('aai.endpoint')).thenReturn('http://localhost:28090') + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/') + + CreateAAIVfModule myproc = new CreateAAIVfModule() + AaiUtil aaiUtil = new AaiUtil(myproc) + def uri = aaiUtil.getCloudInfrastructureCloudRegionEndpoint(mockExecution) + assertEquals('http://localhost:28090/aai/v8/cloud-infrastructure/cloud-regions/cloud-region/att-aic', uri) + } + + @Test + public void testGetCloudInfrastructureCloudRegionUri() { + ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8') + + when(mockExecution.getVariable("mso.workflow.default.aai.v8.cloud-region.uri")).thenReturn('/aai/v8/cloud-infrastructure/cloud-regions/cloud-region/att-aic') + + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/') + + + CreateAAIVfModule myproc = new CreateAAIVfModule() + AaiUtil aaiUtil = new AaiUtil(myproc) + def uri = aaiUtil.getCloudInfrastructureCloudRegionUri(mockExecution) + assertEquals('/aai/v8/cloud-infrastructure/cloud-regions/cloud-region/att-aic', uri) + } + + @Test + public void testGetCloudInfrastructureTenantUri() { + ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8') + when(mockExecution.getVariable("mso.workflow.default.aai.v8.tenant.uri")).thenReturn('/aai/v8/cloud-infrastructure/tenants/tenant') + + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/') + + CreateAAIVfModule myproc = new CreateAAIVfModule() + AaiUtil aaiUtil = new AaiUtil(myproc) + def uri = aaiUtil.getCloudInfrastructureTenantUri(mockExecution) + assertEquals('/aai/v8/cloud-infrastructure/tenants/tenant', uri) + } + + @Test + public void testGetSearchNodesQueryUri() { + ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8') + + when(mockExecution.getVariable("mso.workflow.default.aai.v8.nodes-query.uri")).thenReturn('/aai/v8/search/nodes-query') + + when(mockExecution.getVariable('aai.endpoint')).thenReturn('http://localhost:28090') + + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/') + + + CreateAAIVfModule myproc = new CreateAAIVfModule() + AaiUtil aaiUtil = new AaiUtil(myproc) + def uri = aaiUtil.getSearchNodesQueryUri(mockExecution) + assertEquals('/aai/v8/search/nodes-query', uri) + } + + @Test + public void testGetSearchNodesQueryEndpoint() { + ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8') + + when(mockExecution.getVariable("mso.workflow.default.aai.v8.nodes-query.uri")).thenReturn('/aai/v8/search/nodes-query') + + when(mockExecution.getVariable('aai.endpoint')).thenReturn('http://localhost:28090') + + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/') + + CreateAAIVfModule myproc = new CreateAAIVfModule() + AaiUtil aaiUtil = new AaiUtil(myproc) + def uri = aaiUtil.getSearchNodesQueryEndpoint(mockExecution) + assertEquals('http://localhost:28090/aai/v8/search/nodes-query', uri) + } + + @Test + public void testGetSearchGenericQueryUri() { + ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8') + + when(mockExecution.getVariable("mso.workflow.default.aai.v8.generic-query.uri")).thenReturn('/aai/v8/search/generic-query') + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/') + + + CreateAAIVfModule myproc = new CreateAAIVfModule() + AaiUtil aaiUtil = new AaiUtil(myproc) + def uri = aaiUtil.getSearchGenericQueryUri(mockExecution) + assertEquals('/aai/v8/search/generic-query', uri) + } + + @Test + public void testGetNamespaceFromUri() { + ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('6') + when(mockExecution.getVariable("mso.workflow.default.aai.v6.l3-network.uri")).thenReturn('/aai/v6/network/l3-networks/l3-network') + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + CreateAAIVfModule myproc = new CreateAAIVfModule() + AaiUtil aaiUtil = new AaiUtil(myproc) + def uri = aaiUtil.getNetworkL3NetworkUri(mockExecution) // Required to populate the namespace in the class + def ns = aaiUtil.getNamespaceFromUri('/aai/v6/search/generic-query') + assertEquals('http://org.openecomp.aai.inventory/v6', ns) + } + + @Test + public void testExecuteAAIGetCall() { + ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("aai.auth")).thenReturn("9B2278E8B8E95F256A560719055F4DF3") + when(mockExecution.getVariable("mso.msoKey")).thenReturn("aa3871669d893c7fb8abbcda31b88b4f") + CreateAAIVfModule myproc = new CreateAAIVfModule() + AaiUtil aaiUtil = new AaiUtil(myproc) + def uri = aaiUtil.executeAAIGetCall(mockExecution,"http://localhost:8090/aai/v9/business/customers/customer/CUST/service-subscriptions/service-subscription/SVC/service-instances/service-instance/NST/allotted-resources/allotted-resource/allottedResourceId") + } + + + @Test + public void testExecuteAAIPutCall() { + ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("aai.auth")).thenReturn("9B2278E8B8E95F256A560719055F4DF3") + when(mockExecution.getVariable("mso.msoKey")).thenReturn("aa3871669d893c7fb8abbcda31b88b4f") + CreateAAIVfModule myproc = new CreateAAIVfModule() + AaiUtil aaiUtil = new AaiUtil(myproc) + def uri = aaiUtil.executeAAIPutCall(mockExecution,"http://localhost:8090/aai/v9/business/customers/customer/CUST/service-subscriptions/service-subscription/SVC/service-instances/service-instance/NST/allotted-resources/allotted-resource/allottedResourceId",aaiPaylod) + } + + @Test + public void testGetNamespaceFromUri2() { + ExecutionEntity mockExecution = setupMock('DeleteVfModuleVolumeInfraV1') + // + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('10') + when(mockExecution.getVariable("mso.workflow.default.aai.v10.l3-network.uri")).thenReturn('/aai/v10/network/l3-networks/l3-network') + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/') + // + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + CreateAAIVfModule myproc = new CreateAAIVfModule() + AaiUtil aaiUtil = new AaiUtil(myproc) + def uri = aaiUtil.getNetworkL3NetworkUri(mockExecution) // Required to populate the namespace in the class + def ns = aaiUtil.getNamespaceFromUri('/aai/v10/search/generic-query') + assertEquals('http://org.openecomp.aai.inventory/v10', ns) + } + + @Test + public void testGetNamespaceFromUri3() { + ExecutionEntity mockExecution = setupMock('DeleteVfModuleVolumeInfraV1') + // + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('100') + when(mockExecution.getVariable("mso.workflow.default.aai.v100.l3-network.uri")).thenReturn('/aai/v100/network/l3-networks/l3-network') + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/') + // + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + CreateAAIVfModule myproc = new CreateAAIVfModule() + AaiUtil aaiUtil = new AaiUtil(myproc) + def uri = aaiUtil.getNetworkL3NetworkUri(mockExecution) // Required to populate the namespace in the class + def ns = aaiUtil.getNamespaceFromUri('/aai/v100/search/generic-query') + assertEquals('http://org.openecomp.aai.inventory/v100', ns) + } + + @Test + public void testGetNamespaceFromUri_twoArguments() { // (execution, uri) + ExecutionEntity mockExecution = setupMock('DeleteVfModuleVolumeInfraV1') + // + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('10') + when(mockExecution.getVariable("mso.workflow.default.aai.v10.l3-network.uri")).thenReturn('/aai/v10/network/l3-networks/l3-network') + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/') + // + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + CreateAAIVfModule myproc = new CreateAAIVfModule() + AaiUtil aaiUtil = new AaiUtil(myproc) + def ns = aaiUtil.getNamespaceFromUri(mockExecution, '/aai/v10/search/generic-query') + assertEquals('http://org.openecomp.aai.inventory/v10', ns) + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/AbstractServiceTaskProcessorTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/AbstractServiceTaskProcessorTest.groovy new file mode 100644 index 0000000000..86a175d811 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/AbstractServiceTaskProcessorTest.groovy @@ -0,0 +1,182 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts + +import org.camunda.bpm.engine.delegate.DelegateExecution +import org.junit.Assert +import org.mockito.ArgumentCaptor +import org.mockito.Captor +import org.mockito.Mockito +import org.onap.so.bpmn.core.WorkflowException; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.* + +import org.onap.so.rest.HttpHeader +import org.mockito.MockitoAnnotations +import org.mockito.runners.MockitoJUnitRunner +import org.mockito.internal.debugging.MockitoDebuggerImpl +import org.junit.Before +import org.onap.so.bpmn.common.scripts.AaiUtil; +import org.junit.Rule; +import org.junit.Test +import org.junit.Ignore +import org.junit.runner.RunWith +import org.junit.Before; +import org.junit.Test; +import org.camunda.bpm.engine.ProcessEngineServices +import org.camunda.bpm.engine.RepositoryService +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.camunda.bpm.engine.impl.pvm.process.ProcessDefinitionImpl +import org.camunda.bpm.engine.repository.ProcessDefinition + + + +class AbstractServiceTaskProcessorImpl extends AbstractServiceTaskProcessor{ + + @Override + void preProcessRequest(DelegateExecution execution) { + + } +} + +@RunWith(MockitoJUnitRunner.class) +public class AbstractServiceTaskProcessorTest extends MsoGroovyTest { + + @Captor + ArgumentCaptor captor= ArgumentCaptor.forClass(ExecutionEntity.class); + + @Test + public void testCreateCallbackURL_Success() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("mso.workflow.message.endpoint")).thenReturn('http://localhost:18080/mso/WorkflowMessage/') + AbstractServiceTaskProcessorImpl serviceTaskProcessor = new AbstractServiceTaskProcessorImpl(); + def endpoint = serviceTaskProcessor.createCallbackURL(mockExecution, 'testMessageType', 'testCorrelator') + assertEquals('http://localhost:18080/mso/WorkflowMessage/testMessageType/testCorrelator', endpoint) + } + + @Test + public void testCreateCallbackURL_NullEndpoint() { + + ExecutionEntity mockExecution = setupMock() + try { + + when(mockExecution.getVariable("mso.workflow.message.endpoint")).thenReturn("") + AbstractServiceTaskProcessorImpl serviceTaskProcessor = new AbstractServiceTaskProcessorImpl(); + def endpoint = serviceTaskProcessor.createCallbackURL(mockExecution, 'testMessageType', 'testCorrelator') + } + catch(Exception ex){ + } + Mockito.verify(mockExecution,times(1)).setVariable(captor.capture(),captor.capture()) + WorkflowException workflowException = captor.getValue() + Assert.assertEquals("mso:workflow:message:endpoint URN mapping is not set",workflowException.getErrorMessage()) + Assert.assertEquals(2000,workflowException.getErrorCode()) + } + + @Test + public void testCreateWorkflowMessageAdapterCallbackURL_Success() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("mso.adapters.workflow.message.endpoint")).thenReturn('http://localhost:18080/workflows/messages/message/') + + AbstractServiceTaskProcessorImpl serviceTaskProcessor = new AbstractServiceTaskProcessorImpl(); + def endpoint = serviceTaskProcessor.createWorkflowMessageAdapterCallbackURL(mockExecution, 'testMessageType', 'testCorrelator') + assertEquals('http://localhost:18080/workflows/messages/message/testMessageType/testCorrelator', endpoint) + } + + @Test + public void testCreateWorkflowMessageAdapterCallbackURL_NullEndpoint() { + + ExecutionEntity mockExecution = setupMock() + try { + + when(mockExecution.getVariable("mso.adapters.workflow.message.endpoint")).thenReturn("") + + AbstractServiceTaskProcessorImpl serviceTaskProcessor = new AbstractServiceTaskProcessorImpl(); + def endpoint = serviceTaskProcessor.createWorkflowMessageAdapterCallbackURL(mockExecution, 'testMessageType', 'testCorrelator') + } + catch(Exception ex){ + } + Mockito.verify(mockExecution,times(1)).setVariable(captor.capture(),captor.capture()) + WorkflowException workflowException = captor.getValue() + Assert.assertEquals("mso:adapters:workflow:message:endpoint URN mapping is not set",workflowException.getErrorMessage()) + Assert.assertEquals(2000,workflowException.getErrorCode()) + } + + @Test + public void testSetRollbackEnabledNullOrEmptyDisableRollback() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("prefix")).thenReturn('TEST_PREFIX') + when(mockExecution.getVariable("disableRollback")).thenReturn(null) + when(mockExecution.getVariable("mso.rollback")).thenReturn("") + + AbstractServiceTaskProcessorImpl serviceTaskProcessor = new AbstractServiceTaskProcessorImpl(); + serviceTaskProcessor.setRollbackEnabled(mockExecution, "true") + assertEquals(null, mockExecution.getVariable('TEST_PREFIXbackoutOnFailure')) + } + + @Test + public void testSetRollbackEnabledDisableRollback() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("prefix")).thenReturn('TEST_PREFIX') + when(mockExecution.getVariable("disableRollback")).thenReturn(true) + when(mockExecution.getVariable("mso.rollback")).thenReturn("true") + + AbstractServiceTaskProcessorImpl serviceTaskProcessor = new AbstractServiceTaskProcessorImpl(); + serviceTaskProcessor.setRollbackEnabled(mockExecution, "true") + verify(mockExecution).setVariable("TEST_PREFIXbackoutOnFailure",false) + } + + @Test + public void testSetRollbackEnabledRollback() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("prefix")).thenReturn('TEST_PREFIX') + when(mockExecution.getVariable("disableRollback")).thenReturn(false) + when(mockExecution.getVariable("mso.rollback")).thenReturn("true") + + AbstractServiceTaskProcessorImpl serviceTaskProcessor = new AbstractServiceTaskProcessorImpl(); + serviceTaskProcessor.setRollbackEnabled(mockExecution, "true") + verify(mockExecution).setVariable("TEST_PREFIXbackoutOnFailure",true) + } + + @Test + public void testSetRollbackEnabledDefaultRollback() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("prefix")).thenReturn('TEST_PREFIX') + when(mockExecution.getVariable("disableRollback")).thenReturn("test") + when(mockExecution.getVariable("mso.rollback")).thenReturn("true") + + AbstractServiceTaskProcessorImpl serviceTaskProcessor = new AbstractServiceTaskProcessorImpl(); + serviceTaskProcessor.setRollbackEnabled(mockExecution, "true") + verify(mockExecution).setVariable("TEST_PREFIXbackoutOnFailure",true) + } + + @Test + public void testSetBasicDBAuthHeader_Success() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("mso.adapters.db.auth")).thenReturn('9B2278E8B8E95F256A560719055F4DF3') + when(mockExecution.getVariable("mso.msoKey")).thenReturn('aa3871669d893c7fb8abbcda31b88b4f') + + AbstractServiceTaskProcessorImpl serviceTaskProcessor = new AbstractServiceTaskProcessorImpl(); + serviceTaskProcessor.setBasicDBAuthHeader(mockExecution, "true") + verify(mockExecution).setVariable("BasicAuthHeaderValueDB",'Basic dXAyMTE4OnVwMjExOA==') + } + +} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CatalogDbUtilsTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CatalogDbUtilsTest.groovy new file mode 100644 index 0000000000..39064caa28 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CatalogDbUtilsTest.groovy @@ -0,0 +1,98 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts + +import com.github.tomakehurst.wiremock.junit.WireMockRule +import org.camunda.bpm.engine.ProcessEngineServices +import org.camunda.bpm.engine.RepositoryService +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.camunda.bpm.engine.repository.ProcessDefinition +import org.junit.Assert +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mockito +import org.mockito.runners.MockitoJUnitRunner +import org.onap.so.bpmn.mock.FileUtil + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse +import static com.github.tomakehurst.wiremock.client.WireMock.get +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor +import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching +import static org.mockito.Mockito.mock +import static org.mockito.Mockito.mock +import static org.mockito.Mockito.mock +import static org.mockito.Mockito.mock +import static org.mockito.Mockito.when +import static org.mockito.Mockito.when +import static org.mockito.Mockito.when +import static org.mockito.Mockito.when +import static org.mockito.Mockito.when +import static org.mockito.Mockito.when +import static org.mockito.Mockito.when + +@RunWith(MockitoJUnitRunner.class) +class CatalogDbUtilsTest { + + + @Rule + public WireMockRule wireMockRule = new WireMockRule(8090) + + @Test + public void testGetResponseFromCatalogDb() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("mso.catalog.db.endpoint")).thenReturn('http://localhost:8090') + when(mockExecution.getVariable("mso.adapters.db.auth")).thenReturn('757A94191D685FD2092AC1490730A4FC') + when(mockExecution.getVariable("mso.msoKey")).thenReturn('07a7159d3bf51a0e53be7a8f89699be7') + + stubFor(get(urlMatching(".*/serviceNetworks[?]serviceModelUuid=12345")) + .willReturn(aResponse() + .withStatus(200) + .withBodyFile("catalogDbFiles/DoCreateServiceInstance_request.json"))) + + CatalogDbUtils obj = new CatalogDbUtils() + String str = obj.getResponseFromCatalogDb(mockExecution, "/serviceNetworks?serviceModelUuid=12345") + String expectedValue = + FileUtil.readResourceFile("__files/catalogDbFiles/DoCreateServiceInstance_request.json"); + Assert.assertEquals(expectedValue, str) + + } + + private ExecutionEntity setupMock() { + + ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class) + when(mockProcessDefinition.getKey()).thenReturn("GenericGetService") + RepositoryService mockRepositoryService = mock(RepositoryService.class) + when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition) + when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("GenericGetService") + when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100") + ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class) + when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService) + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getId()).thenReturn("100") + when(mockExecution.getProcessDefinitionId()).thenReturn("GenericGetService") + when(mockExecution.getProcessInstanceId()).thenReturn("GenericGetService") + when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices) + when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition) + return mockExecution + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CompleteMsoProcessTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CompleteMsoProcessTest.groovy new file mode 100644 index 0000000000..9aa8425a50 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CompleteMsoProcessTest.groovy @@ -0,0 +1,170 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts + +import org.camunda.bpm.engine.delegate.BpmnError +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.ArgumentCaptor +import org.mockito.MockitoAnnotations +import org.mockito.runners.MockitoJUnitRunner +import org.onap.so.bpmn.core.WorkflowException + +import static org.assertj.core.api.Assertions.assertThat +import static org.assertj.core.api.Assertions.assertThatThrownBy +import static org.mockito.Matchers.eq +import static org.mockito.Mockito.* + +@RunWith(MockitoJUnitRunner.class) +class CompleteMsoProcessTest { + @Before + public void init() { + MockitoAnnotations.initMocks(this) + } + + private String completeMsoProcessRequest = """ + + + uCPE1020_STUW105_5002 + Layer3ServiceActivateRequest + COMPLETE + OMX + http://localhost:28090/CCD/StatusNotification + 10205000 + 1 + + UCPELayer3ServiceActivateV1 + + """ + + @Test + public void testPreProcessRequest() { + + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getVariable("CompleteMsoProcessRequest")).thenReturn(completeMsoProcessRequest) + when(mockExecution.getVariable("mso.adapters.db.auth")).thenReturn("757A94191D685FD2092AC1490730A4FC"); + when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7"); + + CompleteMsoProcess completeMsoProcess = new CompleteMsoProcess() + completeMsoProcess.preProcessRequest(mockExecution) + + /* Initialize all the process request variables in this block */ + verify(mockExecution).setVariable("prefix","CMSO_") + //verify(mockExecution).setVariable("getLayer3ServiceDetailsV1Response","") + verify(mockExecution).setVariable("CMSO_request_id","") + verify(mockExecution).setVariable("CMSO_notification-url","") + verify(mockExecution).setVariable("CMSO_mso-bpel-name","") + verify(mockExecution).setVariable("CMSO_request_action","") + + verify(mockExecution).setVariable("CMSO_notification-url-Ok", false) + verify(mockExecution).setVariable("CMSO_request_id-Ok", false) + + //updateRequest Adapter process variables + verify(mockExecution).setVariable("CMSO_updateRequestResponse", "") + verify(mockExecution).setVariable("CMSO_updateRequestResponseCode", "") + verify(mockExecution).setVariable("CMSO_updateFinalNotifyAckStatusFailedPayload", "") + + //Set DB adapter variables here + verify(mockExecution).setVariable("CMSO_updateDBStatusToSuccessPayload", "") + verify(mockExecution).setVariable("CMSO_updateInfraRequestDBPayload", "") + verify(mockExecution).setVariable("CMSO_setUpdateDBstatustoSuccessPayload", "") + + //Auth variables + verify(mockExecution).setVariable("BasicAuthHeaderValue","") + + //Response variables + verify(mockExecution).setVariable("CompletionHandlerResponse","") + verify(mockExecution).setVariable("CMSO_ErrorResponse", null) + verify(mockExecution).setVariable("CMSO_ResponseCode", "") + + verify(mockExecution).setVariable("CMSO_notification-url-Ok",true) + verify(mockExecution).setVariable("CMSO_request_id-Ok",true) + verify(mockExecution).setVariable("CMSO_notification-url","http://localhost:28090/CCD/StatusNotification") + verify(mockExecution).setVariable("CMSO_request_id","uCPE1020_STUW105_5002") + verify(mockExecution).setVariable("CMSO_request_action","Layer3ServiceActivateRequest") + verify(mockExecution).setVariable("CMSO_source","OMX") + + } + + private String setUpdateDBstatustoSuccessPayload = """ + + + + + testReqId + BPEL + Resource Completed Successfully + COMPLETE + 100 + + + + """ + + @Test + public void testsetUpdateDBstatustoSuccessPayload(){ + + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getVariable("CMSO_request_id")).thenReturn("testReqId") + when(mockExecution.getVariable("CMSO_mso-bpel-name")).thenReturn("BPEL") + when(mockExecution.getVariable("mso.adapters.db.auth")).thenReturn("757A94191D685FD2092AC1490730A4FC"); + when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7"); + + CompleteMsoProcess completeMsoProcess = new CompleteMsoProcess() + completeMsoProcess.setUpdateDBstatustoSuccessPayload(mockExecution) + + verify(mockExecution).setVariable("CMSO_setUpdateDBstatustoSuccessPayload",setUpdateDBstatustoSuccessPayload) + } + + private String msoCompletionResponse = """onse xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"> + BPEL BPEL-NAME FAILED +""" + +/* + private String msoCompletionResponse = """ + BPEL BPEL-NAME FAILED +""" +*/ + @Test + void testBuildDataError() { + // given + def message = "Some-Message" + + def mockExecution = mock ExecutionEntity.class + when mockExecution.getVariable("CMSO_mso-bpel-name") thenReturn "BPEL-NAME" + when mockExecution.getVariable("testProcessKey") thenReturn "CompleteMsoProcess" + + def completeMsoProcess = new CompleteMsoProcess() + // when + assertThatThrownBy { completeMsoProcess.buildDataError(mockExecution, message) } isInstanceOf BpmnError + // then + verify mockExecution setVariable("CompleteMsoProcessResponse", msoCompletionResponse) + def argumentCaptor = ArgumentCaptor.forClass WorkflowException.class + verify mockExecution setVariable(eq("WorkflowException"), argumentCaptor.capture()) + def capturedException = argumentCaptor.value + + assertThat capturedException.processKey isEqualTo "CompleteMsoProcess" + assertThat capturedException.errorCode isEqualTo 500 + assertThat capturedException.errorMessage isEqualTo message + } +} \ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupNameTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupNameTest.groovy new file mode 100644 index 0000000000..9b3b8c2fb0 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupNameTest.groovy @@ -0,0 +1,130 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts + +import com.github.tomakehurst.wiremock.junit.WireMockRule + +import static org.junit.Assert.*; +import static org.mockito.Mockito.* + +import org.onap.so.rest.HttpHeader +import org.mockito.MockitoAnnotations +import org.mockito.runners.MockitoJUnitRunner +import org.mockito.internal.debugging.MockitoDebuggerImpl +import org.junit.Before +import org.onap.so.bpmn.common.scripts.AaiUtil; +import org.junit.Rule; +import org.junit.Test +import org.junit.Ignore +import org.junit.runner.RunWith +import org.junit.Before; +import org.junit.Test; +import org.camunda.bpm.engine.ProcessEngineServices +import org.camunda.bpm.engine.RepositoryService +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.camunda.bpm.engine.impl.pvm.process.ProcessDefinitionImpl +import org.camunda.bpm.engine.repository.ProcessDefinition +import org.junit.Assert +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.ArgumentCaptor +import org.mockito.Captor +import org.mockito.Mockito +import org.mockito.runners.MockitoJUnitRunner +import org.onap.so.bpmn.common.scripts.ConfirmVolumeGroupName +import org.onap.so.bpmn.core.WorkflowException + +import static com.github.tomakehurst.wiremock.client.WireMock.* +import static org.mockito.Mockito.* + +@RunWith(MockitoJUnitRunner.class) +@Ignore +class ConfirmVolumeGroupNameTest extends MsoGroovyTest { + + @Captor + ArgumentCaptor captor= ArgumentCaptor.forClass(ExecutionEntity.class); + + @Rule + public WireMockRule wireMockRule = new WireMockRule(8090); + + @Test + public void testQueryAAIForVolumeGroupId() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("aai.endpoint")).thenReturn('http://localhost:8090') + when(mockExecution.getVariable("CVGN_volumeGroupGetEndpoint")).thenReturn('/aai/test/volume-groups/volume-group/testVolumeGroup') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + + mockData() + + ConfirmVolumeGroupName confirmVolumeGroupName = new ConfirmVolumeGroupName() + confirmVolumeGroupName.queryAAIForVolumeGroupId(mockExecution) + verify(mockExecution).setVariable("CVGN_queryVolumeGroupResponseCode",200) + verify(mockExecution).setVariable("CVGN_queryVolumeGroupResponse","") + } + + @Test + public void testQueryAAIForVolumeGroupId_404() { + + ExecutionEntity mockExecution = setupMock() + try { + when(mockExecution.getVariable("CVGN_volumeGroupGetEndpoint")).thenReturn('/aai/test/volume-groups/volume-group/testVolumeGroup') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + + mockData() + + ConfirmVolumeGroupName confirmVolumeGroupName = new ConfirmVolumeGroupName() + confirmVolumeGroupName.queryAAIForVolumeGroupId(mockExecution) + } + catch(Exception ex){ + + } + Mockito.verify(mockExecution,times(4)).setVariable(captor.capture(),captor.capture()) + WorkflowException workflowException = captor.getValue() + Assert.assertEquals("AAI GET Failed",workflowException.getErrorMessage()) + Assert.assertEquals(500,workflowException.getErrorCode()) + } + private void mockData() { + stubFor(get(urlMatching("/aai/test/volume-groups/volume-group/testVolumeGroup")) + .willReturn(aResponse() + .withStatus(200))) + } + + private ExecutionEntity setupMock() { + + ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class) + when(mockProcessDefinition.getKey()).thenReturn("ConfirmVolumeGroupName") + RepositoryService mockRepositoryService = mock(RepositoryService.class) + when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition) + when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("ConfirmVolumeGroupName") + when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100") + ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class) + when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService) + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getId()).thenReturn("100") + when(mockExecution.getProcessDefinitionId()).thenReturn("ConfirmVolumeGroupName") + when(mockExecution.getProcessInstanceId()).thenReturn("ConfirmVolumeGroupName") + when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices) + when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition) + return mockExecution + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupTenantTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupTenantTest.groovy new file mode 100644 index 0000000000..1b76f5cb3f --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupTenantTest.groovy @@ -0,0 +1,125 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts + +import com.github.tomakehurst.wiremock.junit.WireMockRule + +import static org.junit.Assert.*; +import static org.mockito.Mockito.* + +import org.onap.so.rest.HttpHeader +import org.mockito.MockitoAnnotations +import org.mockito.runners.MockitoJUnitRunner +import org.mockito.internal.debugging.MockitoDebuggerImpl +import org.junit.Before +import org.onap.so.bpmn.common.scripts.AaiUtil; +import org.junit.Rule; +import org.junit.Test +import org.junit.Ignore +import org.junit.runner.RunWith +import org.junit.Before; +import org.junit.Test; +import org.camunda.bpm.engine.ProcessEngineServices +import org.camunda.bpm.engine.RepositoryService +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.camunda.bpm.engine.impl.pvm.process.ProcessDefinitionImpl +import org.camunda.bpm.engine.repository.ProcessDefinition +import org.junit.Assert +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.ArgumentCaptor +import org.mockito.Captor +import org.mockito.Mockito +import org.mockito.runners.MockitoJUnitRunner +import org.onap.so.bpmn.common.scripts.ConfirmVolumeGroupTenant +import org.onap.so.bpmn.core.WorkflowException + +import static com.github.tomakehurst.wiremock.client.WireMock.* +import static org.mockito.Mockito.* + +@RunWith(MockitoJUnitRunner.class) +@Ignore +class ConfirmVolumeGroupTenantTest extends MsoGroovyTest { + + @Captor + ArgumentCaptor captor = ArgumentCaptor.forClass(ExecutionEntity.class); + + @Rule + public WireMockRule wireMockRule = new WireMockRule(8090); + + @Test + public void testpreProcessRequest() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("aai.endpoint")).thenReturn('http://localhost:8090') + when(mockExecution.getVariable("volumeGroupId")).thenReturn('testVolumeGroupId') + when(mockExecution.getVariable("volumeGroupName")).thenReturn('testVolumeGroupName') + when(mockExecution.getVariable("tenantId")).thenReturn('tenantId') + when(mockExecution.getVariable("aicCloudRegion")).thenReturn('aicCloudRegion') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8') + when(mockExecution.getVariable("mso.workflow.default.aai.v8.cloud-region.uri")).thenReturn('/aai/v8/cloud-infrastructure/cloud-regions/cloud-region/att-aic') + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/') + + + mockData() + + + ConfirmVolumeGroupTenant confirmVolumeGroupTenant = new ConfirmVolumeGroupTenant() + confirmVolumeGroupTenant.preProcessRequest(mockExecution) + /* Mockito.verify(mockExecution, times(5)).setVariable(captor.capture(), captor.capture())*/ + verify(mockExecution).setVariable("prefix", "CVGT_") + verify(mockExecution).setVariable("queryVolumeGroupResponseCode", 200) + verify(mockExecution).setVariable("queryAAIVolumeGroupResponse", "17ef4658-bd1f-4ef0-9ca0-ea76e2bf122cMSOTESTVOL103a-vSAMP12_base_module-0_vol9d1f53e3-3158-44f8-8032-a6bf40bbc9dbpcrf-capacityActive0000020tenantcloud-region.cloud-owneratt-aiccloud-region.cloud-region-idRegionOnetenant.tenant-id22eb191dd41a4f3c9be370fc638322f4") + verify(mockExecution).setVariable("tenantIdsMatch", false) + verify(mockExecution).setVariable("groupNamesMatch", false) + } + + + private void mockData() { + stubFor(get(urlMatching("/aai/v8/cloud-infrastructure/cloud-regions/cloud-region/att-aic/aicCloudRegion/volume-groups/volume-group/testVolumeGroupId")) + .willReturn(aResponse() + .withStatus(200) + .withBody("17ef4658-bd1f-4ef0-9ca0-ea76e2bf122cMSOTESTVOL103a-vSAMP12_base_module-0_vol9d1f53e3-3158-44f8-8032-a6bf40bbc9dbpcrf-capacityActive0000020tenantcloud-region.cloud-owneratt-aiccloud-region.cloud-region-idRegionOnetenant.tenant-id22eb191dd41a4f3c9be370fc638322f4"))) + } + + private ExecutionEntity setupMock() { + + ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class) + when(mockProcessDefinition.getKey()).thenReturn("ConfirmVolumeGroupTenant") + RepositoryService mockRepositoryService = mock(RepositoryService.class) + when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition) + when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("ConfirmVolumeGroupTenant") + when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100") + ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class) + when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService) + + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getId()).thenReturn("100") + when(mockExecution.getProcessDefinitionId()).thenReturn("ConfirmVolumeGroupTenant") + when(mockExecution.getProcessInstanceId()).thenReturn("ConfirmVolumeGroupTenant") + when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices) + when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition) + + return mockExecution + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CustomE2EGetServiceTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CustomE2EGetServiceTest.groovy new file mode 100644 index 0000000000..a8c10b1e81 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CustomE2EGetServiceTest.groovy @@ -0,0 +1,104 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts + +import com.github.tomakehurst.wiremock.junit.WireMockRule +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.junit.Assert +import org.junit.Before +import org.junit.Ignore +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.ArgumentCaptor +import org.mockito.Captor +import org.mockito.Mockito +import org.mockito.runners.MockitoJUnitRunner + +import static org.mockito.Mockito.times +import static org.mockito.Mockito.when +import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetServiceInstance +import static org.onap.so.bpmn.mock.StubResponseAAI.MockNodeQueryServiceInstanceById +import static org.onap.so.bpmn.mock.StubResponseAAI.MockNodeQueryServiceInstanceByName + +/** + * @author sushilma + * @since January 10, 2018 + */ +@RunWith(MockitoJUnitRunner.class) +@Ignore +class CustomE2EGetServiceTest extends MsoGroovyTest { + + @Rule + public WireMockRule wireMockRule = new WireMockRule(28090) + + @Captor + static ArgumentCaptor captor = ArgumentCaptor.forClass(ExecutionEntity.class) + + @Test + public void testObtainServiceInstanceUrlById (){ + ExecutionEntity mockExecution = setupMockWithPrefix('CustomE2EGetService','GENGS_') + when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090") + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/") + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8') + when(mockExecution.getVariable("mso.workflow.default.aai.v8.nodes-query.uri")).thenReturn('/aai/v8/search/nodes-query') + when(mockExecution.getVariable("GENGS_type")).thenReturn('service-instance') + when(mockExecution.getVariable("GENGS_serviceInstanceId")).thenReturn("MIS%2F1604%2F0026%2FSW_INTERNET") + MockNodeQueryServiceInstanceById("MIS%2F1604%2F0026%2FSW_INTERNET", "GenericFlows/getSIUrlById.xml"); + CustomE2EGetService customE2EGetService = new CustomE2EGetService(); + customE2EGetService.obtainServiceInstanceUrlById(mockExecution) + Mockito.verify(mockExecution, times(9)).setVariable(captor.capture(), captor.capture()) + Assert.assertEquals(200, captor.getAllValues().get(5)) + } + + @Test + public void testObtainServiceInstanceUrlByName (){ + ExecutionEntity mockExecution = setupMockWithPrefix('CustomE2EGetService','GENGS_') + when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090") + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/") + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8') + when(mockExecution.getVariable("mso.workflow.default.aai.v8.nodes-query.uri")).thenReturn('/aai/v8/search/nodes-query') + when(mockExecution.getVariable("GENGS_type")).thenReturn('service-instance') + when(mockExecution.getVariable("GENGS_serviceInstanceName")).thenReturn("1604-MVM-26") + MockNodeQueryServiceInstanceByName("1604-MVM-26", "GenericFlows/getSIUrlByName.xml"); + CustomE2EGetService customE2EGetService = new CustomE2EGetService(); + customE2EGetService.obtainServiceInstanceUrlByName(mockExecution) + Mockito.verify(mockExecution, times(8)).setVariable(captor.capture(), captor.capture()) + Assert.assertEquals(200, captor.getAllValues().get(5)) + } + + @Test + public void testServiceObject (){ + ExecutionEntity mockExecution = setupMockWithPrefix('CustomE2EGetService','GENGS_') + when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090") + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/") + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8') + when(mockExecution.getVariable("mso.workflow.default.aai.v8.nodes-query.uri")).thenReturn('/aai/v8/search/nodes-query') + when(mockExecution.getVariable("GENGS_type")).thenReturn('service-instance') + when(mockExecution.getVariable("GENGS_serviceInstanceId")).thenReturn("MIS%2F1604%2F0026%2FSW_INTERNET") + when(mockExecution.getVariable("GENGS_resourceLink")).thenReturn("/aai/v8/business/customers/customer/MSO_1610_dev/service-subscriptions/service-subscription/MSO-dev-service-type/service-instances/service-instance/1234453") + MockGetServiceInstance("MSO_1610_dev", "MSO-dev-service-type", "1234453", "GenericFlows/getServiceInstance.xml"); + CustomE2EGetService customE2EGetService = new CustomE2EGetService(); + customE2EGetService.getServiceObject(mockExecution) + Mockito.verify(mockExecution, times(7)).setVariable(captor.capture(), captor.capture()) + Assert.assertEquals(200, captor.getAllValues().get(5)) + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CustomE2EPutServiceTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CustomE2EPutServiceTest.groovy new file mode 100644 index 0000000000..879ef7ab4f --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CustomE2EPutServiceTest.groovy @@ -0,0 +1,72 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts + +import com.github.tomakehurst.wiremock.junit.WireMockRule +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.junit.Assert +import org.junit.Before +import org.junit.Ignore +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.ArgumentCaptor +import org.mockito.Captor +import org.mockito.Mockito +import org.mockito.runners.MockitoJUnitRunner + +import static org.mockito.Mockito.times +import static org.mockito.Mockito.when +import static org.onap.so.bpmn.mock.StubResponseAAI.MockPutServiceInstance + +/** + * @author sushilma + * @since January 10, 2018 + */ +@RunWith(MockitoJUnitRunner.class) +@Ignore +class CustomE2EPutServiceTest extends MsoGroovyTest { + @Rule + public WireMockRule wireMockRule = new WireMockRule(28090) + + @Captor + static ArgumentCaptor captor = ArgumentCaptor.forClass(ExecutionEntity.class) + + @Test + public void testPutServiceInstance(){ + ExecutionEntity mockExecution = setupMockWithPrefix('CustomE2EPutService','GENPS_') + when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090") + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/") + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8') + when(mockExecution.getVariable("mso.workflow.default.aai.v8.customer.uri")).thenReturn('/aai/v8/business/customers/customer') + when(mockExecution.getVariable("GENPS_type")).thenReturn('service-instance') + when(mockExecution.getVariable("GENPS_payload")).thenReturn('') + when(mockExecution.getVariable("GENPS_globalSubscriberId")).thenReturn("1604-MVM-26") + when(mockExecution.getVariable("GENPS_serviceType")).thenReturn("SDN-ETHERNET-INTERNET") + when(mockExecution.getVariable("GENPS_serviceInstanceId")).thenReturn( "1234") + MockPutServiceInstance("1604-MVM-26", "SDN-ETHERNET-INTERNET", "1234", "GenericFlows/getServiceInstance.xml"); + + CustomE2EPutService customE2EPutService = new CustomE2EPutService() + customE2EPutService.putServiceInstance(mockExecution); + Mockito.verify(mockExecution, times(6)).setVariable(captor.capture(), captor.capture()) + Assert.assertEquals(200, captor.getAllValues().get(7)) + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/DeleteAAIVfModuleTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/DeleteAAIVfModuleTest.groovy new file mode 100644 index 0000000000..025bea5325 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/DeleteAAIVfModuleTest.groovy @@ -0,0 +1,218 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts + +import com.github.tomakehurst.wiremock.junit.WireMockRule +import org.camunda.bpm.engine.ProcessEngineServices +import org.camunda.bpm.engine.RepositoryService +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.camunda.bpm.engine.repository.ProcessDefinition +import org.junit.Assert +import org.junit.Before +import org.junit.Ignore +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.ArgumentCaptor +import org.mockito.Captor +import org.mockito.Mock +import org.mockito.Mockito +import org.mockito.MockitoAnnotations +import org.mockito.runners.MockitoJUnitRunner +import org.onap.so.bpmn.core.WorkflowException +import org.onap.so.bpmn.mock.StubResponseAAI + +import static com.github.tomakehurst.wiremock.client.WireMock.* +import static org.mockito.Mockito.* + +@RunWith(MockitoJUnitRunner.class) +@Ignore +class DeleteAAIVfModuleTest { + + def prefix = "DAAIVfMod_" + + @Rule + public WireMockRule wireMockRule = new WireMockRule(28090) + + @Captor + static ArgumentCaptor captor = ArgumentCaptor.forClass(ExecutionEntity.class) + + @Before + void init() throws IOException { + MockitoAnnotations.initMocks(this); + } + + @Test + void testQueryAAIForGenericVnf() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("prefix")).thenReturn(prefix) + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable(prefix + "genericVnfEndpoint")).thenReturn("/aai/v8/network/generic-vnfs/generic-vnf/skask") + when(mockExecution.getVariable(prefix + "vfModuleId")).thenReturn("supercool") + when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090") + when(mockExecution.getVariable("aai.auth")).thenReturn("9B2278E8B8E95F256A560719055F4DF3") + when(mockExecution.getVariable("mso.msoKey")).thenReturn("aa3871669d893c7fb8abbcda31b88b4f") + + StubResponseAAI.MockAAIVfModule() + DeleteAAIVfModule obj = new DeleteAAIVfModule() + obj.queryAAIForGenericVnf(mockExecution) + + Mockito.verify(mockExecution).setVariable(prefix + "queryGenericVnfResponseCode", 200) + } + + @Test + void testQueryAAIForGenericVnfEndpointNull() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable(prefix + "genericVnfEndpoint")).thenReturn("/aai/v8/network/generic-vnfs/generic-vnf/skask") + when(mockExecution.getVariable(prefix + "vfModuleId")).thenReturn("supercool") + when(mockExecution.getVariable("aai.endpoint")).thenReturn(null) + when(mockExecution.getVariable("aai.auth")).thenReturn("9B2278E8B8E95F256A560719055F4DF3") + when(mockExecution.getVariable("mso.msoKey")).thenReturn("aa3871669d893c7fb8abbcda31b88b4f") + + StubResponseAAI.MockAAIVfModule() + try { + DeleteAAIVfModule obj = new DeleteAAIVfModule() + obj.queryAAIForGenericVnf(mockExecution) + } catch (Exception ex) { + println " Test End - Handle catch-throw BpmnError()! " + } + + Mockito.verify(mockExecution, times(2)).setVariable(captor.capture(), captor.capture()) + WorkflowException workflowException = captor.getValue() + Assert.assertEquals(5000, workflowException.getErrorCode()) + Assert.assertEquals("Internal Error - Occured during queryAAIForGenericVnf", workflowException.getErrorMessage()) + } + + @Test + void testDeleteGenericVnf() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable(prefix + "genericVnfEndpoint")).thenReturn("/aai/v9/cloud-infrastructure/volume-groups/volume-group/78987") + when(mockExecution.getVariable(prefix + "genVnfRsrcVer")).thenReturn("0000020") + when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090") + when(mockExecution.getVariable("aai.auth")).thenReturn("9B2278E8B8E95F256A560719055F4DF3") + when(mockExecution.getVariable("mso.msoKey")).thenReturn("aa3871669d893c7fb8abbcda31b88b4f") + + stubFor(delete(urlMatching("/aai/v[0-9]+/cloud-infrastructure/volume-groups/volume-group/78987/[?]resource-version=0000020")) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile(""))) + + StubResponseAAI.MockAAIVfModule() + DeleteAAIVfModule obj = new DeleteAAIVfModule() + obj.deleteGenericVnf(mockExecution) + + Mockito.verify(mockExecution).setVariable(prefix + "deleteGenericVnfResponseCode", 200) + } + + @Test + void testDeleteGenericVnfEndpointNull() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable(prefix + "genericVnfEndpoint")).thenReturn("/aai/v9/cloud-infrastructure/volume-groups/volume-group/78987") + when(mockExecution.getVariable(prefix + "genVnfRsrcVer")).thenReturn("0000020") + when(mockExecution.getVariable("aai.endpoint")).thenReturn(null) + when(mockExecution.getVariable("aai.auth")).thenReturn("9B2278E8B8E95F256A560719055F4DF3") + when(mockExecution.getVariable("mso.msoKey")).thenReturn("aa3871669d893c7fb8abbcda31b88b4f") + + StubResponseAAI.MockAAIVfModule() + try { + DeleteAAIVfModule obj = new DeleteAAIVfModule() + obj.deleteGenericVnf(mockExecution) + } catch (Exception ex) { + println " Test End - Handle catch-throw BpmnError()! " + } + + Mockito.verify(mockExecution, times(1)).setVariable(captor.capture(), captor.capture()) + WorkflowException workflowException = captor.getValue() + Assert.assertEquals(5000, workflowException.getErrorCode()) + Assert.assertEquals("Internal Error - Occured during deleteGenericVnf", workflowException.getErrorMessage()) + } + + @Test + void testDeleteVfModule() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable(prefix + "vfModuleEndpoint")).thenReturn("/aai/v9/cloud-infrastructure/volume-groups/volume-group/78987") + when(mockExecution.getVariable(prefix + "vfModRsrcVer")).thenReturn("0000020") + when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090") + when(mockExecution.getVariable("aai.auth")).thenReturn("9B2278E8B8E95F256A560719055F4DF3") + when(mockExecution.getVariable("mso.msoKey")).thenReturn("aa3871669d893c7fb8abbcda31b88b4f") + + stubFor(delete(urlMatching("/aai/v[0-9]+/cloud-infrastructure/volume-groups/volume-group/78987/[?]resource-version=0000020")) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile(""))) + + DeleteAAIVfModule obj = new DeleteAAIVfModule() + obj.deleteVfModule(mockExecution) + + Mockito.verify(mockExecution).setVariable(prefix + "deleteVfModuleResponseCode", 200) + } + + @Test + void testDeleteVfModuleEndpointNull() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable(prefix + "vfModuleEndpoint")).thenReturn("/aai/v9/cloud-infrastructure/volume-groups/volume-group/78987") + when(mockExecution.getVariable(prefix + "vfModRsrcVer")).thenReturn("0000020") + when(mockExecution.getVariable("aai.endpoint")).thenReturn(null) + when(mockExecution.getVariable("aai.auth")).thenReturn("9B2278E8B8E95F256A560719055F4DF3") + when(mockExecution.getVariable("mso.msoKey")).thenReturn("aa3871669d893c7fb8abbcda31b88b4f") + + StubResponseAAI.MockAAIVfModule() + try { + DeleteAAIVfModule obj = new DeleteAAIVfModule() + obj.deleteVfModule(mockExecution) + } catch (Exception ex) { + println " Test End - Handle catch-throw BpmnError()! " + } + + Mockito.verify(mockExecution, times(1)).setVariable(captor.capture(), captor.capture()) + WorkflowException workflowException = captor.getValue() + Assert.assertEquals(5000, workflowException.getErrorCode()) + Assert.assertEquals("Internal Error - Occured during deleteVfModule", workflowException.getErrorMessage()) + } + + private static ExecutionEntity setupMock() { + ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class) + when(mockProcessDefinition.getKey()).thenReturn("DeleteAAIVfModule") + RepositoryService mockRepositoryService = mock(RepositoryService.class) + when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition) + when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("DeleteAAIVfModule") + when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100") + ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class) + when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService) + + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + // Initialize prerequisite variables + when(mockExecution.getId()).thenReturn("100") + when(mockExecution.getProcessDefinitionId()).thenReturn("DeleteAAIVfModule") + when(mockExecution.getProcessInstanceId()).thenReturn("DeleteAAIVfModule") + when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices) + when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition) + + return mockExecution + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/ExceptionUtilTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/ExceptionUtilTest.groovy new file mode 100644 index 0000000000..c7015cda50 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/ExceptionUtilTest.groovy @@ -0,0 +1,98 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts + +import org.junit.Assert +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + + +import org.junit.Ignore; + +import static org.mockito.Mockito.* + +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.junit.Before +import org.junit.runner.RunWith +import org.mockito.MockitoAnnotations +import org.mockito.internal.debugging.MockitoDebuggerImpl +import org.mockito.runners.MockitoJUnitRunner +import org.onap.so.bpmn.common.scripts.ExceptionUtil; +import org.onap.so.bpmn.core.WorkflowException +@RunWith(MockitoJUnitRunner.class) +import org.junit.Test + + + +class ExceptionUtilTest { + + + @Before + public void init() + { + MockitoAnnotations.initMocks(this) + } + + @Test + public void testMapErrorCode5010(){ + String msg = "Connect to njcdtl20ew2988:8070 failed: Connection refused: connect" + ExceptionUtil util = new ExceptionUtil() + Assert.assertEquals("5010",util.MapErrorCode(msg)) + } + + @Test + public void testMapErrorCode5020(){ + String msg = "Connection timed out" + ExceptionUtil util = new ExceptionUtil() + Assert.assertEquals("5020",util.MapErrorCode(msg)) + } + + @Test + public void testGetErrorCode() { + ExceptionUtil eUtil = new ExceptionUtil() + WorkflowException we = new WorkflowException("CreateVCEV2", 400, "SDNC Test Error") + int errCd = eUtil.getErrorCode(we) + Assert.assertEquals(400, errCd) + } + + @Test + public void testGetErrorCodeWithNullWfe() { + ExceptionUtil eUtil = new ExceptionUtil() + int errCd = eUtil.getErrorCode(null) + Assert.assertEquals(2500, errCd) + } + + @Test + public void testGetErrorMessage() { + ExceptionUtil eUtil = new ExceptionUtil() + WorkflowException we = new WorkflowException("CreateVCEV2", 400, "SDNC Test Error") + String errMsg = eUtil.getErrorMessage(we, "CreateVCEV2") + Assert.assertEquals("SDNC Test Error", errMsg) + } + + @Test + public void testGetErrorMessageWithNullWfe() { + ExceptionUtil eUtil = new ExceptionUtil() + String errMsg = eUtil.getErrorMessage(null, "CreateVCEV2") + Assert.assertEquals("Unexpected error encountered in CreateVCEV2", errMsg) + } + +} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/FalloutHandlerTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/FalloutHandlerTest.groovy new file mode 100644 index 0000000000..016d968a12 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/FalloutHandlerTest.groovy @@ -0,0 +1,312 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts + +import org.junit.runner.RunWith; +import static org.mockito.Mockito.* +import static org.junit.Assert.*; + +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.ArgumentCaptor; +import org.mockito.MockitoAnnotations +import org.mockito.runners.MockitoJUnitRunner +import org.onap.so.bpmn.common.scripts.MsoUtils; +import org.onap.so.bpmn.common.scripts.FalloutHandler; + +@RunWith(MockitoJUnitRunner.class) +class FalloutHandlerTest { + + public MsoUtils utils = new MsoUtils() + + @Before + public void init() { + MockitoAnnotations.initMocks(this) + } + + private String falloutHandlerRequest = """ + + + uCPE1020_STUW105_5002 + Layer3ServiceActivateRequest + CANCEL + OMX + 10205000 + 1 + + + Some Error Message - Fallout Handler + Some Error Code - Fallout Handler + Some Source System Error Code- Fallout Handler + + + """ + + private String falloutHandlerResponse = """ + Fallout Handler Failed +""" + + @Test + public void testPreProcessRequest() { + + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + + when(mockExecution.getVariable("FalloutHandlerRequest")).thenReturn(falloutHandlerRequest) + when(mockExecution.getVariable("mso.adapters.db.auth")).thenReturn("757A94191D685FD2092AC1490730A4FC"); + when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7"); + + FalloutHandler falloutHandler = new FalloutHandler() + falloutHandler.preProcessRequest(mockExecution) + + /* Initialize all the process request variables in this block */ + verify(mockExecution).setVariable("prefix","FH_") + //verify(mockExecution).setVariable("getLayer3ServiceDetailsV1Response","") + + //These variables are form the input Message to the BPMN + verify(mockExecution).setVariable("FH_request_id","") + verify(mockExecution).setVariable("FH_request_action","") + verify(mockExecution).setVariable("FH_notification-url","") + verify(mockExecution).setVariable("FH_mso-bpel-name","") + verify(mockExecution).setVariable("FH_ErrorCode", "") + verify(mockExecution).setVariable("FH_ErrorMessage", "") + + verify(mockExecution).setVariable("FH_notification-url-Ok", false) + verify(mockExecution).setVariable("FH_request_id-Ok", false) + + //These variables are for Get Mso Aai Password Adapter + verify(mockExecution).setVariable("FH_deliveryStatus", true) + + //update Response Status to pending ...Adapter variables + verify(mockExecution).setVariable("FH_updateResponseStatusPayload", null) + verify(mockExecution).setVariable("FH_updateResponseStatusResponse", null) + + //update Request Gamma ...Adapter variables + verify(mockExecution).setVariable("FH_updateRequestGammaPayload", "") + verify(mockExecution).setVariable("FH_updateRequestGammaResponse", null) + verify(mockExecution).setVariable("FH_updateRequestGammaResponseCode", null) + + //update Request Infra ...Adapter variables + verify(mockExecution).setVariable("FH_updateRequestInfraPayload", "") + verify(mockExecution).setVariable("FH_updateRequestInfraResponse", null) + verify(mockExecution).setVariable("FH_updateRequestInfraResponseCode", null) + + //assign False to success variable + verify(mockExecution).setVariable("FH_success", true) + + //Set notify status to Failed variable + verify(mockExecution).setVariable("FH_NOTIFY_STATUS", "SUCCESS") + + //Set DB update variable + verify(mockExecution).setVariable("FH_updateRequestPayload", "") + verify(mockExecution).setVariable("FH_updateRequestResponse", null) + verify(mockExecution).setVariable("FH_updateRequestResponseCode", null) + + //Auth variables + verify(mockExecution).setVariable("BasicAuthHeaderValue","") + + //Response variables + verify(mockExecution).setVariable("FalloutHandlerResponse","") + verify(mockExecution).setVariable("FH_ErrorResponse", null) + verify(mockExecution).setVariable("FH_ResponseCode", "") + + verify(mockExecution).setVariable("FH_request_id-Ok",true) + verify(mockExecution).setVariable("FH_request_id","uCPE1020_STUW105_5002") + verify(mockExecution).setVariable("FH_request_action","Layer3ServiceActivateRequest") + verify(mockExecution).setVariable("FH_source","OMX") + verify(mockExecution).setVariable("FH_ErrorCode","Some Error Code - Fallout Handler") + verify(mockExecution).setVariable("FH_ErrorMessage","Some Error Message - Fallout Handler") + + } + + @Test + public void testpostProcessResponse(){ + + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable("FH_success")).thenReturn(false) + + FalloutHandler falloutHandler = new FalloutHandler() + falloutHandler.postProcessResponse(mockExecution) + + // Capture the arguments to setVariable + ArgumentCaptor captor1 = ArgumentCaptor.forClass(String.class); + ArgumentCaptor captor2 = ArgumentCaptor.forClass(String.class); + + verify(mockExecution, times(4)).setVariable(captor1.capture(), captor2.capture()) + List arg2List = captor2.getAllValues() + String payloadResponseActual = arg2List.get(1) + + assertEquals(falloutHandlerResponse.replaceAll("\\s+", ""), payloadResponseActual.replaceAll("\\s+", "")) + + verify(mockExecution).setVariable("FH_ResponseCode","500") + } + + private String updateRequestPayload = """ + + + + + testReqId + BPEL + ErrorMessage + ErrorCode + FAILED + NotifyStatus + + + + """ + + @Test + public void testupdateRequestPayload(){ + + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getVariable("FH_request_id")).thenReturn("testReqId") + when(mockExecution.getVariable("FH_ErrorMessage")).thenReturn("ErrorMessage") + when(mockExecution.getVariable("FH_ErrorCode")).thenReturn("ErrorCode") + when(mockExecution.getVariable("FH_NOTIFY_STATUS")).thenReturn("NotifyStatus") + + FalloutHandler falloutHandler = new FalloutHandler() + falloutHandler.updateRequestPayload(mockExecution) + + // Capture the arguments to setVariable + ArgumentCaptor captor1 = ArgumentCaptor.forClass(String.class); + ArgumentCaptor captor2 = ArgumentCaptor.forClass(String.class); + + verify(mockExecution, times(1)).setVariable(captor1.capture(), captor2.capture()) + List arg2List = captor2.getAllValues() + String payloadRequestActual = arg2List.get(0) + + assertEquals(updateRequestPayload.replaceAll("\\s+", ""), payloadRequestActual.replaceAll("\\s+", "")) + } + + private String updateRequestInfraPayload = """ + + + + + testReqId + BPEL + ErrorMessage + FAILED + 100 + + + + """ + + @Test + public void testupdateRequestInfraPayload(){ + + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getVariable("FH_request_id")).thenReturn("testReqId") + when(mockExecution.getVariable("FH_ErrorMessage")).thenReturn("ErrorMessage") + + FalloutHandler falloutHandler = new FalloutHandler() + falloutHandler.updateRequestInfraPayload(mockExecution) + + // Capture the arguments to setVariable + ArgumentCaptor captor1 = ArgumentCaptor.forClass(String.class); + ArgumentCaptor captor2 = ArgumentCaptor.forClass(String.class); + + verify(mockExecution, times(1)).setVariable(captor1.capture(), captor2.capture()) + List arg2List = captor2.getAllValues() + String payloadRequestActual = arg2List.get(0) + + assertEquals(updateRequestInfraPayload.replaceAll("\\s+", ""), payloadRequestActual.replaceAll("\\s+", "")) + } + + private String updateRequestGammaPayload = """ + + + + + testReqId + BPEL + ErrorMessage + ErrorCode + FAILED + + + + """ + + @Test + public void testupdateRequestGammaPayload(){ + + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getVariable("FH_request_id")).thenReturn("testReqId") + when(mockExecution.getVariable("FH_ErrorMessage")).thenReturn("ErrorMessage") + when(mockExecution.getVariable("FH_ErrorCode")).thenReturn("ErrorCode") + when(mockExecution.getVariable("mso.default.adapter.namespace")).thenReturn("http://org.onap.so"); + + FalloutHandler falloutHandler = new FalloutHandler() + falloutHandler.updateRequestGammaPayload(mockExecution) + + // Capture the arguments to setVariable + ArgumentCaptor captor1 = ArgumentCaptor.forClass(String.class); + ArgumentCaptor captor2 = ArgumentCaptor.forClass(String.class); + + verify(mockExecution, times(1)).setVariable(captor1.capture(), captor2.capture()) + List arg2List = captor2.getAllValues() + String payloadRequestActual = arg2List.get(0) + + assertEquals(updateRequestGammaPayload.replaceAll("\\s+", ""), payloadRequestActual.replaceAll("\\s+", "")) + } + + + String updateResponseStatusPayload = """ + + + + + testReqId + BPEL + SENDING_FINAL_NOTIFY + + + + """ + + @Test + public void testupdateResponseStatusPayload(){ + + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getVariable("FH_request_id")).thenReturn("testReqId") + + FalloutHandler falloutHandler = new FalloutHandler() + falloutHandler.updateResponseStatusPayload(mockExecution) + + // Capture the arguments to setVariable + ArgumentCaptor captor1 = ArgumentCaptor.forClass(String.class); + ArgumentCaptor captor2 = ArgumentCaptor.forClass(String.class); + + verify(mockExecution, times(1)).setVariable(captor1.capture(), captor2.capture()) + List arg2List = captor2.getAllValues() + String payloadResponseActual = arg2List.get(0) + + assertEquals(updateResponseStatusPayload.replaceAll("\\s+", ""), payloadResponseActual.replaceAll("\\s+", "")) + } + +} \ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/GenerateVfModuleNameTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/GenerateVfModuleNameTest.groovy new file mode 100644 index 0000000000..c5baf8cc6c --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/GenerateVfModuleNameTest.groovy @@ -0,0 +1,125 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts + +import com.github.tomakehurst.wiremock.junit.WireMockRule +import org.camunda.bpm.engine.ProcessEngineServices +import org.camunda.bpm.engine.RepositoryService +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.camunda.bpm.engine.repository.ProcessDefinition +import org.junit.Assert +import org.junit.Before +import org.junit.Ignore +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.ArgumentCaptor +import org.mockito.Captor +import org.mockito.Mockito +import org.mockito.runners.MockitoJUnitRunner +import org.onap.so.bpmn.core.WorkflowException + +import static com.github.tomakehurst.wiremock.client.WireMock.* +import static org.mockito.Mockito.* + +@RunWith(MockitoJUnitRunner.class) +@Ignore +class GenerateVfModuleNameTest { + + @Captor + ArgumentCaptor captor = ArgumentCaptor.forClass(ExecutionEntity.class); + + + @Rule + public WireMockRule wireMockRule = new WireMockRule(8090); + + @Test + public void testQueryAAI() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("aai.endpoint")).thenReturn('http://localhost:8090') + when(mockExecution.getVariable("vnfId")).thenReturn('skask') + when(mockExecution.getVariable("personaModelId")).thenReturn('personaModelId_test') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8') + when(mockExecution.getVariable("mso.workflow.default.aai.v8.generic-vnf.uri")).thenReturn('/aai/v8/network/generic-vnfs/generic-vnf') + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/') + when(mockExecution.getVariable("mso.workflow.default.aai.generic-vnf.version")).thenReturn('8') + + mockData() + GenerateVfModuleName obj = new GenerateVfModuleName() + obj.queryAAI(mockExecution) + + Mockito.verify(mockExecution).setVariable("GVFMN_queryAAIVfModuleResponseCode", 200) + } + + @Test + public void testQueryAAIEndpointNull() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("aai.endpoint")).thenReturn(null) + when(mockExecution.getVariable("vnfId")).thenReturn('skask') + when(mockExecution.getVariable("personaModelId")).thenReturn('personaModelId_test') + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8') + when(mockExecution.getVariable("mso.workflow.default.aai.v8.generic-vnf.uri")).thenReturn('/aai/v8/network/generic-vnfs/generic-vnf') + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/') + when(mockExecution.getVariable("mso.workflow.default.aai.generic-vnf.version")).thenReturn('8') + + mockData() + try { + GenerateVfModuleName obj = new GenerateVfModuleName() + obj.queryAAI(mockExecution) + } catch (Exception ex) { + println " Test End - Handle catch-throw BpmnError()! " + } + + Mockito.verify(mockExecution, times(1)).setVariable(captor.capture(), captor.capture()) + WorkflowException workflowException = captor.getValue() + Assert.assertEquals(1002, workflowException.getErrorCode()) + Assert.assertEquals("AAI GET Failed:org.apache.http.client.ClientProtocolException", workflowException.getErrorMessage()) + } + + + private void mockData() { + stubFor(get(urlMatching(".*/aai/v[0-9]+/network/generic-vnfs/generic-vnf.*")) + .willReturn(aResponse() + .withStatus(200).withHeader("Content-Type", "text/xml") + .withBodyFile("GenericFlows/getGenericVnfResponse.xml"))) + } + + private ExecutionEntity setupMock() { + + ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class) + when(mockProcessDefinition.getKey()).thenReturn("GenerateVfModuleName") + RepositoryService mockRepositoryService = mock(RepositoryService.class) + when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition) + when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("GenerateVfModuleName") + when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100") + ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class) + when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService) + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getId()).thenReturn("100") + when(mockExecution.getProcessDefinitionId()).thenReturn("GenerateVfModuleName") + when(mockExecution.getProcessInstanceId()).thenReturn("GenerateVfModuleName") + when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices) + when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition) + return mockExecution + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/GenericGetServiceTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/GenericGetServiceTest.groovy new file mode 100644 index 0000000000..49edd813f7 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/GenericGetServiceTest.groovy @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts + +import com.github.tomakehurst.wiremock.junit.WireMockRule +import org.camunda.bpm.engine.ProcessEngineServices +import org.camunda.bpm.engine.RepositoryService +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.camunda.bpm.engine.repository.ProcessDefinition +import org.junit.Assert +import org.junit.Before +import org.junit.Ignore +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.ArgumentCaptor +import org.mockito.Captor +import org.mockito.Mockito +import org.mockito.runners.MockitoJUnitRunner +import org.onap.so.bpmn.core.WorkflowException + +import static com.github.tomakehurst.wiremock.client.WireMock.* +import static org.mockito.Mockito.* + +@RunWith(MockitoJUnitRunner.class) +@Ignore +class GenericGetServiceTest { + + def prefix = "GENGS_" + @Captor + ArgumentCaptor captor = ArgumentCaptor.forClass(ExecutionEntity.class); + + @Rule + public WireMockRule wireMockRule = new WireMockRule(8090); + + @Test + public void testGetServiceObject() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("aai.endpoint")).thenReturn('http://localhost:8090') + when(mockExecution.getVariable(prefix + "type")).thenReturn('service-instance') + when(mockExecution.getVariable(prefix + "serviceInstanceId")).thenReturn('12345') + when(mockExecution.getVariable(prefix + "resourceLink")).thenReturn("/aai/v8/business/customers/customer/MSO_1610_dev/service-subscriptions/service-subscription/MSO-dev-service-type/service-instances/service-instance/") + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8') + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/') + + mockData() + GenericGetService obj = new GenericGetService() + obj.getServiceObject(mockExecution) + + Mockito.verify(mockExecution).setVariable("prefix", prefix) + Mockito.verify(mockExecution).setVariable(prefix + "getServiceUrl", "http://localhost:8090/aai/v8/business/customers/customer/MSO_1610_dev/service-subscriptions/service-subscription/MSO-dev-service-type/service-instances/service-instance/") + Mockito.verify(mockExecution).setVariable(prefix + "getServiceResponseCode", 200) + } + + @Test + public void testGetServiceObjectEndpointNull() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("aai.endpoint")).thenReturn(null) + when(mockExecution.getVariable(prefix + "type")).thenReturn('service-instance') + when(mockExecution.getVariable(prefix + "serviceInstanceId")).thenReturn('12345') + when(mockExecution.getVariable(prefix + "resourceLink")).thenReturn("/aai/v8/business/customers/customer/MSO_1610_dev/service-subscriptions/service-subscription/MSO-dev-service-type/service-instances/service-instance/") + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8') + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/') + + mockData() + try { + GenericGetService obj = new GenericGetService() + obj.getServiceObject(mockExecution) + } catch (Exception ex) { + println " Test End - Handle catch-throw BpmnError()! " + } + + Mockito.verify(mockExecution, times(3)).setVariable(captor.capture(), captor.capture()) + WorkflowException workflowException = captor.getValue() + Assert.assertEquals(9999, workflowException.getErrorCode()) + Assert.assertEquals("org.apache.http.client.ClientProtocolException", workflowException.getErrorMessage()) + } + + private void mockData() { + stubFor(get(urlMatching(".*/aai/v[0-9]+/business/customers/customer/MSO_1610_dev/service-subscriptions/service-subscription/MSO-dev-service-type/service-instances/service-instance/.*")) + .willReturn(aResponse() + .withStatus(200).withHeader("Content-Type", "text/xml") + .withBodyFile(""))) + } + + private ExecutionEntity setupMock() { + + ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class) + when(mockProcessDefinition.getKey()).thenReturn("GenericGetService") + RepositoryService mockRepositoryService = mock(RepositoryService.class) + when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition) + when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("GenericGetService") + when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100") + ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class) + when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService) + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getId()).thenReturn("100") + when(mockExecution.getProcessDefinitionId()).thenReturn("GenericGetService") + when(mockExecution.getProcessInstanceId()).thenReturn("GenericGetService") + when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices) + when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition) + return mockExecution + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/GenericGetVnfTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/GenericGetVnfTest.groovy new file mode 100644 index 0000000000..1aef78f0d5 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/GenericGetVnfTest.groovy @@ -0,0 +1,180 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts + +import com.github.tomakehurst.wiremock.junit.WireMockRule +import org.camunda.bpm.engine.ProcessEngineServices +import org.camunda.bpm.engine.RepositoryService +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.camunda.bpm.engine.repository.ProcessDefinition +import org.junit.Assert +import org.junit.Before +import org.junit.Ignore +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.ArgumentCaptor +import org.mockito.Captor +import org.mockito.Mockito +import org.mockito.MockitoAnnotations +import org.mockito.runners.MockitoJUnitRunner +import org.onap.so.bpmn.core.WorkflowException + +import static com.github.tomakehurst.wiremock.client.WireMock.* +import static org.mockito.Mockito.mock +import static org.mockito.Mockito.times +import static org.mockito.Mockito.when + +@RunWith(MockitoJUnitRunner.class) +@Ignore +class GenericGetVnfTest { + + def prefix = "GENGV_" + + @Rule + public WireMockRule wireMockRule = new WireMockRule(28090) + + @Captor + static ArgumentCaptor captor = ArgumentCaptor.forClass(ExecutionEntity.class) + + + @Before + public void init() + { + MockitoAnnotations.initMocks(this) + } + + @Test + public void testGetVnfByName() { + + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090") + when(mockExecution.getVariable(prefix+"vnfName")).thenReturn("genricVnf_test") + when(mockExecution.getVariable(prefix+"type")).thenReturn("generic-vnf") + when(mockExecution.getVariable("mso.workflow.DoCreateVfModule.aai.generic-vnf.uri")).thenReturn("/aai/v9/network/generic-vnfs/generic-vnf") + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/") + + mockData() + GenericGetVnf obj = new GenericGetVnf() + obj.getVnfByName(mockExecution) + + Mockito.verify(mockExecution).setVariable("prefix","GENGV_") + Mockito.verify(mockExecution).setVariable(prefix+"getVnfPath","http://localhost:28090/aai/v9/network/generic-vnfs/generic-vnf?vnf-name=genricVnf_test&depth=1") + } + + @Test + public void testGetVnfByNameEndpointNull() { + + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable("aai.endpoint")).thenReturn(null) + when(mockExecution.getVariable(prefix+"vnfName")).thenReturn("genricVnf_test") + when(mockExecution.getVariable(prefix+"type")).thenReturn("generic-vnf") + when(mockExecution.getVariable("mso.workflow.DoCreateVfModule.aai.generic-vnf.uri")).thenReturn("/aai/v9/network/generic-vnfs/generic-vnf") + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/") + + mockData() + try{ + GenericGetVnf obj = new GenericGetVnf() + obj.getVnfByName(mockExecution) + }catch (Exception ex) { + println " Test End - Handle catch-throw BpmnError()! " + } + + Mockito.verify(mockExecution, times(3)).setVariable(captor.capture(), captor.capture()) + WorkflowException workflowException = captor.getValue() + Assert.assertEquals(9999, workflowException.getErrorCode()) + Assert.assertEquals("org.apache.http.client.ClientProtocolException", workflowException.getErrorMessage()) + } + + @Test + public void testGetVnfById() { + + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090") + when(mockExecution.getVariable(prefix+"vnfId")).thenReturn("genricVnf_test") + when(mockExecution.getVariable(prefix+"type")).thenReturn("generic-vnf") + when(mockExecution.getVariable("mso.workflow.DoCreateVfModule.aai.generic-vnf.uri")).thenReturn("/aai/v9/network/generic-vnfs/generic-vnf") + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/") + + mockData() + GenericGetVnf obj = new GenericGetVnf() + obj.getVnfById(mockExecution) + + Mockito.verify(mockExecution).setVariable("prefix","GENGV_") + Mockito.verify(mockExecution).setVariable(prefix+"getVnfPath","http://localhost:28090/aai/v9/network/generic-vnfs/generic-vnf/genricVnf_test?depth=1") + } + + @Test + public void testGetVnfByIdEndpointNull() { + + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable("aai.endpoint")).thenReturn(null) + when(mockExecution.getVariable(prefix+"vnfId")).thenReturn("genricVnf_test") + when(mockExecution.getVariable(prefix+"type")).thenReturn("generic-vnf") + when(mockExecution.getVariable("mso.workflow.DoCreateVfModule.aai.generic-vnf.uri")).thenReturn("/aai/v9/network/generic-vnfs/generic-vnf") + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/") + + mockData() + try{ + GenericGetVnf obj = new GenericGetVnf() + obj.getVnfById(mockExecution) + }catch (Exception ex) { + println " Test End - Handle catch-throw BpmnError()! " + } + + Mockito.verify(mockExecution, times(3)).setVariable(captor.capture(), captor.capture()) + WorkflowException workflowException = captor.getValue() + Assert.assertEquals(9999, workflowException.getErrorCode()) + Assert.assertEquals("org.apache.http.client.ClientProtocolException", workflowException.getErrorMessage()) + } + + private static ExecutionEntity setupMock() { + ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class) + when(mockProcessDefinition.getKey()).thenReturn("DoCreateVfModule") + RepositoryService mockRepositoryService = mock(RepositoryService.class) + when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition) + when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("DoCreateVfModule") + when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100") + ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class) + when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService) + + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + // Initialize prerequisite variables + when(mockExecution.getId()).thenReturn("100") + when(mockExecution.getProcessDefinitionId()).thenReturn("DoCreateVfModule") + when(mockExecution.getProcessInstanceId()).thenReturn("DoCreateVfModule") + when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices) + when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition) + + return mockExecution + } + + private static void mockData() { + stubFor(get(urlMatching(".*/aai/v[0-9]+/network/generic-vnfs/generic-vnf.*")) + .willReturn(aResponse() + .withStatus(200).withHeader("Content-Type", "text/xml") + .withBodyFile("GenericFlows/getGenericVnfResponse.xml"))) + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/GenericPutServiceTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/GenericPutServiceTest.groovy new file mode 100644 index 0000000000..d4ea8ce71f --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/GenericPutServiceTest.groovy @@ -0,0 +1,235 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts + +import static org.mockito.Mockito.* +import static org.onap.so.bpmn.mock.StubResponseAAI.MockPutServiceInstance; + +import org.camunda.bpm.engine.ProcessEngineServices +import org.camunda.bpm.engine.RepositoryService +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.camunda.bpm.engine.repository.ProcessDefinition +import org.junit.Before +import org.junit.Ignore +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.MockitoAnnotations +import org.mockito.internal.debugging.MockitoDebuggerImpl +import org.mockito.runners.MockitoJUnitRunner + +import com.github.tomakehurst.wiremock.client.WireMock +import com.github.tomakehurst.wiremock.junit.WireMockRule +import org.apache.commons.lang3.* + +@RunWith(MockitoJUnitRunner.class) +@Ignore +class GenericPutServiceTest { + + @Rule + public WireMockRule wireMockRule = new WireMockRule(8090); + + @Before + public void init() + { + MockitoAnnotations.initMocks(this) + + } + + @Test + public void preProcessRequest() { + + + println "************ preProcessRequest ************* " + + ExecutionEntity mockExecution = setupMock() + + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable("GENPS_globalSubscriberId")).thenReturn("1604-MVM-26") + when(mockExecution.getVariable("GENPS_serviceInstanceId")).thenReturn("MIS%2F1604%2F0026%2FSW_INTERNET") + when(mockExecution.getVariable("GENPS_serviceType")).thenReturn("SDN-ETHERNET-INTERNET") + when(mockExecution.getVariable("GENPS_serviceInstanceData")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4") + when(mockExecution.getVariable("GENPS_type")).thenReturn("service-instance") + + GenericPutService putServiceInstance= new GenericPutService() + putServiceInstance.preProcessRequest(mockExecution) + + // check the sequence of variable invocation + //MockitoDebuggerImpl preDebugger = new MockitoDebuggerImpl() + //preDebugger.printInvocations(mockExecution) + + verify(mockExecution, atLeast(1)).getVariable("isDebugLogEnabled") + verify(mockExecution).setVariable("prefix", "GENPS_") + + // execution.getVariable("isDebugLogEnabled") + + verify(mockExecution).setVariable("GENPS_SuccessIndicator", false) + // verify(mockExecution).setVariable("globalSubscriberId", "1604-MVM-26") + // verify(mockExecution).setVariable("serviceInstanceId", "MIS%2F1604%2F0026%2FSW_INTERNET") + // verify(mockExecution).setVariable("serviceType", "SDN-ETHERNET-INTERNET") + // verify(mockExecution).setVariable("ServiceInstanceData", "f70e927b-6087-4974-9ef8-c5e4d5847ca4") + + + } + + + @Test + @Ignore + public void putServiceInstance() { + println "************ putServiceInstance ************* " + + WireMock.reset(); + + MockPutServiceInstance("1604-MVM-26", "SDN-ETHERNET-INTERNET", "MIS%252F1604%252F0026%252FSW_INTERNET", "GenericPutServiceInstance/GenericPutServiceInstance_PutServiceInstance_AAIResponse_Success.xml"); + ExecutionEntity mockExecution = setupMock() + + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable("GENPS_globalSubscriberId")).thenReturn("1604-MVM-26") + when(mockExecution.getVariable("GENPS_serviceInstanceId")).thenReturn("MIS%2F1604%2F0026%2FSW_INTERNET") + when(mockExecution.getVariable("GENPS_serviceType")).thenReturn("SDN-ETHERNET-INTERNET") + when(mockExecution.getVariable("GENPS_serviceInstanceData")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4") + when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:8090") + when(mockExecution.getVariable("mso.workflow.PutServiceInstance.aai.business.customer.uri")).thenReturn("/aai/v7/business/customers/customer") + when(mockExecution.getVariable("GENPS_serviceInstanceData")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4") + when(mockExecution.getVariable("GENPS_type")).thenReturn("service-instance") + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/') + when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn("7") + when(mockExecution.getVariable("mso.workflow.default.aai.v7.customer.uri")).thenReturn("/aai/v7/business/customers/customer") + when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7") + when(mockExecution.getVariable("aai.auth")).thenReturn("757A94191D685FD2092AC1490730A4FC") + + GenericPutService serviceInstance= new GenericPutService() + serviceInstance.putServiceInstance(mockExecution) + + // check the sequence of variable invocation + MockitoDebuggerImpl preDebugger = new MockitoDebuggerImpl() + preDebugger.printInvocations(mockExecution) + + verify(mockExecution, atLeast(1)).getVariable("isDebugLogEnabled") + verify(mockExecution).setVariable("prefix", "GENPS_") + + // execution.getVariable("isDebugLogEnabled") + // verify(mockExecution).setVariable("GENPSI_serviceInstanceData","f70e927b-6087-4974-9ef8-c5e4d5847ca4") + + String servicePayload = """f70e927b-6087-4974-9ef8-c5e4d5847ca4""" as String + verify(mockExecution).setVariable("GENPS_serviceInstancePayload",servicePayload) + + String serviceAaiPath = "http://localhost:28090/aai/v7/business/customers/customer/1604-MVM-26/service-subscriptions/service-subscription/SDN-ETHERNET-INTERNET/service-instances/service-instance/MIS%252F1604%252F0026%252FSW_INTERNET" + verify(mockExecution).setVariable("GENPS_putServiceInstanceAaiPath", serviceAaiPath) + + int responseCode = 200 + verify(mockExecution).setVariable("GENPS_putServiceInstanceResponseCode", responseCode) + + String aaiResponse = """ + + + + + + + + +""" + + verify(mockExecution).setVariable("GENPS_putServiceInstanceResponse", aaiResponse) + + verify(mockExecution).setVariable("GENPS_SuccessIndicator", true) + } + + @Test + @Ignore + public void putServiceInstance_404() { + + + println "************ putServiceInstance ************* " + + WireMock.reset(); + + ExecutionEntity mockExecution = setupMock() + + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable("GENPS_globalSubscriberId")).thenReturn("1604-MVM-26") + when(mockExecution.getVariable("GENPS_serviceInstanceId")).thenReturn("MIS%2F1604%2F0026%2FSW_INTERNET") + when(mockExecution.getVariable("GENPS_serviceType")).thenReturn("SDN-ETHERNET-INTERNET") + when(mockExecution.getVariable("GENPS_ServiceInstanceData")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4") + when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:8090") + when(mockExecution.getVariable("mso.workflow.PutServiceInstance.aai.business.customer_uri")).thenReturn("/aai/v7/business/customers/customer") + when(mockExecution.getVariable("GENPS_ServiceInstanceData")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4") + + GenericPutService serviceInstance= new GenericPutService() + serviceInstance.putServiceInstance(mockExecution) + + // check the sequence of variable invocation + MockitoDebuggerImpl preDebugger = new MockitoDebuggerImpl() + preDebugger.printInvocations(mockExecution) + + verify(mockExecution, atLeast(1)).getVariable("isDebugLogEnabled") + verify(mockExecution).setVariable("prefix", "GENPS_") + + // execution.getVariable("isDebugLogEnabled") + + + verify(mockExecution).setVariable("GENPS_serviceInstanceData","f70e927b-6087-4974-9ef8-c5e4d5847ca4") + + String serviceInstancepayload = """f70e927b-6087-4974-9ef8-c5e4d5847ca4 + """ as String + verify(mockExecution).setVariable("GENPS_serviceInstancePayload",serviceInstancepayload) + + String serviceInstanceAaiPath = "http://localhost:8090/aai/v7/business/customers/customer/1604-MVM-26/service-subscriptions/service-subscription/SDN-ETHERNET-INTERNET/service-instances/service-instance/MIS%252F1604%252F0026%252FSW_INTERNET" + verify(mockExecution).setVariable("GENPS_putServiceInstanceAaiPath", serviceInstanceAaiPath) + + int responseCode = 404 + verify(mockExecution).setVariable("GENPS_putServiceInstanceResponseCode", responseCode) + + String aaiResponse = "" + verify(mockExecution).setVariable("GENPS_putServiceInstanceResponse", aaiResponse) + + verify(mockExecution).setVariable("GENPS_SuccessIndicator", false) + + + } + + + private ExecutionEntity setupMock() { + + ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class) + when(mockProcessDefinition.getKey()).thenReturn("PutServiceInstance") + RepositoryService mockRepositoryService = mock(RepositoryService.class) + when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition) + when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("PutServiceInstance") + when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100") + ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class) + when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService) + + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + // Initialize prerequisite variables + + when(mockExecution.getId()).thenReturn("100") + when(mockExecution.getProcessDefinitionId()).thenReturn("PutServiceInstance") + when(mockExecution.getProcessInstanceId()).thenReturn("PutServiceInstance") + when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices) + when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition) + + return mockExecution + } + +} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/MsoGroovyTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/MsoGroovyTest.groovy new file mode 100644 index 0000000000..cd95a3a733 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/MsoGroovyTest.groovy @@ -0,0 +1,72 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts + +import static org.mockito.Mockito.* + +import org.mockito.MockitoAnnotations +import org.mockito.runners.MockitoJUnitRunner +import org.mockito.internal.debugging.MockitoDebuggerImpl +import org.camunda.bpm.engine.ProcessEngineServices +import org.camunda.bpm.engine.RepositoryService +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.camunda.bpm.engine.impl.pvm.process.ProcessDefinitionImpl +import org.camunda.bpm.engine.repository.ProcessDefinition + +abstract class MsoGroovyTest { + + protected ExecutionEntity setupMock(String procName) { + ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class) + when(mockProcessDefinition.getKey()).thenReturn(procName) + + RepositoryService mockRepositoryService = mock(RepositoryService.class) + when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition) + when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn(procName) + when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100") + + ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class) + when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService) + + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices) + + return mockExecution + } + + protected ExecutionEntity setupMockWithPrefix(String procName, String prefix) { + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + + when(mockExecution.getVariable("prefix")).thenReturn(prefix) + + ProcessEngineServices processEngineServices = mock(ProcessEngineServices.class) + RepositoryService repositoryService = mock(RepositoryService.class) + ProcessDefinition processDefinition = mock(ProcessDefinition.class) + + when(mockExecution.getProcessEngineServices()).thenReturn(processEngineServices) + when(processEngineServices.getRepositoryService()).thenReturn(repositoryService) + when(repositoryService.getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(processDefinition) + when(processDefinition.getKey()).thenReturn(procName) + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + return mockExecution + } + + +} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/MsoUtilsTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/MsoUtilsTest.groovy new file mode 100644 index 0000000000..dfcf69a931 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/MsoUtilsTest.groovy @@ -0,0 +1,291 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts + +// JUnit 4 +import org.junit.Test +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; + +import static groovy.test.GroovyAssert.shouldFail + +import groovy.util.slurpersupport.NodeChild + +import static groovy.test.GroovyAssert.assertTrue +import static groovy.test.GroovyAssert.assertEquals +import static groovy.test.GroovyAssert.assertNotNull; + +import org.onap.so.bpmn.common.scripts.MsoUtils; +import org.apache.commons.lang3.* + + +class MsoUtilsTest { + + def utils = new MsoUtils() + def origXmlResponse = null + // Expected rebuilds + def expected_buildElements = "10Kbps1192.168.1.15192.168.1.15282192.168.1.16192.168.1.1628" + def expected_rebuildDhcp = "YNY192.168.1.7192.168.1.8192.155.2.328192.168.1.5192.168.1.62.2.2.11.1.1.1192.155.2.428192.168.1.6192.168.1.72.2.2.21.1.1.2N1:51:60:0281:12:23:34:40:0281:12:23:34:4" + def expected_rebuildFirewallLite = "YN0.0.0.11Y110.0.0.22Y22:0Y33:1Y44" + def expected_rebuildInternetEvcAccess = "8Mbpsds" + def expected_rebuildInternetServiceChangeDetails = "10Kbps1192.168.1.15192.168.1.15282192.168.1.16192.168.1.162812001:1890:12e3:2da::2001:1890:12e3:2da::2812001:1890:12e3:2da::2001:1890:12e3:2da::28" + def expected_rebuildInternetServiceChangeDetailsWithVrLanParams = "10Kbps10.10.7.14101192.168.1.15192.168.1.15282192.168.1.16192.168.1.162812001:1890:12e3:2da::2001:1890:12e3:2da::2812001:1890:12e3:2da::2001:1890:12e3:2da::28" + def expected_rebuildL2Home = "AS/VLXM/003717//SWMultiPointMTSNJA4LCP1" + def expected_rebuildL2HomeFor_aic_clli = "AS/VLXM/003717//SWMultiPointMTSNJA4LCP12.5" + def expected_rebuildNat = "Y0.0.0.00.0.0.00.0.0.00.0.0.10.0.0.10.0.0.1" + def expected_rebuildPat = "NY192.168.1.440192.168.1.5192.168.1.4528192.168.1.6" + def expected_rebuildStaticRoutes = "255.255.252.128192.168.1.15255.255.252.228192.168.1.15255.255.252.328192.168.1.152001:1890:12e3:2da::282001:1890:12e3:2da::2001:1890:12e3:2da::282001:1890:12e3:2da::" + def expected_rebuildUcpeVmsServiceInformation = "AVPN1Active2StandbyhostnameactivecodeOOB11ZZJUNIPERMODEL11111122HYJUNIPERMODEL222222" + def expected_rebuildVrLan = "noneprimary10.192.27.254242620:0:10d0:f:ffff:ffff:ffff:fffe64162.200.3.1442001:1890:12e3:2da::1192.168.1.2192.168.1.1281192.168.1.72192.168.1.71281192.168.1.68192.168.1.672812001:1890:12e3:2da::2001:1890:12e3:2da::2812001:1890:12e3:2da::2001:1890:12e3:3da::2812001:1890:12e3:2da::2001:1890:12e3:4da::28YNY192.168.1.7192.168.1.8192.155.2.328192.168.1.5192.168.1.62.2.2.11.1.1.1192.155.2.428192.168.1.6192.168.1.72.2.2.21.1.1.2N1:51:60:0281:12:23:34:40:0281:12:23:34:4NY192.168.1.440192.168.1.5192.168.1.4528192.168.1.6Y0.0.0.00.0.0.00.0.0.00.0.0.10.0.0.10.0.0.1YN0.0.0.11Y110.0.0.22Y22:0Y33:1Y44255.255.252.128192.168.1.15255.255.252.228192.168.1.15255.255.252.328192.168.1.152001:1890:12e3:2da::282001:1890:12e3:2da::2001:1890:12e3:2da::282001:1890:12e3:2da::" + def expected_rebuildVrLanInterfacePartial = "primary10.192.27.254242620:0:10d0:f:ffff:ffff:ffff:fffe64162.200.3.1442001:1890:12e3:2da::1192.168.1.2192.168.1.1281192.168.1.72192.168.1.71281192.168.1.68192.168.1.67281192.168.1.15192.168.1.15282192.168.1.16192.168.1.162812001:1890:12e3:2da::2001:1890:12e3:2da::2812001:1890:12e3:2da::2001:1890:12e3:3da::2812001:1890:12e3:2da::2001:1890:12e3:4da::2812001:1890:12e3:2da::2001:1890:12e3:2da::2812001:1890:12e3:2da::2001:1890:12e3:2da::28" + + @Before + public void setUp() { + def responseAsString = getFile("sdncadaptercallbackrequest.xml") + def varrequestData=utils.getNodeText(responseAsString,"RequestData") + origXmlResponse = utils.getNodeXml(varrequestData, "layer3-service-list").drop(38).trim() + + } + + @Test + public void testBuildL2Home() { + def rebuildL2Home = utils.buildL2HomingInformation(origXmlResponse) + println " rebuildL2Home: " + println " actual - " + rebuildL2Home + println " expected - " + expected_rebuildL2Home + assertEquals("rebuildL2Home - expected vs actual", expected_rebuildL2Home, rebuildL2Home) + } + + @Test + public void testBuildInternetEvcAccess() { + def rebuildInternetEvcAccess = utils.buildInternetEvcAccessInformation(origXmlResponse) + println " rebuildInternetEvcAccess: " + println " actual - " + rebuildInternetEvcAccess + println " expected - " + expected_rebuildInternetEvcAccess + assertEquals("rebuildInternetEvcAccess - expected vs actual", expected_rebuildInternetEvcAccess, rebuildInternetEvcAccess) + } + + @Test + public void testBuildInternetServiceChangeDetails() { + def rebuildInternetServiceChangeDetails = utils.buildInternetServiceChangeDetails(origXmlResponse) + println " rebuildInternetServiceChangeDetails: " + println " actual - " + rebuildInternetServiceChangeDetails + println " expected - " + expected_rebuildInternetServiceChangeDetails + assertEquals("rebuildInternetServiceChangeDetails - expected vs actual", expected_rebuildInternetServiceChangeDetails, rebuildInternetServiceChangeDetails) + } + + @Test + public void testBuildInternetServiceChangeDetailsWithVrLanParams() { + def responseAsString = getFile("sdncadaptercallbackrequest_with_aic_version.xml") + def varrequestData=utils.getNodeText(responseAsString,"RequestData") + def xmlResponse = utils.getNodeXml(varrequestData, "layer3-service-list").drop(38).trim() + def rebuildInternetServiceChangeDetails = utils.buildInternetServiceChangeDetails(xmlResponse) + println " rebuildInternetServiceChangeDetails: " + println " actual - " + rebuildInternetServiceChangeDetails + println " expected - " + expected_rebuildInternetServiceChangeDetails + assertEquals("rebuildInternetServiceChangeDetails - expected vs actual", expected_rebuildInternetServiceChangeDetailsWithVrLanParams, rebuildInternetServiceChangeDetails) + } + + // Coming v100 + @Test + @Ignore + public void testBuildUcpeVmsServiceInformation() { + def rebuildUcpeVmsServiceInformation = utils.buildUcpeVmsServiceInformation(origXmlResponse) + println " rebuildUcpeVmsServiceInformation: " + println " actual - " + rebuildUcpeVmsServiceInformation + println " expected - " + expected_rebuildUcpeVmsServiceInformation + assertEquals("rebuildUcpeVmsServiceInformation - expected vs actual", expected_rebuildUcpeVmsServiceInformation, rebuildUcpeVmsServiceInformation) + } + + @Test + public void testBuildElements() { + // testing utility codes: buildElements() & buildElementsUnblunded() + def internetServiceChangeDetails = utils.getNodeXml(origXmlResponse, "internet-service-change-details").drop(38).trim() + def buildElements = '' + buildElements = "" + buildElements += utils.buildElements(internetServiceChangeDetails, ["internet-evc-speed-value"], "") + buildElements += utils.buildElements(internetServiceChangeDetails, ["internet-evc-speed-units"], "") + def tProvidedV4LanPublicPrefixesChangesList = ["request-index", "v4-next-hop-address", "v4-lan-public-prefix", "v4-lan-public-prefix-length"] + buildElements += utils.buildElementsUnbounded(internetServiceChangeDetails, tProvidedV4LanPublicPrefixesChangesList, "t-provided-v4-lan-public-prefixes") + buildElements += "" + println " buildElements: " + println " actual - " + buildElements + println " expected - " + expected_buildElements + assertEquals("buildElements - expected vs actual", expected_buildElements, buildElements) + } + + @Test + public void testBuildVrLan() { + def rebuildVrLan = utils.buildVrLan(origXmlResponse) + println " rebuildVrLans: " + println " actual - " + rebuildVrLan + println " expected - " + expected_rebuildVrLan + assertEquals("rebuildVrLan - expected vs actual", expected_rebuildVrLan, rebuildVrLan) + } + + @Test + public void testBuildVrLanInterfacePartial() { + def rebuildVrLanInterfacePartial = utils.buildVrLanInterfacePartial(origXmlResponse) + println " rebuildVrLanInterfacePartial: " + println " actual - " + rebuildVrLanInterfacePartial + println " expected - " + expected_rebuildVrLanInterfacePartial + assertEquals("rebuildVrLanInterfacePartial - expected vs actual", expected_rebuildVrLanInterfacePartial, rebuildVrLanInterfacePartial) + } + + @Test + public void testBuildDhcp() { + def rebuildDhcp = utils.buildDhcp(origXmlResponse) + println " rebuildDhcp: " + println " actual - " + rebuildDhcp + println " expected - " + expected_rebuildDhcp + assertEquals("rebuildDhcp - expected vs actual", expected_rebuildDhcp, rebuildDhcp) + } + + @Test + public void testBuildPat() { + def rebuildPat = utils.buildPat(origXmlResponse) + println " rebuildPat: " + println " actual - " + rebuildPat + println " expected - " + expected_rebuildPat + assertEquals("rebuildPat - expected vs actual", expected_rebuildPat, rebuildPat) + } + + @Test + public void testBuildNat() { + def rebuildNat = utils.buildNat(origXmlResponse) + println " rebuildNat: " + println " actual - " + rebuildNat + println " expected - " + expected_rebuildNat + assertEquals("rebuildNat - expected vs actual", expected_rebuildNat, rebuildNat) + } + + @Test + public void testBuildFirewallLite() { + def rebuildFirewallLite = utils.buildFirewallLite(origXmlResponse) + println " rebuildFirewallLite: " + println " actual - " + rebuildFirewallLite + println " expected - " + expected_rebuildFirewallLite + assertEquals("rebuildFirewallLite - expected vs actual", expected_rebuildFirewallLite, rebuildFirewallLite) + } + + @Test + public void testBuildStaticRoutes() { + def rebuildStaticRoutes = utils.buildStaticRoutes(origXmlResponse) + println " rebuildStaticRoutes: " + println " actual - " + rebuildStaticRoutes + println " expected - " + expected_rebuildStaticRoutes + assertEquals("rebuildStaticRoutes - expected vs actual", expected_rebuildStaticRoutes, rebuildStaticRoutes) + } + + @Test + public void testGetBasicAuth(){ + def encodedAuth = utils.getBasicAuth("3E3CFA7BE2F6107AAD4AAA65F8976690","07a7159d3bf51a0e53be7a8f89699be7") + assertEquals("Basic bXlTdHJpbmc=", encodedAuth) + } + + @Test + public void testEncrypt(){ + def encrypted = utils.encrypt("myString","07a7159d3bf51a0e53be7a8f89699be7") + assertEquals("3E3CFA7BE2F6107AAD4AAA65F8976690", encrypted) + + //use to get value for urn properties + //println(utils.encrypt("password")) + } + + @Test + public void testDecrypt(){ + def decrypted = utils.decrypt("3E3CFA7BE2F6107AAD4AAA65F8976690", "07a7159d3bf51a0e53be7a8f89699be7") + assertEquals("myString", decrypted) + } + + @Test + public void testGetPBGFList(){ + def responseAsString = getFile("sdncDeleteResponse.xml") + def nodes = utils.getPBGFList("true", responseAsString) + //assertEquals(2, nodes.size()) + while(!nodes.empty){ + def myBGFXML = nodes.remove(0) + def myBGF= new XmlSlurper().parseText(myBGFXML) + println "borderElmtId: " + myBGF.'border-element-id' + println "vlanid: " + myBGF.'vlan-id' +"\n" + } + } + + @Test + public void testBuildL2HomingInformation_with_aic_clli() { + + def responseAsString = getFile("sdncadaptercallbackrequest_with_aic_version.xml") + def varrequestData=utils.getNodeText(responseAsString,"RequestData") + def xmlResponse = utils.getNodeXml(varrequestData, "layer3-service-list").drop(38).trim() + def rebuildL2Home = utils.buildL2HomingInformation(xmlResponse) + println " rebuildL2Home: " + println " actual - " + rebuildL2Home + println " expected - " + expected_rebuildL2Home + assertEquals("rebuildL2Home - expected vs actual", expected_rebuildL2HomeFor_aic_clli, rebuildL2Home) + } + + @Test + public void testUnescapeNodeContents() { + String output = "AT&T" + String noChangeInput = "AT&T" + String decodeWithNamespacesNodeInput = '<b>AT&amp;T</b>' + String decodeWithNamespacesInput = '<b>AT&amp;T</b>' + String decodeWithNamespacesOutput = 'AT&T' + String decodeWithoutNamespacesInput = '<b>AT&amp;T</b>' + String decodeWithoutNamespacesOutput = 'AT&T' + String normalString = "AT&T" + NodeChild noChangeInputNode = new XmlSlurper().parseText(noChangeInput).'**'.find {it.name() == 'a'} + NodeChild decodeWithNamespacesInputNode = new XmlSlurper().parseText(decodeWithNamespacesNodeInput).'**'.find {it.name() == 'a'} + NodeChild decodeWithoutNamespacesInputNode = new XmlSlurper().parseText(decodeWithoutNamespacesInput).'**'.find {it.name() == 'a'} + NodeChild normalStringNode = new XmlSlurper().parseText(normalString).'**'.find {it.name() == 'a'} + + assertEquals("no change", output, utils.unescapeNodeContents(noChangeInputNode, noChangeInput)) + assertEquals("single unescape", decodeWithNamespacesOutput, utils.unescapeNodeContents(decodeWithNamespacesInputNode, decodeWithNamespacesInput)) + assertEquals("single unescape", decodeWithoutNamespacesOutput, utils.unescapeNodeContents(decodeWithoutNamespacesInputNode, decodeWithoutNamespacesInput)) + assertEquals("unescape normal string", "AT&T", utils.unescapeNodeContents(normalStringNode, "AT&T")) + } + + @Test + public void testXmlEncode() { + + String expected = "&amp;"; + + assertEquals("is double encoded", expected, MsoUtils.xmlEscape("&")) + + } + public String getFile(String fileName) { + def SLASH = File.separator + def pathBase = ' ' + def fileAsString = '' + try { + pathBase = new File(".").getCanonicalPath() + //println "pathBase " + pathBase + "${SLASH}src${SLASH}test${SLASH}resources${SLASH}${fileName}" + fileAsString = new File(pathBase, "${SLASH}src${SLASH}test${SLASH}resources${SLASH}${fileName}").getText() + } catch (Exception ex) { + println " *** getFile error: " + ex.getStackTrace() + } finally { + return fileAsString + } + } + + +} \ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/NetworkUtilsTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/NetworkUtilsTest.groovy new file mode 100644 index 0000000000..510dcf665c --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/NetworkUtilsTest.groovy @@ -0,0 +1,101 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts + +import org.junit.Before +import org.mockito.MockitoAnnotations + +import static org.mockito.Mockito.* +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import static org.junit.Assert.*; +import org.junit.Test; + +class NetworkUtilsTest { + + def volumeRequestXml = """ + + CREATE_VF_MODULE_VOL + VID + + + + + MSOTESTVOL101a-vSAMP12_base_vol_module-0 + Test/vSAMP12 + vSAMP12::base::module-0 + 2.0 + mdt1 + 88a6ca3ee0394ade9403f075db23167e + a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb + + + + STMTN5MMSC20 + US1117MTSNJVBR0246 + +""" + + + @Test + public void testIsRollbackEnabled() { + + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("mso.rollback")).thenReturn(true) + + NetworkUtils networkUtils = new NetworkUtils() + def rollbackEnabled = networkUtils.isRollbackEnabled(mockExecution, volumeRequestXml) + + assertEquals(true, rollbackEnabled) + + } + + @Test + public void testIsRollbackEnabled2() { + + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') + when(mockExecution.getVariable("mso.rollback")).thenReturn(false) + + NetworkUtils networkUtils = new NetworkUtils() + def rollbackEnabled = networkUtils.isRollbackEnabled(mockExecution, volumeRequestXml) + + assertEquals(false, rollbackEnabled) + + } + + @Test + public void testGetIpvVersion() { + + NetworkUtils networkUtils = new NetworkUtils() + println "test: ipv4" + String version4 = networkUtils.getIpvVersion("ipv4") + assertEquals("4", version4) + println "test: ipv6" + String version6 = networkUtils.getIpvVersion("ipv6") + assertEquals("6", version6) + println "test: 4" + String versionDigit4 = networkUtils.getIpvVersion("4") + assertEquals("4", versionDigit4) + + } + +} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/PrepareUpdateAAIVfModuleTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/PrepareUpdateAAIVfModuleTest.groovy new file mode 100644 index 0000000000..c5b8fab9eb --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/PrepareUpdateAAIVfModuleTest.groovy @@ -0,0 +1,171 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts + +import com.github.tomakehurst.wiremock.junit.WireMockRule +import org.camunda.bpm.engine.ProcessEngineServices +import org.camunda.bpm.engine.RepositoryService +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.camunda.bpm.engine.repository.ProcessDefinition +import org.junit.Before +import org.junit.Ignore +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.ArgumentCaptor +import org.mockito.Captor +import org.mockito.MockitoAnnotations +import org.mockito.runners.MockitoJUnitRunner +import org.onap.so.bpmn.mock.StubResponseAAI + +import static org.mockito.Mockito.* + +@RunWith(MockitoJUnitRunner.class) +@Ignore +class PrepareUpdateAAIVfModuleTest { + @Rule + public WireMockRule wireMockRule = new WireMockRule(28090) + + @Captor + static ArgumentCaptor captor = ArgumentCaptor.forClass(ExecutionEntity.class) + + @Before + void init() throws IOException { + MockitoAnnotations.initMocks(this); + } + + @Test + void testGetGenericVnf() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable("PUAAIVfMod_vnfId")).thenReturn("skask") + when(mockExecution.getVariable("mso.workflow.default.aai.v8.generic-vnf.uri")).thenReturn("/aai/v8/network/generic-vnfs/generic-vnf") + when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090") + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/") + when(mockExecution.getVariable("mso.workflow.custom.PrepareUpdateAAIVfModule.aai.version")).thenReturn('8') + + StubResponseAAI.MockAAIVfModule() + + PrepareUpdateAAIVfModule obj = new PrepareUpdateAAIVfModule() + obj.getGenericVnf(mockExecution) + + verify(mockExecution).setVariable("PUAAIVfMod_getVnfResponseCode", 200) + } + + @Test + void testGetGenericVnfEndpointNull() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable("PUAAIVfMod_vnfId")).thenReturn("skask") + when(mockExecution.getVariable("mso.workflow.default.aai.v8.generic-vnf.uri")).thenReturn("/aai/v8/network/generic-vnfs/generic-vnf") + when(mockExecution.getVariable("aai.endpoint")).thenReturn(null) + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/") + when(mockExecution.getVariable("mso.workflow.custom.PrepareUpdateAAIVfModule.aai.version")).thenReturn('8') + + StubResponseAAI.MockAAIVfModule() + try { + PrepareUpdateAAIVfModule obj = new PrepareUpdateAAIVfModule() + obj.getGenericVnf(mockExecution) + } catch (Exception ex) { + println " Test End - Handle catch-throw BpmnError()! " + } + + verify(mockExecution).setVariable("PUAAIVfMod_getVnfResponseCode", 500) + verify(mockExecution).setVariable("PUAAIVfMod_getVnfResponse", "AAI GET Failed:org.apache.http.client.ClientProtocolException") + } + + @Test + void testUpdateVfModule() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable("PUAAIVfMod_vnfId")).thenReturn("skask") + when(mockExecution.getVariable("PUAAIVfMod_vfModuleId")).thenReturn("supercool") + + def node = new Node(null, 'vfModule') + new Node(node, 'vf-module-name', "abc") + VfModule vfModule = new VfModule(node, true) + + when(mockExecution.getVariable("PUAAIVfMod_vfModule")).thenReturn(vfModule) + when(mockExecution.getVariable("PUAAIVfMod_orchestrationStatus")).thenReturn("created") + when(mockExecution.getVariable("mso.workflow.default.aai.v8.generic-vnf.uri")).thenReturn("/aai/v8/network/generic-vnfs/generic-vnf") + when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090") + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/") + when(mockExecution.getVariable("mso.workflow.custom.PrepareUpdateAAIVfModule.aai.version")).thenReturn('8') + + StubResponseAAI.MockAAIVfModule() + PrepareUpdateAAIVfModule obj = new PrepareUpdateAAIVfModule() + obj.updateVfModule(mockExecution) + + verify(mockExecution).setVariable("PUAAIVfMod_updateVfModuleResponseCode", 200) + verify(mockExecution).setVariable("PUAAIVfMod_updateVfModuleResponse", "") + } + + @Test + void testUpdateVfModuleEndpointNull() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable("PUAAIVfMod_vnfId")).thenReturn("skask") + when(mockExecution.getVariable("PUAAIVfMod_vfModuleId")).thenReturn("supercool") + + def node = new Node(null, 'vfModule') + new Node(node, 'vf-module-name', "abc") + VfModule vfModule = new VfModule(node, true) + + when(mockExecution.getVariable("PUAAIVfMod_vfModule")).thenReturn(vfModule) + when(mockExecution.getVariable("PUAAIVfMod_orchestrationStatus")).thenReturn("created") + when(mockExecution.getVariable("mso.workflow.default.aai.v8.generic-vnf.uri")).thenReturn("/aai/v8/network/generic-vnfs/generic-vnf") + when(mockExecution.getVariable("aai.endpoint")).thenReturn(null) + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/") + when(mockExecution.getVariable("mso.workflow.custom.PrepareUpdateAAIVfModule.aai.version")).thenReturn('8') + + StubResponseAAI.MockAAIVfModule() + try { + PrepareUpdateAAIVfModule obj = new PrepareUpdateAAIVfModule() + obj.updateVfModule(mockExecution) + } catch (Exception ex) { + println " Test End - Handle catch-throw BpmnError()! " + } + + verify(mockExecution).setVariable("PUAAIVfMod_updateVfModuleResponseCode", 500) + verify(mockExecution).setVariable("PUAAIVfMod_updateVfModuleResponse", "AAI PATCH Failed:org.apache.http.client.ClientProtocolException") + } + + private static ExecutionEntity setupMock() { + ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class) + when(mockProcessDefinition.getKey()).thenReturn("PrepareUpdateAAIVfModule") + RepositoryService mockRepositoryService = mock(RepositoryService.class) + when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition) + when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("PrepareUpdateAAIVfModule") + when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100") + ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class) + when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService) + + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + // Initialize prerequisite variables + when(mockExecution.getId()).thenReturn("100") + when(mockExecution.getProcessDefinitionId()).thenReturn("PrepareUpdateAAIVfModule") + when(mockExecution.getProcessInstanceId()).thenReturn("PrepareUpdateAAIVfModule") + when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices) + when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition) + + return mockExecution + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterRestV1Test.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterRestV1Test.groovy new file mode 100644 index 0000000000..1079bb48b3 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterRestV1Test.groovy @@ -0,0 +1,151 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts + +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.junit.Before +import org.junit.Ignore +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.MockitoAnnotations +import org.mockito.internal.debugging.MockitoDebuggerImpl +import org.mockito.runners.MockitoJUnitRunner +import org.onap.so.bpmn.mock.FileUtil +import org.onap.so.bpmn.core.json.JsonUtils + +import static org.mockito.Mockito.* + +@RunWith(MockitoJUnitRunner.class) +public class SDNCAdapterRestV1Test { + + @Before + public void init() + { + MockitoAnnotations.initMocks(this) + } + + @Test + public void testPreProcessRequest() { + // bpTimeout is empty and "mso.adapters.sdnc.timeout" is defined + + String sdncAdapterWorkflowRequest = FileUtil.readResourceFile("__files/SDN-ETHERNET-INTERNET/SDNCAdapterRestV1/sdnc_request.json"); + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getVariable("prefix")).thenReturn("SDNCREST_") + when(mockExecution.getVariable("mso-request-id")).thenReturn("testMsoRequestId") + when(mockExecution.getVariable("SDNCREST_Request")).thenReturn(sdncAdapterWorkflowRequest) + when(mockExecution.getVariable("mso.adapters.po.auth")).thenReturn("3141634BF7E070AA289CF2892C986C0B") + when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7") + + when(mockExecution.getVariable("mso.adapters.sdnc.rest.endpoint")).thenReturn("http://localhost:18080/adapters/rest/v1/sdnc/") + + when(mockExecution.getVariable("mso.adapters.sdnc.timeout")).thenReturn("PT5M") + + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable("testProcessKey")).thenReturn("testProcessKey") + + + SDNCAdapterRestV1 sdncAdapterRestV1 = new SDNCAdapterRestV1() + sdncAdapterRestV1.preProcessRequest(mockExecution) + + MockitoDebuggerImpl debugger = new MockitoDebuggerImpl() + //debugger.printInvocations(mockExecution) + + + verify(mockExecution).setVariable("prefix","SDNCREST_") + + verify(mockExecution).setVariable("SDNCREST_SuccessIndicator",false) + verify(mockExecution).setVariable("SDNCREST_requestType","SDNCServiceRequest") + verify(mockExecution).setVariable("SDNCAResponse_CORRELATOR","0d883b7f-dd34-4e1b-9ed5-341d33052360-1511808197479") + verify(mockExecution).setVariable("SDNCREST_sdncAdapterMethod","POST") + verify(mockExecution).setVariable("SDNCREST_timeout","PT5M") + } + + @Test + public void testPreProcessRequestGoodTimeout() { + // bpTimeout is valid and "mso.adapters.sdnc.timeout" is undefined + + String sdncAdapterWorkflowRequest = FileUtil.readResourceFile("__files/SDN-ETHERNET-INTERNET/SDNCAdapterRestV1/sdnc_request.json"); + sdncAdapterWorkflowRequest = JsonUtils.addJsonValue(sdncAdapterWorkflowRequest, "SDNCServiceRequest.bpTimeout", "PT20S") + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getVariable("prefix")).thenReturn("SDNCREST_") + when(mockExecution.getVariable("mso-request-id")).thenReturn("testMsoRequestId") + when(mockExecution.getVariable("SDNCREST_Request")).thenReturn(sdncAdapterWorkflowRequest) + when(mockExecution.getVariable("mso.adapters.po.auth")).thenReturn("3141634BF7E070AA289CF2892C986C0B") + when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7") + + when(mockExecution.getVariable("mso.adapters.sdnc.rest.endpoint")).thenReturn("http://localhost:18080/adapters/rest/v1/sdnc/") + + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable("testProcessKey")).thenReturn("testProcessKey") + + + SDNCAdapterRestV1 sdncAdapterRestV1 = new SDNCAdapterRestV1() + sdncAdapterRestV1.preProcessRequest(mockExecution) + + MockitoDebuggerImpl debugger = new MockitoDebuggerImpl() + //debugger.printInvocations(mockExecution) + + + verify(mockExecution).setVariable("prefix","SDNCREST_") + + verify(mockExecution).setVariable("SDNCREST_SuccessIndicator",false) + verify(mockExecution).setVariable("SDNCREST_requestType","SDNCServiceRequest") + verify(mockExecution).setVariable("SDNCAResponse_CORRELATOR","0d883b7f-dd34-4e1b-9ed5-341d33052360-1511808197479") + verify(mockExecution).setVariable("SDNCREST_sdncAdapterMethod","POST") + verify(mockExecution).setVariable("SDNCREST_timeout","PT20S") + } + + @Test + @Ignore + public void testPreProcessRequestBadTimeout() { + // bpTimeout is invalid and "mso.adapters.sdnc.timeout" is undefined + + String sdncAdapterWorkflowRequest = FileUtil.readResourceFile("__files/SDN-ETHERNET-INTERNET/SDNCAdapterRestV1/sdnc_request.json"); + sdncAdapterWorkflowRequest = JsonUtils.addJsonValue(sdncAdapterWorkflowRequest, "SDNCServiceRequest.bpTimeout", "badTimeout") + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getVariable("prefix")).thenReturn("SDNCREST_") + when(mockExecution.getVariable("mso-request-id")).thenReturn("testMsoRequestId") + when(mockExecution.getVariable("SDNCREST_Request")).thenReturn(sdncAdapterWorkflowRequest) + when(mockExecution.getVariable("mso.adapters.po.auth")).thenReturn("3141634BF7E070AA289CF2892C986C0B") + when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7") + + when(mockExecution.getVariable("mso.adapters.sdnc.rest.endpoint")).thenReturn("http://localhost:18080/adapters/rest/v1/sdnc/") + + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable("testProcessKey")).thenReturn("testProcessKey") + + + SDNCAdapterRestV1 sdncAdapterRestV1 = new SDNCAdapterRestV1() + sdncAdapterRestV1.preProcessRequest(mockExecution) + + MockitoDebuggerImpl debugger = new MockitoDebuggerImpl() + //debugger.printInvocations(mockExecution) + + + verify(mockExecution).setVariable("prefix","SDNCREST_") + + verify(mockExecution).setVariable("SDNCREST_SuccessIndicator",false) + verify(mockExecution).setVariable("SDNCREST_requestType","SDNCServiceRequest") + verify(mockExecution).setVariable("SDNCAResponse_CORRELATOR","0d883b7f-dd34-4e1b-9ed5-341d33052360-1511808197479") + verify(mockExecution).setVariable("SDNCREST_sdncAdapterMethod","POST") + verify(mockExecution).setVariable("SDNCREST_timeout","PT10S") + } +} \ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterRestV2Test.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterRestV2Test.groovy new file mode 100644 index 0000000000..d7fe0ee208 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterRestV2Test.groovy @@ -0,0 +1,151 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts + +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.junit.Before +import org.junit.Ignore +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.MockitoAnnotations +import org.mockito.internal.debugging.MockitoDebuggerImpl +import org.mockito.runners.MockitoJUnitRunner +import org.onap.so.bpmn.mock.FileUtil +import org.onap.so.bpmn.core.json.JsonUtils + +import static org.mockito.Mockito.* + +@RunWith(MockitoJUnitRunner.class) +public class SDNCAdapterRestV2Test { + + @Before + public void init() + { + MockitoAnnotations.initMocks(this) + } + + @Test + public void testPreProcessRequest() { + // bpTimeout is empty and "mso.adapters.sdnc.timeout" is defined + + String sdncAdapterWorkflowRequest = FileUtil.readResourceFile("__files/SDN-ETHERNET-INTERNET/SDNCAdapterRestV1/sdnc_request.json"); + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getVariable("prefix")).thenReturn("SDNCREST_") + when(mockExecution.getVariable("mso-request-id")).thenReturn("testMsoRequestId") + when(mockExecution.getVariable("SDNCREST_Request")).thenReturn(sdncAdapterWorkflowRequest) + when(mockExecution.getVariable("mso.adapters.po.auth")).thenReturn("3141634BF7E070AA289CF2892C986C0B") + when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7") + + when(mockExecution.getVariable("mso.adapters.sdnc.rest.endpoint")).thenReturn("http://localhost:18080/adapters/rest/v1/sdnc/") + + when(mockExecution.getVariable("mso.adapters.sdnc.timeout")).thenReturn("PT5M") + + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable("testProcessKey")).thenReturn("testProcessKey") + + + SDNCAdapterRestV2 sdncAdapterRestV2 = new SDNCAdapterRestV2() + sdncAdapterRestV2.preProcessRequest(mockExecution) + + MockitoDebuggerImpl debugger = new MockitoDebuggerImpl() + //debugger.printInvocations(mockExecution) + + + verify(mockExecution).setVariable("prefix","SDNCREST_") + + verify(mockExecution).setVariable("SDNCREST_SuccessIndicator",false) + verify(mockExecution).setVariable("SDNCREST_requestType","SDNCServiceRequest") + verify(mockExecution).setVariable("SDNCAResponse_CORRELATOR","0d883b7f-dd34-4e1b-9ed5-341d33052360-1511808197479") + verify(mockExecution).setVariable("SDNCREST_sdncAdapterMethod","POST") + verify(mockExecution).setVariable("SDNCREST_timeout","PT5M") + } + + @Test + public void testPreProcessRequestGoodTimeout() { + // bpTimeout is valid and "mso.adapters.sdnc.timeout" is undefined + + String sdncAdapterWorkflowRequest = FileUtil.readResourceFile("__files/SDN-ETHERNET-INTERNET/SDNCAdapterRestV1/sdnc_request.json"); + sdncAdapterWorkflowRequest = JsonUtils.addJsonValue(sdncAdapterWorkflowRequest, "SDNCServiceRequest.bpTimeout", "PT20S") + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getVariable("prefix")).thenReturn("SDNCREST_") + when(mockExecution.getVariable("mso-request-id")).thenReturn("testMsoRequestId") + when(mockExecution.getVariable("SDNCREST_Request")).thenReturn(sdncAdapterWorkflowRequest) + when(mockExecution.getVariable("mso.adapters.po.auth")).thenReturn("3141634BF7E070AA289CF2892C986C0B") + when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7") + + when(mockExecution.getVariable("mso.adapters.sdnc.rest.endpoint")).thenReturn("http://localhost:18080/adapters/rest/v1/sdnc/") + + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable("testProcessKey")).thenReturn("testProcessKey") + + + SDNCAdapterRestV2 sdncAdapterRestV2 = new SDNCAdapterRestV2() + sdncAdapterRestV2.preProcessRequest(mockExecution) + + MockitoDebuggerImpl debugger = new MockitoDebuggerImpl() + //debugger.printInvocations(mockExecution) + + + verify(mockExecution).setVariable("prefix","SDNCREST_") + + verify(mockExecution).setVariable("SDNCREST_SuccessIndicator",false) + verify(mockExecution).setVariable("SDNCREST_requestType","SDNCServiceRequest") + verify(mockExecution).setVariable("SDNCAResponse_CORRELATOR","0d883b7f-dd34-4e1b-9ed5-341d33052360-1511808197479") + verify(mockExecution).setVariable("SDNCREST_sdncAdapterMethod","POST") + verify(mockExecution).setVariable("SDNCREST_timeout","PT20S") + } + + @Ignore + @Test + public void testPreProcessRequestBadTimeout() { + // bpTimeout is invalid and "mso.adapters.sdnc.timeout" is undefined + + String sdncAdapterWorkflowRequest = FileUtil.readResourceFile("__files/SDN-ETHERNET-INTERNET/SDNCAdapterRestV1/sdnc_request.json"); + sdncAdapterWorkflowRequest = JsonUtils.addJsonValue(sdncAdapterWorkflowRequest, "SDNCServiceRequest.bpTimeout", "badTimeout") + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getVariable("prefix")).thenReturn("SDNCREST_") + when(mockExecution.getVariable("mso-request-id")).thenReturn("testMsoRequestId") + when(mockExecution.getVariable("SDNCREST_Request")).thenReturn(sdncAdapterWorkflowRequest) + when(mockExecution.getVariable("mso.adapters.po.auth")).thenReturn("3141634BF7E070AA289CF2892C986C0B") + when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7") + + when(mockExecution.getVariable("mso.adapters.sdnc.rest.endpoint")).thenReturn("http://localhost:18080/adapters/rest/v1/sdnc/") + + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable("testProcessKey")).thenReturn("testProcessKey") + + + SDNCAdapterRestV2 sdncAdapterRestV2 = new SDNCAdapterRestV2() + sdncAdapterRestV2.preProcessRequest(mockExecution) + + MockitoDebuggerImpl debugger = new MockitoDebuggerImpl() + //debugger.printInvocations(mockExecution) + + + verify(mockExecution).setVariable("prefix","SDNCREST_") + + verify(mockExecution).setVariable("SDNCREST_SuccessIndicator",false) + verify(mockExecution).setVariable("SDNCREST_requestType","SDNCServiceRequest") + verify(mockExecution).setVariable("SDNCAResponse_CORRELATOR","0d883b7f-dd34-4e1b-9ed5-341d33052360-1511808197479") + verify(mockExecution).setVariable("SDNCREST_sdncAdapterMethod","POST") + verify(mockExecution).setVariable("SDNCREST_timeout","PT10S") + } +} \ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterTest.groovy new file mode 100644 index 0000000000..18d65d00d8 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterTest.groovy @@ -0,0 +1,951 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts + + +import static org.mockito.Mockito.* + +import org.camunda.bpm.engine.ProcessEngineServices +import org.camunda.bpm.engine.RepositoryService +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.camunda.bpm.engine.repository.ProcessDefinition +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.MockitoAnnotations +import org.mockito.runners.MockitoJUnitRunner +import org.mockito.internal.debugging.MockitoDebuggerImpl +import org.onap.so.bpmn.common.scripts.SDNCAdapter; + +import org.onap.so.bpmn.mock.FileUtil + +@RunWith(MockitoJUnitRunner.class) +public class SDNCAdapterTest { + + @Before + public void init() + { + MockitoAnnotations.initMocks(this) + System.setProperty("jboss.qualified.host.name","myhost.com") + } + + + String workflowResponse = """ + + + testRequestId + 200 + OK + + + + FK/VLXM/003717//SW_INTERNET + + service-configuration-operation + activate + synccomplete + N + Layer3ServiceActivateRequest + SUPP + 2015-04-28T21:32:11.386Z + + + + ds + 8 + Mbps + + + + + + 2001:1890:12e3:2da:: + 2001:1890:12e3:2da:: + 28 + + + 255.255.252.1 + 192.168.1.15 + 28 + + + 2001:1890:12e3:2da:: + 2001:1890:12e3:2da:: + 28 + + + 255.255.252.2 + 192.168.1.15 + 28 + + + 255.255.252.3 + 192.168.1.15 + 28 + + + + N + Y + N + + 192.168.1.7 + + + 192.168.1.8 + + + 1.1.1.1 + 28 + + 192.168.1.5 + + 2.2.2.1 + + 192.168.1.6 + + 192.155.2.3 + + + 1.1.1.2 + 28 + + 192.168.1.6 + + 2.2.2.2 + + 192.168.1.7 + + 192.155.2.4 + + Y + + 1:5 + + + 1:6 + + + 4:4 + 28 + + 1:1 + + 3:3 + + 2:2 + + 0:0 + + + 4:4 + 28 + + 1:1 + + 3:3 + + 2:2 + + 0:0 + + + + N + Y + + 0.0.0.1 + 1 + Y + + 1 + + + 1 + + + + 0.0.0.2 + 2 + Y + + 2 + + + 2 + + + + : + 0 + Y + + 3 + + + 3 + + + + : + 1 + Y + + 4 + + + 4 + + + + + + 192.168.1.44 + 192.168.1.5 + 0 + + Y + N + + 192.168.1.45 + 192.168.1.6 + 28 + + + + Y + + 0.0.0.0 + 0.0.0.0 + 0.0.0.0 + + + 0.0.0.1 + 0.0.0.1 + 0.0.0.1 + + + primary + 162.200.3.144 + 64 + 2001:1890:12e3:2da:: + 2620:0:10d0:f:ffff:ffff:ffff:fffe + 24 + 10.192.27.254 + + + 1 + 192.168.1.2 + 192.168.1.1 + 28 + + + 1 + 192.168.1.72 + 192.168.1.71 + 28 + + + 1 + 192.168.1.68 + 192.168.1.67 + 28 + + + + + 1 + 2001:1890:12e3:2da:: + 2001:1890:12e3:2da:: + 28 + + + 1 + 2001:1890:12e3:2da:: + 2001:1890:12e3:3da:: + 28 + + + 1 + 2001:1890:12e3:2da:: + 2001:1890:12e3:4da:: + 28 + + + + none + + + + AVPN + + 1 + Active + + + 2 + Standby + + + + hostname + activecode + OOB + + + + 1 + 1 + ZZ + JUNIPER + MODEL1 + 1 + 1 + 1 + 1 + 1 + + + 2 + 2 + HY + JUNIPER + MODEL2 + 2 + 2 + 2 + 2 + 2 + + + + + Layer3ServiceActivateRequest + 4281555 + 155415ab-b4a7-4382-b4c6-d17d9sm42855 + https://csi-tst-q22.it.com:22443/Services/com/cingular/csi/sdn/SendManagedNetworkStatusNotification.jws + OMX + 1 + + + activate + https://localhost:8443/adapters/rest/SDNCNotify + 5b1f3c5d-cdf9-488d-8a4b-d3f1229d7760 + + + MultiPoint + MTSNJA4LCP1 + AS/VLXM/003717//SW + + + FK/VLXM/003717//SW_INTERNET + ST E2E Test42855_1300004281555 + SDN-ETHERNET-INTERNET + + + 10 + Kbps + + 1 + 192.168.1.15 + 192.168.1.15 + 28 + + + 2 + 192.168.1.16 + 192.168.1.16 + 28 + + + 1 + 2001:1890:12e3:2da:: + 2001:1890:12e3:2da:: + 28 + + + 1 + 2001:1890:12e3:2da:: + 2001:1890:12e3:2da:: + 28 + + + + + + +""" + + String sdncAdapterRequest = """ + + + + + 745b1b50-e39e-4685-9cc8-c71f0bde8bf0 + query + services/layer3-service-list/AS%2FVLXM%2F000199%2F%2FSB_INTERNET + http://myhost.com:28080/mso/sdncAdapterCallbackServiceImpl + + + + + + 12570a36-7388-4c0a-bec4-189ce3kg9956 + GetLayer3ServiceDetailsRequest + OMX + + + SDN-ETHERNET-INTERNET + PD/VLXM/003717//SW_INTERNET + + + + """ + +def sdncAdapterResponse = """ + + + 39542e39-ccc3-4d1a-8b79-04ce88526613 + 404 + Error processing request to SDNC. Not Found. + https://localhost:8443/restconf/config/L3SDN-API:services/layer3-service-list/MVM%2FVLXP%2F000855%2F%2FShakeout. + SDNC Returned-[error-type:application, error-tag:data-missing, + error-message:Request could not be completed because the relevant + data model content does not exist.] + + + +""" + +def workflowErrorResponse = """ + Received error from SDN-C: Error processing request to SDNC. Not Found. + https://localhost:8443/restconf/config/L3SDN-API:services/layer3-service-list/MVM%2FVLXP%2F000855%2F%2FShakeout. + SDNC Returned-[error-type:application, error-tag:data-missing, + error-message:Request could not be completed because the relevant + data model content does not exist.] + 5300 + 404 + """ + +String workflowErrorResponse1 = """ + Invalid Callback Response from SDNC Adapter + 5300 + """ + +String enhancedCallbackRequestData = + """ + FK/VLXM/003717//SW_INTERNET + + service-configuration-operation + activate + synccomplete + N + Layer3ServiceActivateRequest + SUPP + 2015-04-28T21:32:11.386Z + + + + ds + 8 + Mbps + + + + + + 2001:1890:12e3:2da:: + 2001:1890:12e3:2da:: + 28 + + + 255.255.252.1 + 192.168.1.15 + 28 + + + 2001:1890:12e3:2da:: + 2001:1890:12e3:2da:: + 28 + + + 255.255.252.2 + 192.168.1.15 + 28 + + + 255.255.252.3 + 192.168.1.15 + 28 + + + + N + Y + N + + 192.168.1.7 + + + 192.168.1.8 + + + 1.1.1.1 + 28 + + 192.168.1.5 + + 2.2.2.1 + + 192.168.1.6 + + 192.155.2.3 + + + 1.1.1.2 + 28 + + 192.168.1.6 + + 2.2.2.2 + + 192.168.1.7 + + 192.155.2.4 + + Y + + 1:5 + + + 1:6 + + + 4:4 + 28 + + 1:1 + + 3:3 + + 2:2 + + 0:0 + + + 4:4 + 28 + + 1:1 + + 3:3 + + 2:2 + + 0:0 + + + + N + Y + + 0.0.0.1 + 1 + Y + + 1 + + + 1 + + + + 0.0.0.2 + 2 + Y + + 2 + + + 2 + + + + : + 0 + Y + + 3 + + + 3 + + + + : + 1 + Y + + 4 + + + 4 + + + + + + 192.168.1.44 + 192.168.1.5 + 0 + + Y + N + + 192.168.1.45 + 192.168.1.6 + 28 + + + + Y + + 0.0.0.0 + 0.0.0.0 + 0.0.0.0 + + + 0.0.0.1 + 0.0.0.1 + 0.0.0.1 + + + primary + 162.200.3.144 + 64 + 2001:1890:12e3:2da:: + 2620:0:10d0:f:ffff:ffff:ffff:fffe + 24 + 10.192.27.254 + + + 1 + 192.168.1.2 + 192.168.1.1 + 28 + + + 1 + 192.168.1.72 + 192.168.1.71 + 28 + + + 1 + 192.168.1.68 + 192.168.1.67 + 28 + + + + + 1 + 2001:1890:12e3:2da:: + 2001:1890:12e3:2da:: + 28 + + + 1 + 2001:1890:12e3:2da:: + 2001:1890:12e3:3da:: + 28 + + + 1 + 2001:1890:12e3:2da:: + 2001:1890:12e3:4da:: + 28 + + + + none + + + + AVPN + + 1 + Active + + + 2 + Standby + + + + hostname + activecode + OOB + + + + 1 + 1 + ZZ + JUNIPER + MODEL1 + 1 + 1 + 1 + 1 + 1 + + + 2 + 2 + HY + JUNIPER + MODEL2 + 2 + 2 + 2 + 2 + 2 + + + + + Layer3ServiceActivateRequest + 4281555 + 155415ab-b4a7-4382-b4c6-d17d9sm42855 + https://csi-tst-q22.it.com:22443/Services/com/cingular/csi/sdn/SendManagedNetworkStatusNotification.jws + OMX + 1 + + + activate + https://localhost:8443/adapters/rest/SDNCNotify + 5b1f3c5d-cdf9-488d-8a4b-d3f1229d7760 + + + MultiPoint + MTSNJA4LCP1 + AS/VLXM/003717//SW + + + FK/VLXM/003717//SW_INTERNET + ST E2E Test42855_1300004281555 + SDN-ETHERNET-INTERNET + + + 10 + Kbps + + 1 + 192.168.1.15 + 192.168.1.15 + 28 + + + 2 + 192.168.1.16 + 192.168.1.16 + 28 + + + 1 + 2001:1890:12e3:2da:: + 2001:1890:12e3:2da:: + 28 + + + 1 + 2001:1890:12e3:2da:: + 2001:1890:12e3:2da:: + 28 + + + + + +""" + +def sdncAdapterResponseEmpty = +""" + +""" + +def sdncAdapterResponseError = +""" + + + 39542e39-ccc3-4d1a-8b79-04ce88526613 + 404 + Error processing request to SDNC. Not Found. + https://localhost:8443/restconf/config/L3SDN-API:services/layer3-service-list/MVM%2FVLXP%2F000855%2F%2FShakeout. + SDNC Returned-[error-type:application, error-tag:data-missing, + error-message:Request could not be completed because the relevant + data model content does not exist.] + + +""" + + + @Test + public void testPreProcessRequest() { + + String sdncAdapterWorkflowRequest = FileUtil.readResourceFile("__files/SDN-ETHERNET-INTERNET/SDNCAdapterV1/sdncadapterworkflowrequest.xml"); + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getVariable("mso.adapters.po.auth")).thenReturn("3141634BF7E070AA289CF2892C986C0B") + when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7") + when(mockExecution.getVariable("sdncAdapterWorkflowRequest")).thenReturn(sdncAdapterWorkflowRequest) + when(mockExecution.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("http://someurl.someting.com:28080/mso/sdncAdapterCallbackServiceImpl") + when(mockExecution.getVariable("mso.use.qualified.host")).thenReturn("true") + + when(mockExecution.getProcessInstanceId()).thenReturn("745b1b50-e39e-4685-9cc8-c71f0bde8bf0") + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + + + SDNCAdapter sdncAdapter = new SDNCAdapter() + sdncAdapter.preProcessRequest(mockExecution) + + MockitoDebuggerImpl debugger = new MockitoDebuggerImpl() + debugger.printInvocations(mockExecution) + + + verify(mockExecution).setVariable("prefix","SDNCA_") + verify(mockExecution).setVariable("sdncAdapterResponse","") + verify(mockExecution).setVariable("asynchronousResponseTimeout",false) + verify(mockExecution).setVariable("continueListening",false) + verify(mockExecution).setVariable("BasicAuthHeaderValue","Basic cGFzc3dvcmQ=") + verify(mockExecution).setVariable("serviceConfigActivate",false) + verify(mockExecution).setVariable("SDNCA_requestId", "745b1b50-e39e-4685-9cc8-c71f0bde8bf0") + verify(mockExecution).setVariable("SDNCA_SuccessIndicator",false) + verify(mockExecution).setVariable("source","") + verify(mockExecution).setVariable("SDNCA_InterimNotify",false) + verify(mockExecution).setVariable("sdncAdapterRequest", sdncAdapterRequest) + } + + @Test + public void testProcessResponse() + { + String sdncAdapterCallbackResponse = FileUtil.readResourceFile("__files/SDN-ETHERNET-INTERNET/SDNCAdapterV1mock/sdncadaptercallbackrequest.xml"); + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getVariable("sdncAdapterCallbackRequest")).thenReturn(sdncAdapterCallbackResponse) + SDNCAdapter sdncAdapter = new SDNCAdapter() + sdncAdapter.postProcessResponse(mockExecution) + +// MockitoDebuggerImpl debugger = new MockitoDebuggerImpl() +// debugger.printInvocations(mockExecution) + + verify(mockExecution,times(2)).getVariable("sdncAdapterCallbackRequest") + verify(mockExecution).setVariable("enhancedCallbackRequestData",enhancedCallbackRequestData) + verify(mockExecution).setVariable("sdncAdapterResponse",workflowResponse) + verify(mockExecution).setVariable("continueListening",false) + + } + + @Test + public void testProcessResponse_ErrorCase_404() + { + String sdncAdapterCallbackErrorResponse = FileUtil.readResourceFile("sdncadaptercallbackrequest_404CallBack.xml"); + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getVariable("sdncAdapterCallbackRequest")).thenReturn(sdncAdapterCallbackErrorResponse) + SDNCAdapter sdncAdapter = new SDNCAdapter() + sdncAdapter.postProcessResponse(mockExecution) + + verify(mockExecution,times(2)).getVariable("sdncAdapterCallbackRequest") + verify(mockExecution).setVariable("sdncAdapterResponse", sdncAdapterResponseError) + verify(mockExecution).setVariable("enhancedCallbackRequestData", "") + verify(mockExecution).setVariable("continueListening",false) + + } + + @Test + public void testProcessResponse_ErrorCase_InvalidCallback() + { + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getVariable("sdncAdapterCallbackRequest")).thenReturn("

Service Unavailable

") + SDNCAdapter sdncAdapter = new SDNCAdapter() + sdncAdapter.postProcessResponse(mockExecution) + + verify(mockExecution,times(2)).getVariable("sdncAdapterCallbackRequest") + verify(mockExecution).setVariable("sdncAdapterResponse", sdncAdapterResponseEmpty) + verify(mockExecution).setVariable("enhancedCallbackRequestData", "") + verify(mockExecution).setVariable("continueListening",false) + + } + + @Test + public void postProcessResponse() + { + + String SDNCAdapterCallbackRequest = + """ + + + 3bb02798-b344-4d28-9bca-1f029954d1c9 + 404 + Error processing request to SDNC. Not Found. + https://localhost:8443/restconf/config/L3SDN-API:services/layer3-service-list/85%2FCSIP%2F141203%2FPT_CSI9999998693. + SDNC Returned-[error-type:application, error-tag:data-missing, + error-message:Request could not be completed because the relevant + data model content does not exist ] + +""" + + String sdncAdapterResponse = + """ + + + 3bb02798-b344-4d28-9bca-1f029954d1c9 + 404 + Error processing request to SDNC. Not Found. + https://localhost:8443/restconf/config/L3SDN-API:services/layer3-service-list/85%2FCSIP%2F141203%2FPT_CSI9999998693. + SDNC Returned-[error-type:application, error-tag:data-missing, + error-message:Request could not be completed because the relevant + data model content does not exist ] + + +""" + + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getVariable("sdncAdapterCallbackRequest")).thenReturn(SDNCAdapterCallbackRequest) + SDNCAdapter sdncAdapter = new SDNCAdapter() + sdncAdapter.postProcessResponse(mockExecution) + + verify(mockExecution,times(2)).getVariable("sdncAdapterCallbackRequest") + verify(mockExecution).setVariable("sdncAdapterResponse", sdncAdapterResponse) + verify(mockExecution).setVariable("enhancedCallbackRequestData", "") + verify(mockExecution).setVariable("continueListening",false) + + } + +} \ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterUtilsTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterUtilsTest.groovy new file mode 100644 index 0000000000..803e2b03a3 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterUtilsTest.groovy @@ -0,0 +1,191 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.* + +import org.junit.Before +import org.junit.Ignore +import org.junit.Test +import org.camunda.bpm.engine.delegate.BpmnError +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.camunda.bpm.engine.delegate.DelegateExecution +import org.onap.so.bpmn.core.WorkflowException +import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils + +import org.onap.so.bpmn.mock.FileUtil + +public class SDNCAdapterUtilsTest { + + private def map + private ExecutionEntity svcex + private WorkflowException wfex + private AbstractServiceTaskProcessor tp + private String resp + private SDNCAdapterUtils utils + + @Before + public void init() + { + map = new HashMap() + svcex = mock(ExecutionEntity.class) + wfex = null + tp = new AbstractServiceTaskProcessor() { + @Override + public void preProcessRequest(DelegateExecution execution) { + } + }; + utils = new SDNCAdapterUtils(tp) + + // svcex gets its variables from "map" + when(svcex.getVariable(any())).thenAnswer( + { invocation -> + return map.get(invocation.getArgumentAt(0, String.class)) }) + + // svcex puts its variables into "map" + when(svcex.setVariable(any(), any())).thenAnswer( + { invocation -> + return map.put( + invocation.getArgumentAt(0, String.class), + invocation.getArgumentAt(1, String.class)) }) + + map.put("isDebugLogEnabled", "true") + map.put("prefix", "mypfx-") + map.put("testProcessKey", "mykey") + } + + @Test + public void testValidateSDNCResponse_Success_NoCode() { + resp = """""" + + utils.validateSDNCResponse(svcex, resp, wfex, true) + + assertEquals(true, map.get("mypfx-sdncResponseSuccess")) + assertEquals("0", map.get("mypfx-sdncRequestDataResponseCode")) + assertFalse(map.containsKey("WorkflowException")) + } + + @Test + public void testValidateSDNCResponse_200() { + utils.validateSDNCResponse(svcex, makeResp("200", "OK", ""), wfex, true) + + assertEquals(true, map.get("mypfx-sdncResponseSuccess")) + assertEquals("200", map.get("mypfx-sdncRequestDataResponseCode")) + assertFalse(map.containsKey("WorkflowException")) + } + + @Test + public void testValidateSDNCResponse_408() { + try { + utils.validateSDNCResponse(svcex, makeResp("408", "failed", ""), wfex, true) + + // this has been commented out as, currently, the code doesn't + // throw an exception in this case +// fail("missing exception") + + } catch(BpmnError ex) { + ex.printStackTrace() + } + + assertEquals(false, map.get("mypfx-sdncResponseSuccess")) + assertEquals("408", map.get("mypfx-sdncRequestDataResponseCode")) + + wfex = map.get("WorkflowException") + assertNotNull(wfex) + + assertEquals(5320, wfex.getErrorCode()) + assertEquals("Received error from SDN-C: failed", wfex.getErrorMessage()) + } + + @Test + public void testValidateSDNCResponse_408_200() { + + utils.validateSDNCResponse(svcex, makeResp("408", "failed", makeReq("200", "ok")), wfex, true) + + assertEquals(true , map.get("mypfx-sdncResponseSuccess")) + assertEquals("200", map.get("mypfx-sdncRequestDataResponseCode")) + assertFalse(map.containsKey("WorkflowException")) + } + + @Test + public void testValidateSDNCResponse_408_200_WithEmbeddedLt() { + + utils.validateSDNCResponse(svcex, makeResp("408", "failed", makeReq("200", " message")), wfex, true) + + assertEquals(true, map.get("mypfx-sdncResponseSuccess")) + assertEquals("200", map.get("mypfx-sdncRequestDataResponseCode")) + assertFalse(map.containsKey("WorkflowException")) + } + + @Test + public void testUpdateHomingInfo() { + String actual = utils.updateHomingInfo(null, "AIC3.0") + println actual + assertEquals("AIC3.0", actual) + } + + @Test + public void testUpdateHomingInfo2() { + String homingInfo = "TESTCLLI" + String actual = utils.updateHomingInfo(homingInfo, "AIC3.0") + println actual + assertEquals("TESTCLLIAIC3.0", actual) + } + + private String makeResp(String respcode, String respmsg, String reqdata) { + def rc = respcode + def rm = respmsg + + return """ + + + + myreq + ${MsoUtils.xmlEscape(rc)} + ${MsoUtils.xmlEscape(rm)} + + ${reqdata} + + +""" + + } + + private String makeReq(String respcode, String respmsg) { + def rc = respcode + def rm = respmsg + + def output = """ + + 8b46e36e-b44f-4085-9404-427be1bc8a3 + ${MsoUtils.xmlEscape(rc)} + ${MsoUtils.xmlEscape(rm)} + Y + +""" + output = output + + return """${MsoUtils.xmlEscape(output)}""" + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SniroHomingV1Test.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SniroHomingV1Test.groovy new file mode 100644 index 0000000000..b093aaa491 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SniroHomingV1Test.groovy @@ -0,0 +1,196 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts + +import com.github.tomakehurst.wiremock.junit.WireMockRule +import org.camunda.bpm.engine.ProcessEngineServices +import org.camunda.bpm.engine.RepositoryService +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.camunda.bpm.engine.repository.ProcessDefinition +import org.junit.Assert +import org.junit.Before +import org.junit.Ignore +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.ArgumentCaptor +import org.mockito.Captor +import org.mockito.Mockito +import org.mockito.MockitoAnnotations +import org.mockito.runners.MockitoJUnitRunner +import org.onap.so.bpmn.core.WorkflowException +import org.onap.so.bpmn.core.domain.AllottedResource +import org.onap.so.bpmn.core.domain.ModelInfo +import org.onap.so.bpmn.core.domain.ServiceDecomposition +import org.onap.so.bpmn.core.domain.VnfResource + +import static com.github.tomakehurst.wiremock.client.WireMock.* +import static org.mockito.Mockito.* + +@RunWith(MockitoJUnitRunner.class) +@Ignore +class SniroHomingV1Test { + String subsInfo = "{\"globalSubscriberId\": \"SUB12_0322_DS_1201\",\"subscriberCommonSiteId\": \"DALTX0101\",\"subscriberName\": \"SUB_12_0322_DS_1201\"}" + ServiceDecomposition serviceDecomp + + { + serviceDecomp = new ServiceDecomposition("{\"serviceResources\":{}}", "123") + ModelInfo modelInfo = new ModelInfo() + serviceDecomp.modelInfo = modelInfo + + AllottedResource allottedResource = new AllottedResource() + allottedResource.setModelInfo(modelInfo) + List allottedResourceList = new ArrayList() + allottedResourceList.add(allottedResource) + + VnfResource vnfResource = new VnfResource() + vnfResource.setModelInfo(modelInfo) + List vnfResourceList = new ArrayList() + vnfResourceList.add(vnfResource) + + serviceDecomp.serviceAllottedResources = allottedResourceList + serviceDecomp.setVnfResources(vnfResourceList) + } + + @Rule + public WireMockRule wireMockRule = new WireMockRule(28090) + + @Captor + static ArgumentCaptor captor = ArgumentCaptor.forClass(ExecutionEntity.class) + + + @Before + public void init() { + MockitoAnnotations.initMocks(this) + } + + @Test + public void testCallSniro() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable("msoRequestId")).thenReturn("12345") + when(mockExecution.getVariable("serviceInstanceId")).thenReturn("12345") + when(mockExecution.getVariable("subscriberInfo")).thenReturn(subsInfo) + when(mockExecution.getVariable("serviceDecomposition")).thenReturn(serviceDecomp) + when(mockExecution.getVariable("mso.sniro.auth")).thenReturn("3141634BF7E070AA289CF2892C986C0B") + when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7") + when(mockExecution.getVariable("mso.adapters.workflow.message.endpoint")).thenReturn('http://localhost:18080/workflows/messages/message/') + when(mockExecution.getVariable("mso.service.agnostic.sniro.endpoint")).thenReturn("/sniro") + when(mockExecution.getVariable("mso.service.agnostic.sniro.host")).thenReturn("http://localhost:28090") + when(mockExecution.getVariable("mso.workflow.GenericPutVnf.aai.generic-vnf.uri")).thenReturn("/aai/v9/network/generic-vnfs/generic-vnf") + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/") + + mockData() + + SniroHomingV1 obj = new SniroHomingV1() + obj.callSniro(mockExecution) + + Mockito.verify(mockExecution, times(10)).setVariable(captor.capture(), captor.capture()) + Assert.assertEquals(200, captor.getAllValues().get(17)) + + } + + @Test + public void testCallSniroMissingAuth() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable("msoRequestId")).thenReturn("12345") + when(mockExecution.getVariable("serviceInstanceId")).thenReturn("12345") + when(mockExecution.getVariable("subscriberInfo")).thenReturn(subsInfo) + when(mockExecution.getVariable("serviceDecomposition")).thenReturn(serviceDecomp) + when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7") + when(mockExecution.getVariable("mso.adapters.workflow.message.endpoint")).thenReturn('http://localhost:18080/workflows/messages/message/') + when(mockExecution.getVariable("mso.service.agnostic.sniro.endpoint")).thenReturn("/sniro") + when(mockExecution.getVariable("mso.service.agnostic.sniro.host")).thenReturn("http://localhost:28090") + when(mockExecution.getVariable("mso.workflow.GenericPutVnf.aai.generic-vnf.uri")).thenReturn("/aai/v9/network/generic-vnfs/generic-vnf") + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/") + + mockData() + + try { + SniroHomingV1 obj = new SniroHomingV1() + obj.callSniro(mockExecution) + } catch (Exception ex) { + println " Test End - Handle catch-throw BpmnError()! " + } + Mockito.verify(mockExecution, times(4)).setVariable(captor.capture(), captor.capture()) + WorkflowException workflowException = captor.getValue() + Assert.assertEquals(401, workflowException.getErrorCode()) + Assert.assertEquals("Internal Error - BasicAuth value null", workflowException.getErrorMessage()) + } + + @Test + public void testCallSniroHostNull() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable("msoRequestId")).thenReturn("12345") + when(mockExecution.getVariable("serviceInstanceId")).thenReturn("12345") + when(mockExecution.getVariable("subscriberInfo")).thenReturn(subsInfo) + when(mockExecution.getVariable("serviceDecomposition")).thenReturn(serviceDecomp) + when(mockExecution.getVariable("mso.sniro.auth")).thenReturn("3141634BF7E070AA289CF2892C986C0B") + when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7") + when(mockExecution.getVariable("mso.adapters.workflow.message.endpoint")).thenReturn('http://localhost:18080/workflows/messages/message/') + when(mockExecution.getVariable("mso.service.agnostic.sniro.endpoint")).thenReturn("/sniro") + when(mockExecution.getVariable("mso.service.agnostic.sniro.host")).thenReturn(null) + when(mockExecution.getVariable("mso.workflow.GenericPutVnf.aai.generic-vnf.uri")).thenReturn("/aai/v9/network/generic-vnfs/generic-vnf") + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/") + + mockData() + try { + SniroHomingV1 obj = new SniroHomingV1() + obj.callSniro(mockExecution) + } catch (Exception ex) { + println " Test End - Handle catch-throw BpmnError()! " + } + Mockito.verify(mockExecution, times(9)).setVariable(captor.capture(), captor.capture()) + WorkflowException workflowException = captor.getValue() + Assert.assertEquals(2500, workflowException.getErrorCode()) + Assert.assertEquals("Internal Error - Occured in Homing CallSniro: org.apache.http.client.ClientProtocolException", workflowException.getErrorMessage()) + } + + private static ExecutionEntity setupMock() { + ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class) + when(mockProcessDefinition.getKey()).thenReturn("Homing") + RepositoryService mockRepositoryService = mock(RepositoryService.class) + when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition) + when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("Homing") + when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100") + ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class) + when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService) + + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + // Initialize prerequisite variables + when(mockExecution.getId()).thenReturn("100") + when(mockExecution.getProcessDefinitionId()).thenReturn("Homing") + when(mockExecution.getProcessInstanceId()).thenReturn("Homing") + when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices) + when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition) + + return mockExecution + } + + private static void mockData() { + stubFor(post(urlMatching(".*/sniro")) + .willReturn(aResponse() + .withStatus(200) + .withBody(""))) + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/TrinityExceptionUtilTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/TrinityExceptionUtilTest.groovy new file mode 100644 index 0000000000..52f59a3fad --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/TrinityExceptionUtilTest.groovy @@ -0,0 +1,201 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts + +import org.junit.Assert +import org.junit.Ignore +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + + + +import static org.mockito.Mockito.* + +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.junit.Before +import org.junit.runner.RunWith +import org.mockito.MockitoAnnotations +import org.mockito.internal.debugging.MockitoDebuggerImpl +import org.mockito.runners.MockitoJUnitRunner +import org.onap.so.bpmn.common.scripts.TrinityExceptionUtil; +@RunWith(MockitoJUnitRunner.class) +import org.junit.Test + +class TrinityExceptionUtilTest { + + def aotsFault =""" + xml:space + String + http://test.com + + + + 400 + bad stuff + + + String + *** ERROR *** + String + String + String + String + + String + String + + String + String + String + String + + + + + + String + *** ERROR *** + String + String + String + String + String + String + String + + +""" + + + @Before + public void init() + { + MockitoAnnotations.initMocks(this) + } + + @Test + @Ignore + public void testMapAAIExceptionTCommonException() { + + + + String restFault = """ + + + +SVC3002 +Error writing output performing %1 on %2 (msg=%3) (ec=%4) + +PUTcustomer +SubName01 +Unexpected error reading/updating database:Adding this property for key [service-instance-id] and value [USSTU2CFCNC0101UJZZ01] violates a uniqueness constraint [service-instance-id] +ERR.5.4.5105 + + + + + """ + def errorString = """ + +SVC3002 +Error writing output performing %1 on %2 (msg=%3) (ec=%4) + +PUTcustomer +SubName01 +Unexpected error reading/updating database:Adding this property for key [service-instance-id] and value [USSTU2CFCNC0101UJZZ01] violates a uniqueness constraint [service-instance-id] +ERR.5.4.5105 + + +""" as String + + + + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + + TrinityExceptionUtil util = new TrinityExceptionUtil() + Assert.assertEquals(errorString, util.mapAAIExceptionTCommonException(restFault, mockExecution)) + } + + + + + @Test + public void testBuildException() { + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getVariable("prefix")).thenReturn("test_") + when(mockExecution.getVariable("test_ResponseCode")).thenReturn("400") + ArrayList msgVars = new ArrayList() + msgVars.add("var1") + msgVars.add("var2") + when(mockExecution.getVariable("test_errVariables")).thenReturn(msgVars) + + + TrinityExceptionUtil util = new TrinityExceptionUtil() + String msg = "Bad request" + String errorString = """ + + SVC2000 + The following service error occurred: %1. Error code is %2. + var1 + var2 + +""" + Assert.assertEquals(errorString, util.buildException(msg, mockExecution)) + } + + @Test + public void testMapAOTSExecptionToCommonException() { + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getVariable("prefix")).thenReturn("test_") + when(mockExecution.getVariable("test_ResponseCode")).thenReturn("400") + + TrinityExceptionUtil util = new TrinityExceptionUtil() + String errorString = """ + + SVC2000 + The following service error occurred: %1. Error code is %2. + Received error from AOTS: bad stuff + 400 + +""" + Assert.assertEquals(errorString, util.mapAOTSExecptionToCommonException(aotsFault, mockExecution)) + } + + + @Test + public void testParseError() { + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + String errorString = "The following service error occurred: %1. Error code is %2." + ArrayList msgVars = new ArrayList() + msgVars.add("var1") + msgVars.add("var2") + when(mockExecution.getVariable("prefix")).thenReturn("test_") + when(mockExecution.getVariable("test_errTxt")).thenReturn(errorString) + when(mockExecution.getVariable("test_errVariables")).thenReturn(msgVars) + + TrinityExceptionUtil util = new TrinityExceptionUtil() + + Assert.assertEquals("The following service error occurred: var1. Error code is var2.", util.parseError(mockExecution)) +} + + + +} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIGenericVnfTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIGenericVnfTest.groovy new file mode 100644 index 0000000000..e0166f3602 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIGenericVnfTest.groovy @@ -0,0 +1,172 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts + +import com.github.tomakehurst.wiremock.junit.WireMockRule +import org.camunda.bpm.engine.ProcessEngineServices +import org.camunda.bpm.engine.RepositoryService +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.camunda.bpm.engine.repository.ProcessDefinition +import org.junit.Before +import org.junit.Ignore +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.ArgumentCaptor +import org.mockito.Captor +import org.mockito.Mockito +import org.mockito.MockitoAnnotations +import org.mockito.runners.MockitoJUnitRunner +import org.onap.so.bpmn.core.WorkflowException +import org.onap.so.bpmn.mock.FileUtil +import org.onap.so.bpmn.mock.StubResponseAAI + +import static com.github.tomakehurst.wiremock.client.WireMock.* +import static org.mockito.Matchers.any +import static org.mockito.Matchers.refEq +import static org.mockito.Mockito.* + +@RunWith(MockitoJUnitRunner.class) +@Ignore +class UpdateAAIGenericVnfTest { + + String getVfModuleResponse = FileUtil.readResourceFile("__files/VfModularity/GenericVnf.xml") + @Rule + public WireMockRule wireMockRule = new WireMockRule(28090) + + @Captor + static ArgumentCaptor captor = ArgumentCaptor.forClass(ExecutionEntity.class) + + @Before + void init() throws IOException { + MockitoAnnotations.initMocks(this); + } + + @Test + void testGetGenericVnf() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable("UAAIGenVnf_vnfId")).thenReturn("skask") + when(mockExecution.getVariable("mso.workflow.default.aai.v8.generic-vnf.uri")).thenReturn("/aai/v8/network/generic-vnfs/generic-vnf") + when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090") + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/") + when(mockExecution.getVariable("mso.workflow.custom.UpdateAAIGenericVnf.aai.version")).thenReturn('8') + + StubResponseAAI.MockAAIVfModule() + UpdateAAIGenericVnf obj = new UpdateAAIGenericVnf() + obj.getGenericVnf(mockExecution) + + Mockito.verify(mockExecution).setVariable("UAAIGenVnf_getGenericVnfResponseCode", 200) + } + + @Test + void testGetGenericVnfEndpointNull() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable("UAAIGenVnf_vnfId")).thenReturn("skask") + when(mockExecution.getVariable("mso.workflow.default.aai.v8.generic-vnf.uri")).thenReturn("/aai/v8/network/generic-vnfs/generic-vnf") + when(mockExecution.getVariable("aai.endpoint")).thenReturn(null) + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/") + when(mockExecution.getVariable("mso.workflow.custom.UpdateAAIGenericVnf.aai.version")).thenReturn('8') + + StubResponseAAI.MockAAIVfModule() + try { + UpdateAAIGenericVnf obj = new UpdateAAIGenericVnf() + obj.getGenericVnf(mockExecution) + } catch (Exception ex) { + println " Test End - Handle catch-throw BpmnError()! " + } + + WorkflowException exception = new WorkflowException("UpdateAAIGenericVnf", 9999, "org.apache.http.client.ClientProtocolException") + Mockito.verify(mockExecution).setVariable("WorkflowException", refEq(exception, any(WorkflowException.class))) + Mockito.verify(mockExecution).setVariable("UAAIGenVnf_getGenericVnfResponseCode", 500) + Mockito.verify(mockExecution).setVariable("UAAIGenVnf_getGenericVnfResponse", "AAI GET Failed:null") + } + + @Test + void testUpdateGenericVnf() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable("UAAIGenVnf_vnfId")).thenReturn("skask") + when(mockExecution.getVariable("UAAIGenVnf_getGenericVnfResponse")).thenReturn(getVfModuleResponse) + when(mockExecution.getVariable("mso.workflow.default.aai.v8.generic-vnf.uri")).thenReturn("/aai/v8/network/generic-vnfs/generic-vnf") + when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090") + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/") + when(mockExecution.getVariable("mso.workflow.custom.UpdateAAIGenericVnf.aai.version")).thenReturn('8') + + stubFor(patch(urlMatching(".*/aai/v[0-9]+/network/generic-vnfs/generic-vnf/.*")) + .willReturn(aResponse() + .withStatus(200))) + UpdateAAIGenericVnf obj = new UpdateAAIGenericVnf() + obj.updateGenericVnf(mockExecution) + + Mockito.verify(mockExecution).setVariable("UAAIGenVnf_updateGenericVnfResponseCode", 200) + Mockito.verify(mockExecution).setVariable("UAAIGenVnf_updateGenericVnfResponse", "") + } + + @Test + void testUpdateGenericVnfEndpointNull() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable("UAAIGenVnf_vnfId")).thenReturn("skask") + when(mockExecution.getVariable("UAAIGenVnf_getGenericVnfResponse")).thenReturn(getVfModuleResponse) + when(mockExecution.getVariable("mso.workflow.default.aai.v8.generic-vnf.uri")).thenReturn("/aai/v8/network/generic-vnfs/generic-vnf") + when(mockExecution.getVariable("aai.endpoint")).thenReturn(null) + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/") + when(mockExecution.getVariable("mso.workflow.custom.UpdateAAIGenericVnf.aai.version")).thenReturn('8') + + stubFor(patch(urlMatching(".*/aai/v[0-9]+/network/generic-vnfs/generic-vnf/.*")) + .willReturn(aResponse() + .withStatus(200))) + + try { + UpdateAAIGenericVnf obj = new UpdateAAIGenericVnf() + obj.updateGenericVnf(mockExecution) + } catch (Exception ex) { + println " Test End - Handle catch-throw BpmnError()! " + } + WorkflowException exception = new WorkflowException("UpdateAAIGenericVnf", 9999, "org.apache.http.client.ClientProtocolException") + Mockito.verify(mockExecution).setVariable("WorkflowException", refEq(exception, any(WorkflowException.class))) + Mockito.verify(mockExecution).setVariable("UAAIGenVnf_updateGenericVnfResponseCode", 500) + Mockito.verify(mockExecution).setVariable("UAAIGenVnf_updateGenericVnfResponse", "AAI PATCH Failed:null") + } + + private static ExecutionEntity setupMock() { + ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class) + when(mockProcessDefinition.getKey()).thenReturn("UpdateAAIGenericVnf") + RepositoryService mockRepositoryService = mock(RepositoryService.class) + when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition) + when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("UpdateAAIGenericVnf") + when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100") + ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class) + when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService) + + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + // Initialize prerequisite variables + when(mockExecution.getId()).thenReturn("100") + when(mockExecution.getProcessDefinitionId()).thenReturn("UpdateAAIGenericVnf") + when(mockExecution.getProcessInstanceId()).thenReturn("UpdateAAIGenericVnf") + when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices) + when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition) + + return mockExecution + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIVfModuleTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIVfModuleTest.groovy new file mode 100644 index 0000000000..d2f9095e2d --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIVfModuleTest.groovy @@ -0,0 +1,175 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts + +import com.github.tomakehurst.wiremock.junit.WireMockRule +import org.camunda.bpm.engine.ProcessEngineServices +import org.camunda.bpm.engine.RepositoryService +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.camunda.bpm.engine.repository.ProcessDefinition +import org.junit.Assert +import org.junit.Before +import org.junit.Ignore +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.ArgumentCaptor +import org.mockito.Captor +import org.mockito.Mockito +import org.mockito.MockitoAnnotations +import org.mockito.runners.MockitoJUnitRunner +import org.onap.so.bpmn.core.WorkflowException +import org.onap.so.bpmn.mock.FileUtil +import org.onap.so.bpmn.mock.StubResponseAAI + +import static org.mockito.Mockito.* + +@RunWith(MockitoJUnitRunner.class) +@Ignore +class UpdateAAIVfModuleTest { + def prefix = "UAAIVfMod_" + + @Rule + public WireMockRule wireMockRule = new WireMockRule(28090) + + @Captor + static ArgumentCaptor captor = ArgumentCaptor.forClass(ExecutionEntity.class) + + @Before + void init() throws IOException { + MockitoAnnotations.initMocks(this); + } + + @Test + void testGetVfModule() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("prefix")).thenReturn(prefix) + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable(prefix + "vnfId")).thenReturn("skask") + when(mockExecution.getVariable(prefix + "vfModuleId")).thenReturn("supercool") + when(mockExecution.getVariable("mso.workflow.default.aai.v8.generic-vnf.uri")).thenReturn("/aai/v8/network/generic-vnfs/generic-vnf") + when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090") + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/") + when(mockExecution.getVariable("mso.workflow.custom.UpdateAAIVfModule.aai.version")).thenReturn('8') + + StubResponseAAI.MockAAIVfModule() + UpdateAAIVfModule obj = new UpdateAAIVfModule() + obj.getVfModule(mockExecution) + + verify(mockExecution).setVariable(prefix + "getVfModuleResponseCode", 200) + } + + @Test + void testGetVfModuleEndpointNull() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("prefix")).thenReturn(prefix) + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable(prefix + "vnfId")).thenReturn("skask") + when(mockExecution.getVariable(prefix + "vfModuleId")).thenReturn("supercool") + when(mockExecution.getVariable("mso.workflow.default.aai.v8.generic-vnf.uri")).thenReturn("/aai/v8/network/generic-vnfs/generic-vnf") + when(mockExecution.getVariable("aai.endpoint")).thenReturn(null) + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/") + when(mockExecution.getVariable("mso.workflow.custom.UpdateAAIVfModule.aai.version")).thenReturn('8') + + StubResponseAAI.MockAAIVfModule() + try { + UpdateAAIVfModule obj = new UpdateAAIVfModule() + obj.getVfModule(mockExecution) + } catch (Exception ex) { + println " Test End - Handle catch-throw BpmnError()! " + } + + Mockito.verify(mockExecution, times(3)).setVariable(captor.capture(), captor.capture()) + WorkflowException workflowException = captor.getAllValues().get(1) + Assert.assertEquals(9999, workflowException.getErrorCode()) + Assert.assertEquals("org.apache.http.client.ClientProtocolException", workflowException.getErrorMessage()) + } + + @Test + void testUpdateVfModule() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("prefix")).thenReturn(prefix) + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable(prefix + "vnfId")).thenReturn("skask") + when(mockExecution.getVariable(prefix + "vfModuleId")).thenReturn("supercool") + when(mockExecution.getVariable("mso.workflow.default.aai.v8.generic-vnf.uri")).thenReturn("/aai/v8/network/generic-vnfs/generic-vnf") + when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090") + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/") + when(mockExecution.getVariable("mso.workflow.custom.UpdateAAIVfModule.aai.version")).thenReturn('8') + + String getVfModuleResponse = FileUtil.readResourceFile("__files/VfModularity/GenericVnf.xml") + when(mockExecution.getVariable(prefix + "getVfModuleResponse")).thenReturn(getVfModuleResponse) + StubResponseAAI.MockAAIVfModule() + UpdateAAIVfModule obj = new UpdateAAIVfModule() + obj.updateVfModule(mockExecution) + + verify(mockExecution).setVariable(prefix + "updateVfModuleResponseCode", 200) + } + + @Test + void testUpdateVfModuleEndpointNull() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("prefix")).thenReturn(prefix) + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable(prefix + "vnfId")).thenReturn("skask") + when(mockExecution.getVariable(prefix + "vfModuleId")).thenReturn("supercool") + when(mockExecution.getVariable("mso.workflow.default.aai.v8.generic-vnf.uri")).thenReturn("/aai/v8/network/generic-vnfs/generic-vnf") + when(mockExecution.getVariable("aai.endpoint")).thenReturn(null) + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/") + when(mockExecution.getVariable("mso.workflow.custom.UpdateAAIVfModule.aai.version")).thenReturn('8') + + String getVfModuleResponse = FileUtil.readResourceFile("__files/VfModularity/GenericVnf.xml") + when(mockExecution.getVariable(prefix + "getVfModuleResponse")).thenReturn(getVfModuleResponse) + StubResponseAAI.MockAAIVfModule() + try { + UpdateAAIVfModule obj = new UpdateAAIVfModule() + obj.updateVfModule(mockExecution) + } catch (Exception ex) { + println " Test End - Handle catch-throw BpmnError()! " + } + + Mockito.verify(mockExecution, times(3)).setVariable(captor.capture(), captor.capture()) + WorkflowException workflowException = captor.getAllValues().get(1) + Assert.assertEquals(9999, workflowException.getErrorCode()) + Assert.assertEquals("org.apache.http.client.ClientProtocolException", workflowException.getErrorMessage()) + } + + private static ExecutionEntity setupMock() { + ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class) + when(mockProcessDefinition.getKey()).thenReturn("UpdateAAIVfModule") + RepositoryService mockRepositoryService = mock(RepositoryService.class) + when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition) + when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("UpdateAAIVfModule") + when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100") + ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class) + when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService) + + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + // Initialize prerequisite variables + when(mockExecution.getId()).thenReturn("100") + when(mockExecution.getProcessDefinitionId()).thenReturn("UpdateAAIVfModule") + when(mockExecution.getProcessInstanceId()).thenReturn("UpdateAAIVfModule") + when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices) + when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition) + + return mockExecution + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/VidUtilsTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/VidUtilsTest.groovy new file mode 100644 index 0000000000..1ab049571a --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/VidUtilsTest.groovy @@ -0,0 +1,969 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts; + +import static org.mockito.Mockito.* + +import org.onap.so.bpmn.common.scripts.VidUtils; +import org.onap.so.bpmn.core.WorkflowException + +import groovy.json.JsonSlurper + +import org.camunda.bpm.engine.delegate.BpmnError +import org.camunda.bpm.engine.ProcessEngineServices +import org.camunda.bpm.engine.RepositoryService +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.camunda.bpm.engine.impl.pvm.process.ProcessDefinitionImpl +import org.camunda.bpm.engine.repository.ProcessDefinition +import org.camunda.bpm.engine.delegate.DelegateExecution; + +import static org.junit.Assert.*; + +import org.mockito.MockitoAnnotations +import org.mockito.runners.MockitoJUnitRunner +import org.mockito.internal.debugging.MockitoDebuggerImpl +import org.junit.Before +import org.junit.Rule; +import org.junit.Test +import org.junit.Ignore +import org.junit.runner.RunWith +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity; +import org.junit.Before; +import org.junit.Test; + +@RunWith(MockitoJUnitRunner.class) + +class VidUtilsTest { + + def vfModuleReqJson = """ +{ + "requestDetails": { + "modelInfo": { + "modelType": "vfModule", + "modelInvariantUuid": "ff5256d2-5a33-55df-13ab-12abad84e7ff", + "modelNameVersionId": "fe6478e5-ea33-3346-ac12-ab121484a3fe", + "modelName": "STMTN5MMSC21-MMSC::model-1-0", + "modelVersion": "1", + "modelCustomizationUuid": "ee6478e5-ea33-3346-ac12-ab121484a3fe" + }, + "cloudConfiguration": { + "lcpCloudRegionId": "MDTWNJ21", + "tenantId": "fba1bd1e195a404cacb9ce17a9b2b421" + }, + "requestInfo": { + "instanceName": "PCRF::module-0-2", + "source": "VID", + "suppressRollback": true + }, + "relatedInstanceList": [ + { + "relatedInstance": { + "instanceId": "17ef4658-bd1f-4ef0-9ca0-ea76e2bf122c", + "instanceName": "MSOTESTVOL103a-vSAMP12_base_module-0_vol", + "modelInfo": { + "modelType": "volumeGroup", + "modelInvariantUuid": "ff5256d2-5a33-55df-13ab-12abad84e7ff", + "modelNameVersionId": "fe6478e5-ea33-3346-ac12-ab121484a3fe", + "modelName": "vSAMP12..base..module-0", + "modelVersion": "1" + } + } + }, + { + "relatedInstance": { + "instanceId": "123456", + "modelInfo": { + "modelType": "service", + "modelInvariantUuid": "ff3514e3-5a33-55df-13ab-12abad84e7ff", + "modelNameVersionId": "fe6985cd-ea33-3346-ac12-ab121484a3fe", + "modelName": "SERVICE_MODEL_NAME", + "modelVersion": "1.0" + } + } + }, + { + "relatedInstance": { + "instanceId": "skask", + "instanceName": "skask-test", + "modelInfo": { + "modelType": "vnf", + "modelInvariantUuid": "skask", + "modelNameVersionId": "fe6478e4-ea33-3346-ac12-ab121484a3fe", + "modelName": "vSAMP12", + "modelVersion": "1.0", + "modelInstanceName": "vSAMP12 1" + } + } + } + ], + "requestParameters": { + "userParams": [ + { + "name": "vnfName", + "value": "STMTN5MMSC20" + }, + { + "name": "tenantId", + "value": "vpe-tenant-123" + }, + { + "name": "aicCloudRegion", + "value": "MDTWNJ21" + }, + { + "name": "isAvpnService", + "value": "true" + }, + { + "name": "asn", + "value": "asn-1234" + }, + { + "name": "releaseForAero", + "value": "release-for-aero-something" + }, + { + "name": "aicClli", + "value": "MTJWNJA4LCP" + }, + { + "name": "svcProviderPartNumber", + "value": "svc-provide-number-1234" + } + ] + } + } +} +""" + def bpmnReq1 = """ +{ + "requestDetails": { + "modelInfo": { + "modelType": "volumeGroup", + "modelId": "ff5256d2-5a33-55df-13ab-12abad84e7ff", + "modelNameVersionId": "fe6478e5-ea33-3346-ac12-ab121484a3fe", + "modelName": "vSAMP12::base::module-0", + "modelVersion": "1" + }, + "cloudConfiguration": { + "lcpCloudRegionId": "mdt1", + "tenantId": "88a6ca3ee0394ade9403f075db23167e" + }, + "requestInfo": { + "instanceName": "MSOTESTVOL101a-vSAMP12_base_vol_module-0", + "source": "VID", + "suppressRollback": false + }, + "relatedInstanceList": [ + { + "relatedInstance": { + "instanceId": "{service-instance-id}", + "modelInfo": { + "modelType": "service", + "modelId": "ff3514e3-5a33-55df-13ab-12abad84e7ff", + "modelNameVersionId": "fe6985cd-ea33-3346-ac12-ab121484a3fe", + "modelName": "Test", + "modelVersion": "2.0" + } + } + }, { + "relatedInstance": { + "instanceId": "{vnf-instance-id}", + "modelInfo": { + "modelType": "vnf", + "modelId": "ff5256d1-5a33-55df-13ab-12abad84e7ff", + "modelNameVersionId": "fe6478e4-ea33-3346-ac12-ab121484a3fe", + "modelName": "vSAMP12", + "modelVersion": "1", + "modelInstanceName": "vSAMP12" + } + } + } + ], + "requestParameters": { + "serviceId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", + "userParams": [ + {"name": "vnfName", "value": "STMTN5MMSC20" }, + {"name": "vnfName2", "value": "US1117MTSNJVBR0246" }, + {"name": "vnfNmInformation", "value": "" }, + {"name": "vnfType", "value": "pcrf-capacity" }, + {"name": "vnfId", "value": "skask" }, + {"name": "vnfStackId", "value": "slowburn" }, + {"name": "vnfStatus", "value": "created" }, + {"name": "aicCloudRegion", "value": "MDTWNJ21" }, + {"name": "availabilityZone", "value": "slcp3-esx-az01" }, + {"name": "oamNetworkName", "value": "VLAN-OAM-1323" }, + {"name": "vmName", "value": "slcp34246vbc246ceb" }, + {"name": "ipagNetworkId", "value": "970cd2b9-7f09-4a12-af47-182ea38ba1f0" }, + {"name": "vpeNetworkId", "value": "545cc2c3-1930-4100-b534-5d82d0e12bb6" } + ] + } + } +} +""" + + def vidUtilResp1 = """ + + CREATE_VF_MODULE_VOL + VID + test-service-instance-id-123 + + + + MSOTESTVOL101a-vSAMP12_base_vol_module-0 + Test/vSAMP12 + vSAMP12::base::module-0 + 2.0 + mdt1 + 88a6ca3ee0394ade9403f075db23167e + a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb + true + + + + STMTN5MMSC20 + US1117MTSNJVBR0246 + + pcrf-capacity + skask + slowburn + created + MDTWNJ21 + slcp3-esx-az01 + VLAN-OAM-1323 + slcp34246vbc246ceb + 970cd2b9-7f09-4a12-af47-182ea38ba1f0 + 545cc2c3-1930-4100-b534-5d82d0e12bb6 + + +""" + + def bpmnReq2 = """ +{ + "requestDetails": { + "modelInfo": { + "modelType": "volumeGroup", + "modelId": "ff5256d2-5a33-55df-13ab-12abad84e7ff", + "modelUuid": "fe6478e5-ea33-3346-ac12-ab121484a3fe", + "modelName": "vSAMP12::base::module-0", + "modelVersion": "1" + }, + "cloudConfiguration": { + "lcpCloudRegionId": "mdt1", + "tenantId": "88a6ca3ee0394ade9403f075db23167e" + }, + "requestInfo": { + "instanceName": "MSOTESTVOL101a-vSAMP12_base_vol_module-0", + "source": "VID", + "suppressRollback": false + }, + "relatedInstanceList": [ + { + "relatedInstance": { + "instanceId": "{service-instance-id}", + "modelInfo": { + "modelType": "service", + "modelId": "ff3514e3-5a33-55df-13ab-12abad84e7ff", + "modelUuid": "fe6985cd-ea33-3346-ac12-ab121484a3fe", + "modelName": "Test", + "modelVersion": "2.0" + } + } + }, { + "relatedInstance": { + "instanceId": "{vnf-instance-id}", + "modelInfo": { + "modelType": "vnf", + "modelId": "ff5256d1-5a33-55df-13ab-12abad84e7ff", + "modelUuid": "fe6478e4-ea33-3346-ac12-ab121484a3fe", + "modelName": "vSAMP12", + "modelVersion": "1", + "modelInstanceName": "vSAMP12" + } + } + } + ] + } +} +""" + + def bpmnReqJsonVolumeSuppressRollbackTrue = """ +{ + "requestDetails": { + "modelInfo": { + "modelType": "volumeGroup", + "modelId": "ff5256d2-5a33-55df-13ab-12abad84e7ff", + "modelUuid": "fe6478e5-ea33-3346-ac12-ab121484a3fe", + "modelName": "vSAMP12::base::module-0", + "modelVersion": "1" + }, + "cloudConfiguration": { + "lcpCloudRegionId": "mdt1", + "tenantId": "88a6ca3ee0394ade9403f075db23167e" + }, + "requestInfo": { + "instanceName": "MSOTESTVOL101a-vSAMP12_base_vol_module-0", + "source": "VID", + "suppressRollback": true + }, + "relatedInstanceList": [ + { + "relatedInstance": { + "instanceId": "{service-instance-id}", + "modelInfo": { + "modelType": "service", + "modelId": "ff3514e3-5a33-55df-13ab-12abad84e7ff", + "modelUuid": "fe6985cd-ea33-3346-ac12-ab121484a3fe", + "modelName": "Test", + "modelVersion": "2.0" + } + } + }, { + "relatedInstance": { + "instanceId": "{vnf-instance-id}", + "modelInfo": { + "modelType": "vnf", + "modelId": "ff5256d1-5a33-55df-13ab-12abad84e7ff", + "modelUuid": "fe6478e4-ea33-3346-ac12-ab121484a3fe", + "modelName": "vSAMP12", + "modelVersion": "1", + "modelInstanceName": "vSAMP12" + } + } + } + ] + } +} +""" + +def bpmnReqJsonVolumeSuppressRollbackFalse = """ +{ + "requestDetails": { + "modelInfo": { + "modelType": "volumeGroup", + "modelId": "ff5256d2-5a33-55df-13ab-12abad84e7ff", + "modelUuid": "fe6478e5-ea33-3346-ac12-ab121484a3fe", + "modelName": "vSAMP12::base::module-0", + "modelVersion": "1" + }, + "cloudConfiguration": { + "lcpCloudRegionId": "mdt1", + "tenantId": "88a6ca3ee0394ade9403f075db23167e" + }, + "requestInfo": { + "instanceName": "MSOTESTVOL101a-vSAMP12_base_vol_module-0", + "source": "VID", + "suppressRollback": false + }, + "relatedInstanceList": [ + { + "relatedInstance": { + "instanceId": "{service-instance-id}", + "modelInfo": { + "modelType": "service", + "modelId": "ff3514e3-5a33-55df-13ab-12abad84e7ff", + "modelUuid": "fe6985cd-ea33-3346-ac12-ab121484a3fe", + "modelName": "Test", + "modelVersion": "2.0" + } + } + }, { + "relatedInstance": { + "instanceId": "{vnf-instance-id}", + "modelInfo": { + "modelType": "vnf", + "modelId": "ff5256d1-5a33-55df-13ab-12abad84e7ff", + "modelUuid": "fe6478e4-ea33-3346-ac12-ab121484a3fe", + "modelName": "vSAMP12", + "modelVersion": "1", + "modelInstanceName": "vSAMP12" + } + } + } + ] + } +} +""" + +def bpmnReqJsonVolumeSuppressRollbackNone = """ +{ + "requestDetails": { + "modelInfo": { + "modelType": "volumeGroup", + "modelId": "ff5256d2-5a33-55df-13ab-12abad84e7ff", + "modelUuid": "fe6478e5-ea33-3346-ac12-ab121484a3fe", + "modelName": "vSAMP12::base::module-0", + "modelVersion": "1" + }, + "cloudConfiguration": { + "lcpCloudRegionId": "mdt1", + "tenantId": "88a6ca3ee0394ade9403f075db23167e" + }, + "requestInfo": { + "instanceName": "MSOTESTVOL101a-vSAMP12_base_vol_module-0", + "source": "VID" + }, + "relatedInstanceList": [ + { + "relatedInstance": { + "instanceId": "{service-instance-id}", + "modelInfo": { + "modelType": "service", + "modelId": "ff3514e3-5a33-55df-13ab-12abad84e7ff", + "modelUuid": "fe6985cd-ea33-3346-ac12-ab121484a3fe", + "modelName": "Test", + "modelVersion": "2.0" + } + } + }, { + "relatedInstance": { + "instanceId": "{vnf-instance-id}", + "modelInfo": { + "modelType": "vnf", + "modelId": "ff5256d1-5a33-55df-13ab-12abad84e7ff", + "modelUuid": "fe6478e4-ea33-3346-ac12-ab121484a3fe", + "modelName": "vSAMP12", + "modelVersion": "1", + "modelInstanceName": "vSAMP12" + } + } + } + ] + } +} +""" + + def bpmnReqJsonVfModuleSuppressRollbackTrue = """ +{ +"requestDetails": { +"modelInfo": { +"modelType": "vfModule", +"modelInvariantUuid": "ff5256d2-5a33-55df-13ab-12abad84e7ff", +"modelUuid": "fe6478e5-ea33-3346-ac12-ab121484a3fe", +"modelName": "STMTN5MMSC21-MMSC::model-1-0", +"modelVersion": "1" +}, +"cloudConfiguration": { +"lcpCloudRegionId": "MDTWNJ21", +"tenantId": "fba1bd1e195a404cacb9ce17a9b2b421" +}, +"requestInfo": { +"instanceName": "PCRF::module-0-2", +"source": "VID", +"suppressRollback": true +}, +"relatedInstanceList": [ +{ +"relatedInstance": { +"instanceId": "17ef4658-bd1f-4ef0-9ca0-ea76e2bf122c", +"instanceName": "MSOTESTVOL103a-vSAMP12_base_module-0_vol", +"modelInfo": { +"modelType": "volumeGroup", +"modelInvariantUuid": "ff5256d2-5a33-55df-13ab-12abad84e7ff", +"modelUuid": "fe6478e5-ea33-3346-ac12-ab121484a3fe", +"modelName": "vSAMP12..base..module-0", +"modelVersion": "1" +} +} +}, +{ +"relatedInstance": { +"instanceId": "123456", +"modelInfo": { +"modelType": "service", +"modelInvariantUuid": "ff3514e3-5a33-55df-13ab-12abad84e7ff", +"modelUuid": "fe6985cd-ea33-3346-ac12-ab121484a3fe", +"modelName": "SERVICE_MODEL_NAME", +"modelVersion": "1.0" +} +} +}, +{ +"relatedInstance": { +"instanceId": "skask", +"instanceName": "skask-test", +"modelInfo": { +"modelType": "vnf", +"modelInvariantUuid": "skask", +"modelUuid": "fe6478e4-ea33-3346-ac12-ab121484a3fe", +"modelName": "vSAMP12", +"modelVersion": "1.0", +"modelInstanceName": "vSAMP12 1" +} +} +} +], +"requestParameters": { +"userParams": {} +} +} +} +""" + +def bpmnReqJsonVfModuleSuppressRollbackFalse = """ +{ +"requestDetails": { +"modelInfo": { +"modelType": "vfModule", +"modelInvariantUuid": "ff5256d2-5a33-55df-13ab-12abad84e7ff", +"modelUuid": "fe6478e5-ea33-3346-ac12-ab121484a3fe", +"modelName": "STMTN5MMSC21-MMSC::model-1-0", +"modelVersion": "1" +}, +"cloudConfiguration": { +"lcpCloudRegionId": "MDTWNJ21", +"tenantId": "fba1bd1e195a404cacb9ce17a9b2b421" +}, +"requestInfo": { +"instanceName": "PCRF::module-0-2", +"source": "VID", +"suppressRollback": false +}, +"relatedInstanceList": [ +{ +"relatedInstance": { +"instanceId": "17ef4658-bd1f-4ef0-9ca0-ea76e2bf122c", +"instanceName": "MSOTESTVOL103a-vSAMP12_base_module-0_vol", +"modelInfo": { +"modelType": "volumeGroup", +"modelInvariantUuid": "ff5256d2-5a33-55df-13ab-12abad84e7ff", +"modelUuid": "fe6478e5-ea33-3346-ac12-ab121484a3fe", +"modelName": "vSAMP12..base..module-0", +"modelVersion": "1" +} +} +}, +{ +"relatedInstance": { +"instanceId": "123456", +"modelInfo": { +"modelType": "service", +"modelInvariantUuid": "ff3514e3-5a33-55df-13ab-12abad84e7ff", +"modelUuid": "fe6985cd-ea33-3346-ac12-ab121484a3fe", +"modelName": "SERVICE_MODEL_NAME", +"modelVersion": "1.0" +} +} +}, +{ +"relatedInstance": { +"instanceId": "skask", +"instanceName": "skask-test", +"modelInfo": { +"modelType": "vnf", +"modelInvariantUuid": "skask", +"modelUuid": "fe6478e4-ea33-3346-ac12-ab121484a3fe", +"modelName": "vSAMP12", +"modelVersion": "1.0", +"modelInstanceName": "vSAMP12 1" +} +} +} +], +"requestParameters": { +"userParams": {} +} +} +} +""" + +def bpmnReqJsonVfModuleSuppressRollbackNone = """ +{ +"requestDetails": { +"modelInfo": { +"modelType": "vfModule", +"modelInvariantUuid": "ff5256d2-5a33-55df-13ab-12abad84e7ff", +"modelUuid": "fe6478e5-ea33-3346-ac12-ab121484a3fe", +"modelName": "STMTN5MMSC21-MMSC::model-1-0", +"modelVersion": "1" +}, +"cloudConfiguration": { +"lcpCloudRegionId": "MDTWNJ21", +"tenantId": "fba1bd1e195a404cacb9ce17a9b2b421" +}, +"requestInfo": { +"instanceName": "PCRF::module-0-2", +"source": "VID" +}, +"relatedInstanceList": [ +{ +"relatedInstance": { +"instanceId": "17ef4658-bd1f-4ef0-9ca0-ea76e2bf122c", +"instanceName": "MSOTESTVOL103a-vSAMP12_base_module-0_vol", +"modelInfo": { +"modelType": "volumeGroup", +"modelInvariantUuid": "ff5256d2-5a33-55df-13ab-12abad84e7ff", +"modelUuid": "fe6478e5-ea33-3346-ac12-ab121484a3fe", +"modelName": "vSAMP12..base..module-0", +"modelVersion": "1" +} +} +}, +{ +"relatedInstance": { +"instanceId": "123456", +"modelInfo": { +"modelType": "service", +"modelInvariantUuid": "ff3514e3-5a33-55df-13ab-12abad84e7ff", +"modelUuid": "fe6985cd-ea33-3346-ac12-ab121484a3fe", +"modelName": "SERVICE_MODEL_NAME", +"modelVersion": "1.0" +} +} +}, +{ +"relatedInstance": { +"instanceId": "skask", +"instanceName": "skask-test", +"modelInfo": { +"modelType": "vnf", +"modelInvariantUuid": "skask", +"modelUuid": "fe6478e4-ea33-3346-ac12-ab121484a3fe", +"modelName": "vSAMP12", +"modelVersion": "1.0", +"modelInstanceName": "vSAMP12 1" +} +} +} +], +"requestParameters": { +"userParams": {} +} +} +} +""" + def vidUtilResp2 = """ + + CREATE_VF_MODULE_VOL + VID + test-service-instance-id-123 + + + + MSOTESTVOL101a-vSAMP12_base_vol_module-0 + Test/vSAMP12 + vSAMP12::base::module-0 + 2.0 + mdt1 + 88a6ca3ee0394ade9403f075db23167e + + true + + + + +""" + +def vidUtilVolumeRespBackoutOnFailureFalse = """ + + CREATE_VF_MODULE_VOL + VID + test-service-instance-id-123 + + + + MSOTESTVOL101a-vSAMP12_base_vol_module-0 + Test/vSAMP12 + vSAMP12::base::module-0 + 2.0 + mdt1 + 88a6ca3ee0394ade9403f075db23167e + + false + + + + +""" + +def vidUtilVolumeRespBackoutOnFailureTrue = """ + + CREATE_VF_MODULE_VOL + VID + test-service-instance-id-123 + + + + MSOTESTVOL101a-vSAMP12_base_vol_module-0 + Test/vSAMP12 + vSAMP12::base::module-0 + 2.0 + mdt1 + 88a6ca3ee0394ade9403f075db23167e + + true + + + + +""" + +def vidUtilVolumeRespBackoutOnFailureEmpty = """ + + CREATE_VF_MODULE_VOL + VID + test-service-instance-id-123 + + + + MSOTESTVOL101a-vSAMP12_base_vol_module-0 + Test/vSAMP12 + vSAMP12::base::module-0 + 2.0 + mdt1 + 88a6ca3ee0394ade9403f075db23167e + + + + + + +""" + +def vidUtilVfModuleRespBackoutOnFailureFalse = """ + + test-request-id-123 + CREATE_VF_MODULE + VID + test-service-instance-id-123 + + + skask-test + test-vnf-type-123 + test-vnf-id-123 + test-volume-group-id-123 + test-vf-module-id-123 + PCRF::module-0-2 + STMTN5MMSC21-MMSC::model-1-0 + + false + 1.0 + MDTWNJ21 + fba1bd1e195a404cacb9ce17a9b2b421 + + false + ff5256d2-5a33-55df-13ab-12abad84e7ff + fe6478e5-ea33-3346-ac12-ab121484a3fe + + + +""" + +def vidUtilVfModuleRespBackoutOnFailureTrue = """ + + test-request-id-123 + CREATE_VF_MODULE + VID + test-service-instance-id-123 + + + skask-test + test-vnf-type-123 + test-vnf-id-123 + test-volume-group-id-123 + test-vf-module-id-123 + PCRF::module-0-2 + STMTN5MMSC21-MMSC::model-1-0 + + false + 1.0 + MDTWNJ21 + fba1bd1e195a404cacb9ce17a9b2b421 + + true + ff5256d2-5a33-55df-13ab-12abad84e7ff + fe6478e5-ea33-3346-ac12-ab121484a3fe + + + +""" + +def vidUtilVfModuleRespBackoutOnFailureEmpty = """ + + test-request-id-123 + CREATE_VF_MODULE + VID + test-service-instance-id-123 + + + skask-test + test-vnf-type-123 + test-vnf-id-123 + test-volume-group-id-123 + test-vf-module-id-123 + PCRF::module-0-2 + STMTN5MMSC21-MMSC::model-1-0 + + false + 1.0 + MDTWNJ21 + fba1bd1e195a404cacb9ce17a9b2b421 + + + ff5256d2-5a33-55df-13ab-12abad84e7ff + fe6478e5-ea33-3346-ac12-ab121484a3fe + + + +""" + + @Before + public void init() + { + MockitoAnnotations.initMocks(this) + + } + + @Test + public void test() { + + def jsonSlurper = new JsonSlurper() + Map reqMap = jsonSlurper.parseText(bpmnReq1) + + VidUtils vidUtils = new VidUtils() + def xmlReq = vidUtils.createXmlVolumeRequest(reqMap, 'CREATE_VF_MODULE_VOL', 'test-service-instance-id-123') + print xmlReq + assertEquals(vidUtilResp1, xmlReq) + } + + //@Test + public void testVfModule() { + + def jsonSlurper = new JsonSlurper() + Map reqMap = jsonSlurper.parseText(vfModuleReqJson) + + VidUtils vidUtils = new VidUtils() + def xmlReq = vidUtils.createXmlVfModuleRequest(null, reqMap, "CREATE_VF_MODULE", "test-service-instance-id-123") + print xmlReq + assertTrue(true) + } + + @Test + public void testNoRequestParams() { + + def jsonSlurper = new JsonSlurper() + Map reqMap = jsonSlurper.parseText(bpmnReq2) + + VidUtils vidUtils = new VidUtils() + def xmlReq = vidUtils.createXmlVolumeRequest(reqMap, 'CREATE_VF_MODULE_VOL', 'test-service-instance-id-123') + + assertEquals(vidUtilResp2, xmlReq) + } + + @Test + public void testVfModuleVolumeRollbackTrue() { + + def jsonSlurper = new JsonSlurper() + Map reqMap = jsonSlurper.parseText(bpmnReqJsonVolumeSuppressRollbackTrue) + + VidUtils vidUtils = new VidUtils() + def xmlReq = vidUtils.createXmlVolumeRequest(reqMap, 'CREATE_VF_MODULE_VOL', 'test-service-instance-id-123') + + assertEquals(vidUtilVolumeRespBackoutOnFailureFalse, xmlReq) + } + + @Test + public void testVfModuleVolumeRollbackFalse() { + + def jsonSlurper = new JsonSlurper() + Map reqMap = jsonSlurper.parseText(bpmnReqJsonVolumeSuppressRollbackFalse) + + VidUtils vidUtils = new VidUtils() + def xmlReq = vidUtils.createXmlVolumeRequest(reqMap, 'CREATE_VF_MODULE_VOL', 'test-service-instance-id-123') + + assertEquals(vidUtilVolumeRespBackoutOnFailureTrue, xmlReq) + } + + @Test + public void testVfModuleVolumeRollbackNone() { + + def jsonSlurper = new JsonSlurper() + Map reqMap = jsonSlurper.parseText(bpmnReqJsonVolumeSuppressRollbackNone) + + VidUtils vidUtils = new VidUtils() + def xmlReq = vidUtils.createXmlVolumeRequest(reqMap, 'CREATE_VF_MODULE_VOL', 'test-service-instance-id-123') + + assertEquals(vidUtilVolumeRespBackoutOnFailureEmpty, xmlReq) + } + + @Test + public void testVfModuleRollbackTrue() { + + def jsonSlurper = new JsonSlurper() + Map reqMap = jsonSlurper.parseText(bpmnReqJsonVfModuleSuppressRollbackTrue) + + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getVariable("vnfType")).thenReturn('test-vnf-type-123') + when(mockExecution.getVariable("vnfId")).thenReturn('test-vnf-id-123') + when(mockExecution.getVariable("vfModuleId")).thenReturn('test-vf-module-id-123') + when(mockExecution.getVariable("volumeGroupId")).thenReturn('test-volume-group-id-123') + when(mockExecution.getVariable("isBaseVfModule")).thenReturn('false') + when(mockExecution.getVariable("mso-request-id")).thenReturn('test-request-id-123') + + VidUtils vidUtils = new VidUtils() + def xmlReq = vidUtils.createXmlVfModuleRequest(mockExecution, reqMap, 'CREATE_VF_MODULE', 'test-service-instance-id-123') + + println 'ggg->' + xmlReq + assertEquals(vidUtilVfModuleRespBackoutOnFailureFalse, xmlReq) + } + + @Test + public void testVfModuleRollbackFalse() { + + def jsonSlurper = new JsonSlurper() + Map reqMap = jsonSlurper.parseText(bpmnReqJsonVfModuleSuppressRollbackFalse) + + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getVariable("vnfType")).thenReturn('test-vnf-type-123') + when(mockExecution.getVariable("vnfId")).thenReturn('test-vnf-id-123') + when(mockExecution.getVariable("vfModuleId")).thenReturn('test-vf-module-id-123') + when(mockExecution.getVariable("volumeGroupId")).thenReturn('test-volume-group-id-123') + when(mockExecution.getVariable("isBaseVfModule")).thenReturn('false') + when(mockExecution.getVariable("mso-request-id")).thenReturn('test-request-id-123') + + VidUtils vidUtils = new VidUtils() + def xmlReq = vidUtils.createXmlVfModuleRequest(mockExecution, reqMap, 'CREATE_VF_MODULE', 'test-service-instance-id-123') + + println 'ggg->' + xmlReq + assertEquals(vidUtilVfModuleRespBackoutOnFailureTrue, xmlReq) + } + + @Test + public void testVfModuleRollbackNone() { + + def jsonSlurper = new JsonSlurper() + Map reqMap = jsonSlurper.parseText(bpmnReqJsonVfModuleSuppressRollbackNone) + + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getVariable("vnfType")).thenReturn('test-vnf-type-123') + when(mockExecution.getVariable("vnfId")).thenReturn('test-vnf-id-123') + when(mockExecution.getVariable("vfModuleId")).thenReturn('test-vf-module-id-123') + when(mockExecution.getVariable("volumeGroupId")).thenReturn('test-volume-group-id-123') + when(mockExecution.getVariable("isBaseVfModule")).thenReturn('false') + when(mockExecution.getVariable("mso-request-id")).thenReturn('test-request-id-123') + + VidUtils vidUtils = new VidUtils() + def xmlReq = vidUtils.createXmlVfModuleRequest(mockExecution, reqMap, 'CREATE_VF_MODULE', 'test-service-instance-id-123') + + println 'ggg->' + xmlReq + assertEquals(vidUtilVfModuleRespBackoutOnFailureEmpty, xmlReq) + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/VnfAdapterRestV1Test.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/VnfAdapterRestV1Test.groovy new file mode 100644 index 0000000000..22c8e297ca --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/VnfAdapterRestV1Test.groovy @@ -0,0 +1,118 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts + +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.MockitoAnnotations +import org.mockito.internal.debugging.MockitoDebuggerImpl +import org.mockito.runners.MockitoJUnitRunner +import org.onap.so.bpmn.mock.FileUtil + +import static org.mockito.Mockito.* +import static org.junit.Assert.*; + +@RunWith(MockitoJUnitRunner.class) +public class VnfAdapterRestV1Test { + + @Before + public void init() + { + MockitoAnnotations.initMocks(this) + } + + + @Test + public void testPreProcessRequest() { + + String sdncAdapterWorkflowRequest = FileUtil.readResourceFile("__files/vnfAdapterMocks/vnfadapter_request.xml"); + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getVariable("prefix")).thenReturn("VNFREST_") + when(mockExecution.getVariable("mso-request-id")).thenReturn("testMsoRequestId") + when(mockExecution.getVariable("VNFREST_Request")).thenReturn(sdncAdapterWorkflowRequest) + when(mockExecution.getVariable("mso.adapters.po.auth")).thenReturn("3141634BF7E070AA289CF2892C986C0B") + when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7") + + when(mockExecution.getVariable("mso.adapters.vnf.rest.endpoint")).thenReturn("http://localhost:18080/vnfs/rest/v1/vnfs") + + when(mockExecution.getVariable("mso.adapters.sdnc.timeout")).thenReturn("PT5M") + + when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") + when(mockExecution.getVariable("testProcessKey")).thenReturn("testProcessKey") + + + VnfAdapterRestV1 vnfAdapterRestV1 = new VnfAdapterRestV1() + vnfAdapterRestV1.preProcessRequest(mockExecution) + + MockitoDebuggerImpl debugger = new MockitoDebuggerImpl() + //debugger.printInvocations(mockExecution) + + + verify(mockExecution).setVariable("prefix","VNFREST_") + + verify(mockExecution).setVariable("VNFREST_SuccessIndicator",false) + verify(mockExecution).setVariable("VNFREST_requestType","createVfModuleRequest") + verify(mockExecution).setVariable("VNFAResponse_CORRELATOR","8892cffa-3514-45d4-b2b0-0fde9a96e323-1511813289000") + verify(mockExecution).setVariable("VNFREST_vnfAdapterMethod","POST") + verify(mockExecution).setVariable("VNFREST_notificationUrl","http://localhost:18080/mso/WorkflowMessage/VNFAResponse/8892cffa-3514-45d4-b2b0-0fde9a96e323-1511813289000") + verify(mockExecution).setVariable("VNFREST_vnfAdapterUrl","http://localhost:18080/vnfs/rest/v1/vnfs/6d2e2469-8708-47c3-a0d4-73fa28a8a50b/vf-modules") + + } + + def rollbackReq = """ + + + 8a07b246-155e-4b08-b56e-76e98a3c2d66 + phmaz401me6-vpevre-VOLUMEGROUP/dbd560b6-b03f-4a17-92e7-8942459a60c1 + mtrnj1b + cfb5e0a790374c9a98a1c0d2044206a7 + true + + 1e1a72ca-7300-4ac4-b718-30351f3b6845 + 15eb2c68-f771-4030-b185-cff179fdad44 + + 683ca1ac-2145-4a00-9484-20d48bd701aa + + true + http://localhost:8080/mso/WorkflowMessage/VNFAResponse/683ca1ac-2145-4a00-9484-20d48bd701aa + +""" + + @Test + public void testGetVolumeGroupId() { + Node root = new XmlParser().parseText(rollbackReq) + VnfAdapterRestV1 vnfAdapterRestV1 = new VnfAdapterRestV1() + def volGrpId = vnfAdapterRestV1.getVolumeGroupIdFromRollbackRequest(root) + assertEquals('8a07b246-155e-4b08-b56e-76e98a3c2d66', volGrpId) + } + + + @Test + public void testGetMessageId() { + Node root = new XmlParser().parseText(rollbackReq) + + VnfAdapterRestV1 p = new VnfAdapterRestV1() + def messageId = p.getMessageIdForVolumeGroupRollback(root) + assertEquals('683ca1ac-2145-4a00-9484-20d48bd701aa', messageId) + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/utils/IgnoreNamedElementsDifferenceListener.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/utils/IgnoreNamedElementsDifferenceListener.groovy new file mode 100644 index 0000000000..9c38634885 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/utils/IgnoreNamedElementsDifferenceListener.groovy @@ -0,0 +1,51 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts.utils + +import org.custommonkey.xmlunit.Difference +import org.custommonkey.xmlunit.DifferenceConstants +import org.custommonkey.xmlunit.DifferenceListener +import org.w3c.dom.Node + +class IgnoreNamedElementsDifferenceListener implements DifferenceListener { + private Set blackList = new HashSet(); + + public IgnoreNamedElementsDifferenceListener(String ... ignoreTags) { + for (String name : ignoreTags) { + blackList.add(name); + } + } + + public int differenceFound(Difference difference) { + if (difference.getId() == DifferenceConstants.TEXT_VALUE_ID) { + if (blackList.contains(difference.getControlNodeDetail().getNode().getParentNode().getNodeName())) { + return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL; + } + } + + return DifferenceListener.RETURN_ACCEPT_DIFFERENCE; + } + + + public void skippedComparison(Node node, Node node1) { + + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/utils/XmlComparator.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/utils/XmlComparator.groovy new file mode 100644 index 0000000000..e1c86edd90 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/utils/XmlComparator.groovy @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.bpmn.common.scripts.utils + +import org.custommonkey.xmlunit.DetailedDiff +import org.custommonkey.xmlunit.XMLUnit +import org.junit.Assert + + +class XmlComparator { + + public static void assertXMLEquals(String expectedXML, String actualXML, String ... ignoreTags ) throws Exception { + XMLUnit.setIgnoreWhitespace(true); + XMLUnit.setIgnoreAttributeOrder(true); + + DetailedDiff diff = new DetailedDiff(XMLUnit.compareXML(expectedXML, actualXML)); + + diff.overrideDifferenceListener(new IgnoreNamedElementsDifferenceListener(ignoreTags)); + + List allDifferences = diff.getAllDifferences(); + Assert.assertEquals("Differences found: "+ diff.toString(), 0, allDifferences.size()); + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/AaiUtilTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/AaiUtilTest.groovy deleted file mode 100644 index b4b2b951b2..0000000000 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/AaiUtilTest.groovy +++ /dev/null @@ -1,385 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * 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.scripts; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.* - -import org.openecomp.mso.rest.HttpHeader -import org.mockito.MockitoAnnotations -import org.mockito.runners.MockitoJUnitRunner -import org.mockito.internal.debugging.MockitoDebuggerImpl -import org.junit.Before -import org.openecomp.mso.bpmn.common.scripts.AaiUtil; -import org.junit.Rule; -import org.junit.Test -import org.junit.Ignore -import org.junit.runner.RunWith -import org.junit.Before; -import org.junit.Test; -import org.camunda.bpm.engine.ProcessEngineServices -import org.camunda.bpm.engine.RepositoryService -import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity -import org.camunda.bpm.engine.impl.pvm.process.ProcessDefinitionImpl -import org.camunda.bpm.engine.repository.ProcessDefinition - -@RunWith(MockitoJUnitRunner.class) -class AaiUtilTest extends MsoGroovyTest { - - @Test - public void testGetVersionDefault() { - ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8') - CreateAAIVfModule myproc = new CreateAAIVfModule() - AaiUtil aaiUtil = new AaiUtil(myproc) - def version = aaiUtil.getVersion(mockExecution, 'l3-network', 'CreateAAIVfModule') - assertEquals('8', version) - } - - @Test - public void testGetVersionResourceSpecific() { - ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - when(mockExecution.getVariable("URN_mso_workflow_default_aai_l3_network_version")).thenReturn('7') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8') - CreateAAIVfModule myproc = new CreateAAIVfModule() - AaiUtil aaiUtil = new AaiUtil(myproc) - def version = aaiUtil.getVersion(mockExecution, 'l3-network', 'CreateAAIVfModule') - assertEquals('7', version) - } - - @Test - public void testGetVersionFlowSpecific() { - ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - when(mockExecution.getVariable("URN_mso_workflow_custom_CreateAAIVfModule_aai_version")).thenReturn('6') - when(mockExecution.getVariable("URN_mso_workflow_default_aai_l3_network_version")).thenReturn('7') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8') - CreateAAIVfModule myproc = new CreateAAIVfModule() - AaiUtil aaiUtil = new AaiUtil(myproc) - def version = aaiUtil.getVersion(mockExecution, 'l3-network', 'CreateAAIVfModule') - assertEquals('6', version) - } - - @Test(expected=java.lang.Exception.class) - public void testGetVersionNotDefined() { - ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - CreateAAIVfModule myproc = new CreateAAIVfModule() - AaiUtil aaiUtil = new AaiUtil(myproc) - def version = aaiUtil.getVersion(mockExecution, 'l3-network', 'CreateAAIVfModule') - } - - @Test - public void testGetUriDefaultVersion() { - ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_l3_network_uri")).thenReturn('/aai/v8/network/l3-networks/l3-network') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn('http://org.openecomp.aai.inventory/') - - CreateAAIVfModule myproc = new CreateAAIVfModule() - AaiUtil aaiUtil = new AaiUtil(myproc) - def uri = aaiUtil.getUri(mockExecution, 'l3-network') - assertEquals('/aai/v8/network/l3-networks/l3-network', uri) - } - - @Test - public void testGetUriFlowAndResourceSpecific() { - ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - when(mockExecution.getVariable("URN_mso_workflow_CreateAAIVfModule_aai_l3_network_uri")).thenReturn('/aai/v6/network/l3-networks/l3-network') - when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_l3_network_uri")).thenReturn('/aai/v8/network/l3-networks/l3-network') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn('http://org.openecomp.aai.inventory/') - - CreateAAIVfModule myproc = new CreateAAIVfModule() - AaiUtil aaiUtil = new AaiUtil(myproc) - def uri = aaiUtil.getUri(mockExecution, 'l3-network') - assertEquals('/aai/v6/network/l3-networks/l3-network', uri) - } - - @Test - public void testGetNetworkGenericVnfEndpoint() { - ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8') - when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_generic_vnf_uri")).thenReturn('/aai/v8/network/generic-vnfs/generic-vnf') - when(mockExecution.getVariable('URN_aai_endpoint')).thenReturn('http://localhost:28090') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn('http://org.openecomp.aai.inventory/') - - CreateAAIVfModule myproc = new CreateAAIVfModule() - AaiUtil aaiUtil = new AaiUtil(myproc) - def endpoint = aaiUtil.getNetworkGenericVnfEndpoint(mockExecution) - assertEquals('http://localhost:28090/aai/v8/network/generic-vnfs/generic-vnf', endpoint) - } - - @Test - public void testGetNetworkGenericVnfUri() { - ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8') - when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_generic_vnf_uri")).thenReturn('/aai/v8/network/generic-vnfs/generic-vnf') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn('http://org.openecomp.aai.inventory/') - - CreateAAIVfModule myproc = new CreateAAIVfModule() - AaiUtil aaiUtil = new AaiUtil(myproc) - def uri = aaiUtil.getNetworkGenericVnfUri(mockExecution) - assertEquals('/aai/v8/network/generic-vnfs/generic-vnf', uri) - } - - @Test - public void testGetNetworkVpnBindingUri() { - ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8') - when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_vpn_binding_uri")).thenReturn('/aai/v8/network/vpn-bindings/vpn-binding') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn('http://org.openecomp.aai.inventory/') - - CreateAAIVfModule myproc = new CreateAAIVfModule() - AaiUtil aaiUtil = new AaiUtil(myproc) - def uri = aaiUtil.getNetworkVpnBindingUri(mockExecution) - assertEquals('/aai/v8/network/vpn-bindings/vpn-binding', uri) - } - - @Test - public void testGetNetworkPolicyUri() { - ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8') - when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_network_policy_uri")).thenReturn('/aai/v8/network/network-policies/network-policy') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn('http://org.openecomp.aai.inventory/') - - CreateAAIVfModule myproc = new CreateAAIVfModule() - AaiUtil aaiUtil = new AaiUtil(myproc) - def uri = aaiUtil.getNetworkPolicyUri(mockExecution) - assertEquals('/aai/v8/network/network-policies/network-policy', uri) - } - - @Test - public void testGetNetworkTableReferencesUri() { - ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8') - when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_route_table_reference_uri")).thenReturn('/aai/v8/network/route-table-references/route-table-reference') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn('http://org.openecomp.aai.inventory/') - - CreateAAIVfModule myproc = new CreateAAIVfModule() - AaiUtil aaiUtil = new AaiUtil(myproc) - def uri = aaiUtil.getNetworkTableReferencesUri(mockExecution) - assertEquals('/aai/v8/network/route-table-references/route-table-reference', uri) - } - - @Test - public void testGetNetworkVceUri() { - ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8') - when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_vce_uri")).thenReturn('/aai/v8/network/vces/vce') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn('http://org.openecomp.aai.inventory/') - - CreateAAIVfModule myproc = new CreateAAIVfModule() - AaiUtil aaiUtil = new AaiUtil(myproc) - def uri = aaiUtil.getNetworkVceUri(mockExecution) - assertEquals('/aai/v8/network/vces/vce', uri) - } - - @Test - public void testGetNetworkL3NetworkUri() { - ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8') - when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_l3_network_uri")).thenReturn('/aai/v8/network/l3-networks/l3-network') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn('http://org.openecomp.aai.inventory/') - - CreateAAIVfModule myproc = new CreateAAIVfModule() - AaiUtil aaiUtil = new AaiUtil(myproc) - def uri = aaiUtil.getNetworkL3NetworkUri(mockExecution) - assertEquals('/aai/v8/network/l3-networks/l3-network', uri) - } - - @Test - public void testGetBusinessCustomerUri() { - ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8') - when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_customer_uri")).thenReturn('/aai/v8/business/customers/customer') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn('http://org.openecomp.aai.inventory/') - - CreateAAIVfModule myproc = new CreateAAIVfModule() - AaiUtil aaiUtil = new AaiUtil(myproc) - def uri = aaiUtil.getBusinessCustomerUri(mockExecution) - assertEquals('/aai/v8/business/customers/customer', uri) - } - - @Test - public void testGetCloudInfrastructureCloudRegionEndpoint() { - ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8') - when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_cloud_region_uri")).thenReturn('/aai/v8/cloud-infrastructure/cloud-regions/cloud-region/att-aic') - when(mockExecution.getVariable('URN_aai_endpoint')).thenReturn('http://localhost:28090') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn('http://org.openecomp.aai.inventory/') - - CreateAAIVfModule myproc = new CreateAAIVfModule() - AaiUtil aaiUtil = new AaiUtil(myproc) - def uri = aaiUtil.getCloudInfrastructureCloudRegionEndpoint(mockExecution) - assertEquals('http://localhost:28090/aai/v8/cloud-infrastructure/cloud-regions/cloud-region/att-aic', uri) - } - - @Test - public void testGetCloudInfrastructureCloudRegionUri() { - ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8') - when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_cloud_region_uri")).thenReturn('/aai/v8/cloud-infrastructure/cloud-regions/cloud-region/att-aic') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn('http://org.openecomp.aai.inventory/') - - CreateAAIVfModule myproc = new CreateAAIVfModule() - AaiUtil aaiUtil = new AaiUtil(myproc) - def uri = aaiUtil.getCloudInfrastructureCloudRegionUri(mockExecution) - assertEquals('/aai/v8/cloud-infrastructure/cloud-regions/cloud-region/att-aic', uri) - } - - @Test - public void testGetCloudInfrastructureTenantUri() { - ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8') - when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_tenant_uri")).thenReturn('/aai/v8/cloud-infrastructure/tenants/tenant') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn('http://org.openecomp.aai.inventory/') - - CreateAAIVfModule myproc = new CreateAAIVfModule() - AaiUtil aaiUtil = new AaiUtil(myproc) - def uri = aaiUtil.getCloudInfrastructureTenantUri(mockExecution) - assertEquals('/aai/v8/cloud-infrastructure/tenants/tenant', uri) - } - - @Test - public void testGetSearchNodesQueryUri() { - ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8') - when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_nodes_query_uri")).thenReturn('/aai/v8/search/nodes-query') - when(mockExecution.getVariable('URN_aai_endpoint')).thenReturn('http://localhost:28090') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn('http://org.openecomp.aai.inventory/') - - CreateAAIVfModule myproc = new CreateAAIVfModule() - AaiUtil aaiUtil = new AaiUtil(myproc) - def uri = aaiUtil.getSearchNodesQueryUri(mockExecution) - assertEquals('/aai/v8/search/nodes-query', uri) - } - - @Test - public void testGetSearchNodesQueryEndpoint() { - ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8') - when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_nodes_query_uri")).thenReturn('/aai/v8/search/nodes-query') - when(mockExecution.getVariable('URN_aai_endpoint')).thenReturn('http://localhost:28090') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn('http://org.openecomp.aai.inventory/') - - CreateAAIVfModule myproc = new CreateAAIVfModule() - AaiUtil aaiUtil = new AaiUtil(myproc) - def uri = aaiUtil.getSearchNodesQueryEndpoint(mockExecution) - assertEquals('http://localhost:28090/aai/v8/search/nodes-query', uri) - } - - @Test - public void testGetSearchGenericQueryUri() { - ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('8') - when(mockExecution.getVariable("URN_mso_workflow_default_aai_v8_generic_query_uri")).thenReturn('/aai/v8/search/generic-query') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn('http://org.openecomp.aai.inventory/') - - CreateAAIVfModule myproc = new CreateAAIVfModule() - AaiUtil aaiUtil = new AaiUtil(myproc) - def uri = aaiUtil.getSearchGenericQueryUri(mockExecution) - assertEquals('/aai/v8/search/generic-query', uri) - } - - @Test - public void testGetNamespaceFromUri() { - ExecutionEntity mockExecution = setupMock('CreateAAIVfModule') - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('6') - when(mockExecution.getVariable("URN_mso_workflow_default_aai_v6_l3_network_uri")).thenReturn('/aai/v6/network/l3-networks/l3-network') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn('http://org.openecomp.aai.inventory/') - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - CreateAAIVfModule myproc = new CreateAAIVfModule() - AaiUtil aaiUtil = new AaiUtil(myproc) - def uri = aaiUtil.getNetworkL3NetworkUri(mockExecution) // Required to populate the namespace in the class - def ns = aaiUtil.getNamespaceFromUri('/aai/v6/search/generic-query') - assertEquals('http://org.openecomp.aai.inventory/v6', ns) - } - - @Test - public void testGetNamespaceFromUri2() { - ExecutionEntity mockExecution = setupMock('DeleteVfModuleVolumeInfraV1') - // - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('10') - when(mockExecution.getVariable("URN_mso_workflow_default_aai_v10_l3_network_uri")).thenReturn('/aai/v10/network/l3-networks/l3-network') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn('http://org.openecomp.aai.inventory/') - // - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - CreateAAIVfModule myproc = new CreateAAIVfModule() - AaiUtil aaiUtil = new AaiUtil(myproc) - def uri = aaiUtil.getNetworkL3NetworkUri(mockExecution) // Required to populate the namespace in the class - def ns = aaiUtil.getNamespaceFromUri('/aai/v10/search/generic-query') - assertEquals('http://org.openecomp.aai.inventory/v10', ns) - } - - @Test - public void testGetNamespaceFromUri3() { - ExecutionEntity mockExecution = setupMock('DeleteVfModuleVolumeInfraV1') - // - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('100') - when(mockExecution.getVariable("URN_mso_workflow_default_aai_v100_l3_network_uri")).thenReturn('/aai/v100/network/l3-networks/l3-network') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn('http://org.openecomp.aai.inventory/') - // - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - CreateAAIVfModule myproc = new CreateAAIVfModule() - AaiUtil aaiUtil = new AaiUtil(myproc) - def uri = aaiUtil.getNetworkL3NetworkUri(mockExecution) // Required to populate the namespace in the class - def ns = aaiUtil.getNamespaceFromUri('/aai/v100/search/generic-query') - assertEquals('http://org.openecomp.aai.inventory/v100', ns) - } - - @Test - public void testGetNamespaceFromUri_twoArguments() { // (execution, uri) - ExecutionEntity mockExecution = setupMock('DeleteVfModuleVolumeInfraV1') - // - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn('10') - when(mockExecution.getVariable("URN_mso_workflow_default_aai_v10_l3_network_uri")).thenReturn('/aai/v10/network/l3-networks/l3-network') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn('http://org.openecomp.aai.inventory/') - // - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - CreateAAIVfModule myproc = new CreateAAIVfModule() - AaiUtil aaiUtil = new AaiUtil(myproc) - def ns = aaiUtil.getNamespaceFromUri(mockExecution,'/aai/v10/search/generic-query') - assertEquals('http://org.openecomp.aai.inventory/v10', ns) - } -} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/CompleteMsoProcessTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/CompleteMsoProcessTest.groovy deleted file mode 100644 index 5949c3af53..0000000000 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/CompleteMsoProcessTest.groovy +++ /dev/null @@ -1,170 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * 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.scripts - -import org.camunda.bpm.engine.delegate.BpmnError -import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity -import org.junit.Before -import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.ArgumentCaptor -import org.mockito.MockitoAnnotations -import org.mockito.runners.MockitoJUnitRunner -import org.openecomp.mso.bpmn.core.WorkflowException - -import static org.assertj.core.api.Assertions.assertThat -import static org.assertj.core.api.Assertions.assertThatThrownBy -import static org.mockito.Matchers.eq -import static org.mockito.Mockito.* - -@RunWith(MockitoJUnitRunner.class) -class CompleteMsoProcessTest { - @Before - public void init() { - MockitoAnnotations.initMocks(this) - } - - private String completeMsoProcessRequest = """ - - - uCPE1020_STUW105_5002 - Layer3ServiceActivateRequest - COMPLETE - OMX - http://localhost:28090/CCD/StatusNotification - 10205000 - 1 - - UCPELayer3ServiceActivateV1 - - """ - - @Test - public void testPreProcessRequest() { - - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - when(mockExecution.getVariable("CompleteMsoProcessRequest")).thenReturn(completeMsoProcessRequest) - when(mockExecution.getVariable("URN_mso_adapters_db_auth")).thenReturn("757A94191D685FD2092AC1490730A4FC"); - when(mockExecution.getVariable("URN_mso_msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7"); - - CompleteMsoProcess completeMsoProcess = new CompleteMsoProcess() - completeMsoProcess.preProcessRequest(mockExecution) - - /* Initialize all the process request variables in this block */ - verify(mockExecution).setVariable("prefix","CMSO_") - //verify(mockExecution).setVariable("getLayer3ServiceDetailsV1Response","") - verify(mockExecution).setVariable("CMSO_request_id","") - verify(mockExecution).setVariable("CMSO_notification-url","") - verify(mockExecution).setVariable("CMSO_mso-bpel-name","") - verify(mockExecution).setVariable("CMSO_request_action","") - - verify(mockExecution).setVariable("CMSO_notification-url-Ok", false) - verify(mockExecution).setVariable("CMSO_request_id-Ok", false) - - //updateRequest Adapter process variables - verify(mockExecution).setVariable("CMSO_updateRequestResponse", "") - verify(mockExecution).setVariable("CMSO_updateRequestResponseCode", "") - verify(mockExecution).setVariable("CMSO_updateFinalNotifyAckStatusFailedPayload", "") - - //Set DB adapter variables here - verify(mockExecution).setVariable("CMSO_updateDBStatusToSuccessPayload", "") - verify(mockExecution).setVariable("CMSO_updateInfraRequestDBPayload", "") - verify(mockExecution).setVariable("CMSO_setUpdateDBstatustoSuccessPayload", "") - - //Auth variables - verify(mockExecution).setVariable("BasicAuthHeaderValue","") - - //Response variables - verify(mockExecution).setVariable("CompletionHandlerResponse","") - verify(mockExecution).setVariable("CMSO_ErrorResponse", null) - verify(mockExecution).setVariable("CMSO_ResponseCode", "") - - verify(mockExecution).setVariable("CMSO_notification-url-Ok",true) - verify(mockExecution).setVariable("CMSO_request_id-Ok",true) - verify(mockExecution).setVariable("CMSO_notification-url","http://localhost:28090/CCD/StatusNotification") - verify(mockExecution).setVariable("CMSO_request_id","uCPE1020_STUW105_5002") - verify(mockExecution).setVariable("CMSO_request_action","Layer3ServiceActivateRequest") - verify(mockExecution).setVariable("CMSO_source","OMX") - - } - - private String setUpdateDBstatustoSuccessPayload = """ - - - - - testReqId - BPEL - Resource Completed Successfully - COMPLETE - 100 - - - - """ - - @Test - public void testsetUpdateDBstatustoSuccessPayload(){ - - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - when(mockExecution.getVariable("CMSO_request_id")).thenReturn("testReqId") - when(mockExecution.getVariable("CMSO_mso-bpel-name")).thenReturn("BPEL") - when(mockExecution.getVariable("URN_mso_adapters_db_auth")).thenReturn("757A94191D685FD2092AC1490730A4FC"); - when(mockExecution.getVariable("URN_mso_msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7"); - - CompleteMsoProcess completeMsoProcess = new CompleteMsoProcess() - completeMsoProcess.setUpdateDBstatustoSuccessPayload(mockExecution) - - verify(mockExecution).setVariable("CMSO_setUpdateDBstatustoSuccessPayload",setUpdateDBstatustoSuccessPayload) - } - - private String msoCompletionResponse = """onse xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"> - BPEL BPEL-NAME FAILED -""" - -/* - private String msoCompletionResponse = """ - BPEL BPEL-NAME FAILED -""" -*/ - @Test - void testBuildDataError() { - // given - def message = "Some-Message" - - def mockExecution = mock ExecutionEntity.class - when mockExecution.getVariable("CMSO_mso-bpel-name") thenReturn "BPEL-NAME" - when mockExecution.getVariable("testProcessKey") thenReturn "CompleteMsoProcess" - - def completeMsoProcess = new CompleteMsoProcess() - // when - assertThatThrownBy { completeMsoProcess.buildDataError(mockExecution, message) } isInstanceOf BpmnError - // then - verify mockExecution setVariable("CompleteMsoProcessResponse", msoCompletionResponse) - def argumentCaptor = ArgumentCaptor.forClass WorkflowException.class - verify mockExecution setVariable(eq("WorkflowException"), argumentCaptor.capture()) - def capturedException = argumentCaptor.value - - assertThat capturedException.processKey isEqualTo "CompleteMsoProcess" - assertThat capturedException.errorCode isEqualTo 500 - assertThat capturedException.errorMessage isEqualTo message - } -} \ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/ExceptionUtilTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/ExceptionUtilTest.groovy deleted file mode 100644 index 95272c22af..0000000000 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/ExceptionUtilTest.groovy +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * 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.scripts - -import org.junit.Assert -import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; - - -import org.junit.Ignore; - -import static org.mockito.Mockito.* - -import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity -import org.junit.Before -import org.junit.runner.RunWith -import org.mockito.MockitoAnnotations -import org.mockito.internal.debugging.MockitoDebuggerImpl -import org.mockito.runners.MockitoJUnitRunner -import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil; -@RunWith(MockitoJUnitRunner.class) -import org.junit.Test - - - -class ExceptionUtilTest { - - - @Before - public void init() - { - MockitoAnnotations.initMocks(this) - } - - @Test - public void testMapErrorCode5010(){ - String msg = "Connect to njcdtl20ew2988:8070 failed: Connection refused: connect" - ExceptionUtil util = new ExceptionUtil() - Assert.assertEquals("5010",util.MapErrorCode(msg)) - } - - @Test - public void testMapErrorCode5020(){ - String msg = "Connection timed out" - ExceptionUtil util = new ExceptionUtil() - Assert.assertEquals("5020",util.MapErrorCode(msg)) - } -} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/FalloutHandlerTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/FalloutHandlerTest.groovy deleted file mode 100644 index 730b44065d..0000000000 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/FalloutHandlerTest.groovy +++ /dev/null @@ -1,312 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * 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.scripts - -import org.junit.runner.RunWith; -import static org.mockito.Mockito.* -import static org.junit.Assert.*; - -import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity -import org.junit.Before -import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.ArgumentCaptor; -import org.mockito.MockitoAnnotations -import org.mockito.runners.MockitoJUnitRunner -import org.openecomp.mso.bpmn.common.scripts.MsoUtils; -import org.openecomp.mso.bpmn.common.scripts.FalloutHandler; - -@RunWith(MockitoJUnitRunner.class) -class FalloutHandlerTest { - - public MsoUtils utils = new MsoUtils() - - @Before - public void init() { - MockitoAnnotations.initMocks(this) - } - - private String falloutHandlerRequest = """ - - - uCPE1020_STUW105_5002 - Layer3ServiceActivateRequest - CANCEL - OMX - 10205000 - 1 - - - Some Error Message - Fallout Handler - Some Error Code - Fallout Handler - Some Source System Error Code- Fallout Handler - - - """ - - private String falloutHandlerResponse = """ - Fallout Handler Failed -""" - - @Test - public void testPreProcessRequest() { - - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - - when(mockExecution.getVariable("FalloutHandlerRequest")).thenReturn(falloutHandlerRequest) - when(mockExecution.getVariable("URN_mso_adapters_db_auth")).thenReturn("757A94191D685FD2092AC1490730A4FC"); - when(mockExecution.getVariable("URN_mso_msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7"); - - FalloutHandler falloutHandler = new FalloutHandler() - falloutHandler.preProcessRequest(mockExecution) - - /* Initialize all the process request variables in this block */ - verify(mockExecution).setVariable("prefix","FH_") - //verify(mockExecution).setVariable("getLayer3ServiceDetailsV1Response","") - - //These variables are form the input Message to the BPMN - verify(mockExecution).setVariable("FH_request_id","") - verify(mockExecution).setVariable("FH_request_action","") - verify(mockExecution).setVariable("FH_notification-url","") - verify(mockExecution).setVariable("FH_mso-bpel-name","") - verify(mockExecution).setVariable("FH_ErrorCode", "") - verify(mockExecution).setVariable("FH_ErrorMessage", "") - - verify(mockExecution).setVariable("FH_notification-url-Ok", false) - verify(mockExecution).setVariable("FH_request_id-Ok", false) - - //These variables are for Get Mso Aai Password Adapter - verify(mockExecution).setVariable("FH_deliveryStatus", true) - - //update Response Status to pending ...Adapter variables - verify(mockExecution).setVariable("FH_updateResponseStatusPayload", null) - verify(mockExecution).setVariable("FH_updateResponseStatusResponse", null) - - //update Request Gamma ...Adapter variables - verify(mockExecution).setVariable("FH_updateRequestGammaPayload", "") - verify(mockExecution).setVariable("FH_updateRequestGammaResponse", null) - verify(mockExecution).setVariable("FH_updateRequestGammaResponseCode", null) - - //update Request Infra ...Adapter variables - verify(mockExecution).setVariable("FH_updateRequestInfraPayload", "") - verify(mockExecution).setVariable("FH_updateRequestInfraResponse", null) - verify(mockExecution).setVariable("FH_updateRequestInfraResponseCode", null) - - //assign False to success variable - verify(mockExecution).setVariable("FH_success", true) - - //Set notify status to Failed variable - verify(mockExecution).setVariable("FH_NOTIFY_STATUS", "SUCCESS") - - //Set DB update variable - verify(mockExecution).setVariable("FH_updateRequestPayload", "") - verify(mockExecution).setVariable("FH_updateRequestResponse", null) - verify(mockExecution).setVariable("FH_updateRequestResponseCode", null) - - //Auth variables - verify(mockExecution).setVariable("BasicAuthHeaderValue","") - - //Response variables - verify(mockExecution).setVariable("FalloutHandlerResponse","") - verify(mockExecution).setVariable("FH_ErrorResponse", null) - verify(mockExecution).setVariable("FH_ResponseCode", "") - - verify(mockExecution).setVariable("FH_request_id-Ok",true) - verify(mockExecution).setVariable("FH_request_id","uCPE1020_STUW105_5002") - verify(mockExecution).setVariable("FH_request_action","Layer3ServiceActivateRequest") - verify(mockExecution).setVariable("FH_source","OMX") - verify(mockExecution).setVariable("FH_ErrorCode","Some Error Code - Fallout Handler") - verify(mockExecution).setVariable("FH_ErrorMessage","Some Error Message - Fallout Handler") - - } - - @Test - public void testpostProcessResponse(){ - - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") - when(mockExecution.getVariable("FH_success")).thenReturn(false) - - FalloutHandler falloutHandler = new FalloutHandler() - falloutHandler.postProcessResponse(mockExecution) - - // Capture the arguments to setVariable - ArgumentCaptor captor1 = ArgumentCaptor.forClass(String.class); - ArgumentCaptor captor2 = ArgumentCaptor.forClass(String.class); - - verify(mockExecution, times(4)).setVariable(captor1.capture(), captor2.capture()) - List arg2List = captor2.getAllValues() - String payloadResponseActual = arg2List.get(1) - - assertEquals(falloutHandlerResponse.replaceAll("\\s+", ""), payloadResponseActual.replaceAll("\\s+", "")) - - verify(mockExecution).setVariable("FH_ResponseCode","500") - } - - private String updateRequestPayload = """ - - - - - testReqId - BPEL - ErrorMessage - ErrorCode - FAILED - NotifyStatus - - - - """ - - @Test - public void testupdateRequestPayload(){ - - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - when(mockExecution.getVariable("FH_request_id")).thenReturn("testReqId") - when(mockExecution.getVariable("FH_ErrorMessage")).thenReturn("ErrorMessage") - when(mockExecution.getVariable("FH_ErrorCode")).thenReturn("ErrorCode") - when(mockExecution.getVariable("FH_NOTIFY_STATUS")).thenReturn("NotifyStatus") - - FalloutHandler falloutHandler = new FalloutHandler() - falloutHandler.updateRequestPayload(mockExecution) - - // Capture the arguments to setVariable - ArgumentCaptor captor1 = ArgumentCaptor.forClass(String.class); - ArgumentCaptor captor2 = ArgumentCaptor.forClass(String.class); - - verify(mockExecution, times(1)).setVariable(captor1.capture(), captor2.capture()) - List arg2List = captor2.getAllValues() - String payloadRequestActual = arg2List.get(0) - - assertEquals(updateRequestPayload.replaceAll("\\s+", ""), payloadRequestActual.replaceAll("\\s+", "")) - } - - private String updateRequestInfraPayload = """ - - - - - testReqId - BPEL - ErrorMessage - FAILED - 100 - - - - """ - - @Test - public void testupdateRequestInfraPayload(){ - - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - when(mockExecution.getVariable("FH_request_id")).thenReturn("testReqId") - when(mockExecution.getVariable("FH_ErrorMessage")).thenReturn("ErrorMessage") - - FalloutHandler falloutHandler = new FalloutHandler() - falloutHandler.updateRequestInfraPayload(mockExecution) - - // Capture the arguments to setVariable - ArgumentCaptor captor1 = ArgumentCaptor.forClass(String.class); - ArgumentCaptor captor2 = ArgumentCaptor.forClass(String.class); - - verify(mockExecution, times(1)).setVariable(captor1.capture(), captor2.capture()) - List arg2List = captor2.getAllValues() - String payloadRequestActual = arg2List.get(0) - - assertEquals(updateRequestInfraPayload.replaceAll("\\s+", ""), payloadRequestActual.replaceAll("\\s+", "")) - } - - private String updateRequestGammaPayload = """ - - - - - testReqId - BPEL - ErrorMessage - ErrorCode - FAILED - - - - """ - - @Test - public void testupdateRequestGammaPayload(){ - - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - when(mockExecution.getVariable("FH_request_id")).thenReturn("testReqId") - when(mockExecution.getVariable("FH_ErrorMessage")).thenReturn("ErrorMessage") - when(mockExecution.getVariable("FH_ErrorCode")).thenReturn("ErrorCode") - when(mockExecution.getVariable("URN_mso_default_adapter_namespace")).thenReturn("http://org.openecomp.mso"); - - FalloutHandler falloutHandler = new FalloutHandler() - falloutHandler.updateRequestGammaPayload(mockExecution) - - // Capture the arguments to setVariable - ArgumentCaptor captor1 = ArgumentCaptor.forClass(String.class); - ArgumentCaptor captor2 = ArgumentCaptor.forClass(String.class); - - verify(mockExecution, times(1)).setVariable(captor1.capture(), captor2.capture()) - List arg2List = captor2.getAllValues() - String payloadRequestActual = arg2List.get(0) - - assertEquals(updateRequestGammaPayload.replaceAll("\\s+", ""), payloadRequestActual.replaceAll("\\s+", "")) - } - - - String updateResponseStatusPayload = """ - - - - - testReqId - BPEL - SENDING_FINAL_NOTIFY - - - - """ - - @Test - public void testupdateResponseStatusPayload(){ - - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - when(mockExecution.getVariable("FH_request_id")).thenReturn("testReqId") - - FalloutHandler falloutHandler = new FalloutHandler() - falloutHandler.updateResponseStatusPayload(mockExecution) - - // Capture the arguments to setVariable - ArgumentCaptor captor1 = ArgumentCaptor.forClass(String.class); - ArgumentCaptor captor2 = ArgumentCaptor.forClass(String.class); - - verify(mockExecution, times(1)).setVariable(captor1.capture(), captor2.capture()) - List arg2List = captor2.getAllValues() - String payloadResponseActual = arg2List.get(0) - - assertEquals(updateResponseStatusPayload.replaceAll("\\s+", ""), payloadResponseActual.replaceAll("\\s+", "")) - } - -} \ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/GenericPutServiceTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/GenericPutServiceTest.groovy deleted file mode 100644 index 1e7342de68..0000000000 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/GenericPutServiceTest.groovy +++ /dev/null @@ -1,214 +0,0 @@ -package org.openecomp.mso.bpmn.common.scripts - -import static org.mockito.Mockito.* -import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutServiceInstance; - -import org.camunda.bpm.engine.ProcessEngineServices -import org.camunda.bpm.engine.RepositoryService -import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity -import org.camunda.bpm.engine.repository.ProcessDefinition -import org.junit.Before -import org.junit.Ignore -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.MockitoAnnotations -import org.mockito.internal.debugging.MockitoDebuggerImpl -import org.mockito.runners.MockitoJUnitRunner - -import com.github.tomakehurst.wiremock.client.WireMock -import com.github.tomakehurst.wiremock.junit.WireMockRule -import org.apache.commons.lang3.* - -@RunWith(MockitoJUnitRunner.class) -class GenericPutServiceTest { - - @Rule - public WireMockRule wireMockRule = new WireMockRule(8090); - - @Before - public void init() - { - MockitoAnnotations.initMocks(this) - - } - - @Test - public void preProcessRequest() { - - - println "************ preProcessRequest ************* " - - ExecutionEntity mockExecution = setupMock() - - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") - when(mockExecution.getVariable("GENPS_globalSubscriberId")).thenReturn("1604-MVM-26") - when(mockExecution.getVariable("GENPS_serviceInstanceId")).thenReturn("MIS%2F1604%2F0026%2FSW_INTERNET") - when(mockExecution.getVariable("GENPS_serviceType")).thenReturn("SDN-ETHERNET-INTERNET") - when(mockExecution.getVariable("GENPS_serviceInstanceData")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4") - when(mockExecution.getVariable("GENPS_type")).thenReturn("service-instance") - - GenericPutService putServiceInstance= new GenericPutService() - putServiceInstance.preProcessRequest(mockExecution) - - // check the sequence of variable invocation - //MockitoDebuggerImpl preDebugger = new MockitoDebuggerImpl() - //preDebugger.printInvocations(mockExecution) - - verify(mockExecution, atLeast(1)).getVariable("isDebugLogEnabled") - verify(mockExecution).setVariable("prefix", "GENPS_") - - // execution.getVariable("isDebugLogEnabled") - - verify(mockExecution).setVariable("GENPS_SuccessIndicator", false) - // verify(mockExecution).setVariable("globalSubscriberId", "1604-MVM-26") - // verify(mockExecution).setVariable("serviceInstanceId", "MIS%2F1604%2F0026%2FSW_INTERNET") - // verify(mockExecution).setVariable("serviceType", "SDN-ETHERNET-INTERNET") - // verify(mockExecution).setVariable("ServiceInstanceData", "f70e927b-6087-4974-9ef8-c5e4d5847ca4") - - - } - - - @Test - @Ignore - public void putServiceInstance() { - println "************ putServiceInstance ************* " - - WireMock.reset(); - - MockPutServiceInstance("1604-MVM-26", "SDN-ETHERNET-INTERNET", "MIS%252F1604%252F0026%252FSW_INTERNET", "GenericPutServiceInstance/GenericPutServiceInstance_PutServiceInstance_AAIResponse_Success.xml"); - ExecutionEntity mockExecution = setupMock() - - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") - when(mockExecution.getVariable("GENPS_globalSubscriberId")).thenReturn("1604-MVM-26") - when(mockExecution.getVariable("GENPS_serviceInstanceId")).thenReturn("MIS%2F1604%2F0026%2FSW_INTERNET") - when(mockExecution.getVariable("GENPS_serviceType")).thenReturn("SDN-ETHERNET-INTERNET") - when(mockExecution.getVariable("GENPS_serviceInstanceData")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4") - when(mockExecution.getVariable("URN_aai_endpoint")).thenReturn("http://localhost:8090") - when(mockExecution.getVariable("URN_mso_workflow_PutServiceInstance_aai_business_customer_uri")).thenReturn("/aai/v7/business/customers/customer") - when(mockExecution.getVariable("GENPS_serviceInstanceData")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4") - when(mockExecution.getVariable("GENPS_type")).thenReturn("service-instance") - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn('http://org.openecomp.aai.inventory/') - when(mockExecution.getVariable("URN_mso_workflow_global_default_aai_version")).thenReturn("7") - when(mockExecution.getVariable("URN_mso_workflow_default_aai_v7_customer_uri")).thenReturn("/aai/v7/business/customers/customer") - when(mockExecution.getVariable("URN_mso_msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7") - when(mockExecution.getVariable("URN_aai_auth")).thenReturn("757A94191D685FD2092AC1490730A4FC") - - GenericPutService serviceInstance= new GenericPutService() - serviceInstance.putServiceInstance(mockExecution) - - // check the sequence of variable invocation - MockitoDebuggerImpl preDebugger = new MockitoDebuggerImpl() - preDebugger.printInvocations(mockExecution) - - verify(mockExecution, atLeast(1)).getVariable("isDebugLogEnabled") - verify(mockExecution).setVariable("prefix", "GENPS_") - - // execution.getVariable("isDebugLogEnabled") - // verify(mockExecution).setVariable("GENPSI_serviceInstanceData","f70e927b-6087-4974-9ef8-c5e4d5847ca4") - - String servicePayload = """f70e927b-6087-4974-9ef8-c5e4d5847ca4""" as String - verify(mockExecution).setVariable("GENPS_serviceInstancePayload",servicePayload) - - String serviceAaiPath = "http://localhost:28090/aai/v7/business/customers/customer/1604-MVM-26/service-subscriptions/service-subscription/SDN-ETHERNET-INTERNET/service-instances/service-instance/MIS%252F1604%252F0026%252FSW_INTERNET" - verify(mockExecution).setVariable("GENPS_putServiceInstanceAaiPath", serviceAaiPath) - - int responseCode = 200 - verify(mockExecution).setVariable("GENPS_putServiceInstanceResponseCode", responseCode) - - String aaiResponse = """ - - - - - - - - -""" - - verify(mockExecution).setVariable("GENPS_putServiceInstanceResponse", aaiResponse) - - verify(mockExecution).setVariable("GENPS_SuccessIndicator", true) - } - - @Test - @Ignore - public void putServiceInstance_404() { - - - println "************ putServiceInstance ************* " - - WireMock.reset(); - - ExecutionEntity mockExecution = setupMock() - - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") - when(mockExecution.getVariable("GENPS_globalSubscriberId")).thenReturn("1604-MVM-26") - when(mockExecution.getVariable("GENPS_serviceInstanceId")).thenReturn("MIS%2F1604%2F0026%2FSW_INTERNET") - when(mockExecution.getVariable("GENPS_serviceType")).thenReturn("SDN-ETHERNET-INTERNET") - when(mockExecution.getVariable("GENPS_ServiceInstanceData")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4") - when(mockExecution.getVariable("URN_aai_endpoint")).thenReturn("http://localhost:8090") - when(mockExecution.getVariable("URN_mso_workflow_PutServiceInstance_aai_business_customer_uri")).thenReturn("/aai/v7/business/customers/customer") - when(mockExecution.getVariable("GENPS_ServiceInstanceData")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4") - - GenericPutService serviceInstance= new GenericPutService() - serviceInstance.putServiceInstance(mockExecution) - - // check the sequence of variable invocation - MockitoDebuggerImpl preDebugger = new MockitoDebuggerImpl() - preDebugger.printInvocations(mockExecution) - - verify(mockExecution, atLeast(1)).getVariable("isDebugLogEnabled") - verify(mockExecution).setVariable("prefix", "GENPS_") - - // execution.getVariable("isDebugLogEnabled") - - - verify(mockExecution).setVariable("GENPS_serviceInstanceData","f70e927b-6087-4974-9ef8-c5e4d5847ca4") - - String serviceInstancepayload = """f70e927b-6087-4974-9ef8-c5e4d5847ca4 - """ as String - verify(mockExecution).setVariable("GENPS_serviceInstancePayload",serviceInstancepayload) - - String serviceInstanceAaiPath = "http://localhost:8090/aai/v7/business/customers/customer/1604-MVM-26/service-subscriptions/service-subscription/SDN-ETHERNET-INTERNET/service-instances/service-instance/MIS%252F1604%252F0026%252FSW_INTERNET" - verify(mockExecution).setVariable("GENPS_putServiceInstanceAaiPath", serviceInstanceAaiPath) - - int responseCode = 404 - verify(mockExecution).setVariable("GENPS_putServiceInstanceResponseCode", responseCode) - - String aaiResponse = "" - verify(mockExecution).setVariable("GENPS_putServiceInstanceResponse", aaiResponse) - - verify(mockExecution).setVariable("GENPS_SuccessIndicator", false) - - - } - - - private ExecutionEntity setupMock() { - - ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class) - when(mockProcessDefinition.getKey()).thenReturn("PutServiceInstance") - RepositoryService mockRepositoryService = mock(RepositoryService.class) - when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition) - when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("PutServiceInstance") - when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100") - ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class) - when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService) - - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - // Initialize prerequisite variables - - when(mockExecution.getId()).thenReturn("100") - when(mockExecution.getProcessDefinitionId()).thenReturn("PutServiceInstance") - when(mockExecution.getProcessInstanceId()).thenReturn("PutServiceInstance") - when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices) - when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition) - - return mockExecution - } - -} \ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/MsoGroovyTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/MsoGroovyTest.groovy deleted file mode 100644 index 57055401f3..0000000000 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/MsoGroovyTest.groovy +++ /dev/null @@ -1,72 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * 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.scripts - -import static org.mockito.Mockito.* - -import org.mockito.MockitoAnnotations -import org.mockito.runners.MockitoJUnitRunner -import org.mockito.internal.debugging.MockitoDebuggerImpl -import org.camunda.bpm.engine.ProcessEngineServices -import org.camunda.bpm.engine.RepositoryService -import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity -import org.camunda.bpm.engine.impl.pvm.process.ProcessDefinitionImpl -import org.camunda.bpm.engine.repository.ProcessDefinition - -abstract class MsoGroovyTest { - - protected ExecutionEntity setupMock(String procName) { - ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class) - when(mockProcessDefinition.getKey()).thenReturn(procName) - - RepositoryService mockRepositoryService = mock(RepositoryService.class) - when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition) - when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn(procName) - when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100") - - ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class) - when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService) - - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices) - - return mockExecution - } - - protected ExecutionEntity setupMockWithPrefix(String procName, String prefix) { - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - - when(mockExecution.getVariable("prefix")).thenReturn(prefix) - - ProcessEngineServices processEngineServices = mock(ProcessEngineServices.class) - RepositoryService repositoryService = mock(RepositoryService.class) - ProcessDefinition processDefinition = mock(ProcessDefinition.class) - - when(mockExecution.getProcessEngineServices()).thenReturn(processEngineServices) - when(processEngineServices.getRepositoryService()).thenReturn(repositoryService) - when(repositoryService.getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(processDefinition) - when(processDefinition.getKey()).thenReturn(procName) - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") - return mockExecution - } - - -} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/MsoUtilsTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/MsoUtilsTest.groovy deleted file mode 100644 index 12e7855808..0000000000 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/MsoUtilsTest.groovy +++ /dev/null @@ -1,233 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * 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.scripts - -// JUnit 4 -import org.junit.Test -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Rule; - -import static groovy.test.GroovyAssert.shouldFail -import static groovy.test.GroovyAssert.assertTrue -import static groovy.test.GroovyAssert.assertEquals - -import org.openecomp.mso.bpmn.common.scripts.MsoUtils; -import org.apache.commons.lang3.* - - -class MsoUtilsTest { - - def utils = new MsoUtils() - def origXmlResponse = null - // Expected rebuilds - def expected_buildElements = "10Kbps1192.168.1.15192.168.1.15282192.168.1.16192.168.1.1628" - def expected_rebuildDhcp = "YNY192.168.1.7192.168.1.8192.155.2.328192.168.1.5192.168.1.62.2.2.11.1.1.1192.155.2.428192.168.1.6192.168.1.72.2.2.21.1.1.2N1:51:60:0281:12:23:34:40:0281:12:23:34:4" - def expected_rebuildFirewallLite = "YN0.0.0.11Y110.0.0.22Y22:0Y33:1Y44" - def expected_rebuildInternetEvcAccess = "8Mbpsds" - def expected_rebuildInternetServiceChangeDetails = "10Kbps1192.168.1.15192.168.1.15282192.168.1.16192.168.1.162812001:1890:12e3:2da::2001:1890:12e3:2da::2812001:1890:12e3:2da::2001:1890:12e3:2da::28" - def expected_rebuildL2Home = "AS/VLXM/003717//SWMultiPointMTSNJA4LCP1" - def expected_rebuildNat = "Y0.0.0.00.0.0.00.0.0.00.0.0.10.0.0.10.0.0.1" - def expected_rebuildPat = "NY192.168.1.440192.168.1.5192.168.1.4528192.168.1.6" - def expected_rebuildStaticRoutes = "255.255.252.128192.168.1.15255.255.252.228192.168.1.15255.255.252.328192.168.1.152001:1890:12e3:2da::282001:1890:12e3:2da::2001:1890:12e3:2da::282001:1890:12e3:2da::" - def expected_rebuildUcpeVmsServiceInformation = "AVPN1Active2StandbyhostnameactivecodeOOB11ZZJUNIPERMODEL11111122HYJUNIPERMODEL222222" - def expected_rebuildVrLan = "noneprimary10.192.27.254242620:0:10d0:f:ffff:ffff:ffff:fffe64162.200.3.1442001:1890:12e3:2da::1192.168.1.2192.168.1.1281192.168.1.72192.168.1.71281192.168.1.68192.168.1.672812001:1890:12e3:2da::2001:1890:12e3:2da::2812001:1890:12e3:2da::2001:1890:12e3:3da::2812001:1890:12e3:2da::2001:1890:12e3:4da::28YNY192.168.1.7192.168.1.8192.155.2.328192.168.1.5192.168.1.62.2.2.11.1.1.1192.155.2.428192.168.1.6192.168.1.72.2.2.21.1.1.2N1:51:60:0281:12:23:34:40:0281:12:23:34:4NY192.168.1.440192.168.1.5192.168.1.4528192.168.1.6Y0.0.0.00.0.0.00.0.0.00.0.0.10.0.0.10.0.0.1YN0.0.0.11Y110.0.0.22Y22:0Y33:1Y44255.255.252.128192.168.1.15255.255.252.228192.168.1.15255.255.252.328192.168.1.152001:1890:12e3:2da::282001:1890:12e3:2da::2001:1890:12e3:2da::282001:1890:12e3:2da::" - def expected_rebuildVrLanInterfacePartial = "primary10.192.27.254242620:0:10d0:f:ffff:ffff:ffff:fffe64162.200.3.1442001:1890:12e3:2da::1192.168.1.2192.168.1.1281192.168.1.72192.168.1.71281192.168.1.68192.168.1.67281192.168.1.15192.168.1.15282192.168.1.16192.168.1.162812001:1890:12e3:2da::2001:1890:12e3:2da::2812001:1890:12e3:2da::2001:1890:12e3:3da::2812001:1890:12e3:2da::2001:1890:12e3:4da::2812001:1890:12e3:2da::2001:1890:12e3:2da::2812001:1890:12e3:2da::2001:1890:12e3:2da::28" - - @Before - public void setUp() { - def responseAsString = getFile("sdncadaptercallbackrequest.xml") - def varrequestData=utils.getNodeText(responseAsString,"RequestData") - //def varResponseListData = StringEscapeUtils.unescapeXml(varrequestData) - def varResponseListData = varrequestData.replace("&", "&") - origXmlResponse = utils.getNodeXml(varResponseListData, "layer3-service-list").drop(38).trim() - - } - - @Test - public void testBuildL2Home() { - def rebuildL2Home = utils.buildL2HomingInformation(origXmlResponse) - println " rebuildL2Home: " - println " actual - " + rebuildL2Home - println " expected - " + expected_rebuildL2Home - assertEquals("rebuildL2Home - expected vs actual", expected_rebuildL2Home, rebuildL2Home) - } - - @Test - public void testBuildInternetEvcAccess() { - def rebuildInternetEvcAccess = utils.buildInternetEvcAccessInformation(origXmlResponse) - println " rebuildInternetEvcAccess: " - println " actual - " + rebuildInternetEvcAccess - println " expected - " + expected_rebuildInternetEvcAccess - assertEquals("rebuildInternetEvcAccess - expected vs actual", expected_rebuildInternetEvcAccess, rebuildInternetEvcAccess) - } - - @Test - public void testBuildInternetServiceChangeDetails() { - def rebuildInternetServiceChangeDetails = utils.buildInternetServiceChangeDetails(origXmlResponse) - println " rebuildInternetServiceChangeDetails: " - println " actual - " + rebuildInternetServiceChangeDetails - println " expected - " + expected_rebuildInternetServiceChangeDetails - assertEquals("rebuildInternetServiceChangeDetails - expected vs actual", expected_rebuildInternetServiceChangeDetails, rebuildInternetServiceChangeDetails) - } - - // Coming v100 - @Test - @Ignore - public void testBuildUcpeVmsServiceInformation() { - def rebuildUcpeVmsServiceInformation = utils.buildUcpeVmsServiceInformation(origXmlResponse) - println " rebuildUcpeVmsServiceInformation: " - println " actual - " + rebuildUcpeVmsServiceInformation - println " expected - " + expected_rebuildUcpeVmsServiceInformation - assertEquals("rebuildUcpeVmsServiceInformation - expected vs actual", expected_rebuildUcpeVmsServiceInformation, rebuildUcpeVmsServiceInformation) - } - - @Test - public void testBuildElements() { - // testing utility codes: buildElements() & buildElementsUnblunded() - def internetServiceChangeDetails = utils.getNodeXml(origXmlResponse, "internet-service-change-details").drop(38).trim() - def buildElements = '' - buildElements = "" - buildElements += utils.buildElements(internetServiceChangeDetails, ["internet-evc-speed-value"], "") - buildElements += utils.buildElements(internetServiceChangeDetails, ["internet-evc-speed-units"], "") - def tProvidedV4LanPublicPrefixesChangesList = ["request-index", "v4-next-hop-address", "v4-lan-public-prefix", "v4-lan-public-prefix-length"] - buildElements += utils.buildElementsUnbounded(internetServiceChangeDetails, tProvidedV4LanPublicPrefixesChangesList, "t-provided-v4-lan-public-prefixes") - buildElements += "" - println " buildElements: " - println " actual - " + buildElements - println " expected - " + expected_buildElements - assertEquals("buildElements - expected vs actual", expected_buildElements, buildElements) - } - - @Test - public void testBuildVrLan() { - def rebuildVrLan = utils.buildVrLan(origXmlResponse) - println " rebuildVrLans: " - println " actual - " + rebuildVrLan - println " expected - " + expected_rebuildVrLan - assertEquals("rebuildVrLan - expected vs actual", expected_rebuildVrLan, rebuildVrLan) - } - - @Test - public void testBuildVrLanInterfacePartial() { - def rebuildVrLanInterfacePartial = utils.buildVrLanInterfacePartial(origXmlResponse) - println " rebuildVrLanInterfacePartial: " - println " actual - " + rebuildVrLanInterfacePartial - println " expected - " + expected_rebuildVrLanInterfacePartial - assertEquals("rebuildVrLanInterfacePartial - expected vs actual", expected_rebuildVrLanInterfacePartial, rebuildVrLanInterfacePartial) - } - - @Test - public void testBuildDhcp() { - def rebuildDhcp = utils.buildDhcp(origXmlResponse) - println " rebuildDhcp: " - println " actual - " + rebuildDhcp - println " expected - " + expected_rebuildDhcp - assertEquals("rebuildDhcp - expected vs actual", expected_rebuildDhcp, rebuildDhcp) - } - - @Test - public void testBuildPat() { - def rebuildPat = utils.buildPat(origXmlResponse) - println " rebuildPat: " - println " actual - " + rebuildPat - println " expected - " + expected_rebuildPat - assertEquals("rebuildPat - expected vs actual", expected_rebuildPat, rebuildPat) - } - - @Test - public void testBuildNat() { - def rebuildNat = utils.buildNat(origXmlResponse) - println " rebuildNat: " - println " actual - " + rebuildNat - println " expected - " + expected_rebuildNat - assertEquals("rebuildNat - expected vs actual", expected_rebuildNat, rebuildNat) - } - - @Test - public void testBuildFirewallLite() { - def rebuildFirewallLite = utils.buildFirewallLite(origXmlResponse) - println " rebuildFirewallLite: " - println " actual - " + rebuildFirewallLite - println " expected - " + expected_rebuildFirewallLite - assertEquals("rebuildFirewallLite - expected vs actual", expected_rebuildFirewallLite, rebuildFirewallLite) - } - - @Test - public void testBuildStaticRoutes() { - def rebuildStaticRoutes = utils.buildStaticRoutes(origXmlResponse) - println " rebuildStaticRoutes: " - println " actual - " + rebuildStaticRoutes - println " expected - " + expected_rebuildStaticRoutes - assertEquals("rebuildStaticRoutes - expected vs actual", expected_rebuildStaticRoutes, rebuildStaticRoutes) - } - - @Test - public void testGetBasicAuth(){ - def encodedAuth = utils.getBasicAuth("3E3CFA7BE2F6107AAD4AAA65F8976690","07a7159d3bf51a0e53be7a8f89699be7") - assertEquals("Basic bXlTdHJpbmc=", encodedAuth) - } - - @Test - public void testEncrypt(){ - def encrypted = utils.encrypt("myString","07a7159d3bf51a0e53be7a8f89699be7") - assertEquals("3E3CFA7BE2F6107AAD4AAA65F8976690", encrypted) - - //use to get value for urn properties - //println(utils.encrypt("password")) - } - - @Test - public void testDecrypt(){ - def decrypted = utils.decrypt("3E3CFA7BE2F6107AAD4AAA65F8976690", "07a7159d3bf51a0e53be7a8f89699be7") - assertEquals("myString", decrypted) - } - - @Test - public void testGetPBGFList(){ - def responseAsString = getFile("sdncDeleteResponse.xml") - def nodes = utils.getPBGFList("true", responseAsString) - //assertEquals(2, nodes.size()) - while(!nodes.empty){ - def myBGFXML = nodes.remove(0) - def myBGF= new XmlSlurper().parseText(myBGFXML) - println "borderElmtId: " + myBGF.'border-element-id' - println "vlanid: " + myBGF.'vlan-id' +"\n" - } - } - - public String getFile(String fileName) { - def SLASH = File.separator - def pathBase = ' ' - def fileAsString = '' - try { - pathBase = new File(".").getCanonicalPath() - //println "pathBase " + pathBase + "${SLASH}src${SLASH}test${SLASH}resources${SLASH}${fileName}" - fileAsString = new File(pathBase, "${SLASH}src${SLASH}test${SLASH}resources${SLASH}${fileName}").getText() - } catch (Exception ex) { - println " *** getFile error: " + ex.getStackTrace() - } finally { - return fileAsString - } - } - - -} \ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/NetworkUtilsTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/NetworkUtilsTest.groovy deleted file mode 100644 index 63d88f5c3a..0000000000 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/NetworkUtilsTest.groovy +++ /dev/null @@ -1,97 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * 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.scripts - -import static org.mockito.Mockito.* -import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity -import static org.junit.Assert.*; -import org.junit.Test; - -class NetworkUtilsTest { - - def volumeRequestXml = """ - - CREATE_VF_MODULE_VOL - VID - - - - - MSOTESTVOL101a-vSAMP12_base_vol_module-0 - Test/vSAMP12 - vSAMP12::base::module-0 - 2.0 - mdt1 - 88a6ca3ee0394ade9403f075db23167e - a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb - - - - STMTN5MMSC20 - US1117MTSNJVBR0246 - -""" - - @Test - public void testIsRollbackEnabled() { - - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - when(mockExecution.getVariable("URN_mso_rollback")).thenReturn(true) - - NetworkUtils networkUtils = new NetworkUtils() - def rollbackEnabled = networkUtils.isRollbackEnabled(mockExecution, volumeRequestXml) - - assertEquals(true, rollbackEnabled) - - } - - @Test - public void testIsRollbackEnabled2() { - - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true') - when(mockExecution.getVariable("URN_mso_rollback")).thenReturn(false) - - NetworkUtils networkUtils = new NetworkUtils() - def rollbackEnabled = networkUtils.isRollbackEnabled(mockExecution, volumeRequestXml) - - assertEquals(false, rollbackEnabled) - - } - - @Test - public void testGetIpvVersion() { - - NetworkUtils networkUtils = new NetworkUtils() - println "test: ipv4" - String version4 = networkUtils.getIpvVersion("ipv4") - assertEquals("4", version4) - println "test: ipv6" - String version6 = networkUtils.getIpvVersion("ipv6") - assertEquals("6", version6) - println "test: 4" - String versionDigit4 = networkUtils.getIpvVersion("4") - assertEquals("4", versionDigit4) - - } - -} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/SDNCAdapterTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/SDNCAdapterTest.groovy deleted file mode 100644 index 2ecb108b4e..0000000000 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/SDNCAdapterTest.groovy +++ /dev/null @@ -1,948 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * 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.scripts; - -import static org.mockito.Mockito.* - -import org.camunda.bpm.engine.ProcessEngineServices -import org.camunda.bpm.engine.RepositoryService -import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity -import org.camunda.bpm.engine.repository.ProcessDefinition -import org.junit.Before -import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.MockitoAnnotations -import org.mockito.runners.MockitoJUnitRunner -import org.mockito.internal.debugging.MockitoDebuggerImpl -import org.openecomp.mso.bpmn.common.scripts.SDNCAdapter; - -import org.openecomp.mso.bpmn.mock.FileUtil - -@RunWith(MockitoJUnitRunner.class) -public class SDNCAdapterTest { - - @Before - public void init() - { - MockitoAnnotations.initMocks(this) - System.setProperty("jboss.qualified.host.name","myhost.com") - } - - - def workflowResponse = """ - - - testRequestId - 200 - OK - - <layer3-service-list xmlns="com:att:sdnctl:l3api"> - <service-instance-id>FK/VLXM/003717//SW_INTERNET</service-instance-id> - <service-status> - <rpc-name>service-configuration-operation</rpc-name> - <rpc-action>activate</rpc-action> - <request-status>synccomplete</request-status> - <final-indicator>N</final-indicator> - <l3sdn-action>Layer3ServiceActivateRequest</l3sdn-action> - <l3sdn-subaction>SUPP</l3sdn-subaction> - <response-timestamp>2015-04-28T21:32:11.386Z</response-timestamp> - </service-status> - <service-data> - <internet-evc-access-information> - <ip-version>ds</ip-version> - <internet-evc-speed-value>8</internet-evc-speed-value> - <internet-evc-speed-units>Mbps</internet-evc-speed-units> - </internet-evc-access-information> - <vr-lan xmlns="com:att:sdnctl:l3api"> - <vr-lan-interface> - <static-routes> - <v6-static-routes> - <v6-next-hop-address>2001:1890:12e3:2da::</v6-next-hop-address> - <v6-static-route-prefix>2001:1890:12e3:2da::</v6-static-route-prefix> - <v6-static-route-prefix-length>28</v6-static-route-prefix-length> - </v6-static-routes> - <v4-static-routes> - <v4-static-route-prefix>255.255.252.1</v4-static-route-prefix> - <v4-next-hop-address>192.168.1.15</v4-next-hop-address> - <v4-static-route-prefix-length>28</v4-static-route-prefix-length> - </v4-static-routes> - <v6-static-routes> - <v6-next-hop-address>2001:1890:12e3:2da::</v6-next-hop-address> - <v6-static-route-prefix>2001:1890:12e3:2da::</v6-static-route-prefix> - <v6-static-route-prefix-length>28</v6-static-route-prefix-length> - </v6-static-routes> - <v4-static-routes> - <v4-static-route-prefix>255.255.252.2</v4-static-route-prefix> - <v4-next-hop-address>192.168.1.15</v4-next-hop-address> - <v4-static-route-prefix-length>28</v4-static-route-prefix-length> - </v4-static-routes> - <v4-static-routes> - <v4-static-route-prefix>255.255.252.3</v4-static-route-prefix> - <v4-next-hop-address>192.168.1.15</v4-next-hop-address> - <v4-static-route-prefix-length>28</v4-static-route-prefix-length> - </v4-static-routes> - </static-routes> - <dhcp> - <v6-dhcp-server-enabled>N</v6-dhcp-server-enabled> - <v4-dhcp-server-enabled>Y</v4-dhcp-server-enabled> - <use-v6-default-pool>N</use-v6-default-pool> - <excluded-v4-dhcp-addresses-from-default-pool> - <excluded-v4-address>192.168.1.7</excluded-v4-address> - </excluded-v4-dhcp-addresses-from-default-pool> - <excluded-v4-dhcp-addresses-from-default-pool> - <excluded-v4-address>192.168.1.8</excluded-v4-address> - </excluded-v4-dhcp-addresses-from-default-pool> - <v4-dhcp-pools> - <v4-dhcp-relay-next-hop-address>1.1.1.1</v4-dhcp-relay-next-hop-address> - <v4-dhcp-pool-prefix-length>28</v4-dhcp-pool-prefix-length> - <excluded-v4-addresses> - <excluded-v4-address>192.168.1.5</excluded-v4-address> - </excluded-v4-addresses> - <v4-dhcp-relay-gateway-address>2.2.2.1</v4-dhcp-relay-gateway-address> - <excluded-v4-addresses> - <excluded-v4-address>192.168.1.6</excluded-v4-address> - </excluded-v4-addresses> - <v4-dhcp-pool-prefix>192.155.2.3</v4-dhcp-pool-prefix> - </v4-dhcp-pools> - <v4-dhcp-pools> - <v4-dhcp-relay-next-hop-address>1.1.1.2</v4-dhcp-relay-next-hop-address> - <v4-dhcp-pool-prefix-length>28</v4-dhcp-pool-prefix-length> - <excluded-v4-addresses> - <excluded-v4-address>192.168.1.6</excluded-v4-address> - </excluded-v4-addresses> - <v4-dhcp-relay-gateway-address>2.2.2.2</v4-dhcp-relay-gateway-address> - <excluded-v4-addresses> - <excluded-v4-address>192.168.1.7</excluded-v4-address> - </excluded-v4-addresses> - <v4-dhcp-pool-prefix>192.155.2.4</v4-dhcp-pool-prefix> - </v4-dhcp-pools> - <use-v4-default-pool>Y</use-v4-default-pool> - <excluded-v6-dhcp-addresses-from-default-pool> - <excluded-v6-address>1:5</excluded-v6-address> - </excluded-v6-dhcp-addresses-from-default-pool> - <excluded-v6-dhcp-addresses-from-default-pool> - <excluded-v6-address>1:6</excluded-v6-address> - </excluded-v6-dhcp-addresses-from-default-pool> - <v6-dhcp-pools> - <v6-dhcp-relay-next-hop-address>4:4</v6-dhcp-relay-next-hop-address> - <v6-dhcp-pool-prefix-length>28</v6-dhcp-pool-prefix-length> - <excluded-v6-addresses> - <excluded-v6-address>1:1</excluded-v6-address> - </excluded-v6-addresses> - <v6-dhcp-relay-gateway-address>3:3</v6-dhcp-relay-gateway-address> - <excluded-v6-addresses> - <excluded-v6-address>2:2</excluded-v6-address> - </excluded-v6-addresses> - <v6-dhcp-pool-prefix>0:0</v6-dhcp-pool-prefix> - </v6-dhcp-pools> - <v6-dhcp-pools> - <v6-dhcp-relay-next-hop-address>4:4</v6-dhcp-relay-next-hop-address> - <v6-dhcp-pool-prefix-length>28</v6-dhcp-pool-prefix-length> - <excluded-v6-addresses> - <excluded-v6-address>1:1</excluded-v6-address> - </excluded-v6-addresses> - <v6-dhcp-relay-gateway-address>3:3</v6-dhcp-relay-gateway-address> - <excluded-v6-addresses> - <excluded-v6-address>2:2</excluded-v6-address> - </excluded-v6-addresses> - <v6-dhcp-pool-prefix>0:0</v6-dhcp-pool-prefix> - </v6-dhcp-pools> - </dhcp> - <firewall-lite> - <stateful-firewall-lite-v6-enabled>N</stateful-firewall-lite-v6-enabled> - <stateful-firewall-lite-v4-enabled>Y</stateful-firewall-lite-v4-enabled> - <v4-firewall-packet-filters> - <v4-firewall-prefix>0.0.0.1</v4-firewall-prefix> - <v4-firewall-prefix-length>1</v4-firewall-prefix-length> - <allow-icmp-ping>Y</allow-icmp-ping> - <udp-ports> - <port-number>1</port-number> - </udp-ports> - <tcp-ports> - <port-number>1</port-number> - </tcp-ports> - </v4-firewall-packet-filters> - <v4-firewall-packet-filters> - <v4-firewall-prefix>0.0.0.2</v4-firewall-prefix> - <v4-firewall-prefix-length>2</v4-firewall-prefix-length> - <allow-icmp-ping>Y</allow-icmp-ping> - <udp-ports> - <port-number>2</port-number> - </udp-ports> - <tcp-ports> - <port-number>2</port-number> - </tcp-ports> - </v4-firewall-packet-filters> - <v6-firewall-packet-filters> - <v6-firewall-prefix>:</v6-firewall-prefix> - <v6-firewall-prefix-length>0</v6-firewall-prefix-length> - <allow-icmp-ping>Y</allow-icmp-ping> - <udp-ports> - <port-number>3</port-number> - </udp-ports> - <tcp-ports> - <port-number>3</port-number> - </tcp-ports> - </v6-firewall-packet-filters> - <v6-firewall-packet-filters> - <v6-firewall-prefix>:</v6-firewall-prefix> - <v6-firewall-prefix-length>1</v6-firewall-prefix-length> - <allow-icmp-ping>Y</allow-icmp-ping> - <udp-ports> - <port-number>4</port-number> - </udp-ports> - <tcp-ports> - <port-number>4</port-number> - </tcp-ports> - </v6-firewall-packet-filters> - </firewall-lite> - <pat> - <v4-pat-pools> - <v4-pat-pool-prefix>192.168.1.44</v4-pat-pool-prefix> - <v4-pat-pool-next-hop-address>192.168.1.5</v4-pat-pool-next-hop-address> - <v4-pat-pool-prefix-length>0</v4-pat-pool-prefix-length> - </v4-pat-pools> - <use-v4-default-pool>Y</use-v4-default-pool> - <v4-pat-enabled>N</v4-pat-enabled> - <v4-pat-pools> - <v4-pat-pool-prefix>192.168.1.45</v4-pat-pool-prefix> - <v4-pat-pool-next-hop-address>192.168.1.6</v4-pat-pool-next-hop-address> - <v4-pat-pool-prefix-length>28</v4-pat-pool-prefix-length> - </v4-pat-pools> - </pat> - <nat> - <v4-nat-enabled>Y</v4-nat-enabled> - <v4-nat-mapping-entries> - <v4-nat-internal>0.0.0.0</v4-nat-internal> - <v4-nat-next-hop-address>0.0.0.0</v4-nat-next-hop-address> - <v4-nat-external>0.0.0.0</v4-nat-external> - </v4-nat-mapping-entries> - <v4-nat-mapping-entries> - <v4-nat-internal>0.0.0.1</v4-nat-internal> - <v4-nat-next-hop-address>0.0.0.1</v4-nat-next-hop-address> - <v4-nat-external>0.0.0.1</v4-nat-external> - </v4-nat-mapping-entries> - </nat> - <vr-designation>primary</vr-designation> - <v4-vce-loopback-address>162.200.3.144</v4-vce-loopback-address> - <v6-vr-lan-prefix-length>64</v6-vr-lan-prefix-length> - <v6-vce-wan-address>2001:1890:12e3:2da::</v6-vce-wan-address> - <v6-vr-lan-prefix>2620:0:10d0:f:ffff:ffff:ffff:fffe</v6-vr-lan-prefix> - <v4-vr-lan-prefix-length>24</v4-vr-lan-prefix-length> - <v4-vr-lan-prefix>10.192.27.254</v4-vr-lan-prefix> - <v4-public-lan-prefixes> - <t-provided-v4-lan-public-prefixes> - <request-index>1</request-index> - <v4-next-hop-address>192.168.1.2</v4-next-hop-address> - <v4-lan-public-prefix>192.168.1.1</v4-lan-public-prefix> - <v4-lan-public-prefix-length>28</v4-lan-public-prefix-length> - </t-provided-v4-lan-public-prefixes> - <t-provided-v4-lan-public-prefixes> - <request-index>1</request-index> - <v4-next-hop-address>192.168.1.72</v4-next-hop-address> - <v4-lan-public-prefix>192.168.1.71</v4-lan-public-prefix> - <v4-lan-public-prefix-length>28</v4-lan-public-prefix-length> - </t-provided-v4-lan-public-prefixes> - <t-provided-v4-lan-public-prefixes> - <request-index>1</request-index> - <v4-next-hop-address>192.168.1.68</v4-next-hop-address> - <v4-lan-public-prefix>192.168.1.67</v4-lan-public-prefix> - <v4-lan-public-prefix-length>28</v4-lan-public-prefix-length> - </t-provided-v4-lan-public-prefixes> - </v4-public-lan-prefixes> - <v6-public-lan-prefixes> - <t-provided-v6-lan-public-prefixes> - <request-index>1</request-index> - <v6-next-hop-address>2001:1890:12e3:2da::</v6-next-hop-address> - <v6-lan-public-prefix>2001:1890:12e3:2da::</v6-lan-public-prefix> - <v6-lan-public-prefix-length>28</v6-lan-public-prefix-length> - </t-provided-v6-lan-public-prefixes> - <t-provided-v6-lan-public-prefixes> - <request-index>1</request-index> - <v6-next-hop-address>2001:1890:12e3:2da::</v6-next-hop-address> - <v6-lan-public-prefix>2001:1890:12e3:3da::</v6-lan-public-prefix> - <v6-lan-public-prefix-length>28</v6-lan-public-prefix-length> - </t-provided-v6-lan-public-prefixes> - <t-provided-v6-lan-public-prefixes> - <request-index>1</request-index> - <v6-next-hop-address>2001:1890:12e3:2da::</v6-next-hop-address> - <v6-lan-public-prefix>2001:1890:12e3:4da::</v6-lan-public-prefix> - <v6-lan-public-prefix-length>28</v6-lan-public-prefix-length> - </t-provided-v6-lan-public-prefixes> - </v6-public-lan-prefixes> - </vr-lan-interface> - <routing-protocol>none</routing-protocol> - </vr-lan> -<ucpe-vms-service-information> - <transport-service-information> - <transport-service-type>AVPN</transport-service-type> - <access-circuit-info> - <access-circuit-id>1</access-circuit-id> - <dual-mode>Active</dual-mode> - </access-circuit-info> - <access-circuit-info> - <access-circuit-id>2</access-circuit-id> - <dual-mode>Standby</dual-mode> - </access-circuit-info> - </transport-service-information> - <ucpe-information> - <ucpe-host-name>hostname</ucpe-host-name> - <ucpe-activation-code>activecode</ucpe-activation-code> - <out-of-band-management-modem>OOB</out-of-band-management-modem> - </ucpe-information> - <vnf-list> - <vnf-information> - <vnf-instance-id>1</vnf-instance-id> - <vnf-sequence-number>1</vnf-sequence-number> - <vnf-type>ZZ</vnf-type> - <vnf-vendor>JUNIPER</vnf-vendor> - <vnf-model>MODEL1</vnf-model> - <vnf-id>1</vnf-id> - <prov-status>1</prov-status> - <operational-state>1</operational-state> - <orchestration-status>1</orchestration-status> - <equipment-role>1</equipment-role> - </vnf-information> - <vnf-information> - <vnf-instance-id>2</vnf-instance-id> - <vnf-sequence-number>2</vnf-sequence-number> - <vnf-type>HY</vnf-type> - <vnf-vendor>JUNIPER</vnf-vendor> - <vnf-model>MODEL2</vnf-model> - <vnf-id>2</vnf-id> - <prov-status>2</prov-status> - <operational-state>2</operational-state> - <orchestration-status>2</orchestration-status> - <equipment-role>2</equipment-role> - </vnf-information> - </vnf-list> - </ucpe-vms-service-information> - <request-information> - <request-action>Layer3ServiceActivateRequest</request-action> - <order-number>4281555</order-number> - <request-id>155415ab-b4a7-4382-b4c6-d17d9sm42855</request-id> - <notification-url>https://csi-tst-q22.it.com:22443/Services/com/cingular/csi/sdn/SendManagedNetworkStatusNotification.jws</notification-url> - <source>OMX</source> - <order-version>1</order-version> - </request-information> - <sdnc-request-header> - <svc-action>activate</svc-action> - <svc-notification-url>https://msojra.mtsnjdcp1.aic.cip.com:8443/adapters/rest/SDNCNotify</svc-notification-url> - <svc-request-id>5b1f3c5d-cdf9-488d-8a4b-d3f1229d7760</svc-request-id> - </sdnc-request-header> - <l2-homing-information> - <topology>MultiPoint</topology> - <preferred-aic-clli>MTSNJA4LCP1</preferred-aic-clli> - <evc-name>AS/VLXM/003717//SW</evc-name> - </l2-homing-information> - <service-information> - <service-instance-id>FK/VLXM/003717//SW_INTERNET</service-instance-id> - <subscriber-name>ST E2E Test42855_1300004281555</subscriber-name> - <service-type>SDN-ETHERNET-INTERNET</service-type> - </service-information> - <internet-service-change-details> - <internet-evc-speed-value>10</internet-evc-speed-value> - <internet-evc-speed-units>Kbps</internet-evc-speed-units> - <t-provided-v4-lan-public-prefixes> - <request-index>1</request-index> - <v4-next-hop-address>192.168.1.15</v4-next-hop-address> - <v4-lan-public-prefix>192.168.1.15</v4-lan-public-prefix> - <v4-lan-public-prefix-length>28</v4-lan-public-prefix-length> - </t-provided-v4-lan-public-prefixes> - <t-provided-v4-lan-public-prefixes> - <request-index>2</request-index> - <v4-next-hop-address>192.168.1.16</v4-next-hop-address> - <v4-lan-public-prefix>192.168.1.16</v4-lan-public-prefix> - <v4-lan-public-prefix-length>28</v4-lan-public-prefix-length> - </t-provided-v4-lan-public-prefixes> - <t-provided-v6-lan-public-prefixes> - <request-index>1</request-index> - <v6-next-hop-address>2001:1890:12e3:2da::</v6-next-hop-address> - <v6-lan-public-prefix>2001:1890:12e3:2da::</v6-lan-public-prefix> - <v6-lan-public-prefix-length>28</v6-lan-public-prefix-length> - </t-provided-v6-lan-public-prefixes> - <t-provided-v6-lan-public-prefixes> - <request-index>1</request-index> - <v6-next-hop-address>2001:1890:12e3:2da::</v6-next-hop-address> - <v6-lan-public-prefix>2001:1890:12e3:2da::</v6-lan-public-prefix> - <v6-lan-public-prefix-length>28</v6-lan-public-prefix-length> - </t-provided-v6-lan-public-prefixes> - </internet-service-change-details> - </service-data> - </layer3-service-list> - - -""" - - String sdncAdapterRequest = """ - - - - - 745b1b50-e39e-4685-9cc8-c71f0bde8bf0 - query - services/layer3-service-list/AS%2FVLXM%2F000199%2F%2FSB_INTERNET - http://myhost.com:28080/mso/sdncAdapterCallbackServiceImpl - - - - - 12570a36-7388-4c0a-bec4-189ce3kg9956 - GetLayer3ServiceDetailsRequest - OMX - - - SDN-ETHERNET-INTERNET - PD/VLXM/003717//SW_INTERNET - - -""" - -def sdncAdapterResponse = """ - - - 39542e39-ccc3-4d1a-8b79-04ce88526613 - 404 - Error processing request to SDNC. Not Found. - https://sdncodl.us.aic.cip.com:8443/restconf/config/L3SDN-API:services/layer3-service-list/MVM%2FVLXP%2F000855%2F%2FShakeout. - SDNC Returned-[error-type:application, error-tag:data-missing, - error-message:Request could not be completed because the relevant - data model content does not exist.] - - - -""" - -def workflowErrorResponse = """ - Received error from SDN-C: Error processing request to SDNC. Not Found. - https://sdncodl.us.aic.cip.com:8443/restconf/config/L3SDN-API:services/layer3-service-list/MVM%2FVLXP%2F000855%2F%2FShakeout. - SDNC Returned-[error-type:application, error-tag:data-missing, - error-message:Request could not be completed because the relevant - data model content does not exist.] - 5300 - 404 - """ - -def workflowErrorResponse1 = """ - Invalid Callback Response from SDNC Adapter - 5300 - """ - -def enhancedCallbackRequestData = - """ - FK/VLXM/003717//SW_INTERNET - - service-configuration-operation - activate - synccomplete - N - Layer3ServiceActivateRequest - SUPP - 2015-04-28T21:32:11.386Z - - - - ds - 8 - Mbps - - - - - - 2001:1890:12e3:2da:: - 2001:1890:12e3:2da:: - 28 - - - 255.255.252.1 - 192.168.1.15 - 28 - - - 2001:1890:12e3:2da:: - 2001:1890:12e3:2da:: - 28 - - - 255.255.252.2 - 192.168.1.15 - 28 - - - 255.255.252.3 - 192.168.1.15 - 28 - - - - N - Y - N - - 192.168.1.7 - - - 192.168.1.8 - - - 1.1.1.1 - 28 - - 192.168.1.5 - - 2.2.2.1 - - 192.168.1.6 - - 192.155.2.3 - - - 1.1.1.2 - 28 - - 192.168.1.6 - - 2.2.2.2 - - 192.168.1.7 - - 192.155.2.4 - - Y - - 1:5 - - - 1:6 - - - 4:4 - 28 - - 1:1 - - 3:3 - - 2:2 - - 0:0 - - - 4:4 - 28 - - 1:1 - - 3:3 - - 2:2 - - 0:0 - - - - N - Y - - 0.0.0.1 - 1 - Y - - 1 - - - 1 - - - - 0.0.0.2 - 2 - Y - - 2 - - - 2 - - - - : - 0 - Y - - 3 - - - 3 - - - - : - 1 - Y - - 4 - - - 4 - - - - - - 192.168.1.44 - 192.168.1.5 - 0 - - Y - N - - 192.168.1.45 - 192.168.1.6 - 28 - - - - Y - - 0.0.0.0 - 0.0.0.0 - 0.0.0.0 - - - 0.0.0.1 - 0.0.0.1 - 0.0.0.1 - - - primary - 162.200.3.144 - 64 - 2001:1890:12e3:2da:: - 2620:0:10d0:f:ffff:ffff:ffff:fffe - 24 - 10.192.27.254 - - - 1 - 192.168.1.2 - 192.168.1.1 - 28 - - - 1 - 192.168.1.72 - 192.168.1.71 - 28 - - - 1 - 192.168.1.68 - 192.168.1.67 - 28 - - - - - 1 - 2001:1890:12e3:2da:: - 2001:1890:12e3:2da:: - 28 - - - 1 - 2001:1890:12e3:2da:: - 2001:1890:12e3:3da:: - 28 - - - 1 - 2001:1890:12e3:2da:: - 2001:1890:12e3:4da:: - 28 - - - - none - - - - AVPN - - 1 - Active - - - 2 - Standby - - - - hostname - activecode - OOB - - - - 1 - 1 - ZZ - JUNIPER - MODEL1 - 1 - 1 - 1 - 1 - 1 - - - 2 - 2 - HY - JUNIPER - MODEL2 - 2 - 2 - 2 - 2 - 2 - - - - - Layer3ServiceActivateRequest - 4281555 - 155415ab-b4a7-4382-b4c6-d17d9sm42855 - https://csi-tst-q22.it.com:22443/Services/com/cingular/csi/sdn/SendManagedNetworkStatusNotification.jws - OMX - 1 - - - activate - https://msojra.mtsnjdcp1.aic.cip.com:8443/adapters/rest/SDNCNotify - 5b1f3c5d-cdf9-488d-8a4b-d3f1229d7760 - - - MultiPoint - MTSNJA4LCP1 - AS/VLXM/003717//SW - - - FK/VLXM/003717//SW_INTERNET - ST E2E Test42855_1300004281555 - SDN-ETHERNET-INTERNET - - - 10 - Kbps - - 1 - 192.168.1.15 - 192.168.1.15 - 28 - - - 2 - 192.168.1.16 - 192.168.1.16 - 28 - - - 1 - 2001:1890:12e3:2da:: - 2001:1890:12e3:2da:: - 28 - - - 1 - 2001:1890:12e3:2da:: - 2001:1890:12e3:2da:: - 28 - - - - - -""" - -def sdncAdapterResponseEmpty = -""" - -""" - -def sdncAdapterResponseError = -""" - - - 39542e39-ccc3-4d1a-8b79-04ce88526613 - 404 - Error processing request to SDNC. Not Found. - https://sdncodl.us.aic.cip.com:8443/restconf/config/L3SDN-API:services/layer3-service-list/MVM%2FVLXP%2F000855%2F%2FShakeout. - SDNC Returned-[error-type:application, error-tag:data-missing, - error-message:Request could not be completed because the relevant - data model content does not exist.] - - -""" - - - @Test - public void testPreProcessRequest() { - - String sdncAdapterWorkflowRequest = FileUtil.readResourceFile("__files/SDN-ETHERNET-INTERNET/SDNCAdapterV1/sdncadapterworkflowrequest.xml"); - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - when(mockExecution.getVariable("URN_mso_adapters_po_auth")).thenReturn("3141634BF7E070AA289CF2892C986C0B") - when(mockExecution.getVariable("URN_mso_msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7") - when(mockExecution.getVariable("sdncAdapterWorkflowRequest")).thenReturn(sdncAdapterWorkflowRequest) - when(mockExecution.getVariable("URN_mso_workflow_sdncadapter_callback")).thenReturn("http://someurl.someting.com:28080/mso/sdncAdapterCallbackServiceImpl") - when(mockExecution.getVariable("URN_mso_use_qualified_host")).thenReturn("true") - when(mockExecution.getProcessInstanceId()).thenReturn("745b1b50-e39e-4685-9cc8-c71f0bde8bf0") - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") - - - SDNCAdapter sdncAdapter = new SDNCAdapter() - sdncAdapter.preProcessRequest(mockExecution) - - MockitoDebuggerImpl debugger = new MockitoDebuggerImpl() - debugger.printInvocations(mockExecution) - - - verify(mockExecution).setVariable("prefix","SDNCA_") - verify(mockExecution).setVariable("sdncAdapterResponse","") - verify(mockExecution).setVariable("asynchronousResponseTimeout",false) - verify(mockExecution).setVariable("continueListening",false) - verify(mockExecution).setVariable("BasicAuthHeaderValue","Basic cGFzc3dvcmQ=") - verify(mockExecution).setVariable("serviceConfigActivate",false) - verify(mockExecution).setVariable("SDNCA_requestId", "745b1b50-e39e-4685-9cc8-c71f0bde8bf0") - verify(mockExecution).setVariable("SDNCA_SuccessIndicator",false) - verify(mockExecution).setVariable("source","") - verify(mockExecution).setVariable("sdncAdapterRequest", sdncAdapterRequest) - } - - @Test - public void testProcessResponse() - { - String sdncAdapterCallbackResponse = FileUtil.readResourceFile("__files/SDN-ETHERNET-INTERNET/SDNCAdapterV1mock/sdncadaptercallbackrequest.xml"); - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - when(mockExecution.getVariable("sdncAdapterCallbackRequest")).thenReturn(sdncAdapterCallbackResponse) - SDNCAdapter sdncAdapter = new SDNCAdapter() - sdncAdapter.postProcessResponse(mockExecution) - -// MockitoDebuggerImpl debugger = new MockitoDebuggerImpl() -// debugger.printInvocations(mockExecution) - - verify(mockExecution).getVariable("isDebugLogEnabled") - verify(mockExecution,times(2)).getVariable("sdncAdapterCallbackRequest") - verify(mockExecution).setVariable("sdncAdapterResponse",workflowResponse) - verify(mockExecution).setVariable("enhancedCallbackRequestData",enhancedCallbackRequestData) - verify(mockExecution).setVariable("continueListening",false) - - } - - @Test - public void testProcessResponse_ErrorCase_404() - { - String sdncAdapterCallbackErrorResponse = FileUtil.readResourceFile("sdncadaptercallbackrequest_404CallBack.xml"); - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - when(mockExecution.getVariable("sdncAdapterCallbackRequest")).thenReturn(sdncAdapterCallbackErrorResponse) - SDNCAdapter sdncAdapter = new SDNCAdapter() - sdncAdapter.postProcessResponse(mockExecution) - - verify(mockExecution, times(1)).getVariable("isDebugLogEnabled") - verify(mockExecution,times(2)).getVariable("sdncAdapterCallbackRequest") - verify(mockExecution).setVariable("sdncAdapterResponse", sdncAdapterResponseError) - verify(mockExecution).setVariable("enhancedCallbackRequestData", "") - verify(mockExecution).setVariable("continueListening",false) - - } - - @Test - public void testProcessResponse_ErrorCase_InvalidCallback() - { - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - when(mockExecution.getVariable("sdncAdapterCallbackRequest")).thenReturn("

Service Unavailable

") - SDNCAdapter sdncAdapter = new SDNCAdapter() - sdncAdapter.postProcessResponse(mockExecution) - - verify(mockExecution).getVariable("isDebugLogEnabled") - verify(mockExecution,times(2)).getVariable("sdncAdapterCallbackRequest") - verify(mockExecution).setVariable("sdncAdapterResponse", sdncAdapterResponseEmpty) - verify(mockExecution).setVariable("enhancedCallbackRequestData", "") - verify(mockExecution).setVariable("continueListening",false) - - } - - @Test - public void postProcessResponse() - { - - String SDNCAdapterCallbackRequest = - """ - - - 3bb02798-b344-4d28-9bca-1f029954d1c9 - 404 - Error processing request to SDNC. Not Found. - https://sdncodl.us.infra.aic.net:8443/restconf/config/L3SDN-API:services/layer3-service-list/85%2FCSIP%2F141203%2FPT_CSI9999998693. - SDNC Returned-[error-type:application, error-tag:data-missing, - error-message:Request could not be completed because the relevant - data model content does not exist ] - -""" - - String sdncAdapterResponse = - """ - - - 3bb02798-b344-4d28-9bca-1f029954d1c9 - 404 - Error processing request to SDNC. Not Found. - https://sdncodl.us.infra.aic.net:8443/restconf/config/L3SDN-API:services/layer3-service-list/85%2FCSIP%2F141203%2FPT_CSI9999998693. - SDNC Returned-[error-type:application, error-tag:data-missing, - error-message:Request could not be completed because the relevant - data model content does not exist ] - - -""" - - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - when(mockExecution.getVariable("sdncAdapterCallbackRequest")).thenReturn(SDNCAdapterCallbackRequest) - SDNCAdapter sdncAdapter = new SDNCAdapter() - sdncAdapter.postProcessResponse(mockExecution) - - verify(mockExecution).getVariable("isDebugLogEnabled") - verify(mockExecution,times(2)).getVariable("sdncAdapterCallbackRequest") - verify(mockExecution).setVariable("sdncAdapterResponse", sdncAdapterResponse) - verify(mockExecution).setVariable("enhancedCallbackRequestData", "") - verify(mockExecution).setVariable("continueListening",false) - - } - -} \ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/SDNCAdapterUtilsTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/SDNCAdapterUtilsTest.groovy deleted file mode 100644 index 161b71cb9c..0000000000 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/SDNCAdapterUtilsTest.groovy +++ /dev/null @@ -1,213 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * 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.scripts; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.* - -import org.junit.Before -import org.junit.Ignore -import org.junit.Test -import org.camunda.bpm.engine.delegate.BpmnError -import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity -import org.camunda.bpm.engine.delegate.DelegateExecution -import org.openecomp.mso.bpmn.core.WorkflowException -import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils - -import org.openecomp.mso.bpmn.mock.FileUtil - -public class SDNCAdapterUtilsTest { - - private def map - private ExecutionEntity svcex - private WorkflowException wfex - private AbstractServiceTaskProcessor tp - private String resp - private SDNCAdapterUtils utils - - @Before - public void init() - { - map = new HashMap() - svcex = mock(ExecutionEntity.class) - wfex = null - tp = new AbstractServiceTaskProcessor() { - @Override - public void preProcessRequest(DelegateExecution execution) { - } - }; - utils = new SDNCAdapterUtils(tp) - - // svcex gets its variables from "map" - when(svcex.getVariable(any())).thenAnswer( - { invocation -> - return map.get(invocation.getArgumentAt(0, String.class)) }) - - // svcex puts its variables into "map" - when(svcex.setVariable(any(), any())).thenAnswer( - { invocation -> - return map.put( - invocation.getArgumentAt(0, String.class), - invocation.getArgumentAt(1, String.class)) }) - - map.put("isDebugLogEnabled", "true") - map.put("prefix", "mypfx-") - map.put("testProcessKey", "mykey") - } - - @Test - public void testValidateSDNCResponse_Success_NoCode() { - resp = """""" - - utils.validateSDNCResponse(svcex, resp, wfex, true) - - assertEquals(true, map.get("mypfx-sdncResponseSuccess")) - assertEquals("0", map.get("mypfx-sdncRequestDataResponseCode")) - assertFalse(map.containsKey("WorkflowException")) - } - - @Test - public void testValidateSDNCResponse_200() { - utils.validateSDNCResponse(svcex, makeResp("200", "OK", ""), wfex, true) - - assertEquals(true, map.get("mypfx-sdncResponseSuccess")) - assertEquals("200", map.get("mypfx-sdncRequestDataResponseCode")) - assertFalse(map.containsKey("WorkflowException")) - } - - @Test - public void testValidateSDNCResponse_408() { - try { - utils.validateSDNCResponse(svcex, makeResp("408", "failed", ""), wfex, true) - - // this has been commented out as, currently, the code doesn't - // throw an exception in this case -// fail("missing exception") - - } catch(BpmnError ex) { - ex.printStackTrace() - } - - assertEquals(false, map.get("mypfx-sdncResponseSuccess")) - assertEquals("408", map.get("mypfx-sdncRequestDataResponseCode")) - - wfex = map.get("WorkflowException") - assertNotNull(wfex) - - assertEquals(5320, wfex.getErrorCode()) - assertEquals("Received error from SDN-C: failed", wfex.getErrorMessage()) - } - - @Test - public void testValidateSDNCResponse_408_200() { - - utils.validateSDNCResponse(svcex, makeResp("408", "failed", makeReq("200", "ok")), wfex, true) - - assertEquals(true, map.get("mypfx-sdncResponseSuccess")) - assertEquals("200", map.get("mypfx-sdncRequestDataResponseCode")) - assertFalse(map.containsKey("WorkflowException")) - } - - @Ignore // 1802 merge - @Test - public void testValidateSDNCResponse_408_200_WithEmbeddedLt() { - - utils.validateSDNCResponse(svcex, makeResp("408", "failed", makeReq("200", " message")), wfex, true) - - assertEquals(true, map.get("mypfx-sdncResponseSuccess")) - assertEquals("200", map.get("mypfx-sdncRequestDataResponseCode")) - assertFalse(map.containsKey("WorkflowException")) - } - - @Test - public void testUpdateHomingInfo() { - String actual = utils.updateHomingInfo(null, "AIC3.0") - println actual - assertEquals("AIC3.0", actual) - } - - @Test - public void testUpdateHomingInfo2() { - String homingInfo = "TESTCLLI" - String actual = utils.updateHomingInfo(homingInfo, "AIC3.0") - println actual - assertEquals("TESTCLLIAIC3.0", actual) - } - - @Ignore // 1802 merge - testing method that doesn't exist - @Test - public void testUpdateServiceInfo() { - String actual = utils.updateServiceInfo(null, "96688f6f-ab06-4ef6-ae55-9d3af28ae909") - println actual - assertEquals("96688f6f-ab06-4ef6-ae55-9d3af28ae909", actual) - } - - @Ignore // 1802 merge - testing method that doesn't exist - @Test - public void testUpdateServiceInfo2() { - String serviceInfo = "SDN-ETHERNET-INTERNETMIS/1602/00029/SB_INTERNET" - String actual = utils.updateServiceInfo(serviceInfo, "96688f6f-ab06-4ef6-ae55-9d3af28ae909") - println actual - assertEquals("SDN-ETHERNET-INTERNETMIS/1602/00029/SB_INTERNET96688f6f-ab06-4ef6-ae55-9d3af28ae909", actual) - } - - private String makeResp(String respcode, String respmsg, String reqdata) { - def rc = encodeXml(respcode) - def rm = encodeXml(respmsg) - - return """ - - - - myreq - ${rc} - ${rm} - - ${reqdata} - - -""" - - } - - private String makeReq(String respcode, String respmsg) { - def rc = encodeXml(respcode) - def rm = encodeXml(respmsg) - - def output = """ - - 8b46e36e-b44f-4085-9404-427be1bc8a3 - ${rc} - ${rm} - Y - -""" - output = encodeXml(output) - - return """${output}""" - } - - private String encodeXml(String txt) { - return txt.replace("&", "&").replace("<", "<") - } -} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/TrinityExceptionUtilTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/TrinityExceptionUtilTest.groovy deleted file mode 100644 index 203f11a42e..0000000000 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/TrinityExceptionUtilTest.groovy +++ /dev/null @@ -1,201 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * 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.scripts - -import org.junit.Assert -import org.junit.Ignore -import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; - - - -import static org.mockito.Mockito.* - -import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity -import org.junit.Before -import org.junit.runner.RunWith -import org.mockito.MockitoAnnotations -import org.mockito.internal.debugging.MockitoDebuggerImpl -import org.mockito.runners.MockitoJUnitRunner -import org.openecomp.mso.bpmn.common.scripts.TrinityExceptionUtil; -@RunWith(MockitoJUnitRunner.class) -import org.junit.Test - -class TrinityExceptionUtilTest { - - def aotsFault =""" - xml:space - String - http://test.com - - - - 400 - bad stuff - - - String - *** ERROR *** - String - String - String - String - - String - String - - String - String - String - String - - - - - - String - *** ERROR *** - String - String - String - String - String - String - String - - -""" - - - @Before - public void init() - { - MockitoAnnotations.initMocks(this) - } - - @Test - @Ignore - public void testMapAAIExceptionTCommonException() { - - - - String restFault = """ - - - -SVC3002 -Error writing output performing %1 on %2 (msg=%3) (ec=%4) - -PUTcustomer -SubName01 -Unexpected error reading/updating database:Adding this property for key [service-instance-id] and value [USSTU2CFCNC0101UJZZ01] violates a uniqueness constraint [service-instance-id] -ERR.5.4.5105 - - - - - """ - def errorString = """ - -SVC3002 -Error writing output performing %1 on %2 (msg=%3) (ec=%4) - -PUTcustomer -SubName01 -Unexpected error reading/updating database:Adding this property for key [service-instance-id] and value [USSTU2CFCNC0101UJZZ01] violates a uniqueness constraint [service-instance-id] -ERR.5.4.5105 - - -""" as String - - - - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - - TrinityExceptionUtil util = new TrinityExceptionUtil() - Assert.assertEquals(errorString, util.mapAAIExceptionTCommonException(restFault, mockExecution)) - } - - - - - @Test - public void testBuildException() { - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - when(mockExecution.getVariable("prefix")).thenReturn("test_") - when(mockExecution.getVariable("test_ResponseCode")).thenReturn("400") - ArrayList msgVars = new ArrayList() - msgVars.add("var1") - msgVars.add("var2") - when(mockExecution.getVariable("test_errVariables")).thenReturn(msgVars) - - - TrinityExceptionUtil util = new TrinityExceptionUtil() - String msg = "Bad request" - String errorString = """ - - SVC2000 - The following service error occurred: %1. Error code is %2. - var1 - var2 - -""" - Assert.assertEquals(errorString, util.buildException(msg, mockExecution)) - } - - @Test - public void testMapAOTSExecptionToCommonException() { - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - when(mockExecution.getVariable("prefix")).thenReturn("test_") - when(mockExecution.getVariable("test_ResponseCode")).thenReturn("400") - - TrinityExceptionUtil util = new TrinityExceptionUtil() - String errorString = """ - - SVC2000 - The following service error occurred: %1. Error code is %2. - Received error from AOTS: bad stuff - 400 - -""" - Assert.assertEquals(errorString, util.mapAOTSExecptionToCommonException(aotsFault, mockExecution)) - } - - - @Test - public void testParseError() { - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - String errorString = "The following service error occurred: %1. Error code is %2." - ArrayList msgVars = new ArrayList() - msgVars.add("var1") - msgVars.add("var2") - when(mockExecution.getVariable("prefix")).thenReturn("test_") - when(mockExecution.getVariable("test_errTxt")).thenReturn(errorString) - when(mockExecution.getVariable("test_errVariables")).thenReturn(msgVars) - - TrinityExceptionUtil util = new TrinityExceptionUtil() - - Assert.assertEquals("The following service error occurred: var1. Error code is var2.", util.parseError(mockExecution)) -} - - - -} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/VidUtilsTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/VidUtilsTest.groovy deleted file mode 100644 index ffdaf0653d..0000000000 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/VidUtilsTest.groovy +++ /dev/null @@ -1,972 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * 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.scripts; - -import static org.mockito.Mockito.* - -import org.openecomp.mso.bpmn.common.scripts.VidUtils; -import org.openecomp.mso.bpmn.core.WorkflowException - -import groovy.json.JsonSlurper - -import org.camunda.bpm.engine.delegate.BpmnError -import org.camunda.bpm.engine.ProcessEngineServices -import org.camunda.bpm.engine.RepositoryService -import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity -import org.camunda.bpm.engine.impl.pvm.process.ProcessDefinitionImpl -import org.camunda.bpm.engine.repository.ProcessDefinition -import org.camunda.bpm.engine.delegate.DelegateExecution; - -import static org.junit.Assert.*; - -import org.mockito.MockitoAnnotations -import org.mockito.runners.MockitoJUnitRunner -import org.mockito.internal.debugging.MockitoDebuggerImpl -import org.junit.Before -import org.junit.Rule; -import org.junit.Test -import org.junit.Ignore -import org.junit.runner.RunWith -import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity; -import org.junit.Before; -import org.junit.Test; - -@RunWith(MockitoJUnitRunner.class) - -class VidUtilsTest { - - def vfModuleReqJson = """ -{ - "requestDetails": { - "modelInfo": { - "modelType": "vfModule", - "modelInvariantUuid": "ff5256d2-5a33-55df-13ab-12abad84e7ff", - "modelNameVersionId": "fe6478e5-ea33-3346-ac12-ab121484a3fe", - "modelName": "STMTN5MMSC21-MMSC::model-1-0", - "modelVersion": "1", - "modelCustomizationUuid": "ee6478e5-ea33-3346-ac12-ab121484a3fe" - }, - "cloudConfiguration": { - "lcpCloudRegionId": "MDTWNJ21", - "tenantId": "fba1bd1e195a404cacb9ce17a9b2b421" - }, - "requestInfo": { - "instanceName": "PCRF::module-0-2", - "source": "VID", - "suppressRollback": true - }, - "relatedInstanceList": [ - { - "relatedInstance": { - "instanceId": "17ef4658-bd1f-4ef0-9ca0-ea76e2bf122c", - "instanceName": "MSOTESTVOL103a-vSAMP12_base_module-0_vol", - "modelInfo": { - "modelType": "volumeGroup", - "modelInvariantUuid": "ff5256d2-5a33-55df-13ab-12abad84e7ff", - "modelNameVersionId": "fe6478e5-ea33-3346-ac12-ab121484a3fe", - "modelName": "vSAMP12..base..module-0", - "modelVersion": "1" - } - } - }, - { - "relatedInstance": { - "instanceId": "123456", - "modelInfo": { - "modelType": "service", - "modelInvariantUuid": "ff3514e3-5a33-55df-13ab-12abad84e7ff", - "modelNameVersionId": "fe6985cd-ea33-3346-ac12-ab121484a3fe", - "modelName": "SERVICE_MODEL_NAME", - "modelVersion": "1.0" - } - } - }, - { - "relatedInstance": { - "instanceId": "skask", - "instanceName": "skask-test", - "modelInfo": { - "modelType": "vnf", - "modelInvariantUuid": "skask", - "modelNameVersionId": "fe6478e4-ea33-3346-ac12-ab121484a3fe", - "modelName": "vSAMP12", - "modelVersion": "1.0", - "modelInstanceName": "vSAMP12 1" - } - } - } - ], - "requestParameters": { - "userParams": [ - { - "name": "vnfName", - "value": "STMTN5MMSC20" - }, - { - "name": "tenantId", - "value": "vpe-tenant-123" - }, - { - "name": "aicCloudRegion", - "value": "MDTWNJ21" - }, - { - "name": "isAvpnService", - "value": "true" - }, - { - "name": "asn", - "value": "asn-1234" - }, - { - "name": "releaseForAero", - "value": "release-for-aero-something" - }, - { - "name": "aicClli", - "value": "MTJWNJA4LCP" - }, - { - "name": "svcProviderPartNumber", - "value": "svc-provide-number-1234" - } - ] - } - } -} -""" - def bpmnReq1 = """ -{ - "requestDetails": { - "modelInfo": { - "modelType": "volumeGroup", - "modelId": "ff5256d2-5a33-55df-13ab-12abad84e7ff", - "modelNameVersionId": "fe6478e5-ea33-3346-ac12-ab121484a3fe", - "modelName": "vSAMP12::base::module-0", - "modelVersion": "1" - }, - "cloudConfiguration": { - "lcpCloudRegionId": "mdt1", - "tenantId": "88a6ca3ee0394ade9403f075db23167e" - }, - "requestInfo": { - "instanceName": "MSOTESTVOL101a-vSAMP12_base_vol_module-0", - "source": "VID", - "suppressRollback": false - }, - "relatedInstanceList": [ - { - "relatedInstance": { - "instanceId": "{service-instance-id}", - "modelInfo": { - "modelType": "service", - "modelId": "ff3514e3-5a33-55df-13ab-12abad84e7ff", - "modelNameVersionId": "fe6985cd-ea33-3346-ac12-ab121484a3fe", - "modelName": "Test", - "modelVersion": "2.0" - } - } - }, { - "relatedInstance": { - "instanceId": "{vnf-instance-id}", - "modelInfo": { - "modelType": "vnf", - "modelId": "ff5256d1-5a33-55df-13ab-12abad84e7ff", - "modelNameVersionId": "fe6478e4-ea33-3346-ac12-ab121484a3fe", - "modelName": "vSAMP12", - "modelVersion": "1", - "modelInstanceName": "vSAMP12" - } - } - } - ], - "requestParameters": { - "serviceId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", - "userParams": [ - {"name": "vnfName", "value": "STMTN5MMSC20" }, - {"name": "vnfName2", "value": "US1117MTSNJVBR0246" }, - {"name": "vnfNmInformation", "value": "" }, - {"name": "vnfType", "value": "pcrf-capacity" }, - {"name": "vnfId", "value": "skask" }, - {"name": "vnfStackId", "value": "slowburn" }, - {"name": "vnfStatus", "value": "created" }, - {"name": "aicCloudRegion", "value": "MDTWNJ21" }, - {"name": "availabilityZone", "value": "slcp3-esx-az01" }, - {"name": "oamNetworkName", "value": "VLAN-OAM-1323" }, - {"name": "vmName", "value": "slcp34246vbc246ceb" }, - {"name": "ipagNetworkId", "value": "970cd2b9-7f09-4a12-af47-182ea38ba1f0" }, - {"name": "vpeNetworkId", "value": "545cc2c3-1930-4100-b534-5d82d0e12bb6" } - ] - } - } -} -""" - - def vidUtilResp1 = """ - - CREATE_VF_MODULE_VOL - VID - test-service-instance-id-123 - - - - MSOTESTVOL101a-vSAMP12_base_vol_module-0 - Test/vSAMP12 - vSAMP12::base::module-0 - 2.0 - mdt1 - 88a6ca3ee0394ade9403f075db23167e - a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb - true - - - - STMTN5MMSC20 - US1117MTSNJVBR0246 - - pcrf-capacity - skask - slowburn - created - MDTWNJ21 - slcp3-esx-az01 - VLAN-OAM-1323 - slcp34246vbc246ceb - 970cd2b9-7f09-4a12-af47-182ea38ba1f0 - 545cc2c3-1930-4100-b534-5d82d0e12bb6 - - -""" - - def bpmnReq2 = """ -{ - "requestDetails": { - "modelInfo": { - "modelType": "volumeGroup", - "modelId": "ff5256d2-5a33-55df-13ab-12abad84e7ff", - "modelUuid": "fe6478e5-ea33-3346-ac12-ab121484a3fe", - "modelName": "vSAMP12::base::module-0", - "modelVersion": "1" - }, - "cloudConfiguration": { - "lcpCloudRegionId": "mdt1", - "tenantId": "88a6ca3ee0394ade9403f075db23167e" - }, - "requestInfo": { - "instanceName": "MSOTESTVOL101a-vSAMP12_base_vol_module-0", - "source": "VID", - "suppressRollback": false - }, - "relatedInstanceList": [ - { - "relatedInstance": { - "instanceId": "{service-instance-id}", - "modelInfo": { - "modelType": "service", - "modelId": "ff3514e3-5a33-55df-13ab-12abad84e7ff", - "modelUuid": "fe6985cd-ea33-3346-ac12-ab121484a3fe", - "modelName": "Test", - "modelVersion": "2.0" - } - } - }, { - "relatedInstance": { - "instanceId": "{vnf-instance-id}", - "modelInfo": { - "modelType": "vnf", - "modelId": "ff5256d1-5a33-55df-13ab-12abad84e7ff", - "modelUuid": "fe6478e4-ea33-3346-ac12-ab121484a3fe", - "modelName": "vSAMP12", - "modelVersion": "1", - "modelInstanceName": "vSAMP12" - } - } - } - ] - } -} -""" - - def bpmnReqJsonVolumeSuppressRollbackTrue = """ -{ - "requestDetails": { - "modelInfo": { - "modelType": "volumeGroup", - "modelId": "ff5256d2-5a33-55df-13ab-12abad84e7ff", - "modelUuid": "fe6478e5-ea33-3346-ac12-ab121484a3fe", - "modelName": "vSAMP12::base::module-0", - "modelVersion": "1" - }, - "cloudConfiguration": { - "lcpCloudRegionId": "mdt1", - "tenantId": "88a6ca3ee0394ade9403f075db23167e" - }, - "requestInfo": { - "instanceName": "MSOTESTVOL101a-vSAMP12_base_vol_module-0", - "source": "VID", - "suppressRollback": true - }, - "relatedInstanceList": [ - { - "relatedInstance": { - "instanceId": "{service-instance-id}", - "modelInfo": { - "modelType": "service", - "modelId": "ff3514e3-5a33-55df-13ab-12abad84e7ff", - "modelUuid": "fe6985cd-ea33-3346-ac12-ab121484a3fe", - "modelName": "Test", - "modelVersion": "2.0" - } - } - }, { - "relatedInstance": { - "instanceId": "{vnf-instance-id}", - "modelInfo": { - "modelType": "vnf", - "modelId": "ff5256d1-5a33-55df-13ab-12abad84e7ff", - "modelUuid": "fe6478e4-ea33-3346-ac12-ab121484a3fe", - "modelName": "vSAMP12", - "modelVersion": "1", - "modelInstanceName": "vSAMP12" - } - } - } - ] - } -} -""" - -def bpmnReqJsonVolumeSuppressRollbackFalse = """ -{ - "requestDetails": { - "modelInfo": { - "modelType": "volumeGroup", - "modelId": "ff5256d2-5a33-55df-13ab-12abad84e7ff", - "modelUuid": "fe6478e5-ea33-3346-ac12-ab121484a3fe", - "modelName": "vSAMP12::base::module-0", - "modelVersion": "1" - }, - "cloudConfiguration": { - "lcpCloudRegionId": "mdt1", - "tenantId": "88a6ca3ee0394ade9403f075db23167e" - }, - "requestInfo": { - "instanceName": "MSOTESTVOL101a-vSAMP12_base_vol_module-0", - "source": "VID", - "suppressRollback": false - }, - "relatedInstanceList": [ - { - "relatedInstance": { - "instanceId": "{service-instance-id}", - "modelInfo": { - "modelType": "service", - "modelId": "ff3514e3-5a33-55df-13ab-12abad84e7ff", - "modelUuid": "fe6985cd-ea33-3346-ac12-ab121484a3fe", - "modelName": "Test", - "modelVersion": "2.0" - } - } - }, { - "relatedInstance": { - "instanceId": "{vnf-instance-id}", - "modelInfo": { - "modelType": "vnf", - "modelId": "ff5256d1-5a33-55df-13ab-12abad84e7ff", - "modelUuid": "fe6478e4-ea33-3346-ac12-ab121484a3fe", - "modelName": "vSAMP12", - "modelVersion": "1", - "modelInstanceName": "vSAMP12" - } - } - } - ] - } -} -""" - -def bpmnReqJsonVolumeSuppressRollbackNone = """ -{ - "requestDetails": { - "modelInfo": { - "modelType": "volumeGroup", - "modelId": "ff5256d2-5a33-55df-13ab-12abad84e7ff", - "modelUuid": "fe6478e5-ea33-3346-ac12-ab121484a3fe", - "modelName": "vSAMP12::base::module-0", - "modelVersion": "1" - }, - "cloudConfiguration": { - "lcpCloudRegionId": "mdt1", - "tenantId": "88a6ca3ee0394ade9403f075db23167e" - }, - "requestInfo": { - "instanceName": "MSOTESTVOL101a-vSAMP12_base_vol_module-0", - "source": "VID" - }, - "relatedInstanceList": [ - { - "relatedInstance": { - "instanceId": "{service-instance-id}", - "modelInfo": { - "modelType": "service", - "modelId": "ff3514e3-5a33-55df-13ab-12abad84e7ff", - "modelUuid": "fe6985cd-ea33-3346-ac12-ab121484a3fe", - "modelName": "Test", - "modelVersion": "2.0" - } - } - }, { - "relatedInstance": { - "instanceId": "{vnf-instance-id}", - "modelInfo": { - "modelType": "vnf", - "modelId": "ff5256d1-5a33-55df-13ab-12abad84e7ff", - "modelUuid": "fe6478e4-ea33-3346-ac12-ab121484a3fe", - "modelName": "vSAMP12", - "modelVersion": "1", - "modelInstanceName": "vSAMP12" - } - } - } - ] - } -} -""" - - def bpmnReqJsonVfModuleSuppressRollbackTrue = """ -{ -"requestDetails": { -"modelInfo": { -"modelType": "vfModule", -"modelInvariantUuid": "ff5256d2-5a33-55df-13ab-12abad84e7ff", -"modelUuid": "fe6478e5-ea33-3346-ac12-ab121484a3fe", -"modelName": "STMTN5MMSC21-MMSC::model-1-0", -"modelVersion": "1" -}, -"cloudConfiguration": { -"lcpCloudRegionId": "MDTWNJ21", -"tenantId": "fba1bd1e195a404cacb9ce17a9b2b421" -}, -"requestInfo": { -"instanceName": "PCRF::module-0-2", -"source": "VID", -"suppressRollback": true -}, -"relatedInstanceList": [ -{ -"relatedInstance": { -"instanceId": "17ef4658-bd1f-4ef0-9ca0-ea76e2bf122c", -"instanceName": "MSOTESTVOL103a-vSAMP12_base_module-0_vol", -"modelInfo": { -"modelType": "volumeGroup", -"modelInvariantUuid": "ff5256d2-5a33-55df-13ab-12abad84e7ff", -"modelUuid": "fe6478e5-ea33-3346-ac12-ab121484a3fe", -"modelName": "vSAMP12..base..module-0", -"modelVersion": "1" -} -} -}, -{ -"relatedInstance": { -"instanceId": "123456", -"modelInfo": { -"modelType": "service", -"modelInvariantUuid": "ff3514e3-5a33-55df-13ab-12abad84e7ff", -"modelUuid": "fe6985cd-ea33-3346-ac12-ab121484a3fe", -"modelName": "SERVICE_MODEL_NAME", -"modelVersion": "1.0" -} -} -}, -{ -"relatedInstance": { -"instanceId": "skask", -"instanceName": "skask-test", -"modelInfo": { -"modelType": "vnf", -"modelInvariantUuid": "skask", -"modelUuid": "fe6478e4-ea33-3346-ac12-ab121484a3fe", -"modelName": "vSAMP12", -"modelVersion": "1.0", -"modelInstanceName": "vSAMP12 1" -} -} -} -], -"requestParameters": { -"userParams": {} -} -} -} -""" - -def bpmnReqJsonVfModuleSuppressRollbackFalse = """ -{ -"requestDetails": { -"modelInfo": { -"modelType": "vfModule", -"modelInvariantUuid": "ff5256d2-5a33-55df-13ab-12abad84e7ff", -"modelUuid": "fe6478e5-ea33-3346-ac12-ab121484a3fe", -"modelName": "STMTN5MMSC21-MMSC::model-1-0", -"modelVersion": "1" -}, -"cloudConfiguration": { -"lcpCloudRegionId": "MDTWNJ21", -"tenantId": "fba1bd1e195a404cacb9ce17a9b2b421" -}, -"requestInfo": { -"instanceName": "PCRF::module-0-2", -"source": "VID", -"suppressRollback": false -}, -"relatedInstanceList": [ -{ -"relatedInstance": { -"instanceId": "17ef4658-bd1f-4ef0-9ca0-ea76e2bf122c", -"instanceName": "MSOTESTVOL103a-vSAMP12_base_module-0_vol", -"modelInfo": { -"modelType": "volumeGroup", -"modelInvariantUuid": "ff5256d2-5a33-55df-13ab-12abad84e7ff", -"modelUuid": "fe6478e5-ea33-3346-ac12-ab121484a3fe", -"modelName": "vSAMP12..base..module-0", -"modelVersion": "1" -} -} -}, -{ -"relatedInstance": { -"instanceId": "123456", -"modelInfo": { -"modelType": "service", -"modelInvariantUuid": "ff3514e3-5a33-55df-13ab-12abad84e7ff", -"modelUuid": "fe6985cd-ea33-3346-ac12-ab121484a3fe", -"modelName": "SERVICE_MODEL_NAME", -"modelVersion": "1.0" -} -} -}, -{ -"relatedInstance": { -"instanceId": "skask", -"instanceName": "skask-test", -"modelInfo": { -"modelType": "vnf", -"modelInvariantUuid": "skask", -"modelUuid": "fe6478e4-ea33-3346-ac12-ab121484a3fe", -"modelName": "vSAMP12", -"modelVersion": "1.0", -"modelInstanceName": "vSAMP12 1" -} -} -} -], -"requestParameters": { -"userParams": {} -} -} -} -""" - -def bpmnReqJsonVfModuleSuppressRollbackNone = """ -{ -"requestDetails": { -"modelInfo": { -"modelType": "vfModule", -"modelInvariantUuid": "ff5256d2-5a33-55df-13ab-12abad84e7ff", -"modelUuid": "fe6478e5-ea33-3346-ac12-ab121484a3fe", -"modelName": "STMTN5MMSC21-MMSC::model-1-0", -"modelVersion": "1" -}, -"cloudConfiguration": { -"lcpCloudRegionId": "MDTWNJ21", -"tenantId": "fba1bd1e195a404cacb9ce17a9b2b421" -}, -"requestInfo": { -"instanceName": "PCRF::module-0-2", -"source": "VID" -}, -"relatedInstanceList": [ -{ -"relatedInstance": { -"instanceId": "17ef4658-bd1f-4ef0-9ca0-ea76e2bf122c", -"instanceName": "MSOTESTVOL103a-vSAMP12_base_module-0_vol", -"modelInfo": { -"modelType": "volumeGroup", -"modelInvariantUuid": "ff5256d2-5a33-55df-13ab-12abad84e7ff", -"modelUuid": "fe6478e5-ea33-3346-ac12-ab121484a3fe", -"modelName": "vSAMP12..base..module-0", -"modelVersion": "1" -} -} -}, -{ -"relatedInstance": { -"instanceId": "123456", -"modelInfo": { -"modelType": "service", -"modelInvariantUuid": "ff3514e3-5a33-55df-13ab-12abad84e7ff", -"modelUuid": "fe6985cd-ea33-3346-ac12-ab121484a3fe", -"modelName": "SERVICE_MODEL_NAME", -"modelVersion": "1.0" -} -} -}, -{ -"relatedInstance": { -"instanceId": "skask", -"instanceName": "skask-test", -"modelInfo": { -"modelType": "vnf", -"modelInvariantUuid": "skask", -"modelUuid": "fe6478e4-ea33-3346-ac12-ab121484a3fe", -"modelName": "vSAMP12", -"modelVersion": "1.0", -"modelInstanceName": "vSAMP12 1" -} -} -} -], -"requestParameters": { -"userParams": {} -} -} -} -""" - def vidUtilResp2 = """ - - CREATE_VF_MODULE_VOL - VID - test-service-instance-id-123 - - - - MSOTESTVOL101a-vSAMP12_base_vol_module-0 - Test/vSAMP12 - vSAMP12::base::module-0 - 2.0 - mdt1 - 88a6ca3ee0394ade9403f075db23167e - - true - - - - -""" - -def vidUtilVolumeRespBackoutOnFailureFalse = """ - - CREATE_VF_MODULE_VOL - VID - test-service-instance-id-123 - - - - MSOTESTVOL101a-vSAMP12_base_vol_module-0 - Test/vSAMP12 - vSAMP12::base::module-0 - 2.0 - mdt1 - 88a6ca3ee0394ade9403f075db23167e - - false - - - - -""" - -def vidUtilVolumeRespBackoutOnFailureTrue = """ - - CREATE_VF_MODULE_VOL - VID - test-service-instance-id-123 - - - - MSOTESTVOL101a-vSAMP12_base_vol_module-0 - Test/vSAMP12 - vSAMP12::base::module-0 - 2.0 - mdt1 - 88a6ca3ee0394ade9403f075db23167e - - true - - - - -""" - -def vidUtilVolumeRespBackoutOnFailureEmpty = """ - - CREATE_VF_MODULE_VOL - VID - test-service-instance-id-123 - - - - MSOTESTVOL101a-vSAMP12_base_vol_module-0 - Test/vSAMP12 - vSAMP12::base::module-0 - 2.0 - mdt1 - 88a6ca3ee0394ade9403f075db23167e - - - - - - -""" - -def vidUtilVfModuleRespBackoutOnFailureFalse = """ - - test-request-id-123 - CREATE_VF_MODULE - VID - - test-service-instance-id-123 - - - skask-test - test-vnf-type-123 - test-vnf-id-123 - test-volume-group-id-123 - test-vf-module-id-123 - PCRF::module-0-2 - STMTN5MMSC21-MMSC::model-1-0 - - false - 1.0 - MDTWNJ21 - fba1bd1e195a404cacb9ce17a9b2b421 - - false - ff5256d2-5a33-55df-13ab-12abad84e7ff - fe6478e5-ea33-3346-ac12-ab121484a3fe - - - -""" - -def vidUtilVfModuleRespBackoutOnFailureTrue = """ - - test-request-id-123 - CREATE_VF_MODULE - VID - - test-service-instance-id-123 - - - skask-test - test-vnf-type-123 - test-vnf-id-123 - test-volume-group-id-123 - test-vf-module-id-123 - PCRF::module-0-2 - STMTN5MMSC21-MMSC::model-1-0 - - false - 1.0 - MDTWNJ21 - fba1bd1e195a404cacb9ce17a9b2b421 - - true - ff5256d2-5a33-55df-13ab-12abad84e7ff - fe6478e5-ea33-3346-ac12-ab121484a3fe - - - -""" - -def vidUtilVfModuleRespBackoutOnFailureEmpty = """ - - test-request-id-123 - CREATE_VF_MODULE - VID - - test-service-instance-id-123 - - - skask-test - test-vnf-type-123 - test-vnf-id-123 - test-volume-group-id-123 - test-vf-module-id-123 - PCRF::module-0-2 - STMTN5MMSC21-MMSC::model-1-0 - - false - 1.0 - MDTWNJ21 - fba1bd1e195a404cacb9ce17a9b2b421 - - - ff5256d2-5a33-55df-13ab-12abad84e7ff - fe6478e5-ea33-3346-ac12-ab121484a3fe - - - -""" - - @Before - public void init() - { - MockitoAnnotations.initMocks(this) - - } - - @Test - public void test() { - - def jsonSlurper = new JsonSlurper() - Map reqMap = jsonSlurper.parseText(bpmnReq1) - - VidUtils vidUtils = new VidUtils() - def xmlReq = vidUtils.createXmlVolumeRequest(reqMap, 'CREATE_VF_MODULE_VOL', 'test-service-instance-id-123') - print xmlReq - assertEquals(vidUtilResp1, xmlReq) - } - - //@Test - public void testVfModule() { - - def jsonSlurper = new JsonSlurper() - Map reqMap = jsonSlurper.parseText(vfModuleReqJson) - - VidUtils vidUtils = new VidUtils() - def xmlReq = vidUtils.createXmlVfModuleRequest(null, reqMap, "CREATE_VF_MODULE", "test-service-instance-id-123") - print xmlReq - assertTrue(true) - } - - @Test - public void testNoRequestParams() { - - def jsonSlurper = new JsonSlurper() - Map reqMap = jsonSlurper.parseText(bpmnReq2) - - VidUtils vidUtils = new VidUtils() - def xmlReq = vidUtils.createXmlVolumeRequest(reqMap, 'CREATE_VF_MODULE_VOL', 'test-service-instance-id-123') - - assertEquals(vidUtilResp2, xmlReq) - } - - @Test - public void testVfModuleVolumeRollbackTrue() { - - def jsonSlurper = new JsonSlurper() - Map reqMap = jsonSlurper.parseText(bpmnReqJsonVolumeSuppressRollbackTrue) - - VidUtils vidUtils = new VidUtils() - def xmlReq = vidUtils.createXmlVolumeRequest(reqMap, 'CREATE_VF_MODULE_VOL', 'test-service-instance-id-123') - - assertEquals(vidUtilVolumeRespBackoutOnFailureFalse, xmlReq) - } - - @Test - public void testVfModuleVolumeRollbackFalse() { - - def jsonSlurper = new JsonSlurper() - Map reqMap = jsonSlurper.parseText(bpmnReqJsonVolumeSuppressRollbackFalse) - - VidUtils vidUtils = new VidUtils() - def xmlReq = vidUtils.createXmlVolumeRequest(reqMap, 'CREATE_VF_MODULE_VOL', 'test-service-instance-id-123') - - assertEquals(vidUtilVolumeRespBackoutOnFailureTrue, xmlReq) - } - - @Test - public void testVfModuleVolumeRollbackNone() { - - def jsonSlurper = new JsonSlurper() - Map reqMap = jsonSlurper.parseText(bpmnReqJsonVolumeSuppressRollbackNone) - - VidUtils vidUtils = new VidUtils() - def xmlReq = vidUtils.createXmlVolumeRequest(reqMap, 'CREATE_VF_MODULE_VOL', 'test-service-instance-id-123') - - assertEquals(vidUtilVolumeRespBackoutOnFailureEmpty, xmlReq) - } - - @Test - public void testVfModuleRollbackTrue() { - - def jsonSlurper = new JsonSlurper() - Map reqMap = jsonSlurper.parseText(bpmnReqJsonVfModuleSuppressRollbackTrue) - - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - when(mockExecution.getVariable("vnfType")).thenReturn('test-vnf-type-123') - when(mockExecution.getVariable("vnfId")).thenReturn('test-vnf-id-123') - when(mockExecution.getVariable("vfModuleId")).thenReturn('test-vf-module-id-123') - when(mockExecution.getVariable("volumeGroupId")).thenReturn('test-volume-group-id-123') - when(mockExecution.getVariable("isBaseVfModule")).thenReturn('false') - when(mockExecution.getVariable("mso-request-id")).thenReturn('test-request-id-123') - - VidUtils vidUtils = new VidUtils() - def xmlReq = vidUtils.createXmlVfModuleRequest(mockExecution, reqMap, 'CREATE_VF_MODULE', 'test-service-instance-id-123') - - println 'ggg->' + xmlReq - assertEquals(vidUtilVfModuleRespBackoutOnFailureFalse, xmlReq) - } - - @Test - public void testVfModuleRollbackFalse() { - - def jsonSlurper = new JsonSlurper() - Map reqMap = jsonSlurper.parseText(bpmnReqJsonVfModuleSuppressRollbackFalse) - - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - when(mockExecution.getVariable("vnfType")).thenReturn('test-vnf-type-123') - when(mockExecution.getVariable("vnfId")).thenReturn('test-vnf-id-123') - when(mockExecution.getVariable("vfModuleId")).thenReturn('test-vf-module-id-123') - when(mockExecution.getVariable("volumeGroupId")).thenReturn('test-volume-group-id-123') - when(mockExecution.getVariable("isBaseVfModule")).thenReturn('false') - when(mockExecution.getVariable("mso-request-id")).thenReturn('test-request-id-123') - - VidUtils vidUtils = new VidUtils() - def xmlReq = vidUtils.createXmlVfModuleRequest(mockExecution, reqMap, 'CREATE_VF_MODULE', 'test-service-instance-id-123') - - println 'ggg->' + xmlReq - assertEquals(vidUtilVfModuleRespBackoutOnFailureTrue, xmlReq) - } - - @Test - public void testVfModuleRollbackNone() { - - def jsonSlurper = new JsonSlurper() - Map reqMap = jsonSlurper.parseText(bpmnReqJsonVfModuleSuppressRollbackNone) - - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - when(mockExecution.getVariable("vnfType")).thenReturn('test-vnf-type-123') - when(mockExecution.getVariable("vnfId")).thenReturn('test-vnf-id-123') - when(mockExecution.getVariable("vfModuleId")).thenReturn('test-vf-module-id-123') - when(mockExecution.getVariable("volumeGroupId")).thenReturn('test-volume-group-id-123') - when(mockExecution.getVariable("isBaseVfModule")).thenReturn('false') - when(mockExecution.getVariable("mso-request-id")).thenReturn('test-request-id-123') - - VidUtils vidUtils = new VidUtils() - def xmlReq = vidUtils.createXmlVfModuleRequest(mockExecution, reqMap, 'CREATE_VF_MODULE', 'test-service-instance-id-123') - - println 'ggg->' + xmlReq - assertEquals(vidUtilVfModuleRespBackoutOnFailureEmpty, xmlReq) - } -} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/VnfAdapterRestV1Test.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/VnfAdapterRestV1Test.groovy deleted file mode 100644 index b37676a044..0000000000 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/VnfAdapterRestV1Test.groovy +++ /dev/null @@ -1,44 +0,0 @@ -package org.openecomp.mso.bpmn.common.scripts - -import org.junit.Test -import static org.junit.Assert.*; - -class VnfAdapterRestV1Test { - - - def rollbackReq = """ - - - 8a07b246-155e-4b08-b56e-76e98a3c2d66 - phmaz401me6-vpevre-VOLUMEGROUP/dbd560b6-b03f-4a17-92e7-8942459a60c1 - mtrnj1b - cfb5e0a790374c9a98a1c0d2044206a7 - true - - 1e1a72ca-7300-4ac4-b718-30351f3b6845 - 15eb2c68-f771-4030-b185-cff179fdad44 - - 683ca1ac-2145-4a00-9484-20d48bd701aa - - true - http://msobpel-app-e2e.ecomp.cci.att.com:8080/mso/WorkflowMessage/VNFAResponse/683ca1ac-2145-4a00-9484-20d48bd701aa - -""" - - @Test - public void testGetNodeText() { - Node root = new XmlParser().parseText(rollbackReq) - def volGrpId = root.'volumeGroupRollback'.'volumeGroupId'.text() - assertEquals('8a07b246-155e-4b08-b56e-76e98a3c2d66', volGrpId) - } - - @Test - public void testGetMessageId() { - Node root = new XmlParser().parseText(rollbackReq) - //def messageId = root.'volumeGroupRollback'.'messageId'.text() - - VnfAdapterRestV1 p = new VnfAdapterRestV1() - def messageId = p.getMessageIdForVolumeGroupRollback(root) - assertEquals('683ca1ac-2145-4a00-9484-20d48bd701aa', messageId) - } -} -- cgit 1.2.3-korg