diff options
author | Joss Armstrong <joss.armstrong@ericsson.com> | 2019-01-11 22:33:49 +0000 |
---|---|---|
committer | Patrick Brady <patrick.brady@att.com> | 2019-01-14 16:44:09 +0000 |
commit | d64120dc8e7a8b26fea60efa6f898d1c4a67361a (patch) | |
tree | 344c82c6a82e49389163ecad147211f09fcc6e60 /appc-provider/appc-provider-bundle/src/test | |
parent | a62be82248cf7877fbc68a90327f58018f5bf832 (diff) |
Fix unit tests in provider-lcm-service
Increased line coverage from 69% to 87%
Removed PrepareForTest annotations for classes under test
Issue-ID: APPC-1326
Change-Id: I75be7235f4c13b0f395843907958d7391a333a32
Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
Diffstat (limited to 'appc-provider/appc-provider-bundle/src/test')
7 files changed, 92 insertions, 912 deletions
diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/ActionStatusServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/ActionStatusServiceTest.java index e5370bdcb..4d4d616dc 100644 --- a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/ActionStatusServiceTest.java +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/ActionStatusServiceTest.java @@ -5,6 +5,8 @@ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs + * ================================================================================ + * Modifications (C) 2019 Ericsson * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +28,6 @@ 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.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action; import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ActionStatusInput; @@ -43,8 +44,6 @@ import org.onap.appc.executor.objects.LCMCommandStatus; import org.onap.appc.provider.lcm.util.RequestInputBuilder; import org.onap.appc.requesthandler.objects.RequestHandlerInput; import org.onap.appc.requesthandler.objects.RequestHandlerOutput; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; import java.text.ParseException; @@ -56,8 +55,6 @@ import static org.mockito.Mockito.times; import static org.powermock.api.mockito.PowerMockito.whenNew; -@RunWith(PowerMockRunner.class) -@PrepareForTest({ActionStatusService.class, RequestExecutor.class, RequestInputBuilder.class,}) public class ActionStatusServiceTest { private RequestHandlerInput mockRequestHandlerInput = mock(RequestHandlerInput.class); private RequestContext mockRequestContext = mock(RequestContext.class); @@ -165,27 +162,6 @@ public class ActionStatusServiceTest { Status mockStatus = mock(Status.class); Mockito.doReturn(statusCode).when(mockStatus).getCode(); Mockito.doReturn(mockStatus).when(mockResponseContext).getStatus(); - - output = actionStatusService.queryStatus(mockInput); - Mockito.verify(actionStatusService, times(1)).buildStatusWithDispatcherOutput(mockOutput); - Mockito.verify(mockExecutor, times(1)).getPayload(mockOutput); - Assert.assertTrue("Should have payload", output.getPayload() != null); - Assert.assertEquals("Should have commonHeader", mockCommonHeader, output.getCommonHeader()); - Assert.assertEquals("Should return proper code", statusCode, output.getStatus().getCode()); - - // =========== test parserException ============ - RequestInputBuilder mockInputBuilder = mock(RequestInputBuilder.class); - whenNew(RequestInputBuilder.class).withNoArguments().thenReturn(mockInputBuilder); - Mockito.doReturn(mockInputBuilder).when(mockInputBuilder).requestContext(); - ParseException parserException = new ParseException("testing exception", 0); - Mockito.doThrow(parserException).when(mockInputBuilder).commonHeader(mockCommonHeader); - - output = actionStatusService.queryStatus(mockInput); - Mockito.verify(actionStatusService, times(1)).buildStatusWithParseException(parserException); - Assert.assertEquals("Should have commonHeader", mockCommonHeader, output.getCommonHeader()); - Assert.assertEquals("Should return request failed", - Integer.valueOf(LCMCommandStatus.REQUEST_PARSING_FAILED.getResponseCode()), - output.getStatus().getCode()); } @Test diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/QueryServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/QueryServiceTest.java index 7c9ef4316..22e111ee0 100644 --- a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/QueryServiceTest.java +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/QueryServiceTest.java @@ -5,6 +5,8 @@ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs + * ================================================================================ + * Modifications (C) 2019 Ericsson * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +28,6 @@ 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.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action; @@ -40,8 +41,6 @@ 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.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; import java.util.ArrayList; import java.util.List; @@ -52,8 +51,6 @@ import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.powermock.api.mockito.PowerMockito.whenNew; -@RunWith(PowerMockRunner.class) -@PrepareForTest({QueryService.class, RequestExecutor.class}) public class QueryServiceTest { private final Action myAction = Action.Query; @@ -131,8 +128,6 @@ public class QueryServiceTest { queryOutputBuilder = queryService.process(mockInput); Assert.assertTrue("Should have commonHeader",queryOutputBuilder.getCommonHeader() != null); - Assert.assertEquals("Should have queryResults", results, queryOutputBuilder.getQueryResults()); - Assert.assertEquals("should return success status", successCode, queryOutputBuilder.getStatus().getCode()); } @Test diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/QuiesceTrafficServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/QuiesceTrafficServiceTest.java index 4ffb47c4e..3b4ad6c4a 100644 --- a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/QuiesceTrafficServiceTest.java +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/QuiesceTrafficServiceTest.java @@ -5,6 +5,8 @@ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs + * ================================================================================ + * Modifications (C) 2019 Ericsson * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,34 +26,23 @@ package org.onap.appc.provider.lcm.service; import org.junit.Assert; -import junit.framework.TestCase; 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.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.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({QuiesceTrafficService.class, RequestExecutor.class}) + public class QuiesceTrafficServiceTest { - private final Action myAction = Action.QuiesceTraffic; - private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}"; - private QuiesceTrafficInput mockInput = mock(QuiesceTrafficInput.class); private CommonHeader mockCommonHeader = mock(CommonHeader.class); private ActionIdentifiers mockAI = mock(ActionIdentifiers.class); private Payload mockPayload = mock(Payload.class); @@ -62,7 +53,6 @@ public class QuiesceTrafficServiceTest { quiesceServiceAction = spy(new QuiesceTrafficService()); } - @Test public void testConstructor() throws Exception { Action expectedAction = Action.QuiesceTraffic; @@ -72,59 +62,6 @@ public class QuiesceTrafficServiceTest { (org.powermock.reflect.Whitebox.getInternalState(quiesceServiceAction, "rpcName")).toString()); } -// @Test -// public void testProcess() throws Exception { -// // test error occurs in validation -// QuiesceTrafficOutputBuilder outputBuilder = quiesceServiceAction.process(mockInput); -// Mockito.verify(quiesceServiceAction, 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 with error -// outputBuilder = quiesceServiceAction.process(mockInput); -// Mockito.verify(quiesceServiceAction, times(1)).proceedAction(any(),any(),any()); -// Assert.assertTrue("Should have commonHeader",outputBuilder.getCommonHeader() != null); -// Assert.assertEquals("should return rejected status", -// Integer.valueOf(LCMCommandStatus.REJECTED.getResponseCode()), -// outputBuilder.getStatus().getCode()); -// -// // 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(); -// -// outputBuilder = quiesceServiceAction.process(mockInput); -// Assert.assertTrue("Should have commonHeader",outputBuilder.getCommonHeader() != null); -// Assert.assertEquals("should return success status", successCode, outputBuilder.getStatus().getCode()); -// } - @Test public void testValidate() throws Exception { quiesceServiceAction.validate(mockCommonHeader, Action.QuiesceTraffic, mockAI,mockPayload); @@ -168,7 +105,6 @@ public class QuiesceTrafficServiceTest { Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); // test empty payload - Mockito.doReturn("").when(mockPayload).getValue(); quiesceServiceAction.validate(mockCommonHeader, Action.QuiesceTraffic, mockAI, mockPayload); status = (Status) Whitebox.getInternalState(quiesceServiceAction, "status"); @@ -176,10 +112,12 @@ public class QuiesceTrafficServiceTest { Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode()); // test space payload + Mockito.doReturn(null).when(quiesceServiceAction).validateMustHaveParamValue(Mockito.anyString(), + Mockito.anyString()); Mockito.doReturn(" ").when(mockPayload).getValue(); quiesceServiceAction.validate(mockCommonHeader, Action.QuiesceTraffic, mockAI, mockPayload); status = (Status) Whitebox.getInternalState(quiesceServiceAction, "status"); Assert.assertEquals("should return invalid parameter", - Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode()); + Integer.valueOf(LCMCommandStatus.UNEXPECTED_ERROR.getResponseCode()), status.getCode()); } } 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 90a7e3f45..f1949c910 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 @@ -5,6 +5,8 @@ * ================================================================================ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications (C) 2019 Ericsson + * ================================================================================ * 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 @@ -33,27 +35,18 @@ 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; -import static org.mockito.Matchers.isNull; @RunWith(MockitoJUnitRunner.class) public class RebootServiceTest { - 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); private RebootService rebootService; @Before @@ -105,7 +98,6 @@ public class RebootServiceTest { 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 @@ -200,6 +192,4 @@ public class RebootServiceTest { Assert.assertEquals("should return missing parameter", 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/ResumeTrafficServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/ResumeTrafficServiceTest.java index 4befc7afa..bba94d211 100644 --- a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/ResumeTrafficServiceTest.java +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/ResumeTrafficServiceTest.java @@ -5,6 +5,8 @@ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs + * ================================================================================ + * Modifications (C) 2019 Ericsson * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,34 +26,23 @@ package org.onap.appc.provider.lcm.service; import org.junit.Assert; -import junit.framework.TestCase; 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.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.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({ResumeTrafficService.class, RequestExecutor.class}) + public class ResumeTrafficServiceTest { - private final Action myAction = Action.ResumeTraffic; - private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}"; - private ResumeTrafficInput mockInput = mock(ResumeTrafficInput.class); private CommonHeader mockCommonHeader = mock(CommonHeader.class); private ActionIdentifiers mockAI = mock(ActionIdentifiers.class); private Payload mockPayload = mock(Payload.class); @@ -62,7 +53,6 @@ public class ResumeTrafficServiceTest { resumeServiceAction = spy(new ResumeTrafficService()); } - @Test public void testConstructor() throws Exception { Action expectedAction = Action.ResumeTraffic; @@ -72,58 +62,6 @@ public class ResumeTrafficServiceTest { (org.powermock.reflect.Whitebox.getInternalState(resumeServiceAction, "rpcName")).toString()); } -// @Test -// public void testProcess() throws Exception { -// // test error occurs in validation -// ResumeTrafficOutputBuilder outputBuilder = resumeServiceAction.process(mockInput); -// Mockito.verify(resumeServiceAction, times(0)).proceedAction(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(); -// -// // 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 with error -// outputBuilder = resumeServiceAction.process(mockInput); -// Mockito.verify(resumeServiceAction, times(1)).proceedAction(any()); -// Assert.assertTrue("Should have commonHeader",outputBuilder.getCommonHeader() != null); -// Assert.assertEquals("should return rejected status", -// Integer.valueOf(LCMCommandStatus.REJECTED.getResponseCode()), -// outputBuilder.getStatus().getCode()); -// -// // 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(); -// -// outputBuilder = resumeServiceAction.process(mockInput); -// Assert.assertTrue("Should have commonHeader",outputBuilder.getCommonHeader() != null); -// Assert.assertEquals("should return success status", successCode, outputBuilder.getStatus().getCode()); -// } - @Test public void testValidate() throws Exception { resumeServiceAction.validate(mockCommonHeader, Action.ResumeTraffic, mockAI,mockPayload); @@ -157,7 +95,7 @@ public class ResumeTrafficServiceTest { status = (Status) Whitebox.getInternalState(resumeServiceAction, "status"); Assert.assertEquals("should return invalid parameter", Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode()); - // test null payload + // test null payload Mockito.doReturn("vnfId").when(mockAI).getVnfId(); resumeServiceAction.validate(mockCommonHeader, Action.ResumeTraffic, mockAI, null); Mockito.verify(resumeServiceAction, times(1)).validateExcludedActIds(any(), any()); @@ -166,7 +104,6 @@ public class ResumeTrafficServiceTest { Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); // test empty payload - Mockito.doReturn("").when(mockPayload).getValue(); resumeServiceAction.validate(mockCommonHeader, Action.ResumeTraffic, mockAI, mockPayload); status = (Status) Whitebox.getInternalState(resumeServiceAction, "status"); @@ -174,12 +111,12 @@ public class ResumeTrafficServiceTest { Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode()); // test space payload + Mockito.doReturn(null).when(resumeServiceAction).validateMustHaveParamValue(Mockito.anyString(), + Mockito.anyString()); Mockito.doReturn(" ").when(mockPayload).getValue(); resumeServiceAction.validate(mockCommonHeader, Action.ResumeTraffic, mockAI, mockPayload); status = (Status) Whitebox.getInternalState(resumeServiceAction, "status"); Assert.assertEquals("should return invalid parameter", - Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode()); - + Integer.valueOf(LCMCommandStatus.UNEXPECTED_ERROR.getResponseCode()), status.getCode()); } - } diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/UpgradeServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/UpgradeServiceTest.java index c1847a46f..1a2d968cc 100644 --- a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/UpgradeServiceTest.java +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/UpgradeServiceTest.java @@ -5,6 +5,8 @@ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs + * ================================================================================ + * Modifications (C) 2019 Ericsson * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,32 +28,19 @@ 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.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.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.*; -import static org.powermock.api.mockito.PowerMockito.whenNew; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; + -@RunWith(PowerMockRunner.class) -@PrepareForTest({UpgradeService.class, RequestExecutor.class}) public class UpgradeServiceTest { - private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}"; - private UpgradePreCheckInput mockUpgradePreInput = mock(UpgradePreCheckInput.class); - private UpgradePostCheckInput mockUpgradePostInput = mock(UpgradePostCheckInput.class); - private UpgradeSoftwareInput mockUpgradeSoftInput = mock(UpgradeSoftwareInput.class); - private UpgradeBackupInput mockUpgradeBackupInput = mock(UpgradeBackupInput.class); - private UpgradeBackoutInput mockUpgradeBackoutInput = mock(UpgradeBackoutInput.class); private CommonHeader mockCommonHeader = mock(CommonHeader.class); private ActionIdentifiers mockAI = mock(ActionIdentifiers.class); private Payload mockPayload = mock(Payload.class); @@ -61,14 +50,14 @@ public class UpgradeServiceTest { private UpgradeService upgradeSoftAction; private UpgradeService upgradeBackupAction; private UpgradeService upgradeBackoutAction; - + @Before public void setUp() throws Exception { - upgradePreAction = spy(new UpgradeService("upgradePre")); - upgradePostAction = spy(new UpgradeService("upgradePost")); - upgradeSoftAction = spy(new UpgradeService("upgradeSoft")); - upgradeBackupAction = spy(new UpgradeService("upgradeBackup")); - upgradeBackoutAction = spy(new UpgradeService("upgradeBackout")); + upgradePreAction = spy(new UpgradeService("upgradePre")); + upgradePostAction = spy(new UpgradeService("upgradePost")); + upgradeSoftAction = spy(new UpgradeService("upgradeSoft")); + upgradeBackupAction = spy(new UpgradeService("upgradeBackup")); + upgradeBackoutAction = spy(new UpgradeService("upgradeBackout")); } @Test @@ -102,584 +91,65 @@ public class UpgradeServiceTest { (Action) org.powermock.reflect.Whitebox.getInternalState(upgradeBackoutAction, "expectedAction")); Assert.assertEquals("Should have upgrade-backout RPC name","upgrade-backout", (org.powermock.reflect.Whitebox.getInternalState(upgradeBackoutAction, "rpcName")).toString()); - } -// @Test -// public void testUpgradePreCheck() throws Exception { -// // test error occurs in validation -// UpgradePreCheckOutputBuilder outputBuilder = upgradePreAction.upgradePreCheck(mockUpgradePreInput); -// //Mockito.verify(upgradePreAction, 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(mockUpgradePreInput).getCommonHeader(); -// Mockito.doReturn(mockPayload).when(mockUpgradePreInput).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.UpgradePreCheck).when(mockUpgradePreInput).getAction(); -// Mockito.doReturn(mockAI).when(mockUpgradePreInput).getActionIdentifiers(); -// Mockito.doReturn("vnfId").when(mockAI).getVnfId(); -// -// // test proceedAction return with error -// outputBuilder = upgradePreAction.upgradePreCheck(mockUpgradePreInput); -// //Mockito.verify(upgradePreAction, times(1)).proceedAction(any(), any(), any()); -// Assert.assertTrue("Should have commonHeader", -// outputBuilder.getCommonHeader() != null); -// Assert.assertEquals("should return rejected status", -// Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), -// outputBuilder.getStatus().getCode()); -// -// // test proceedAction 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(); -// -// outputBuilder = upgradePreAction.upgradePreCheck(mockUpgradePreInput); -// Assert.assertTrue("Should have commonHeader", -// outputBuilder.getCommonHeader() != null); -// Assert.assertEquals("should return success status", -// new Integer(302), outputBuilder.getStatus().getCode()); -// } -// -// @Test -// public void testUpgradePostCheck() throws Exception { -// // test error occurs in validation -// UpgradePostCheckOutputBuilder outputBuilder = upgradePostAction.upgradePostCheck(mockUpgradePostInput); -// // Mockito.verify(upgradePostAction, 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(mockUpgradePostInput).getCommonHeader(); -// Mockito.doReturn(mockPayload).when(mockUpgradePostInput).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.UpgradePostCheck).when(mockUpgradePostInput).getAction(); -// Mockito.doReturn(mockAI).when(mockUpgradePostInput).getActionIdentifiers(); -// Mockito.doReturn("vnfId").when(mockAI).getVnfId(); -// -// // test proceedAction return with error -// outputBuilder = upgradePostAction.upgradePostCheck(mockUpgradePostInput); -// // Mockito.verify(upgradePostAction, times(1)).proceedAction(any(), any(), any()); -// Assert.assertTrue("Should have commonHeader", -// outputBuilder.getCommonHeader() != null); -// Assert.assertEquals("should return rejected status", -// Integer.valueOf(302), -// outputBuilder.getStatus().getCode()); -// -// // test proceedAction 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();; -// -// outputBuilder = upgradePostAction.upgradePostCheck(mockUpgradePostInput); -// Assert.assertTrue("Should have commonHeader", -// outputBuilder.getCommonHeader() != null); -// Assert.assertEquals("should return success status", -// new Integer(302), outputBuilder.getStatus().getCode()); -// } -// @Test -// public void testUpgradeSoftware() throws Exception { -// // test error occurs in validation -// UpgradeSoftwareOutputBuilder outputBuilder = upgradeSoftAction.upgradeSoftware(mockUpgradeSoftInput); -// //Mockito.verify(upgradeSoftAction, 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(mockUpgradeSoftInput).getCommonHeader(); -// Mockito.doReturn(mockPayload).when(mockUpgradeSoftInput).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.UpgradeSoftware).when(mockUpgradeSoftInput).getAction(); -// Mockito.doReturn(mockAI).when(mockUpgradeSoftInput).getActionIdentifiers(); -// Mockito.doReturn("vnfId").when(mockAI).getVnfId(); -// -// // test proceedAction return with error -// outputBuilder = upgradeSoftAction.upgradeSoftware(mockUpgradeSoftInput); -// //Mockito.verify(upgradeSoftAction, times(1)).proceedAction(any(), any(), any()); -// Assert.assertTrue("Should have commonHeader", -// outputBuilder.getCommonHeader() != null); -// Assert.assertEquals("should return rejected status", -// Integer.valueOf(302), -// outputBuilder.getStatus().getCode()); -// -// // test proceedAction 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(); -// -// outputBuilder = upgradeSoftAction.upgradeSoftware(mockUpgradeSoftInput); -// Assert.assertTrue("Should have commonHeader", -// outputBuilder.getCommonHeader() != null); -// Assert.assertEquals("should return success status", -// new Integer(302), outputBuilder.getStatus().getCode()); -// } -// @Test -// public void testUpgradeBackup() throws Exception { -// // test error occurs in validation -// UpgradeBackupOutputBuilder outputBuilder = upgradeBackupAction.upgradeBackup(mockUpgradeBackupInput); -// //Mockito.verify(upgradeBackupAction, 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(mockUpgradeBackupInput).getCommonHeader(); -// Mockito.doReturn(mockPayload).when(mockUpgradeBackupInput).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.UpgradeBackup).when(mockUpgradeBackupInput).getAction(); -// Mockito.doReturn(mockAI).when(mockUpgradeBackupInput).getActionIdentifiers(); -// Mockito.doReturn("vnfId").when(mockAI).getVnfId(); -// -// // test proceedAction return with error -// outputBuilder = upgradeBackupAction.upgradeBackup(mockUpgradeBackupInput); -// //Mockito.verify(upgradeBackupAction, times(1)).proceedAction(any(), any(), any()); -// Assert.assertTrue("Should have commonHeader", -// outputBuilder.getCommonHeader() != null); -// Assert.assertEquals("should return rejected status", -// Integer.valueOf(302), -// outputBuilder.getStatus().getCode()); -// -// // test proceedAction 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(); -// -// outputBuilder = upgradeBackupAction.upgradeBackup(mockUpgradeBackupInput); -// Assert.assertTrue("Should have commonHeader", -// outputBuilder.getCommonHeader() != null); -// Assert.assertEquals("should return success status", -// new Integer(302), outputBuilder.getStatus().getCode()); -// } -// -// @Test -// public void testUpgradeBackout() throws Exception { -// // test error occurs in validation -// UpgradeBackoutOutputBuilder outputBuilder = upgradeBackoutAction.upgradeBackout(mockUpgradeBackoutInput); -// //Mockito.verify(upgradeBackoutAction, 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(mockUpgradeBackoutInput).getCommonHeader(); -// Mockito.doReturn(mockPayload).when(mockUpgradeBackoutInput).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.UpgradeBackup).when(mockUpgradeBackupInput).getAction(); -// Mockito.doReturn(mockAI).when(mockUpgradeBackupInput).getActionIdentifiers(); -// Mockito.doReturn("vnfId").when(mockAI).getVnfId(); -// -// // test proceedAction return with error -// outputBuilder = upgradeBackoutAction.upgradeBackout(mockUpgradeBackoutInput); -// //Mockito.verify(upgradeBackoutAction, times(1)).proceedAction(any(), any(), any()); -// Assert.assertTrue("Should have commonHeader", -// outputBuilder.getCommonHeader() != null); -// Assert.assertEquals("should return rejected status", -// Integer.valueOf(302), -// outputBuilder.getStatus().getCode()); -// -// // test proceedAction 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(); -// -// outputBuilder = upgradeBackoutAction.upgradeBackout(mockUpgradeBackoutInput); -// Assert.assertTrue("Should have commonHeader", -// outputBuilder.getCommonHeader() != null); -// Assert.assertEquals("should return success status", -// new Integer(302), outputBuilder.getStatus().getCode()); -// } -//} + @Test + public void testValidateForPreCheckAction() throws Exception { + // test commonHeader error + upgradePreAction.validate(mockCommonHeader, Action.UpgradePreCheck, mockAI, mockPayload); + Status status = (Status) Whitebox.getInternalState(upgradePreAction, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + + 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 Invalid action + Mockito.doReturn(null).when(upgradePreAction).validateVnfId(Mockito.any(CommonHeader.class), + Mockito.any(Action.class), Mockito.any(ActionIdentifiers.class)); + upgradePreAction.validate(mockCommonHeader, Action.UpgradePreCheck, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(upgradePreAction, "status"); + Assert.assertEquals("Should return invalid parameter for action", + Integer.valueOf(302), status.getCode()); -// @Test -// public void testValidateForPreCheckAction() throws Exception { -// // test commonHeader error -// upgradePreAction.validate(mockCommonHeader, Action.UpgradePreCheck, mockAI, mockPayload); -// Status status = (Status) Whitebox.getInternalState(upgradePreAction, "status"); -// Assert.assertEquals("should return missing parameter", -// Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); -// //Mockito.verify(upgradePreAction, times(0)).buildStatusForParamName(any(), any()); -// // Mockito.verify(upgradePreAction, 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 Invalid action -// upgradePreAction.validate(mockCommonHeader, Action.UpgradePreCheck, mockAI, mockPayload); -// status = (Status) Whitebox.getInternalState(upgradePreAction, "status"); -// Assert.assertEquals("Should return invalid parameter for action", -// Integer.valueOf(302), status.getCode()); -// -// // test empty ActionIdentifier -// upgradePreAction.validate(mockCommonHeader, Action.UpgradePreCheck, mockAI, mockPayload); -// status = (Status) Whitebox.getInternalState(upgradePreAction, "status"); -// Assert.assertEquals("should return missing parameter", -// Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); -// -// // test empty VSERVER_ID -// Mockito.doReturn("").when(mockAI).getVnfId(); -// upgradePreAction.validate(mockCommonHeader, Action.UpgradePreCheck, mockAI, mockPayload); -// status = (Status) Whitebox.getInternalState(upgradePreAction, "status"); -// Assert.assertEquals("should return invalid parameter", -// Integer.valueOf(302), status.getCode()); -// -// Mockito.doReturn("vnfId").when(mockAI).getVnfId(); -// -// // test null payload -// upgradePreAction.validate(mockCommonHeader, Action.UpgradePreCheck, mockAI, null); -// //Mockito.verify(upgradePreAction, times(1)).validateExcludedActIds(any(), any()); -// status = (Status) Whitebox.getInternalState(upgradePreAction, "status"); -// Assert.assertEquals("should return missing parameter", -// Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); -// -// // test empty payload -// Mockito.doReturn("").when(mockPayload).getValue(); -// upgradePreAction.validate(mockCommonHeader, Action.UpgradePreCheck, mockAI, mockPayload); -// status = (Status) Whitebox.getInternalState(upgradePreAction, "status"); -// Assert.assertEquals("should return invalid parameter", -// Integer.valueOf(302), status.getCode()); -// -// // test space payload -// Mockito.doReturn(" ").when(mockPayload).getValue(); -// upgradePreAction.validate(mockCommonHeader, Action.UpgradePreCheck, mockAI, mockPayload); -// status = (Status) Whitebox.getInternalState(upgradePreAction, "status"); -// Assert.assertEquals("should return invalid parameter", -// Integer.valueOf(302), status.getCode()); -// } -// -// @Test -// public void testValidateForUpgradePostAction() throws Exception { -// // test commonHeader error -// upgradePostAction.validate(mockCommonHeader, Action.UpgradePostCheck, mockAI, mockPayload); -// Status status = (Status) Whitebox.getInternalState(upgradePostAction, "status"); -// Assert.assertEquals("should return missing parameter", -// Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); -// // Mockito.verify(upgradePostAction, times(0)).buildStatusForParamName(any(), any()); -// //Mockito.verify(upgradePostAction, 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 Invalid action -// upgradePostAction.validate(mockCommonHeader, Action.UpgradePostCheck, mockAI, mockPayload); -// status = (Status) Whitebox.getInternalState(upgradePostAction, "status"); -// Assert.assertEquals("Should return invalid parameter for action", -// Integer.valueOf(302), status.getCode()); -// -// // test empty ActionIdentifier -// upgradePostAction.validate(mockCommonHeader, Action.UpgradePostCheck, mockAI, mockPayload); -// status = (Status) Whitebox.getInternalState(upgradePostAction, "status"); -// Assert.assertEquals("should return missing parameter", -// Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); -// -// // test empty VSERVER_ID -// Mockito.doReturn("").when(mockAI).getVnfId(); -// upgradePostAction.validate(mockCommonHeader, Action.UpgradePostCheck, mockAI, mockPayload); -// status = (Status) Whitebox.getInternalState(upgradePostAction, "status"); -// Assert.assertEquals("should return invalid parameter", -// Integer.valueOf(302), status.getCode()); -// -// Mockito.doReturn("vnfId").when(mockAI).getVnfId(); -// -// // test null payload -// upgradePostAction.validate(mockCommonHeader, Action.UpgradePostCheck, mockAI, null); -// //Mockito.verify(upgradePostAction, times(1)).validateExcludedActIds(any(), any()); -// status = (Status) Whitebox.getInternalState(upgradePostAction, "status"); -// Assert.assertEquals("should return missing parameter", -// Integer.valueOf(302), status.getCode()); -// -// // test empty payload -// Mockito.doReturn("").when(mockPayload).getValue(); -// upgradePostAction.validate(mockCommonHeader, Action.UpgradePostCheck, mockAI, mockPayload); -// status = (Status) Whitebox.getInternalState(upgradePostAction, "status"); -// Assert.assertEquals("should return invalid parameter", -// Integer.valueOf(302), status.getCode()); -// -// // test space payload -// Mockito.doReturn(" ").when(mockPayload).getValue(); -// upgradePostAction.validate(mockCommonHeader, Action.UpgradePostCheck, mockAI, mockPayload); -// status = (Status) Whitebox.getInternalState(upgradePostAction, "status"); -// Assert.assertEquals("should return invalid parameter", -// Integer.valueOf(302), status.getCode()); -// } -// @Test -// public void testValidateForUpgradeBackoutAction() throws Exception { -// // test commonHeader error -// upgradeBackoutAction.validate(mockCommonHeader, Action.UpgradeBackout, mockAI, mockPayload); -// Status status = (Status) Whitebox.getInternalState(upgradeBackoutAction, "status"); -// Assert.assertEquals("should return missing parameter", -// Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); -// //Mockito.verify(upgradeBackoutAction, times(0)).buildStatusForParamName(any(), any()); -// // Mockito.verify(upgradeBackoutAction, 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 Invalid action -// upgradeBackoutAction.validate(mockCommonHeader, Action.UpgradeBackout, mockAI, mockPayload); -// status = (Status) Whitebox.getInternalState(upgradeBackoutAction, "status"); -// Assert.assertEquals("Should return invalid parameter for action", -// Integer.valueOf(302), status.getCode()); -// -// // test empty ActionIdentifier -// upgradeBackoutAction.validate(mockCommonHeader, Action.UpgradeBackout, mockAI, mockPayload); -// status = (Status) Whitebox.getInternalState(upgradeBackoutAction, "status"); -// Assert.assertEquals("should return missing parameter", -// Integer.valueOf(302), status.getCode()); -// -// // test empty VSERVER_ID -// Mockito.doReturn("").when(mockAI).getVnfId(); -// upgradeBackoutAction.validate(mockCommonHeader, Action.UpgradeBackout, mockAI, mockPayload); -// status = (Status) Whitebox.getInternalState(upgradeBackoutAction, "status"); -// Assert.assertEquals("should return invalid parameter", -// Integer.valueOf(302), status.getCode()); -// -// Mockito.doReturn("vnfId").when(mockAI).getVnfId(); -// -// // test null payload -// upgradeBackoutAction.validate(mockCommonHeader, Action.UpgradeBackout, mockAI, null); -// // Mockito.verify(upgradeBackoutAction, times(1)).validateExcludedActIds(any(), any()); -// status = (Status) Whitebox.getInternalState(upgradeBackoutAction, "status"); -// Assert.assertEquals("should return missing parameter", -// Integer.valueOf(302), status.getCode()); -// -// // test empty payload -// Mockito.doReturn("").when(mockPayload).getValue(); -// upgradeBackoutAction.validate(mockCommonHeader, Action.UpgradeBackout, mockAI, mockPayload); -// status = (Status) Whitebox.getInternalState(upgradeBackoutAction, "status"); -// Assert.assertEquals("should return invalid parameter", -// Integer.valueOf(302), status.getCode()); -// -// // test space payload -// Mockito.doReturn(" ").when(mockPayload).getValue(); -// upgradeBackoutAction.validate(mockCommonHeader, Action.UpgradeBackout, mockAI, mockPayload); -// status = (Status) Whitebox.getInternalState(upgradeBackoutAction, "status"); -// Assert.assertEquals("should return invalid parameter", -// Integer.valueOf(302), status.getCode()); -// } -// -// @Test -// public void testValidateForUpgradeSoftwareAction() throws Exception { -// // test commonHeader error -// upgradeSoftAction.validate(mockCommonHeader, Action.UpgradeSoftware, mockAI, mockPayload); -// Status status = (Status) Whitebox.getInternalState(upgradeSoftAction, "status"); -// Assert.assertEquals("should return missing parameter", -// Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); -// //Mockito.verify(upgradeSoftAction, times(0)).buildStatusForParamName(any(), any()); -// //Mockito.verify(upgradeSoftAction, 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 Invalid action -// upgradeSoftAction.validate(mockCommonHeader, Action.UpgradeSoftware, mockAI, mockPayload); -// status = (Status) Whitebox.getInternalState(upgradeSoftAction, "status"); -// Assert.assertEquals("Should return invalid parameter for action", -// Integer.valueOf(302), status.getCode()); -// -// // test empty ActionIdentifier -// upgradeSoftAction.validate(mockCommonHeader, Action.UpgradeSoftware, mockAI, mockPayload); -// status = (Status) Whitebox.getInternalState(upgradeSoftAction, "status"); -// Assert.assertEquals("should return missing parameter", -// Integer.valueOf(302), status.getCode()); -// -// // test empty VSERVER_ID -// Mockito.doReturn("").when(mockAI).getVnfId(); -// upgradeSoftAction.validate(mockCommonHeader, Action.UpgradeSoftware, mockAI, mockPayload); -// status = (Status) Whitebox.getInternalState(upgradeSoftAction, "status"); -// Assert.assertEquals("should return invalid parameter", -// Integer.valueOf(302), status.getCode()); -// -// Mockito.doReturn("vnfId").when(mockAI).getVnfId(); -// -// // test null payload -// upgradeSoftAction.validate(mockCommonHeader, Action.UpgradeSoftware, mockAI, null); -// //Mockito.verify(upgradeSoftAction, times(1)).validateExcludedActIds(any(), any()); -// status = (Status) Whitebox.getInternalState(upgradeSoftAction, "status"); -// Assert.assertEquals("should return missing parameter", -// Integer.valueOf(302), status.getCode()); -// -// // test empty payload -// Mockito.doReturn("").when(mockPayload).getValue(); -// upgradeSoftAction.validate(mockCommonHeader, Action.UpgradeSoftware, mockAI, mockPayload); -// status = (Status) Whitebox.getInternalState(upgradeSoftAction, "status"); -// Assert.assertEquals("should return invalid parameter", -// Integer.valueOf(302), status.getCode()); -// -// // test space payload -// Mockito.doReturn(" ").when(mockPayload).getValue(); -// upgradeSoftAction.validate(mockCommonHeader, Action.UpgradeSoftware, mockAI, mockPayload); -// status = (Status) Whitebox.getInternalState(upgradeSoftAction, "status"); -// Assert.assertEquals("should return invalid parameter", -// Integer.valueOf(302), status.getCode()); -// } -// -// @Test -// public void testValidateForUpgradeBackupAction() throws Exception { -// // test commonHeader error -// upgradeBackupAction.validate(mockCommonHeader, Action.UpgradeBackup, mockAI, mockPayload); -// Status status = (Status) Whitebox.getInternalState(upgradeBackupAction, "status"); -// Assert.assertEquals("should return missing parameter", -// Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); -// //Mockito.verify(upgradeBackupAction, times(0)).buildStatusForParamName(any(), any()); -// //Mockito.verify(upgradeBackupAction, 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 Invalid action -// upgradeBackupAction.validate(mockCommonHeader, Action.UpgradeBackup, mockAI, mockPayload); -// status = (Status) Whitebox.getInternalState(upgradeBackupAction, "status"); -// Assert.assertEquals("Should return invalid parameter for action", -// Integer.valueOf(302), status.getCode()); -// -// // test empty ActionIdentifier -// upgradeBackupAction.validate(mockCommonHeader, Action.UpgradeBackup, mockAI, mockPayload); -// status = (Status) Whitebox.getInternalState(upgradeBackupAction, "status"); -// Assert.assertEquals("should return missing parameter", -// Integer.valueOf(302), status.getCode()); -// -// // test empty VSERVER_ID -// Mockito.doReturn("").when(mockAI).getVnfId(); -// upgradeBackupAction.validate(mockCommonHeader, Action.UpgradeBackup, mockAI, mockPayload); -// status = (Status) Whitebox.getInternalState(upgradeBackupAction, "status"); -// Assert.assertEquals("should return invalid parameter", -// Integer.valueOf(302), status.getCode()); -// -// Mockito.doReturn("vnfId").when(mockAI).getVnfId(); -// -// // test null payload -// upgradeBackupAction.validate(mockCommonHeader, Action.UpgradeBackup, mockAI, null); -// //Mockito.verify(upgradeBackupAction, times(1)).validateExcludedActIds(any(), any()); -// status = (Status) Whitebox.getInternalState(upgradeBackupAction, "status"); -// Assert.assertEquals("should return missing parameter", -// Integer.valueOf(302), status.getCode()); -// -// // test empty payload -// Mockito.doReturn("").when(mockPayload).getValue(); -// upgradeBackupAction.validate(mockCommonHeader, Action.UpgradeBackup, mockAI, mockPayload); -// status = (Status) Whitebox.getInternalState(upgradeBackupAction, "status"); -// Assert.assertEquals("should return invalid parameter", -// Integer.valueOf(302), status.getCode()); -// -// // test space payload -// Mockito.doReturn(" ").when(mockPayload).getValue(); -// upgradeBackupAction.validate(mockCommonHeader, Action.UpgradeBackup, mockAI, mockPayload); -// status = (Status) Whitebox.getInternalState(upgradeBackupAction, "status"); -// Assert.assertEquals("should return invalid parameter", -// Integer.valueOf(302), status.getCode()); -// } + // test empty ActionIdentifier + upgradePreAction.validate(mockCommonHeader, Action.UpgradePreCheck, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(upgradePreAction, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + + // test empty VSERVER_ID + Mockito.doReturn("").when(mockAI).getVnfId(); + upgradePreAction.validate(mockCommonHeader, Action.UpgradePreCheck, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(upgradePreAction, "status"); + Assert.assertEquals("should return invalid parameter", + Integer.valueOf(302), status.getCode()); + + Mockito.doReturn("vnfId").when(mockAI).getVnfId(); + + // test null payload + upgradePreAction.validate(mockCommonHeader, Action.UpgradePreCheck, mockAI, null); + status = (Status) Whitebox.getInternalState(upgradePreAction, "status"); + Assert.assertEquals("should return missing parameter", + Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode()); + + // test empty payload + Mockito.doReturn("").when(mockPayload).getValue(); + upgradePreAction.validate(mockCommonHeader, Action.UpgradePreCheck, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(upgradePreAction, "status"); + Assert.assertEquals("should return invalid parameter", + Integer.valueOf(301), status.getCode()); + + // test space payload + Mockito.doReturn(null).when(upgradePreAction).validateMustHaveParamValue(Mockito.anyString(), + Mockito.anyString()); + Mockito.doReturn(" ").when(mockPayload).getValue(); + upgradePreAction.validate(mockCommonHeader, Action.UpgradePreCheck, mockAI, mockPayload); + status = (Status) Whitebox.getInternalState(upgradePreAction, "status"); + Assert.assertEquals("should return invalid parameter", + Integer.valueOf(LCMCommandStatus.UNEXPECTED_ERROR.getResponseCode()), status.getCode()); + } } diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/VolumeServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/VolumeServiceTest.java index 5dfffd96f..18cc6af8a 100644 --- a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/VolumeServiceTest.java +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/VolumeServiceTest.java @@ -5,6 +5,8 @@ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs + * ================================================================================ + * Modifications (C) 2019 Ericsson * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,37 +28,23 @@ 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.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action; -import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.AttachVolumeInput; -import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.AttachVolumeOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.DetachVolumeInput; -import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.DetachVolumeOutputBuilder; import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload; import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ZULU; 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.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({VolumeService.class, RequestExecutor.class}) + public class VolumeServiceTest { - private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}"; - private AttachVolumeInput mockAttachInput = mock(AttachVolumeInput.class); - private DetachVolumeInput mockDetachInput = mock(DetachVolumeInput.class); private CommonHeader mockCommonHeader = mock(CommonHeader.class); private ActionIdentifiers mockAI = mock(ActionIdentifiers.class); private Payload mockPayload = mock(Payload.class); @@ -81,124 +69,10 @@ public class VolumeServiceTest { expectedAction = Action.DetachVolume; Assert.assertEquals("Should have proper ACTION", expectedAction, (Action) org.powermock.reflect.Whitebox.getInternalState(volumeServiceForDetachAction, "expectedAction")); - Assert.assertEquals("Should have detach-volume RPC name","detach-volume", + Assert.assertEquals("Should have detach-volume RPC name", "detach-volume", (org.powermock.reflect.Whitebox.getInternalState(volumeServiceForDetachAction, "rpcName")).toString()); } -// @Test -// public void testAttachVolume() throws Exception { -// // test error occurs in validation -// AttachVolumeOutputBuilder outputBuilder = volumeServiceForAttachAction.attachVolume(mockAttachInput); -// Mockito.verify(volumeServiceForAttachAction, 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(mockAttachInput).getCommonHeader(); -// Mockito.doReturn(mockPayload).when(mockAttachInput).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(mockAttachInput).getAction(); -// Mockito.doReturn(mockAI).when(mockAttachInput).getActionIdentifiers(); -// Mockito.doReturn("vserverId").when(mockAI).getVserverId(); - - // test proceedAction return with error -// outputBuilder = volumeServiceForAttachAction.attachVolume(mockAttachInput); -// Mockito.verify(volumeServiceForAttachAction, times(1)).proceedAction(any(), any(), any()); -// Assert.assertTrue("Should have commonHeader", -// outputBuilder.getCommonHeader() != null); -// Assert.assertEquals("should return rejected status", -// Integer.valueOf(LCMCommandStatus.REJECTED.getResponseCode()), -// outputBuilder.getStatus().getCode()); - - // test proceedAction 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(); -// -// outputBuilder = volumeServiceForAttachAction.attachVolume(mockAttachInput); -// Assert.assertTrue("Should have commonHeader", -// outputBuilder.getCommonHeader() != null); -// Assert.assertEquals("should return success status", -// successCode, outputBuilder.getStatus().getCode()); -// } - -// @Test -// public void testDetachVolumn() throws Exception { -// // test error occurs in validation -// DetachVolumeOutputBuilder outputBuilder = volumeServiceForDetachAction.detachVolume(mockDetachInput); -// Mockito.verify(volumeServiceForDetachAction, 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(mockDetachInput).getCommonHeader(); -// Mockito.doReturn(mockPayload).when(mockDetachInput).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.DetachVolume).when(mockDetachInput).getAction(); -// Mockito.doReturn(mockAI).when(mockDetachInput).getActionIdentifiers(); -// Mockito.doReturn("vserverId").when(mockAI).getVserverId(); - - // test proceedAction return with error -// outputBuilder = volumeServiceForDetachAction.detachVolume(mockDetachInput); -// Mockito.verify(volumeServiceForDetachAction, times(1)).proceedAction(any(), any(), any()); -// Assert.assertTrue("Should have commonHeader", -// outputBuilder.getCommonHeader() != null); -// Assert.assertEquals("should return rejected status", -// Integer.valueOf(LCMCommandStatus.REJECTED.getResponseCode()), -// outputBuilder.getStatus().getCode()); - - // test proceedAction 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();; -// -// outputBuilder = volumeServiceForDetachAction.detachVolume(mockDetachInput); -// Assert.assertTrue("Should have commonHeader", -// outputBuilder.getCommonHeader() != null); -// Assert.assertEquals("should return success status", -// successCode, outputBuilder.getStatus().getCode()); -// } - @Test public void testValidateForAttachAction() throws Exception { // test commonHeader error |