diff options
author | Lukasz Muszkieta <lukasz.muszkieta@nokia.com> | 2018-11-08 15:46:26 +0100 |
---|---|---|
committer | Rob Daugherty <rd472p@att.com> | 2018-11-14 20:54:11 +0000 |
commit | 181c40dc08d42c019bbaeb85fbcfc72a9dc685a5 (patch) | |
tree | c0a9ef4e9e6fac2a45c033174061c7b1f5943541 /bpmn/MSOCommonBPMN/src/test/groovy/org | |
parent | 78e9c0c84da529b26f25ab66c4d2e596fd180282 (diff) |
Add junit tests for CreateAAIVfModule
Change-Id: If71c2472aefc7edd1387837bdbbb24a186c1316c
Issue-ID: SO-784
Signed-off-by: Lukasz Muszkieta <lukasz.muszkieta@nokia.com>
Diffstat (limited to 'bpmn/MSOCommonBPMN/src/test/groovy/org')
-rw-r--r-- | bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CreateAAIVfModuleTest.groovy | 132 |
1 files changed, 126 insertions, 6 deletions
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 index 886e92bd45..1fa10a56c5 100644 --- 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 @@ -10,9 +10,9 @@ * 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. @@ -23,6 +23,8 @@ package org.onap.so.bpmn.common.scripts +import org.camunda.bpm.engine.delegate.DelegateExecution + import static org.assertj.core.api.Assertions.assertThat import static org.mockito.ArgumentMatchers.any import static org.mockito.ArgumentMatchers.anyObject @@ -57,12 +59,12 @@ class CreateAAIVfModuleTest extends MsoGroovyTest{ 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" - + @Spy CreateAAIVfModule createAAIVfModule ; private DelegateExecutionFake executionFake; - + @Before public void init() throws IOException { super.init("CreateAAIVfModule") @@ -236,7 +238,7 @@ class CreateAAIVfModuleTest extends MsoGroovyTest{ @Test void parseForAddOnModule_moduleNameFound() { - + GenericVnf vnf = new GenericVnf(); VfModule module = new VfModule(); VfModules modules = new VfModules(); @@ -302,7 +304,7 @@ class CreateAAIVfModuleTest extends MsoGroovyTest{ modules.getVfModule().add(module) module.setVfModuleName(VF_MODULE_NAME) module.setIsBaseVfModule(true) - + executionFake.setVariable("CAAIVfMod_queryGenericVnfResponse", vnf) executionFake.setVariable("CAAIVfMod_baseModuleConflict", false) @@ -331,6 +333,103 @@ class CreateAAIVfModuleTest extends MsoGroovyTest{ .isEqualTo("VF Module " + VF_MODULE_NAME + " does not exist for Generic VNF " + VNF_NAME) } + @Test + void handleFailure_errorCode5000() { + executionFake.setVariable("CAAIVfMod_createGenericVnfResponseCode", "123") + executionFake.setVariable("CAAIVfMod_createGenericVnfResponse", "responseTest") + + ExceptionUtilForTesting exceptionUtilForTesting = new ExceptionUtilForTesting() + createAAIVfModule.setExceptionUtil(exceptionUtilForTesting) + + createAAIVfModule.handleCreateVfModuleFailure(executionFake) + + assertThat(exceptionUtilForTesting.getErrorCode()).isEqualTo(5000) + assertThat(exceptionUtilForTesting.getErrorMessage()).isEqualTo("responseTest") + } + + @Test + void handleFailure_errorCode1002() { + executionFake.setVariable("CAAIVfMod_queryGenericVnfResponse", "responseTest") + executionFake.setVariable("CAAIVfMod_newGenericVnf", true) + + ExceptionUtilForTesting exceptionUtilForTesting = new ExceptionUtilForTesting() + createAAIVfModule.setExceptionUtil(exceptionUtilForTesting) + + createAAIVfModule.handleCreateVfModuleFailure(executionFake) + + assertThat(exceptionUtilForTesting.getErrorCode()).isEqualTo(1002) + assertThat(exceptionUtilForTesting.getErrorMessage()).isEqualTo("responseTest") + } + + @Test + void handleFailure_errorCode1002_queryGenericVnfResponse() { + executionFake.setVariable("CAAIVfMod_queryGenericVnfResponse", "responseTest") + executionFake.setVariable("CAAIVfMod_queryGenericVnfResponseCode", 404) + executionFake.setVariable("CAAIVfMod_newGenericVnf", false) + + ExceptionUtilForTesting exceptionUtilForTesting = new ExceptionUtilForTesting() + createAAIVfModule.setExceptionUtil(exceptionUtilForTesting) + + createAAIVfModule.handleCreateVfModuleFailure(executionFake) + + assertThat(exceptionUtilForTesting.getErrorCode()).isEqualTo(1002) + assertThat(exceptionUtilForTesting.getErrorMessage()).isEqualTo("responseTest") + } + + @Test + void handleFailure_errorCode5000_createVfModuleResponseCode() { + executionFake.setVariable("CAAIVfMod_createVfModuleResponseCode", "123") + executionFake.setVariable("CAAIVfMod_createVfModuleResponse", "responseTest") + + ExceptionUtilForTesting exceptionUtilForTesting = new ExceptionUtilForTesting() + createAAIVfModule.setExceptionUtil(exceptionUtilForTesting) + + createAAIVfModule.handleCreateVfModuleFailure(executionFake) + + assertThat(exceptionUtilForTesting.getErrorCode()).isEqualTo(5000) + assertThat(exceptionUtilForTesting.getErrorMessage()).isEqualTo("responseTest") + } + + @Test + void handleFailure_errorCode1002_moduleExists() { + executionFake.setVariable("CAAIVfMod_moduleExists", true) + executionFake.setVariable("CAAIVfMod_parseModuleResponse", "responseTest") + + ExceptionUtilForTesting exceptionUtilForTesting = new ExceptionUtilForTesting() + createAAIVfModule.setExceptionUtil(exceptionUtilForTesting) + + createAAIVfModule.handleCreateVfModuleFailure(executionFake) + + assertThat(exceptionUtilForTesting.getErrorCode()).isEqualTo(1002) + assertThat(exceptionUtilForTesting.getErrorMessage()).isEqualTo("responseTest") + } + + @Test + void handleFailure_errorCode1002_baseModuleConflict() { + executionFake.setVariable("CAAIVfMod_baseModuleConflict", true) + executionFake.setVariable("CAAIVfMod_parseModuleResponse", "responseTest") + + ExceptionUtilForTesting exceptionUtilForTesting = new ExceptionUtilForTesting() + createAAIVfModule.setExceptionUtil(exceptionUtilForTesting) + + createAAIVfModule.handleCreateVfModuleFailure(executionFake) + + assertThat(exceptionUtilForTesting.getErrorCode()).isEqualTo(1002) + assertThat(exceptionUtilForTesting.getErrorMessage()).isEqualTo("responseTest") + } + + @Test + void handleFailure_errorCode2000() { + ExceptionUtilForTesting exceptionUtilForTesting = new ExceptionUtilForTesting() + createAAIVfModule.setExceptionUtil(exceptionUtilForTesting) + + createAAIVfModule.handleCreateVfModuleFailure(executionFake) + + assertThat(exceptionUtilForTesting.getErrorCode()).isEqualTo(2000) + assertThat(exceptionUtilForTesting.getErrorMessage()). + isEqualTo("Unknown error occurred during CreateAAIVfModule flow") + } + private void prepareUrnPropertiesReader() { Environment mockEnvironment = mock(Environment.class) when(mockEnvironment.getProperty("mso.workflow.global.default.aai.version")).thenReturn(DEFAULT_AAI_VERSION) @@ -338,4 +437,25 @@ class CreateAAIVfModuleTest extends MsoGroovyTest{ UrnPropertiesReader urnPropertiesReader = new UrnPropertiesReader() urnPropertiesReader.setEnvironment(mockEnvironment) } + + class ExceptionUtilForTesting extends ExceptionUtil { + private int errorCode + private String errorMessage + + int getErrorCode() { + return errorCode + } + + String getErrorMessage() { + return errorMessage + } + + @Override + void buildAndThrowWorkflowException(DelegateExecution execution, int errorCode, + String errorMessage) { + this.errorCode = errorCode + this.errorMessage = errorMessage + } + } + } |