diff options
Diffstat (limited to 'appc-provider/appc-provider-bundle/src/test/java')
13 files changed, 2252 insertions, 0 deletions
diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/GetConfigServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/GetConfigServiceTest.java new file mode 100644 index 000000000..b258b7609 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/GetConfigServiceTest.java @@ -0,0 +1,167 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018-2019 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 GetConfigServiceTest {
+ private final Action myAction = Action.GetConfig;
+ private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}";
+ private GetConfigInput mockInput = mock(GetConfigInput.class);
+ private CommonHeader mockCommonHeader = mock(CommonHeader.class);
+ private ActionIdentifiers mockAI = mock(ActionIdentifiers.class);
+ private Payload mockPayload = mock(Payload.class);
+
+ private GetConfigService getConfigureAction;
+ @Before
+ public void setUp() throws Exception {
+ getConfigureAction = spy(new GetConfigService());
+ }
+
+ @Test
+ public void testProcess() throws Exception {
+ // test error occurs in validation
+ GetConfigOutputBuilder outputBuilder = getConfigureAction.process(mockInput);
+ Mockito.verify(getConfigureAction, 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 = getConfigureAction.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 {
+ getConfigureAction.validate(mockCommonHeader, Action.GetConfig, mockAI,mockPayload);
+ Status status = (Status) Whitebox.getInternalState(getConfigureAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+ Mockito.verify(getConfigureAction, times(0)).buildStatusForParamName(any(), any());
+ Mockito.verify(getConfigureAction, 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
+ getConfigureAction.validate(mockCommonHeader, Action.GetConfig, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(getConfigureAction, "status");
+ Assert.assertEquals("Should return missing parameter for action",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test empty ActionIdentifier
+ getConfigureAction.validate(mockCommonHeader, Action.GetConfig, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(getConfigureAction, "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();
+ getConfigureAction.validate(mockCommonHeader, Action.GetConfig, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(getConfigureAction, "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();
+ getConfigureAction.validate(mockCommonHeader, Action.GetConfig, mockAI, null);
+ Mockito.verify(getConfigureAction, times(1)).validateExcludedActIds(any(), any());
+ status = (Status) Whitebox.getInternalState(getConfigureAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+
+ // test empty payload
+
+ Mockito.doReturn("").when(mockPayload).getValue();
+ getConfigureAction.validate(mockCommonHeader, Action.GetConfig, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(getConfigureAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+
+ // test space payload
+ Mockito.doReturn(" ").when(mockPayload).getValue();
+ getConfigureAction.validate(mockCommonHeader, Action.GetConfig, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(getConfigureAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+ }
+}
+
diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/LicenseManagementServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/LicenseManagementServiceTest.java new file mode 100644 index 000000000..a7cc37193 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/LicenseManagementServiceTest.java @@ -0,0 +1,166 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 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 LicenseManagementServiceTest {
+ private final Action myAction = Action.LicenseManagement;
+ private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}";
+ private LicenseManagementInput mockInput = mock(LicenseManagementInput.class);
+ private CommonHeader mockCommonHeader = mock(CommonHeader.class);
+ private ActionIdentifiers mockAI = mock(ActionIdentifiers.class);
+ private Payload mockPayload = mock(Payload.class);
+
+ private LicenseManagementService licenseManagementAction;
+ @Before
+ public void setUp() throws Exception {
+ licenseManagementAction = spy(new LicenseManagementService());
+ }
+
+ @Test
+ public void testProcess() throws Exception {
+ // test error occurs in validation
+ LicenseManagementOutputBuilder outputBuilder = licenseManagementAction.process(mockInput);
+ Mockito.verify(licenseManagementAction, 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 = licenseManagementAction.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 {
+ licenseManagementAction.validate(mockCommonHeader, Action.LicenseManagement, mockAI,mockPayload);
+ Status status = (Status) Whitebox.getInternalState(licenseManagementAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+ Mockito.verify(licenseManagementAction, times(0)).buildStatusForParamName(any(), any());
+ Mockito.verify(licenseManagementAction, 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
+ licenseManagementAction.validate(mockCommonHeader, Action.LicenseManagement, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(licenseManagementAction, "status");
+ Assert.assertEquals("Should return missing parameter for action",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test empty ActionIdentifier
+ licenseManagementAction.validate(mockCommonHeader, Action.LicenseManagement, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(licenseManagementAction, "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();
+ licenseManagementAction.validate(mockCommonHeader, Action.LicenseManagement, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(licenseManagementAction, "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();
+ licenseManagementAction.validate(mockCommonHeader, Action.LicenseManagement, mockAI, null);
+ Mockito.verify(licenseManagementAction, times(1)).validateExcludedActIds(any(), any());
+ status = (Status) Whitebox.getInternalState(licenseManagementAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+
+ // test empty payload
+
+ Mockito.doReturn("").when(mockPayload).getValue();
+ licenseManagementAction.validate(mockCommonHeader, Action.LicenseManagement, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(licenseManagementAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+
+ // test space payload
+ Mockito.doReturn(" ").when(mockPayload).getValue();
+ licenseManagementAction.validate(mockCommonHeader, Action.LicenseManagement, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(licenseManagementAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+ }
+}
\ No newline at end of file diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PostEvacuateServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PostEvacuateServiceTest.java new file mode 100644 index 000000000..7f229ebfa --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PostEvacuateServiceTest.java @@ -0,0 +1,168 @@ + +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 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 PostEvacuateServiceTest { + private final Action myAction = Action.PostEvacuate; + private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}"; + private PostEvacuateInput mockInput = mock(PostEvacuateInput.class); + private CommonHeader mockCommonHeader = mock(CommonHeader.class); + private ActionIdentifiers mockAI = mock(ActionIdentifiers.class); + private Payload mockPayload = mock(Payload.class); + + private PostEvacuateService postevacuateServiceAction; + @Before + public void setUp() throws Exception { + postevacuateServiceAction = spy(new PostEvacuateService()); + } + + @Test + public void testProcess() throws Exception { + // test error occurs in validation + PostEvacuateOutputBuilder outputBuilder = postevacuateServiceAction.process(mockInput); + Mockito.verify(postevacuateServiceAction, 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 = postevacuateServiceAction.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 { + postevacuateServiceAction.validate(mockCommonHeader, Action.PostEvacuate, mockAI,mockPayload); + Status status = (Status) Whitebox.getInternalState(postevacuateServiceAction, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + Mockito.verify(postevacuateServiceAction, times(0)).buildStatusForParamName(any(), any()); + Mockito.verify(postevacuateServiceAction, 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 + postevacuateServiceAction.validate(mockCommonHeader, Action.PostEvacuate, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(postevacuateServiceAction, "status"); + Assert.assertEquals("Should return missing parameter for action", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + + // test empty ActionIdentifier + postevacuateServiceAction.validate(mockCommonHeader, Action.PostEvacuate, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(postevacuateServiceAction, "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(); + postevacuateServiceAction.validate(mockCommonHeader, Action.PostEvacuate, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(postevacuateServiceAction, "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(); + postevacuateServiceAction.validate(mockCommonHeader, Action.PostEvacuate, mockAI, null); + Mockito.verify(postevacuateServiceAction, times(1)).validateExcludedActIds(any(), any()); + status = (Status) Whitebox.getInternalState(postevacuateServiceAction, "status"); + Assert.assertTrue("Should skip Payload",true); + + // test empty payload + + Mockito.doReturn("").when(mockPayload).getValue(); + postevacuateServiceAction.validate(mockCommonHeader, Action.PostEvacuate, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(postevacuateServiceAction, "status"); + Assert.assertTrue("Should skip Payload",true); + + // test space payload + Mockito.doReturn(" ").when(mockPayload).getValue(); + postevacuateServiceAction.validate(mockCommonHeader, Action.PostEvacuate, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(postevacuateServiceAction, "status"); + Assert.assertTrue("Should skip Payload",true); + } +} + diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PostMigrateServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PostMigrateServiceTest.java new file mode 100644 index 000000000..5752a3088 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PostMigrateServiceTest.java @@ -0,0 +1,168 @@ + +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 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 PostMigrateServiceTest { + private final Action myAction = Action.PostMigrate; + private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}"; + private PostMigrateInput mockInput = mock(PostMigrateInput.class); + private CommonHeader mockCommonHeader = mock(CommonHeader.class); + private ActionIdentifiers mockAI = mock(ActionIdentifiers.class); + private Payload mockPayload = mock(Payload.class); + + private PostMigrateService postmigrateServiceAction; + @Before + public void setUp() throws Exception { + postmigrateServiceAction = spy(new PostMigrateService()); + } + + @Test + public void testProcess() throws Exception { + // test error occurs in validation + PostMigrateOutputBuilder outputBuilder = postmigrateServiceAction.process(mockInput); + Mockito.verify(postmigrateServiceAction, 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 = postmigrateServiceAction.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 { + postmigrateServiceAction.validate(mockCommonHeader, Action.PostMigrate, mockAI,mockPayload); + Status status = (Status) Whitebox.getInternalState(postmigrateServiceAction, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + Mockito.verify(postmigrateServiceAction, times(0)).buildStatusForParamName(any(), any()); + Mockito.verify(postmigrateServiceAction, 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 + postmigrateServiceAction.validate(mockCommonHeader, Action.PostMigrate, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(postmigrateServiceAction, "status"); + Assert.assertEquals("Should return missing parameter for action", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + + // test empty ActionIdentifier + postmigrateServiceAction.validate(mockCommonHeader, Action.PostMigrate, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(postmigrateServiceAction, "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(); + postmigrateServiceAction.validate(mockCommonHeader, Action.PostMigrate, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(postmigrateServiceAction, "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(); + postmigrateServiceAction.validate(mockCommonHeader, Action.PostMigrate, mockAI, null); + Mockito.verify(postmigrateServiceAction, times(1)).validateExcludedActIds(any(), any()); + status = (Status) Whitebox.getInternalState(postmigrateServiceAction, "status"); + Assert.assertTrue("Should skip Payload",true); + + // test empty payload + + Mockito.doReturn("").when(mockPayload).getValue(); + postmigrateServiceAction.validate(mockCommonHeader, Action.PostMigrate, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(postmigrateServiceAction, "status"); + Assert.assertTrue("Should skip Payload",true); + + // test space payload + Mockito.doReturn(" ").when(mockPayload).getValue(); + postmigrateServiceAction.validate(mockCommonHeader, Action.PostMigrate, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(postmigrateServiceAction, "status"); + Assert.assertTrue("Should skip Payload",true); + } +} + diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PostRebuildTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PostRebuildTest.java new file mode 100644 index 000000000..693cba823 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PostRebuildTest.java @@ -0,0 +1,167 @@ +/*-
+ * ============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 PostRebuildTest {
+ private final Action myAction = Action.PostRebuild;
+ private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}";
+ private PostRebuildInput mockInput = mock(PostRebuildInput.class);
+ private CommonHeader mockCommonHeader = mock(CommonHeader.class);
+ private ActionIdentifiers mockAI = mock(ActionIdentifiers.class);
+ private Payload mockPayload = mock(Payload.class);
+
+ private PostRebuild postRebuildAction;
+ @Before
+ public void setUp() throws Exception {
+ postRebuildAction = spy(new PostRebuild());
+ }
+
+ @Test
+ public void testProcess() throws Exception {
+ // test error occurs in validation
+ PostRebuildOutputBuilder outputBuilder = postRebuildAction.process(mockInput);
+ Mockito.verify(postRebuildAction, 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 = postRebuildAction.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 {
+ postRebuildAction.validate(mockCommonHeader, Action.PostRebuild, mockAI,mockPayload);
+ Status status = (Status) Whitebox.getInternalState(postRebuildAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+ Mockito.verify(postRebuildAction, times(0)).buildStatusForParamName(any(), any());
+ Mockito.verify(postRebuildAction, 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
+ postRebuildAction.validate(mockCommonHeader, Action.PostRebuild, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(postRebuildAction, "status");
+ Assert.assertEquals("Should return missing parameter for action",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test empty ActionIdentifier
+ postRebuildAction.validate(mockCommonHeader, Action.PostRebuild, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(postRebuildAction, "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();
+ postRebuildAction.validate(mockCommonHeader, Action.PostRebuild, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(postRebuildAction, "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();
+ postRebuildAction.validate(mockCommonHeader, Action.PostRebuild, mockAI, null);
+ Mockito.verify(postRebuildAction, times(1)).validateExcludedActIds(any(), any());
+ status = (Status) Whitebox.getInternalState(postRebuildAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+
+ // test empty payload
+
+ Mockito.doReturn("").when(mockPayload).getValue();
+ postRebuildAction.validate(mockCommonHeader, Action.PostRebuild, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(postRebuildAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+
+ // test space payload
+ Mockito.doReturn(" ").when(mockPayload).getValue();
+ postRebuildAction.validate(mockCommonHeader, Action.PostRebuild, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(postRebuildAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+ }
+}
+
diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PreConfigureTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PreConfigureTest.java new file mode 100644 index 000000000..e5fb6741e --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PreConfigureTest.java @@ -0,0 +1,167 @@ +/*-
+ * ============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 PreConfigureTest {
+ private final Action myAction = Action.PreConfigure;
+ private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}";
+ private PreConfigureInput mockInput = mock(PreConfigureInput.class);
+ private CommonHeader mockCommonHeader = mock(CommonHeader.class);
+ private ActionIdentifiers mockAI = mock(ActionIdentifiers.class);
+ private Payload mockPayload = mock(Payload.class);
+
+ private PreConfigure preConfigureAction;
+ @Before
+ public void setUp() throws Exception {
+ preConfigureAction = spy(new PreConfigure());
+ }
+
+ @Test
+ public void testProcess() throws Exception {
+ // test error occurs in validation
+ PreConfigureOutputBuilder outputBuilder = preConfigureAction.process(mockInput);
+ Mockito.verify(preConfigureAction, 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 = preConfigureAction.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 {
+ preConfigureAction.validate(mockCommonHeader, Action.PreConfigure, mockAI,mockPayload);
+ Status status = (Status) Whitebox.getInternalState(preConfigureAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+ Mockito.verify(preConfigureAction, times(0)).buildStatusForParamName(any(), any());
+ Mockito.verify(preConfigureAction, 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
+ preConfigureAction.validate(mockCommonHeader, Action.PreConfigure, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(preConfigureAction, "status");
+ Assert.assertEquals("Should return missing parameter for action",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test empty ActionIdentifier
+ preConfigureAction.validate(mockCommonHeader, Action.PreConfigure, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(preConfigureAction, "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();
+ preConfigureAction.validate(mockCommonHeader, Action.PreConfigure, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(preConfigureAction, "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();
+ preConfigureAction.validate(mockCommonHeader, Action.PreConfigure, mockAI, null);
+ Mockito.verify(preConfigureAction, times(1)).validateExcludedActIds(any(), any());
+ status = (Status) Whitebox.getInternalState(preConfigureAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+
+ // test empty payload
+
+ Mockito.doReturn("").when(mockPayload).getValue();
+ preConfigureAction.validate(mockCommonHeader, Action.PreConfigure, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(preConfigureAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+
+ // test space payload
+ Mockito.doReturn(" ").when(mockPayload).getValue();
+ preConfigureAction.validate(mockCommonHeader, Action.PreConfigure, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(preConfigureAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+ }
+}
+
diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PreEvacuateTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PreEvacuateTest.java new file mode 100644 index 000000000..e023745b4 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PreEvacuateTest.java @@ -0,0 +1,208 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 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 org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.powermock.api.mockito.PowerMockito.whenNew; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({PreEvacuate.class, RequestExecutor.class}) +public class PreEvacuateTest { + private final Action myAction = Action.PreEvacuate; + private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}"; + private PreEvacuateInput mockInput = mock(PreEvacuateInput.class); + private CommonHeader mockCommonHeader = mock(CommonHeader.class); + private ActionIdentifiers mockAI = mock(ActionIdentifiers.class); + private Payload mockPayload = mock(Payload.class); + + private PreEvacuate preEvacuateAction; + + @Before + public void setUp() throws Exception { + preEvacuateAction = spy(new PreEvacuate()); + } + + @Test + public void testProcess() throws Exception { + // test error occurs in validation + PreEvacuateOutputBuilder outputBuilder = preEvacuateAction.process(mockInput); + Mockito.verify(preEvacuateAction, 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("2.34").when(mockCommonHeader).getApiVer(); + Mockito.doReturn("originator 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()); + String successMsg = "Simulated SUCCESS"; + Mockito.doReturn(successCode).when(mockStatus).getCode(); + Mockito.doReturn(successMsg).when(mockStatus).getMessage(); + Mockito.doReturn(mockStatus).when(mockResponseContext).getStatus(); + + try { + outputBuilder = preEvacuateAction.process(mockInput); + } catch(Exception e) { + Assert.assertTrue("Encountered Exception " + e.toString() + " processing action", false); + } + Assert.assertTrue("Should have commonHeader", + outputBuilder != null && outputBuilder.getCommonHeader() != null); + Assert.assertEquals("should return success status", successCode, outputBuilder.getStatus().getCode()); + } + + @Test + public void testValidate() throws Exception { + preEvacuateAction.validate(mockCommonHeader, Action.PreEvacuate, mockAI, mockPayload); + Status status = (Status) Whitebox.getInternalState(preEvacuateAction, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + Mockito.verify(preEvacuateAction, times(0)).buildStatusForParamName(any(), any()); + Mockito.verify(preEvacuateAction, times(0)).buildStatusForErrorMsg(any(), any()); + + Mockito.doReturn("mocked AI").when(mockAI).toString(); + Mockito.doReturn("mocked CommonHeader").when(mockCommonHeader).toString(); + Mockito.doReturn("mocked Input").when(mockInput).toString(); + Mockito.doReturn("mocked Payload").when(mockPayload).toString(); + ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z"); + Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp(); + Mockito.doReturn("2.34").when(mockCommonHeader).getApiVer(); + Mockito.doReturn("originator Id").when(mockCommonHeader).getOriginatorId(); + Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId(); + + // test empty action + preEvacuateAction.validate(mockCommonHeader, Action.PreEvacuate, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(preEvacuateAction, "status"); + Assert.assertEquals("Should return missing parameter for action", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), + status.getCode()); + + // test empty ActionIdentifier + preEvacuateAction.validate(mockCommonHeader, Action.PreEvacuate, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(preEvacuateAction, "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(); + preEvacuateAction.validate(mockCommonHeader, Action.PreEvacuate, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(preEvacuateAction, "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(); + preEvacuateAction.validate(mockCommonHeader, Action.PreEvacuate, mockAI, null); + Mockito.verify(preEvacuateAction, times(1)).validateExcludedActIds(any(), any()); + status = (Status) Whitebox.getInternalState(preEvacuateAction, "status"); + if ((PreEvacuate.payloadConfig & PreEvacuate.PAYLOAD_ACCEPT_NULL) != 0) { + Assert.assertTrue("Configuration indicates should accept null Payload", status == null); + } else { + Assert.assertEquals("Configuration indicates should reject null Payload", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), + status.getCode()); + } + + // test empty payload + Mockito.doReturn("").when(mockPayload).getValue(); + preEvacuateAction.validate(mockCommonHeader, Action.PreEvacuate, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(preEvacuateAction, "status"); + if ((PreEvacuate.payloadConfig & PreEvacuate.PAYLOAD_ACCEPT_NULL) != 0 + && (PreEvacuate.payloadConfig & PreEvacuate.PAYLOAD_TREAT_EMPTY_AS_NULL) != 0) { + Assert.assertTrue("Configuration indicates should accept empty Payload", status == null); + } else if ((PreEvacuate.payloadConfig & PreEvacuate.PAYLOAD_TREAT_EMPTY_AS_NULL) != 0) { + Assert.assertEquals("Configuration indicates should reject empty Payload", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), + status.getCode()); + } else { + Assert.assertEquals("Configuration indicates should reject empty Payload", + Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), + status.getCode()); + } + + // test space payload + Mockito.doReturn(" ").when(mockPayload).getValue(); + preEvacuateAction.validate(mockCommonHeader, Action.PreEvacuate, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(preEvacuateAction, "status"); + if ((PreEvacuate.payloadConfig & PreEvacuate.PAYLOAD_ACCEPT_NULL) != 0 + && (PreEvacuate.payloadConfig & PreEvacuate.PAYLOAD_AUTO_TRIM) != 0 + && (PreEvacuate.payloadConfig & PreEvacuate.PAYLOAD_TREAT_EMPTY_AS_NULL) != 0) { + Assert.assertTrue("Configuration indicates should accept blank Payload", status == null); + } else if ((PreEvacuate.payloadConfig & PreEvacuate.PAYLOAD_AUTO_TRIM) != 0 + && (PreEvacuate.payloadConfig & PreEvacuate.PAYLOAD_TREAT_EMPTY_AS_NULL) != 0) { + Assert.assertEquals("Configuration indicates should reject blank Payload", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), + status.getCode()); + } else { + Assert.assertEquals("Configuration indicates should reject blank Payload", + Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), + status.getCode()); + } + } +} diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PreMigrateServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PreMigrateServiceTest.java new file mode 100644 index 000000000..c9e944acf --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PreMigrateServiceTest.java @@ -0,0 +1,168 @@ + +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 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 PreMigrateServiceTest { + private final Action myAction = Action.PreMigrate; + private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}"; + private PreMigrateInput mockInput = mock(PreMigrateInput.class); + private CommonHeader mockCommonHeader = mock(CommonHeader.class); + private ActionIdentifiers mockAI = mock(ActionIdentifiers.class); + private Payload mockPayload = mock(Payload.class); + + private PreMigrateService premigrateServiceAction; + @Before + public void setUp() throws Exception { + premigrateServiceAction = spy(new PreMigrateService()); + } + + @Test + public void testProcess() throws Exception { + // test error occurs in validation + PreMigrateOutputBuilder outputBuilder = premigrateServiceAction.process(mockInput); + Mockito.verify(premigrateServiceAction, 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 = premigrateServiceAction.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 { + premigrateServiceAction.validate(mockCommonHeader, Action.PreMigrate, mockAI,mockPayload); + Status status = (Status) Whitebox.getInternalState(premigrateServiceAction, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + Mockito.verify(premigrateServiceAction, times(0)).buildStatusForParamName(any(), any()); + Mockito.verify(premigrateServiceAction, 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 + premigrateServiceAction.validate(mockCommonHeader, Action.PreMigrate, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(premigrateServiceAction, "status"); + Assert.assertEquals("Should return missing parameter for action", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + + // test empty ActionIdentifier + premigrateServiceAction.validate(mockCommonHeader, Action.PreMigrate, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(premigrateServiceAction, "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(); + premigrateServiceAction.validate(mockCommonHeader, Action.PreMigrate, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(premigrateServiceAction, "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(); + premigrateServiceAction.validate(mockCommonHeader, Action.PreMigrate, mockAI, null); + Mockito.verify(premigrateServiceAction, times(1)).validateExcludedActIds(any(), any()); + status = (Status) Whitebox.getInternalState(premigrateServiceAction, "status"); + Assert.assertTrue("Should skip Payload",true); + + // test empty payload + + Mockito.doReturn("").when(mockPayload).getValue(); + premigrateServiceAction.validate(mockCommonHeader, Action.PreMigrate, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(premigrateServiceAction, "status"); + Assert.assertTrue("Should skip Payload",true); + + // test space payload + Mockito.doReturn(" ").when(mockPayload).getValue(); + premigrateServiceAction.validate(mockCommonHeader, Action.PreMigrate, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(premigrateServiceAction, "status"); + Assert.assertTrue("Should skip Payload",true); + } +} + diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PreRebuildTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PreRebuildTest.java new file mode 100644 index 000000000..7ffbeecc1 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/PreRebuildTest.java @@ -0,0 +1,167 @@ +/*-
+ * ============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 PreRebuildTest {
+ private final Action myAction = Action.PreRebuild;
+ private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}";
+ private PreRebuildInput mockInput = mock(PreRebuildInput.class);
+ private CommonHeader mockCommonHeader = mock(CommonHeader.class);
+ private ActionIdentifiers mockAI = mock(ActionIdentifiers.class);
+ private Payload mockPayload = mock(Payload.class);
+
+ private PreRebuild preRebuildAction;
+ @Before
+ public void setUp() throws Exception {
+ preRebuildAction = spy(new PreRebuild());
+ }
+
+ @Test
+ public void testProcess() throws Exception {
+ // test error occurs in validation
+ PreRebuildOutputBuilder outputBuilder = preRebuildAction.process(mockInput);
+ Mockito.verify(preRebuildAction, 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 = preRebuildAction.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 {
+ preRebuildAction.validate(mockCommonHeader, Action.PreRebuild, mockAI,mockPayload);
+ Status status = (Status) Whitebox.getInternalState(preRebuildAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+ Mockito.verify(preRebuildAction, times(0)).buildStatusForParamName(any(), any());
+ Mockito.verify(preRebuildAction, 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
+ preRebuildAction.validate(mockCommonHeader, Action.PreRebuild, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(preRebuildAction, "status");
+ Assert.assertEquals("Should return missing parameter for action",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test empty ActionIdentifier
+ preRebuildAction.validate(mockCommonHeader, Action.PreRebuild, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(preRebuildAction, "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();
+ preRebuildAction.validate(mockCommonHeader, Action.PreRebuild, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(preRebuildAction, "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();
+ preRebuildAction.validate(mockCommonHeader, Action.PreRebuild, mockAI, null);
+ Mockito.verify(preRebuildAction, times(1)).validateExcludedActIds(any(), any());
+ status = (Status) Whitebox.getInternalState(preRebuildAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+
+ // test empty payload
+
+ Mockito.doReturn("").when(mockPayload).getValue();
+ preRebuildAction.validate(mockCommonHeader, Action.PreRebuild, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(preRebuildAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+
+ // test space payload
+ Mockito.doReturn(" ").when(mockPayload).getValue();
+ preRebuildAction.validate(mockCommonHeader, Action.PreRebuild, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(preRebuildAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+ }
+}
+
diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/ProvisioningServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/ProvisioningServiceTest.java new file mode 100644 index 000000000..ef94e18fa --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/ProvisioningServiceTest.java @@ -0,0 +1,166 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 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 ProvisioningServiceTest {
+ private final Action myAction = Action.Provisioning;
+ private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}";
+ private ProvisioningInput mockInput = mock(ProvisioningInput.class);
+ private CommonHeader mockCommonHeader = mock(CommonHeader.class);
+ private ActionIdentifiers mockAI = mock(ActionIdentifiers.class);
+ private Payload mockPayload = mock(Payload.class);
+
+ private ProvisioningService provisioningAction;
+ @Before
+ public void setUp() throws Exception {
+ provisioningAction = spy(new ProvisioningService());
+ }
+
+ @Test
+ public void testProcess() throws Exception {
+ // test error occurs in validation
+ ProvisioningOutputBuilder outputBuilder = provisioningAction.process(mockInput);
+ Mockito.verify(provisioningAction, 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 = provisioningAction.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 {
+ provisioningAction.validate(mockCommonHeader, Action.Provisioning, mockAI,mockPayload);
+ Status status = (Status) Whitebox.getInternalState(provisioningAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+ Mockito.verify(provisioningAction, times(0)).buildStatusForParamName(any(), any());
+ Mockito.verify(provisioningAction, 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
+ provisioningAction.validate(mockCommonHeader, Action.Provisioning, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(provisioningAction, "status");
+ Assert.assertEquals("Should return missing parameter for action",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test empty ActionIdentifier
+ provisioningAction.validate(mockCommonHeader, Action.Provisioning, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(provisioningAction, "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();
+ provisioningAction.validate(mockCommonHeader, Action.Provisioning, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(provisioningAction, "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();
+ provisioningAction.validate(mockCommonHeader, Action.Provisioning, mockAI, null);
+ Mockito.verify(provisioningAction, times(1)).validateExcludedActIds(any(), any());
+ status = (Status) Whitebox.getInternalState(provisioningAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+
+ // test empty payload
+
+ Mockito.doReturn("").when(mockPayload).getValue();
+ provisioningAction.validate(mockCommonHeader, Action.Provisioning, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(provisioningAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+
+ // test space payload
+ Mockito.doReturn(" ").when(mockPayload).getValue();
+ provisioningAction.validate(mockCommonHeader, Action.Provisioning, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(provisioningAction, "status");
+ Assert.assertTrue("Should skip Payload",true);
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/StartTrafficTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/StartTrafficTest.java new file mode 100644 index 000000000..83919bde5 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/StartTrafficTest.java @@ -0,0 +1,166 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 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 StartTrafficTest { + private final Action myAction = Action.StartTraffic; + private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}"; + private StartTrafficInput mockInput = mock(StartTrafficInput.class); + private CommonHeader mockCommonHeader = mock(CommonHeader.class); + private ActionIdentifiers mockAI = mock(ActionIdentifiers.class); + private Payload mockPayload = mock(Payload.class); + + private StartTraffic startTrafficAction; + @Before + public void setUp() throws Exception { + startTrafficAction = spy(new StartTraffic()); + } + + @Test + public void testProcess() throws Exception { + // test error occurs in validation + StartTrafficOutputBuilder outputBuilder = startTrafficAction.process(mockInput); + Mockito.verify(startTrafficAction, 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 = startTrafficAction.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 { + startTrafficAction.validate(mockCommonHeader, Action.StartTraffic, mockAI,mockPayload); + Status status = (Status) Whitebox.getInternalState(startTrafficAction, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + Mockito.verify(startTrafficAction, times(0)).buildStatusForParamName(any(), any()); + Mockito.verify(startTrafficAction, 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 + startTrafficAction.validate(mockCommonHeader, Action.StartTraffic, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(startTrafficAction, "status"); + Assert.assertEquals("Should return missing parameter for action", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + + // test empty ActionIdentifier + startTrafficAction.validate(mockCommonHeader, Action.StartTraffic, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(startTrafficAction, "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(); + startTrafficAction.validate(mockCommonHeader, Action.StartTraffic, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(startTrafficAction, "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(); + startTrafficAction.validate(mockCommonHeader, Action.StartTraffic, mockAI, null); + Mockito.verify(startTrafficAction, times(1)).validateExcludedActIds(any(), any()); + status = (Status) Whitebox.getInternalState(startTrafficAction, "status"); + Assert.assertTrue("Should skip Payload",true); + + // test empty payload + + Mockito.doReturn("").when(mockPayload).getValue(); + startTrafficAction.validate(mockCommonHeader, Action.StartTraffic, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(startTrafficAction, "status"); + Assert.assertTrue("Should skip Payload",true); + + // test space payload + Mockito.doReturn(" ").when(mockPayload).getValue(); + startTrafficAction.validate(mockCommonHeader, Action.StartTraffic, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(startTrafficAction, "status"); + Assert.assertTrue("Should skip Payload",true); + } +} diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/StatusTrafficTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/StatusTrafficTest.java new file mode 100644 index 000000000..c84a81292 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/StatusTrafficTest.java @@ -0,0 +1,166 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 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 StatusTrafficTest { + private final Action myAction = Action.StatusTraffic; + private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}"; + private StatusTrafficInput mockInput = mock(StatusTrafficInput.class); + private CommonHeader mockCommonHeader = mock(CommonHeader.class); + private ActionIdentifiers mockAI = mock(ActionIdentifiers.class); + private Payload mockPayload = mock(Payload.class); + + private StatusTraffic statusTrafficAction; + @Before + public void setUp() throws Exception { + statusTrafficAction = spy(new StatusTraffic()); + } + + @Test + public void testProcess() throws Exception { + // test error occurs in validation + StatusTrafficOutputBuilder outputBuilder = statusTrafficAction.process(mockInput); + Mockito.verify(statusTrafficAction, 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 = statusTrafficAction.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 { + statusTrafficAction.validate(mockCommonHeader, Action.StatusTraffic, mockAI,mockPayload); + Status status = (Status) Whitebox.getInternalState(statusTrafficAction, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + Mockito.verify(statusTrafficAction, times(0)).buildStatusForParamName(any(), any()); + Mockito.verify(statusTrafficAction, 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 + statusTrafficAction.validate(mockCommonHeader, Action.StatusTraffic, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(statusTrafficAction, "status"); + Assert.assertEquals("Should return missing parameter for action", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + + // test empty ActionIdentifier + statusTrafficAction.validate(mockCommonHeader, Action.StatusTraffic, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(statusTrafficAction, "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(); + statusTrafficAction.validate(mockCommonHeader, Action.StatusTraffic, mockAI,mockPayload); + status = (Status) Whitebox.getInternalState(statusTrafficAction, "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(); + statusTrafficAction.validate(mockCommonHeader, Action.StatusTraffic, mockAI, null); + Mockito.verify(statusTrafficAction, times(1)).validateExcludedActIds(any(), any()); + status = (Status) Whitebox.getInternalState(statusTrafficAction, "status"); + Assert.assertTrue("Should skip Payload",true); + + // test empty payload + + Mockito.doReturn("").when(mockPayload).getValue(); + statusTrafficAction.validate(mockCommonHeader, Action.StatusTraffic, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(statusTrafficAction, "status"); + Assert.assertTrue("Should skip Payload",true); + + // test space payload + Mockito.doReturn(" ").when(mockPayload).getValue(); + statusTrafficAction.validate(mockCommonHeader, Action.StatusTraffic, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(statusTrafficAction, "status"); + Assert.assertTrue("Should skip Payload",true); + } +} diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/StopTrafficTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/StopTrafficTest.java new file mode 100644 index 000000000..c7d627914 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/StopTrafficTest.java @@ -0,0 +1,208 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 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 org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.powermock.api.mockito.PowerMockito.whenNew; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({StopTraffic.class, RequestExecutor.class}) +public class StopTrafficTest { + private final Action myAction = Action.StopTraffic; + private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}"; + private StopTrafficInput mockInput = mock(StopTrafficInput.class); + private CommonHeader mockCommonHeader = mock(CommonHeader.class); + private ActionIdentifiers mockAI = mock(ActionIdentifiers.class); + private Payload mockPayload = mock(Payload.class); + + private StopTraffic stopTrafficAction; + + @Before + public void setUp() throws Exception { + stopTrafficAction = spy(new StopTraffic()); + } + + @Test + public void testProcess() throws Exception { + // test error occurs in validation + StopTrafficOutputBuilder outputBuilder = stopTrafficAction.process(mockInput); + Mockito.verify(stopTrafficAction, 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("2.34").when(mockCommonHeader).getApiVer(); + Mockito.doReturn("originator 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()); + String successMsg = "Simulated SUCCESS"; + Mockito.doReturn(successCode).when(mockStatus).getCode(); + Mockito.doReturn(successMsg).when(mockStatus).getMessage(); + Mockito.doReturn(mockStatus).when(mockResponseContext).getStatus(); + + try { + outputBuilder = stopTrafficAction.process(mockInput); + } catch(Exception e) { + Assert.assertTrue("Encountered Exception " + e.toString() + " processing action", false); + } + Assert.assertTrue("Should have commonHeader", + outputBuilder != null && outputBuilder.getCommonHeader() != null); + Assert.assertEquals("should return success status", successCode, outputBuilder.getStatus().getCode()); + } + + @Test + public void testValidate() throws Exception { + stopTrafficAction.validate(mockCommonHeader, Action.StopTraffic, mockAI, mockPayload); + Status status = (Status) Whitebox.getInternalState(stopTrafficAction, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + Mockito.verify(stopTrafficAction, times(0)).buildStatusForParamName(any(), any()); + Mockito.verify(stopTrafficAction, times(0)).buildStatusForErrorMsg(any(), any()); + + Mockito.doReturn("mocked AI").when(mockAI).toString(); + Mockito.doReturn("mocked CommonHeader").when(mockCommonHeader).toString(); + Mockito.doReturn("mocked Input").when(mockInput).toString(); + Mockito.doReturn("mocked Payload").when(mockPayload).toString(); + ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z"); + Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp(); + Mockito.doReturn("2.34").when(mockCommonHeader).getApiVer(); + Mockito.doReturn("originator Id").when(mockCommonHeader).getOriginatorId(); + Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId(); + + // test empty action + stopTrafficAction.validate(mockCommonHeader, Action.StopTraffic, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(stopTrafficAction, "status"); + Assert.assertEquals("Should return missing parameter for action", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), + status.getCode()); + + // test empty ActionIdentifier + stopTrafficAction.validate(mockCommonHeader, Action.StopTraffic, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(stopTrafficAction, "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(); + stopTrafficAction.validate(mockCommonHeader, Action.StopTraffic, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(stopTrafficAction, "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(); + stopTrafficAction.validate(mockCommonHeader, Action.StopTraffic, mockAI, null); + Mockito.verify(stopTrafficAction, times(1)).validateExcludedActIds(any(), any()); + status = (Status) Whitebox.getInternalState(stopTrafficAction, "status"); + if ((StopTraffic.payloadConfig & StopTraffic.PAYLOAD_ACCEPT_NULL) != 0) { + Assert.assertTrue("Configuration indicates should accept null Payload", status == null); + } else { + Assert.assertEquals("Configuration indicates should reject null Payload", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), + status.getCode()); + } + + // test empty payload + Mockito.doReturn("").when(mockPayload).getValue(); + stopTrafficAction.validate(mockCommonHeader, Action.StopTraffic, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(stopTrafficAction, "status"); + if ((StopTraffic.payloadConfig & StopTraffic.PAYLOAD_ACCEPT_NULL) != 0 + && (StopTraffic.payloadConfig & StopTraffic.PAYLOAD_TREAT_EMPTY_AS_NULL) != 0) { + Assert.assertTrue("Configuration indicates should accept empty Payload", status == null); + } else if ((StopTraffic.payloadConfig & StopTraffic.PAYLOAD_TREAT_EMPTY_AS_NULL) != 0) { + Assert.assertEquals("Configuration indicates should reject empty Payload", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), + status.getCode()); + } else { + Assert.assertEquals("Configuration indicates should reject empty Payload", + Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), + status.getCode()); + } + + // test space payload + Mockito.doReturn(" ").when(mockPayload).getValue(); + stopTrafficAction.validate(mockCommonHeader, Action.StopTraffic, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(stopTrafficAction, "status"); + if ((StopTraffic.payloadConfig & StopTraffic.PAYLOAD_ACCEPT_NULL) != 0 + && (StopTraffic.payloadConfig & StopTraffic.PAYLOAD_AUTO_TRIM) != 0 + && (StopTraffic.payloadConfig & StopTraffic.PAYLOAD_TREAT_EMPTY_AS_NULL) != 0) { + Assert.assertTrue("Configuration indicates should accept blank Payload", status == null); + } else if ((StopTraffic.payloadConfig & StopTraffic.PAYLOAD_AUTO_TRIM) != 0 + && (StopTraffic.payloadConfig & StopTraffic.PAYLOAD_TREAT_EMPTY_AS_NULL) != 0) { + Assert.assertEquals("Configuration indicates should reject blank Payload", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), + status.getCode()); + } else { + Assert.assertEquals("Configuration indicates should reject blank Payload", + Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), + status.getCode()); + } + } +} |