aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/MSOCommonBPMN
diff options
context:
space:
mode:
Diffstat (limited to 'bpmn/MSOCommonBPMN')
-rw-r--r--bpmn/MSOCommonBPMN/pom.xml2
-rw-r--r--bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CreateAAIVfModule.groovy34
-rw-r--r--bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CreateAAIVfModuleTest.groovy205
-rw-r--r--bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/MsoGroovyTest.groovy95
4 files changed, 220 insertions, 116 deletions
diff --git a/bpmn/MSOCommonBPMN/pom.xml b/bpmn/MSOCommonBPMN/pom.xml
index 456b8ae074..26379882f2 100644
--- a/bpmn/MSOCommonBPMN/pom.xml
+++ b/bpmn/MSOCommonBPMN/pom.xml
@@ -6,7 +6,7 @@
<parent>
<groupId>org.onap.so</groupId>
<artifactId>bpmn</artifactId>
- <version>1.3.0-SNAPSHOT</version>
+ <version>1.4.0-SNAPSHOT</version>
</parent>
<artifactId>MSOCommonBPMN</artifactId>
<name>MSOCommonBPMN</name>
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CreateAAIVfModule.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CreateAAIVfModule.groovy
index 3bbc4bd110..d4777e234c 100644
--- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CreateAAIVfModule.groovy
+++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CreateAAIVfModule.groovy
@@ -21,7 +21,6 @@
package org.onap.so.bpmn.common.scripts
import org.camunda.bpm.engine.delegate.DelegateExecution
import org.onap.so.bpmn.core.RollbackData
-import org.onap.so.bpmn.core.UrnPropertiesReader
import org.onap.so.client.aai.AAIObjectType
import org.onap.so.client.aai.entities.uri.AAIResourceUri
import org.onap.so.client.aai.entities.uri.AAIUriFactory
@@ -29,7 +28,6 @@ import org.onap.so.client.graphinventory.entities.uri.Depth
import org.onap.so.logger.MessageEnum
import org.onap.so.logger.MsoLogger
import org.onap.so.rest.APIResponse
-import org.springframework.web.util.UriUtils
public class CreateAAIVfModule extends AbstractServiceTaskProcessor{
private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, CreateAAIVfModule.class);
@@ -163,7 +161,7 @@ public class CreateAAIVfModule extends AbstractServiceTaskProcessor{
String aaiNamespace = aaiUriUtil.getNamespace()
msoLogger.debug('AAI namespace is: ' + aaiNamespace)
- execution.setVariable("CAAIVfMod_aaiNamespace","${aaiNamespace}")
+ execution.setVariable("CAAIVfMod_aaiNamespace",aaiNamespace)
}
@@ -212,8 +210,6 @@ public class CreateAAIVfModule extends AbstractServiceTaskProcessor{
// process the result from queryAAIForGenericVnf()
// note: this method is primarily for logging as the actual decision logic is embedded in the bpmn flow
public void processAAIGenericVnfQuery(DelegateExecution execution) {
- def result = execution.getVariable("CAAIVfMod_queryGenericVnfResponse")
-
if (execution.getVariable("CAAIVfMod_queryGenericVnfResponseCode") == 404 &&
execution.getVariable("CAAIVfMod_vnfId").isEmpty()) {
msoLogger.debug("New Generic VNF requested and it does not already exist")
@@ -310,7 +306,6 @@ public class CreateAAIVfModule extends AbstractServiceTaskProcessor{
moduleIndex = aaiUtil.getLowestUnusedVfModuleIndexFromAAIVnfResponse(execution, aaiVnfResponse,
fieldToCheck, personaModelId)
}
- def moduleIndexString = String.valueOf(moduleIndex)
// if we get to this point, we may be about to create the Vf Module,
// add rollback information about the Generic VNF for this base/add-on module
@@ -366,7 +361,7 @@ public class CreateAAIVfModule extends AbstractServiceTaskProcessor{
String responseOut = ""
String isVidRequest = execution.getVariable("isVidRequest")
-
+ def moduleIndexString = String.valueOf(moduleIndex)
if (isBaseModule && (isVidRequest == null || "false".equals(isVidRequest))) {
responseOut = """<CreateAAIVfModuleResponse>
@@ -411,20 +406,18 @@ public class CreateAAIVfModule extends AbstractServiceTaskProcessor{
for (String qryModuleName : qryModuleNameList) {
if (newModuleName.equals(qryModuleName)) {
// a module with the requested name already exists - failure
- msoLogger.debug("VF Module " + qryModuleName + " already exists for Generic VNF " + execution.getVariable("CAAIVfMod_vnfNameFromAAI"))
+ msoLogger.debug("VF Module " + qryModuleName + " already exists for Generic VNF " + vnfNameFromAAI)
execution.setVariable("CAAIVfMod_moduleExists", true)
execution.setVariable("CAAIVfMod_parseModuleResponse",
- "VF Module " + qryModuleName + " already exists for Generic VNF " +
- execution.getVariable("CAAIVfMod_vnfNameFromAAI"))
+ "VF Module " + qryModuleName + " already exists for Generic VNF " + vnfNameFromAAI)
break
}
}
}
if (execution.getVariable("CAAIVfMod_moduleExists") == false) {
- msoLogger.debug("VF Module " + execution.getVariable("CAAIVfMod_moduleName") + " does not exist for Generic VNF " + execution.getVariable("CAAIVfMod_vnfNameFromAAI"))
+ msoLogger.debug("VF Module " + execution.getVariable("CAAIVfMod_moduleName") + " does not exist for Generic VNF " + vnfNameFromAAI)
execution.setVariable("CAAIVfMod_parseModuleResponse",
- "VF Module " + newModuleName + " does not exist for Generic VNF " +
- execution.getVariable("CAAIVfMod_vnfNameFromAAI"))
+ "VF Module " + newModuleName + " does not exist for Generic VNF " + vnfNameFromAAI)
}
}
@@ -445,11 +438,10 @@ public class CreateAAIVfModule extends AbstractServiceTaskProcessor{
for (String qryModuleName : qryModuleNameList) {
if (newModuleName.equals(qryModuleName)) {
// a module with the requested name already exists - failure
- msoLogger.debug("VF Module " + qryModuleName + " already exists for Generic VNF " + execution.getVariable("CAAIVfMod_vnfNameFromAAI"))
+ msoLogger.debug("VF Module " + qryModuleName + " already exists for Generic VNF " + vnfNameFromAAI)
execution.setVariable("CAAIVfMod_baseModuleConflict", true)
execution.setVariable("CAAIVfMod_parseModuleResponse",
- "VF Module " + qryModuleName + " already exists for Generic VNF " +
- execution.getVariable("CAAIVfMod_vnfNameFromAAI"))
+ "VF Module " + qryModuleName + " already exists for Generic VNF " + vnfNameFromAAI)
break
}
}
@@ -460,21 +452,19 @@ public class CreateAAIVfModule extends AbstractServiceTaskProcessor{
for (String baseValue : isBaseVfModuleList) {
if (baseValue.equals("true")) {
// a base module already exists in this VNF - failure
- msoLogger.debug("Base VF Module already exists for Generic VNF " + execution.getVariable("CAAIVfMod_vnfNameFromAAI"))
+ msoLogger.debug("Base VF Module already exists for Generic VNF " + vnfNameFromAAI)
execution.setVariable("CAAIVfMod_baseModuleConflict", true)
execution.setVariable("CAAIVfMod_parseModuleResponse",
- "Base VF Module already exists for Generic VNF " +
- execution.getVariable("CAAIVfMod_vnfNameFromAAI"))
+ "Base VF Module already exists for Generic VNF " + vnfNameFromAAI)
break
}
}
}
- if (execution.getVariable("CAAIVfMod_moduleExists") == false && execution.getVariable("CAAIVfMod_baseModuleConflict") == false) {
+ if (execution.getVariable("CAAIVfMod_baseModuleConflict") == false) {
msoLogger.debug("VF Module " + execution.getVariable("CAAIVfMod_moduleName") + " does not exist for Generic VNF " + execution.getVariable("CAAIVfMod_vnfNameFromAAI"))
execution.setVariable("CAAIVfMod_parseModuleResponse",
- "VF Module " + newModuleName + " does not exist for Generic VNF " +
- execution.getVariable("CAAIVfMod_vnfNameFromAAI"))
+ "VF Module " + newModuleName + " does not exist for Generic VNF " + vnfNameFromAAI)
}
}
diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CreateAAIVfModuleTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CreateAAIVfModuleTest.groovy
new file mode 100644
index 0000000000..999a12c869
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CreateAAIVfModuleTest.groovy
@@ -0,0 +1,205 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2018 Nokia.
+ * ================================================================================
+ * 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 joptsimple.internal.Strings
+import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake
+import org.junit.Before
+import org.junit.Test
+import org.onap.so.bpmn.core.UrnPropertiesReader
+import org.springframework.core.env.Environment
+
+import static org.assertj.core.api.Assertions.assertThat
+import static org.mockito.Mockito.mock
+import static org.mockito.Mockito.when
+
+class CreateAAIVfModuleTest {
+
+ private static final String VNF_ID = "vnfIdTest"
+ private static final String VNF_TYPE = "vnfTypeTest"
+ private static final String VNF_NAME = "testVnf"
+ private static final String SERVICE_ID = "123"
+ private static final String PERSONAL_MODEL_ID = "modelTest"
+ private static final String PERSONAL_MODEL_VERSION = "12"
+ private static final String MODEL_CUST_ID = "modelCustIdTest"
+ private static final String VNF_PERSONAL_MODEL_ID = "perModIdTest"
+ private static final String VNF_PERSONAL_MODEL_VER = "14"
+ private static final String VF_MODULE_NAME = "modTestName"
+ private static final String VF_MODULE_MODEL_NAME = "modModelNameTest"
+ private static final String DEFAULT_AAI_VERSION = "9"
+ private static final String DEFAULT_AAI_NAMESPACE = "defaultTestNamespace"
+
+ private CreateAAIVfModule testedObject
+ private DelegateExecutionFake executionFake
+
+ @Before
+ void setupTest() {
+ testedObject = new CreateAAIVfModule()
+ executionFake = new DelegateExecutionFake()
+ }
+
+ @Test
+ void preProcessRequest_successful() {
+ //given
+ prepareUrnPropertiesReader()
+ executionFake.setVariable("vnfId", VNF_ID)
+ executionFake.setVariable("vnfType", VNF_TYPE)
+ executionFake.setVariable("vnfName", VNF_NAME)
+ executionFake.setVariable("serviceId", SERVICE_ID)
+ executionFake.setVariable("personaModelId", PERSONAL_MODEL_ID)
+ executionFake.setVariable("personaModelVersion", PERSONAL_MODEL_VERSION)
+ executionFake.setVariable("modelCustomizationId", MODEL_CUST_ID)
+ executionFake.setVariable("vnfPersonaModelId", VNF_PERSONAL_MODEL_ID)
+ executionFake.setVariable("vnfPersonaModelVersion", VNF_PERSONAL_MODEL_VER)
+ executionFake.setVariable("isBaseVfModule", "true")
+ executionFake.setVariable("vfModuleName", VF_MODULE_NAME)
+ executionFake.setVariable("vfModuleModelName", VF_MODULE_MODEL_NAME)
+ //when
+ testedObject.preProcessRequest(executionFake)
+ //then
+ assertThat(executionFake.getVariable("CAAIVfMod_vnfId")).isEqualTo(VNF_ID)
+ assertThat(executionFake.getVariable("CAAIVfMod_vnfName")).isEqualTo(VNF_NAME)
+ assertThat(executionFake.getVariable("CAAIVfMod_vnfType")).isEqualTo(VNF_TYPE)
+ assertThat(executionFake.getVariable("CAAIVfMod_serviceId")).isEqualTo(SERVICE_ID)
+ assertThat(executionFake.getVariable("CAAIVfMod_personaId")).isEqualTo(PERSONAL_MODEL_ID)
+ assertThat(executionFake.getVariable("CAAIVfMod_personaVer")).isEqualTo(PERSONAL_MODEL_VERSION)
+ assertThat(executionFake.getVariable("CAAIVfMod_modelCustomizationId")).isEqualTo(MODEL_CUST_ID)
+ assertThat(executionFake.getVariable("CAAIVfMod_vnfPersonaId")).isEqualTo(VNF_PERSONAL_MODEL_ID)
+ assertThat(executionFake.getVariable("CAAIVfMod_vnfPersonaVer")).isEqualTo(VNF_PERSONAL_MODEL_VER)
+ assertThat(executionFake.getVariable("CAAIVfMod_isBaseVfModule")).isEqualTo(true)
+ assertThat(executionFake.getVariable("CAAIVfMod_moduleName")).isEqualTo(VF_MODULE_NAME)
+ assertThat(executionFake.getVariable("CAAIVfMod_moduleModelName")).isEqualTo(VF_MODULE_MODEL_NAME)
+ assertThat(executionFake.getVariable("CAAIVfMod_aaiNamespace"))
+ .isEqualTo(DEFAULT_AAI_NAMESPACE + "v" + DEFAULT_AAI_VERSION)
+ }
+
+ @Test
+ void processAAIGenericVnfQuery_setVnfResponse() {
+ executionFake.setVariable("CAAIVfMod_queryGenericVnfResponseCode", 200)
+ executionFake.setVariable("CAAIVfMod_vnfId", Strings.EMPTY)
+ executionFake.setVariable("CAAIVfMod_vnfName", VNF_NAME)
+
+ testedObject.processAAIGenericVnfQuery(executionFake)
+
+ assertThat(executionFake.getVariable("CAAIVfMod_queryGenericVnfResponse"))
+ .isEqualTo("Invalid request for new Generic VNF which already exists, Vnf Name=" + VNF_NAME)
+ }
+
+ @Test
+ void processAAIGenericVnfQuery_setVfModuleResponse() {
+ executionFake.setVariable("CAAIVfMod_queryGenericVnfResponseCode", 500)
+ executionFake.setVariable("CAAIVfMod_vnfId", VNF_ID)
+
+ testedObject.processAAIGenericVnfQuery(executionFake)
+
+ assertThat(executionFake.getVariable("CAAIVfMod_createVfModuleResponse"))
+ .isEqualTo("Invalid request for Add-on Module requested for non-existant Generic VNF, VNF Id=" + VNF_ID)
+ }
+
+ @Test
+ void parseForAddOnModule_moduleNameFound() {
+ String xml = "<CAAIVfMod_queryGenericVnfResponse><vnf-name>" + VNF_NAME + "</vnf-name>" +
+ "<vf-module-name>" + VF_MODULE_NAME + "</vf-module-name></CAAIVfMod_queryGenericVnfResponse>"
+ executionFake.setVariable("CAAIVfMod_queryGenericVnfResponse", xml)
+ executionFake.setVariable("CAAIVfMod_moduleName", VF_MODULE_NAME)
+
+ testedObject.parseForAddOnModule(executionFake)
+
+ assertThat(executionFake.getVariable("CAAIVfMod_vnfNameFromAAI")).isEqualTo(VNF_NAME)
+ assertThat(executionFake.getVariable("CAAIVfMod_moduleExists")).isEqualTo(true)
+ assertThat(executionFake.getVariable("CAAIVfMod_parseModuleResponse"))
+ .isEqualTo("VF Module " + VF_MODULE_NAME + " already exists for Generic VNF " + VNF_NAME)
+ }
+
+ @Test
+ void parseForAddOnModule_moduleNameNotFound() {
+ String xml = "<CAAIVfMod_queryGenericVnfResponse><vnf-name>" + VNF_NAME + "</vnf-name>" +
+ "</CAAIVfMod_queryGenericVnfResponse>"
+ executionFake.setVariable("CAAIVfMod_queryGenericVnfResponse", xml)
+ executionFake.setVariable("CAAIVfMod_moduleName", VF_MODULE_NAME)
+ executionFake.setVariable("CAAIVfMod_moduleExists", false)
+
+ testedObject.parseForAddOnModule(executionFake)
+
+ assertThat(executionFake.getVariable("CAAIVfMod_vnfNameFromAAI")).isEqualTo(VNF_NAME)
+ assertThat(executionFake.getVariable("CAAIVfMod_moduleExists")).isEqualTo(false)
+ assertThat(executionFake.getVariable("CAAIVfMod_parseModuleResponse"))
+ .isEqualTo("VF Module " + VF_MODULE_NAME + " does not exist for Generic VNF " + VNF_NAME)
+ }
+
+ @Test
+ void parseForBaseModule_moduleNameFound() {
+ String xml = "<CAAIVfMod_queryGenericVnfResponse><vnf-name>" + VNF_NAME + "</vnf-name>" +
+ "<vf-module-name>" + VF_MODULE_NAME + "</vf-module-name></CAAIVfMod_queryGenericVnfResponse>"
+ executionFake.setVariable("CAAIVfMod_queryGenericVnfResponse", xml)
+ executionFake.setVariable("CAAIVfMod_moduleName", VF_MODULE_NAME)
+
+ testedObject.parseForBaseModule(executionFake)
+
+ assertThat(executionFake.getVariable("CAAIVfMod_vnfNameFromAAI")).isEqualTo(VNF_NAME)
+ assertThat(executionFake.getVariable("CAAIVfMod_moduleExists")).isEqualTo(false)
+ assertThat(executionFake.getVariable("CAAIVfMod_baseModuleConflict")).isEqualTo(true)
+ assertThat(executionFake.getVariable("CAAIVfMod_parseModuleResponse"))
+ .isEqualTo("VF Module " + VF_MODULE_NAME + " already exists for Generic VNF " + VNF_NAME)
+ }
+
+ @Test
+ void parseForBaseModule_isBaseVfModule() {
+ String xml = "<CAAIVfMod_queryGenericVnfResponse><vnf-name>" + VNF_NAME + "</vnf-name>" +
+ "<is-base-vf-module>true</is-base-vf-module></CAAIVfMod_queryGenericVnfResponse>"
+ executionFake.setVariable("CAAIVfMod_queryGenericVnfResponse", xml)
+ executionFake.setVariable("CAAIVfMod_baseModuleConflict", false)
+
+ testedObject.parseForBaseModule(executionFake)
+
+ assertThat(executionFake.getVariable("CAAIVfMod_vnfNameFromAAI")).isEqualTo(VNF_NAME)
+ assertThat(executionFake.getVariable("CAAIVfMod_moduleExists")).isEqualTo(false)
+ assertThat(executionFake.getVariable("CAAIVfMod_baseModuleConflict")).isEqualTo(true)
+ assertThat(executionFake.getVariable("CAAIVfMod_parseModuleResponse"))
+ .isEqualTo("Base VF Module already exists for Generic VNF " + VNF_NAME)
+ }
+
+ @Test
+ void parseForBaseModule_baseModuleConflictIsFalse() {
+ String xml = "<CAAIVfMod_queryGenericVnfResponse><vnf-name>" + VNF_NAME + "</vnf-name></CAAIVfMod_queryGenericVnfResponse>"
+ executionFake.setVariable("CAAIVfMod_queryGenericVnfResponse", xml)
+ executionFake.setVariable("CAAIVfMod_baseModuleConflict", false)
+ executionFake.setVariable("CAAIVfMod_moduleName", VF_MODULE_NAME)
+
+ testedObject.parseForBaseModule(executionFake)
+
+ assertThat(executionFake.getVariable("CAAIVfMod_vnfNameFromAAI")).isEqualTo(VNF_NAME)
+ assertThat(executionFake.getVariable("CAAIVfMod_moduleExists")).isEqualTo(false)
+ assertThat(executionFake.getVariable("CAAIVfMod_parseModuleResponse"))
+ .isEqualTo("VF Module " + VF_MODULE_NAME + " does not exist for Generic VNF " + VNF_NAME)
+ }
+
+ private void prepareUrnPropertiesReader() {
+ Environment mockEnvironment = mock(Environment.class)
+ when(mockEnvironment.getProperty("mso.workflow.global.default.aai.version")).thenReturn(DEFAULT_AAI_VERSION)
+ when(mockEnvironment.getProperty("mso.workflow.global.default.aai.namespace")).thenReturn(DEFAULT_AAI_NAMESPACE)
+ UrnPropertiesReader urnPropertiesReader = new UrnPropertiesReader()
+ urnPropertiesReader.setEnvironment(mockEnvironment)
+ }
+
+}
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
index 3a2673c9ee..19638f42da 100644
--- 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
@@ -16,7 +16,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- */
+ */
package org.onap.so.bpmn.common.scripts
@@ -30,29 +30,15 @@ import org.junit.Rule
import org.junit.rules.ExpectedException
import org.junit.runner.RunWith
import org.mockito.runners.MockitoJUnitRunner
-import org.onap.aai.domain.yang.GenericVnf
-import org.onap.so.bpmn.mock.FileUtil
-import org.onap.so.client.aai.AAIObjectPlurals
-import org.onap.so.client.aai.AAIObjectType
import org.onap.so.client.aai.AAIResourcesClient
-import org.onap.so.client.aai.entities.AAIResultWrapper
-import org.onap.so.client.aai.entities.uri.AAIResourceUri
-import org.onap.so.client.aai.entities.uri.AAIUriFactory
-import org.onap.so.client.graphinventory.entities.uri.Depth
-import org.onap.so.constants.Defaults
@RunWith(MockitoJUnitRunner.class)
abstract class MsoGroovyTest {
-
+
@Rule
public ExpectedException thrown = ExpectedException.none()
-
protected ExecutionEntity mockExecution
protected AAIResourcesClient client
- protected AllottedResourceUtils allottedResourceUtils_MOCK
- protected final String SEARCH_RESULT_AAI_WITH_RESULTDATA =
- FileUtil.readResourceFile("__files/aai/searchResults.json")
- protected static final String CLOUD_OWNER = Defaults.CLOUD_OWNER.toString();
protected void init(String procName){
mockExecution = setupMock(procName)
@@ -63,91 +49,14 @@ 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
- }
-
- protected <T> Optional<T> getAAIObjectFromJson(Class<T> clazz , String file){
- String json = FileUtil.readResourceFile(file)
- AAIResultWrapper resultWrapper = new AAIResultWrapper(json)
- return resultWrapper.asBean(clazz)
- }
-
- protected Optional<GenericVnf> mockAAIGenericVnf(String vnfId){
- return mockAAIGenericVnf(vnfId,"__files/aai/GenericVnf.json")
- }
-
- protected Optional<GenericVnf> mockAAIGenericVnf(String vnfId,String file){
- AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
- AAIResourceUri resourceUriDepthOne = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId).depth(Depth.ONE)
- Optional<GenericVnf> genericVnf = getAAIObjectFromJson(GenericVnf.class,file);
- when(client.get(GenericVnf.class, resourceUri)).thenReturn(genericVnf)
- when(client.get(GenericVnf.class, resourceUriDepthOne)).thenReturn(genericVnf)
- return genericVnf
- }
-
- protected Optional<GenericVnf> mockAAIGenericVnfByName(String vnfName){
- AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF).queryParam("vnf-name", vnfName)
- AAIResourceUri resourceUriDepthOne = AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF).queryParam("vnf-name", vnfName).depth(Depth.ONE)
- Optional<GenericVnf> genericVnf = getAAIObjectFromJson(GenericVnf.class,"__files/aai/GenericVnf.json");
- when(client.get(GenericVnf.class, resourceUri)).thenReturn(genericVnf)
- when(client.get(GenericVnf.class, resourceUriDepthOne)).thenReturn(genericVnf)
- return genericVnf
- }
-
- protected void mockAAIGenericVnfNotFound(String vnfId){
- AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId).depth(Depth.ONE)
- AAIResourceUri resourceUriDepthOne = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId).depth(Depth.ONE)
- when(client.get(GenericVnf.class, resourceUri)).thenReturn(Optional.empty())
- when(client.get(GenericVnf.class, resourceUriDepthOne)).thenReturn(Optional.empty())
- }
-
- protected void mockAAIGenericVnfByNameNotFound(String vnfName){
- AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF).queryParam("vnf-name", vnfName)
- AAIResourceUri resourceUriDepthOne = AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF).queryParam("vnf-name", vnfName).depth(Depth.ONE)
- when(client.get(GenericVnf.class, resourceUri)).thenReturn(Optional.empty())
- when(client.get(GenericVnf.class, resourceUriDepthOne)).thenReturn(Optional.empty())
- }
-
- protected AAIResultWrapper mockVolumeGroupWrapper(String region, String volumeGroupId, String file){
- AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.VOLUME_GROUP,CLOUD_OWNER, region,volumeGroupId)
- String json = FileUtil.readResourceFile(file)
- AAIResultWrapper resultWrapper = new AAIResultWrapper(json)
- when(client.get(resourceUri)).thenReturn(resultWrapper)
- return resultWrapper
- }
-
- void initAR(String procName){
- init(procName)
- allottedResourceUtils_MOCK = spy(new AllottedResourceUtils(mock(AbstractServiceTaskProcessor.class)))
- when(allottedResourceUtils_MOCK.getAAIClient()).thenReturn(client)
- }
}