diff options
Diffstat (limited to 'appc-provider/appc-provider-bundle')
4 files changed, 214 insertions, 134 deletions
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderLcm.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderLcm.java index 1282afacd..c3606df4f 100644 --- a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderLcm.java +++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderLcm.java @@ -445,7 +445,7 @@ public class AppcProviderLcm extends AbstractBaseUtils implements AutoCloseable, @Override public Future<RpcResult<RebootOutput>> reboot(RebootInput input) { logger.debug(String.format("LCM reboot received input: %s", input.toString())); - RebootOutputBuilder outputBuilder = new RebootService().process(input); + RebootOutputBuilder outputBuilder = new RebootService().reboot(input); RpcResult<RebootOutput> result = RpcResultBuilder.<RebootOutput>status(true).withResult(outputBuilder.build()).build(); return Futures.immediateFuture(result); diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/RebootService.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/RebootService.java index 77b287017..19f51e39d 100644 --- a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/RebootService.java +++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/RebootService.java @@ -4,20 +4,18 @@ * ================================================================================ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * ============LICENSE_END========================================================= */ @@ -26,14 +24,19 @@ package org.onap.appc.provider.lcm.service; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload; import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.RebootInput; import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.RebootOutputBuilder; import org.onap.appc.executor.objects.LCMCommandStatus; import org.onap.appc.requesthandler.objects.RequestHandlerInput; import org.onap.appc.util.JsonUtil; +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 java.io.IOException; import java.util.Arrays; +import java.util.EnumSet; import java.util.List; import java.util.Map; @@ -42,8 +45,8 @@ import java.util.Map; */ public class RebootService extends AbstractBaseService { private final EELFLogger myLogger = EELFManager.getInstance().getLogger(RebootService.class); - private static final String REBOOT_TYPE_PARAMETER = "reboot-type"; - private final List<String> rebootTypeList = Arrays.asList("hard", "soft"); + private static final String REBOOT_TYPE_PARAMETER = "type"; + private final List<String> rebootTypeList = Arrays.asList("HARD", "SOFT"); /** * Constructor @@ -52,58 +55,82 @@ public class RebootService extends AbstractBaseService { super(Action.Reboot); } - public RebootOutputBuilder process(RebootInput input) { + public RebootOutputBuilder reboot(RebootInput input) { + validate(input); if (status == null) { proceedAction(input); } - final RebootOutputBuilder outputBuilder = new RebootOutputBuilder(); + RebootOutputBuilder outputBuilder = new RebootOutputBuilder(); outputBuilder.setCommonHeader(input.getCommonHeader()); outputBuilder.setStatus(status); return outputBuilder; } - private void proceedAction(RebootInput input) { + void proceedAction(RebootInput input) { RequestHandlerInput requestHandlerInput = getRequestHandlerInput( - input.getCommonHeader(), input.getActionIdentifiers(), input.getPayload(), this.getClass().getName()); + input.getCommonHeader(), input.getActionIdentifiers(), input.getPayload(), this.getClass().getName()); if (requestHandlerInput != null) { executeAction(requestHandlerInput); } } - private String getRebootType(RebootInput input) { - String rebootType = null; - if (input.getPayload() != null) { - Map<String, String> payloadMap; - try { - payloadMap = JsonUtil.convertJsonStringToFlatMap(input.getPayload().getValue()); - rebootType = payloadMap.get(REBOOT_TYPE_PARAMETER); - } catch (IOException e) { - myLogger.error("Error in converting payload of RebootInput", e.getMessage()); - } - } - - return rebootType; - } - /** * Validate the input. * * @param input of RebootInput from the REST API input */ - private void validate(RebootInput input) { - status = validateVserverId(input.getCommonHeader(), input.getAction(), input.getActionIdentifiers()); + void validate(RebootInput input) { + status = validateVserverIdVnfId(input.getCommonHeader(), input.getAction(), input.getActionIdentifiers()); if (status != null) { return; } + // validate payload + String keyName = "payload"; + if (input.getPayload() == null) { + status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, keyName); + return; + } + String payloadString = input.getPayload().getValue(); + status = validateMustHaveParamValue( + payloadString == null ? payloadString : payloadString.trim(), "payload"); + if (status != null) { + return; + } + + try { + Map<String, String> payloadMap = JsonUtil.convertJsonStringToFlatMap(payloadString); + //reboot-type validation + final String rebootType = payloadMap.get(REBOOT_TYPE_PARAMETER); + if (rebootType == null) { + return; + } else if (!rebootTypeList.contains(rebootType)) { + status = buildStatusForErrorMsg(LCMCommandStatus.INVALID_INPUT_PARAMETER, REBOOT_TYPE_PARAMETER); + return; + } + } catch (IOException e) { + logger.error(String.format("VolumeService (%s) got IOException when converting payload", rpcName), e); + status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, e.getMessage()); + } + } - //reboot-type validation - final String rebootType = getRebootType(input); - if (null == rebootType) { - status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, REBOOT_TYPE_PARAMETER); - } else if (!rebootTypeList.contains(rebootType)) { - status = buildStatusForErrorMsg(LCMCommandStatus.INVALID_INPUT_PARAMETER, REBOOT_TYPE_PARAMETER); + Status validateVserverIdVnfId(CommonHeader commonHeader, Action action, ActionIdentifiers actionIdentifiers ) { + Status validatedStatus = validateInput(commonHeader, action, actionIdentifiers); + + if (validatedStatus != null) { + return validatedStatus; + } + + validatedStatus = validateMustHaveParamValue(actionIdentifiers.getVserverId(), "vserver-id"); + if (validatedStatus == null) { + validatedStatus = validateMustHaveParamValue(actionIdentifiers.getVnfId(), "vnf-id"); + logger.debug("check for vnf-id"); + } + if (validatedStatus == null) { + validatedStatus = validateExcludedActIds(actionIdentifiers, EnumSet.of(ACTID_KEYS.VSERVER_ID, ACTID_KEYS.VNF_ID)); } + logger.debug("check for ActIds"); + return validatedStatus; } } diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/AppcProviderLcmTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/AppcProviderLcmTest.java index 9c74dc877..5c308d27b 100644 --- a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/AppcProviderLcmTest.java +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/AppcProviderLcmTest.java @@ -1214,7 +1214,7 @@ public class AppcProviderLcmTest extends AbstractDataBrokerTest { RebootService mockReboot = mock(RebootService.class); //whenNew(RebootService.class).withNoArguments().thenReturn(mockReboot); - when(mockReboot.process(mockInput)).thenReturn(mockRebootOutputBuilder); + when(mockReboot.reboot(mockInput)).thenReturn(mockRebootOutputBuilder); when(mockRebootOutputBuilder.build()).thenReturn(mockOutput); Future<RpcResult<RebootOutput>> results = appcProviderLcm.reboot(mockInput); diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/RebootServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/RebootServiceTest.java index 4c9fd2228..90a7e3f45 100644 --- a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/RebootServiceTest.java +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/RebootServiceTest.java @@ -1,23 +1,22 @@ + /*- * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * ============LICENSE_END========================================================= */ @@ -27,126 +26,180 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action; -import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload; -import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.RebootInput; -import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.RebootOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ZULU; +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.powermock.api.mockito.PowerMockito; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; - +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; +import static org.mockito.Matchers.isNull; -@RunWith(PowerMockRunner.class) +@RunWith(MockitoJUnitRunner.class) public class RebootServiceTest { - private final String vserverId = "vserverId"; + private final Action myAction = Action.Reboot; + private String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}"; + private RebootInput mockInput = mock(RebootInput.class); + private CommonHeader mockCommonHeader = mock(CommonHeader.class); + private ActionIdentifiers mockAI = mock(ActionIdentifiers.class); + private Payload mockPayload = mock(Payload.class); + private AbstractBaseService abstractService= mock(AbstractBaseService.class); + //private Action action = mock(Action.class); - @Mock private RebootService rebootService; - @Mock - private RebootInput rebootInput; - @Mock - private ActionIdentifiers actionIdentifiers; - @Mock - private org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader commonHeader; - - private Payload payload; - @Before public void setUp() throws Exception { - rebootService = new RebootService(); - payload = new Payload("{\"reboot-type\":\"hard\"}"); - - PowerMockito.doReturn(actionIdentifiers).when(rebootInput).getActionIdentifiers(); - PowerMockito.doReturn(payload).when(rebootInput).getPayload(); - PowerMockito.doReturn(commonHeader).when(rebootInput).getCommonHeader(); - PowerMockito.doReturn(new ZULU("2017-09-05T16:55:55.807Z")).when(commonHeader).getTimestamp(); - PowerMockito.doReturn("2.00").when(commonHeader).getApiVer(); - PowerMockito.doReturn("demo-lcm-stop-id#1").when(commonHeader).getRequestId(); - PowerMockito.doReturn("demo-lcm-stop-id#2").when(commonHeader).getSubRequestId(); - PowerMockito.doReturn("originator-id").when(commonHeader).getOriginatorId(); - PowerMockito.doReturn(Action.Reboot).when(rebootInput).getAction(); + rebootService = spy(new RebootService()); } @Test - public void testConstructor() throws Exception { - Action expectedAction = Action.Reboot; - Assert.assertEquals("Should have proper ACTION", expectedAction, - (Action) org.powermock.reflect.Whitebox.getInternalState(rebootService, "expectedAction")); - Assert.assertEquals("Should have reboot RPC name", expectedAction.name().toLowerCase(), - (org.powermock.reflect.Whitebox.getInternalState(rebootService, "rpcName")).toString()); + public void testValidateMissingParameters() throws Exception { + rebootService.validate(mockInput); + Status status = (Status) Whitebox.getInternalState(rebootService, "status"); + //testing missing parameters in the input + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); } - - @Test - public void testProcessAccepted() throws Exception { - PowerMockito.doReturn(vserverId).when(actionIdentifiers).getVserverId(); - RebootOutputBuilder process = rebootService.process(rebootInput); - PowerMockito.verifyPrivate(rebootService, times(1)).invoke("validate", rebootInput); - Assert.assertNotNull(process.getCommonHeader()); - Assert.assertNotNull(process.getStatus()); - } - @Test - public void testProcessError() throws Exception { - RebootOutputBuilder process = rebootService.process(rebootInput); - PowerMockito.verifyPrivate(rebootService, times(1)) - .invoke("validate", rebootInput); - Assert.assertNotNull(process.getStatus()); + public void testValidateForInvalidAction() throws Exception { + + Mockito.doReturn(mockCommonHeader).when(mockInput).getCommonHeader(); + Mockito.doReturn(mockPayload).when(mockInput).getPayload(); + Mockito.doReturn(PAYLOAD_STRING).when(mockPayload).getValue(); + 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(Action.AttachVolume).when(mockInput).getAction(); + Mockito.doReturn(mockAI).when(mockInput).getActionIdentifiers(); + Mockito.doReturn("vserverId").when(mockAI).getVserverId(); + + // test invalid action + rebootService.validate(mockInput); + Status status = (Status) Whitebox.getInternalState(rebootService, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode()); } @Test - public void testValidateSuccess() throws Exception { - PowerMockito.doReturn(vserverId).when(actionIdentifiers).getVserverId(); - Status validate = Whitebox.invokeMethod(rebootService, "validate", rebootInput); - Assert.assertNull(validate); + public void testValidateForMissingActionIdentifiers() throws Exception { + + Mockito.doReturn(mockCommonHeader).when(mockInput).getCommonHeader(); + Mockito.doReturn(mockPayload).when(mockInput).getPayload(); + Mockito.doReturn(PAYLOAD_STRING).when(mockPayload).getValue(); + 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(Action.Reboot).when(mockInput).getAction(); + //Mockito.doReturn(mockAI).when(mockInput).getActionIdentifiers(); + Mockito.doReturn("vserverId").when(mockAI).getVserverId(); + + // test invalid action + rebootService.validate(mockInput); + Status status = (Status) Whitebox.getInternalState(rebootService, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); } @Test - public void testValidateMissingVserverId() throws Exception { - PowerMockito.doReturn("").when(actionIdentifiers).getVserverId(); - Whitebox.invokeMethod(rebootService, "validate", rebootInput); - Status status = Whitebox.getInternalState(rebootService, "status"); - Assert.assertNotNull(status); + public void testValidateMissingOrIncorrectPayload() throws Exception { + PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"},\"type\":\"HARD\"}"; + + Mockito.doReturn(mockCommonHeader).when(mockInput).getCommonHeader(); + 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(Action.Reboot).when(mockInput).getAction(); + Mockito.doReturn(mockAI).when(mockInput).getActionIdentifiers(); + Mockito.doReturn("vserverId").when(mockAI).getVserverId(); + Mockito.doReturn("vnfId").when(mockAI).getVnfId(); + + //testing missing payload + rebootService.validate(mockInput); + Status status = (Status) Whitebox.getInternalState(rebootService, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + + //testing payload with no value or empty + Mockito.doReturn(mockPayload).when(mockInput).getPayload(); + rebootService.validate(mockInput); + status = (Status) Whitebox.getInternalState(rebootService, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + + //Incorrect PayLoad leads to unexpected error during conversion to map + PAYLOAD_STRING = "{\"A\":\"A-value\"\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"},\"type\":\"HARD\"}"; + Mockito.doReturn(PAYLOAD_STRING).when(mockPayload).getValue(); + rebootService.validate(mockInput); + status = (Status) Whitebox.getInternalState(rebootService, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.UNEXPECTED_ERROR.getResponseCode()), status.getCode()); } @Test - public void testValidateWrongAction() throws Exception { - PowerMockito.doReturn(Action.Audit).when(rebootInput).getAction(); - PowerMockito.doReturn("").when(actionIdentifiers).getVserverId(); - Whitebox.invokeMethod(rebootService, "validate", rebootInput); - Status status = Whitebox.getInternalState(rebootService, "status"); - Assert.assertNotNull(status); - } + public void testValidateMissingRebootType() throws Exception { - @Test - public void testValidateMissingActionIdentifier() throws Exception { - PowerMockito.doReturn(actionIdentifiers).when(rebootInput).getActionIdentifiers(); - Whitebox.invokeMethod(rebootService, "validate", rebootInput); - Status status = Whitebox.getInternalState(rebootService, "status"); - Assert.assertNotNull(status); + Mockito.doReturn(mockCommonHeader).when(mockInput).getCommonHeader(); + Mockito.doReturn(mockPayload).when(mockInput).getPayload(); + Mockito.doReturn(PAYLOAD_STRING).when(mockPayload).getValue(); + 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(Action.Reboot).when(mockInput).getAction(); + Mockito.doReturn(mockAI).when(mockInput).getActionIdentifiers(); + Mockito.doReturn("vserverId").when(mockAI).getVserverId(); + Mockito.doReturn("vnfId").when(mockAI).getVnfId(); + + // testing missing reboot-type in the payload + rebootService.validate(mockInput); + Status status = (Status) Whitebox.getInternalState(rebootService, "status"); + Assert.assertEquals("should return status null", + null, status); } @Test - public void testValidateMissingRebootType() throws Exception { - Payload payload = new Payload("{}"); - PowerMockito.doReturn(payload).when(rebootInput).getPayload(); - PowerMockito.doReturn(vserverId).when(actionIdentifiers).getVserverId(); - Whitebox.invokeMethod(rebootService, "validate", rebootInput); - Status status = Whitebox.getInternalState(rebootService, "status"); - Assert.assertNotNull(status); + public void testValidateInvalidRebootType() throws Exception { + PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"},\"type\":\"test\"}"; + Mockito.doReturn(mockCommonHeader).when(mockInput).getCommonHeader(); + Mockito.doReturn(mockPayload).when(mockInput).getPayload(); + Mockito.doReturn(PAYLOAD_STRING).when(mockPayload).getValue(); + 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(Action.Reboot).when(mockInput).getAction(); + Mockito.doReturn(mockAI).when(mockInput).getActionIdentifiers(); + Mockito.doReturn("vserverId").when(mockAI).getVserverId(); + Mockito.doReturn("vnfId").when(mockAI).getVnfId(); + + // test invalid reboot-type ex: pass "test" in this case + rebootService.validate(mockInput); + Status status = (Status) Whitebox.getInternalState(rebootService, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode()); } - @Test - public void testValidateWrongRebootType() throws Exception { - Payload payload = new Payload("{\"reboot-type\":\"1\"}"); - PowerMockito.doReturn(payload).when(rebootInput).getPayload(); - PowerMockito.doReturn(vserverId).when(actionIdentifiers).getVserverId(); - Whitebox.invokeMethod(rebootService, "validate", rebootInput); - Status status = Whitebox.getInternalState(rebootService, "status"); - Assert.assertNotNull(status); - } } + |