diff options
author | vidhyasree <sn141y@att.com> | 2018-02-22 17:41:31 -0500 |
---|---|---|
committer | Patrick Brady <pb071s@att.com> | 2018-03-01 19:51:11 +0000 |
commit | a8baf016a7b4ce73f054ad77c278a881e8e948c6 (patch) | |
tree | a0168c64b40cbad83cfc359dfc61a1b6d8d8c3c3 /appc-provider | |
parent | c91763af8a65f2e277e338cda2f1c70a168ef8fd (diff) |
Testcases for Configscaleout action
Junit testcases for ONAP scaleout feature
Issue-ID: APPC-544
Change-Id: I43e211f00e7568cb98e564b1cbf60f96b27c5dfa
Signed-off-by: vidhyasree <sn141y@att.com>
Diffstat (limited to 'appc-provider')
3 files changed, 191 insertions, 8 deletions
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/ConfigScaleOutService.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/ConfigScaleOutService.java index a61abf326..c7310839d 100644 --- a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/ConfigScaleOutService.java +++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/ConfigScaleOutService.java @@ -32,21 +32,17 @@ import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.Co import org.onap.appc.executor.objects.LCMCommandStatus; import org.onap.appc.requesthandler.objects.RequestHandlerInput; import org.onap.appc.util.JsonUtil; - import java.io.IOException; import java.util.Map; public class ConfigScaleOutService extends AbstractBaseService { - /** - * Constructor - * - */ - public ConfigScaleOutService() { + + public ConfigScaleOutService() { super(Action.ConfigScaleOut); logger.debug("ConfigScaleOutService starts"); } - public ConfigScaleOutOutputBuilder process(ConfigScaleOutInput input) { - CommonHeader commonHeader = input.getCommonHeader(); + public ConfigScaleOutOutputBuilder process(ConfigScaleOutInput input) { + CommonHeader commonHeader = input.getCommonHeader(); ActionIdentifiers actionIdentifiers = input.getActionIdentifiers(); Payload payload = input.getPayload(); diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/AppcProviderLcmTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/AppcProviderLcmTest.java index 94f1f9f04..659cbce28 100644 --- a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/AppcProviderLcmTest.java +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/AppcProviderLcmTest.java @@ -56,6 +56,9 @@ import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigRestoreInp import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigRestoreOutput; import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigureInput; import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigureOutput; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigScaleOutInput; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigScaleOutOutput; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigScaleOutOutputBuilder; import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.DetachVolumeInput; import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.DetachVolumeOutput; import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.DetachVolumeOutputBuilder; @@ -640,6 +643,19 @@ public class AppcProviderLcmTest extends AbstractDataBrokerTest { } @Test + public void testConfigScaleOut() throws Exception { + ConfigScaleOutInput mockInput = mock(ConfigScaleOutInput.class); + ConfigScaleOutOutput mockOutput = mock(ConfigScaleOutOutput.class); + ConfigScaleOutOutputBuilder mockOutputBuilder = mock(ConfigScaleOutOutputBuilder.class); + ConfigScaleOutService mockService = mock(ConfigScaleOutService.class); + + when(mockService.process(mockInput)).thenReturn(mockOutputBuilder); + when(mockOutputBuilder.build()).thenReturn(mockOutput); + Future<RpcResult<ConfigScaleOutOutput>> results = appcProviderLcm.configScaleOut(mockInput); + Assert.assertTrue(302 == results.get().getResult().getStatus().getCode()); + } + + @Test public void testConfigRestore() throws Exception { // Validation success doReturn("Success").when(successlcmStatus).getMessage(); diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/ConfigScaleOutServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/ConfigScaleOutServiceTest.java new file mode 100644 index 000000000..6ba677a35 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/ConfigScaleOutServiceTest.java @@ -0,0 +1,171 @@ + +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017-2018 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.provider.lcm.service; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.internal.util.reflection.Whitebox; +import org.mockito.runners.MockitoJUnitRunner; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.*; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.Status; +import org.onap.appc.domainmodel.lcm.ResponseContext; +import org.onap.appc.executor.objects.LCMCommandStatus; +import org.onap.appc.requesthandler.objects.RequestHandlerOutput; +import org.onap.appc.requesthandler.objects.RequestHandlerInput; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; + +@RunWith(MockitoJUnitRunner.class) +public class ConfigScaleOutServiceTest { + private final Action myAction = Action.ConfigScaleOut; + private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}"; + private ConfigScaleOutInput mockInput = mock(ConfigScaleOutInput.class); + private CommonHeader mockCommonHeader = mock(CommonHeader.class); + private ActionIdentifiers mockAI = mock(ActionIdentifiers.class); + private Payload mockPayload = mock(Payload.class); + + private ConfigScaleOutService configscaleoutServiceAction; + @Before + public void setUp() throws Exception { + configscaleoutServiceAction = spy(new ConfigScaleOutService()); + } + + @Test + public void testProcess() throws Exception { + // test error occurs in validation + ConfigScaleOutOutputBuilder outputBuilder = configscaleoutServiceAction.process(mockInput); + Mockito.verify(configscaleoutServiceAction, times(0)).proceedAction(any(),any(),any()); + Assert.assertTrue("Should not have commonHeader as we did not mock it",outputBuilder.getCommonHeader() == null); + Assert.assertEquals("should return missing parameter status", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), + outputBuilder.getStatus().getCode()); + + // make validation pass + Mockito.doReturn(mockCommonHeader).when(mockInput).getCommonHeader(); + Mockito.doReturn(mockPayload).when(mockInput).getPayload(); + Mockito.doReturn(PAYLOAD_STRING).when(mockPayload).getValue(); + // to make validation pass + ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z"); + Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp(); + Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer(); + Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId(); + Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId(); + + Mockito.doReturn(myAction).when(mockInput).getAction(); + Mockito.doReturn(mockAI).when(mockInput).getActionIdentifiers(); + Mockito.doReturn("vnfId").when(mockAI).getVnfId(); + + // test processAction return without error + RequestExecutor mockExecutor = mock(RequestExecutor.class); + // whenNew(RequestExecutor.class).withNoArguments().thenReturn(mockExecutor); + + RequestHandlerOutput mockOutput = mock(RequestHandlerOutput.class); + Mockito.doReturn(mockOutput).when(mockExecutor).executeRequest(any()); + + ResponseContext mockResponseContext = mock(ResponseContext.class); + Mockito.doReturn(mockResponseContext).when(mockOutput).getResponseContext(); + + org.onap.appc.domainmodel.lcm.Status mockStatus = mock(org.onap.appc.domainmodel.lcm.Status.class); + Integer successCode = Integer.valueOf(LCMCommandStatus.SUCCESS.getResponseCode()); + Mockito.doReturn(successCode).when(mockStatus).getCode(); + Mockito.doReturn(mockStatus).when(mockResponseContext).getStatus(); + RequestHandlerInput requestHandlerInputInput = mock(RequestHandlerInput.class); + AbstractBaseService abstractBaseService = mock(AbstractBaseService.class); + Mockito.when(abstractBaseService.executeAction(requestHandlerInputInput)).thenReturn(mockOutput); + try { + outputBuilder = configscaleoutServiceAction.process(mockInput); + }catch(Exception e){ + Assert.assertTrue(true); + } + Assert.assertTrue("Should have commonHeader",outputBuilder.getCommonHeader() == null); + Assert.assertEquals("should return success status", new Integer(302), outputBuilder.getStatus().getCode()); + } + + @Test + public void testValidate() throws Exception { + configscaleoutServiceAction.validate(mockCommonHeader, Action.ConfigScaleOut, mockAI,mockPayload); + Status status = (Status) Whitebox.getInternalState(configscaleoutServiceAction, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + Mockito.verify(configscaleoutServiceAction, times(0)).buildStatusForParamName(any(), any()); + Mockito.verify(configscaleoutServiceAction, times(0)).buildStatusForErrorMsg(any(), any()); + + ZULU mockTimeStamp = mock(ZULU.class); + Mockito.doReturn(mockTimeStamp).when(mockCommonHeader).getTimestamp(); + Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer(); + Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId(); + Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId(); + + // test empty action + configscaleoutServiceAction.validate(mockCommonHeader, Action.ConfigScaleOut, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(configscaleoutServiceAction, "status"); + Assert.assertEquals("Should return missing parameter for action", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + + // test empty ActionIdentifier + configscaleoutServiceAction.validate(mockCommonHeader, Action.ConfigScaleOut, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(configscaleoutServiceAction, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + + // test Invalid VNF_ID + Mockito.doReturn("").when(mockAI).getVnfId(); + configscaleoutServiceAction.validate(mockCommonHeader, Action.ConfigScaleOut, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(configscaleoutServiceAction, "status"); + Assert.assertEquals("should return invalid parameter", + Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode()); + + // test null payload + Mockito.doReturn("vnfId").when(mockAI).getVnfId(); + configscaleoutServiceAction.validate(mockCommonHeader, Action.ConfigScaleOut, mockAI, null); + Mockito.verify(configscaleoutServiceAction, times(1)).validateExcludedActIds(any(), any()); + status = (Status) Whitebox.getInternalState(configscaleoutServiceAction, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + + // test empty payload + + Mockito.doReturn("").when(mockPayload).getValue(); + configscaleoutServiceAction.validate(mockCommonHeader, Action.ConfigScaleOut, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(configscaleoutServiceAction, "status"); + Assert.assertEquals("should return invalid parameter", + Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode()); + + // test space payload + Mockito.doReturn(" ").when(mockPayload).getValue(); + configscaleoutServiceAction.validate(mockCommonHeader, Action.ConfigScaleOut, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(configscaleoutServiceAction, "status"); + Assert.assertEquals("should return invalid parameter", + Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode()); + } +} + |