2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * ================================================================================
9 * Modifications (C) 2019 Ericsson
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.provider.lcm.service;
28 import org.junit.Assert;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.mockito.Mockito;
32 import org.mockito.internal.util.reflection.Whitebox;
33 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.*;
34 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers;
35 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader;
36 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.Status;
37 import org.onap.appc.executor.objects.LCMCommandStatus;
39 import static org.mockito.Matchers.any;
40 import static org.mockito.Mockito.mock;
41 import static org.mockito.Mockito.spy;
42 import static org.mockito.Mockito.times;
45 public class ResumeTrafficServiceTest {
46 private CommonHeader mockCommonHeader = mock(CommonHeader.class);
47 private ActionIdentifiers mockAI = mock(ActionIdentifiers.class);
48 private Payload mockPayload = mock(Payload.class);
50 private ResumeTrafficService resumeServiceAction;
52 public void setUp() throws Exception {
53 resumeServiceAction = spy(new ResumeTrafficService());
57 public void testConstructor() throws Exception {
58 Action expectedAction = Action.ResumeTraffic;
59 Assert.assertEquals("Should have proper ACTION", expectedAction,
60 (Action) org.powermock.reflect.Whitebox.getInternalState(resumeServiceAction, "expectedAction"));
61 Assert.assertEquals("Should have resume-traffic RPC name", "resume-traffic",
62 (org.powermock.reflect.Whitebox.getInternalState(resumeServiceAction, "rpcName")).toString());
66 public void testValidate() throws Exception {
67 resumeServiceAction.validate(mockCommonHeader, Action.ResumeTraffic, mockAI,mockPayload);
68 Status status = (Status) Whitebox.getInternalState(resumeServiceAction, "status");
69 Assert.assertEquals("should return missing parameter",
70 Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
71 Mockito.verify(resumeServiceAction, times(0)).buildStatusForParamName(any(), any());
72 Mockito.verify(resumeServiceAction, times(0)).buildStatusForErrorMsg(any(), any());
74 ZULU mockTimeStamp = mock(ZULU.class);
75 Mockito.doReturn(mockTimeStamp).when(mockCommonHeader).getTimestamp();
76 Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
77 Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
78 Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
81 resumeServiceAction.validate(mockCommonHeader, Action.ResumeTraffic, mockAI,mockPayload);
82 status = (Status) Whitebox.getInternalState(resumeServiceAction, "status");
83 Assert.assertEquals("Should return missing parameter for action",
84 Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
86 // test empty ActionIdentifier
87 resumeServiceAction.validate(mockCommonHeader, Action.ResumeTraffic, mockAI,mockPayload);
88 status = (Status) Whitebox.getInternalState(resumeServiceAction, "status");
89 Assert.assertEquals("should return missing parameter",
90 Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
92 // test Invalid VNF_ID
93 Mockito.doReturn("").when(mockAI).getVnfId();
94 resumeServiceAction.validate(mockCommonHeader, Action.ResumeTraffic, mockAI,mockPayload);
95 status = (Status) Whitebox.getInternalState(resumeServiceAction, "status");
96 Assert.assertEquals("should return invalid parameter",
97 Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode());
99 Mockito.doReturn("vnfId").when(mockAI).getVnfId();
100 resumeServiceAction.validate(mockCommonHeader, Action.ResumeTraffic, mockAI, null);
101 Mockito.verify(resumeServiceAction, times(1)).validateExcludedActIds(any(), any());
102 status = (Status) Whitebox.getInternalState(resumeServiceAction, "status");
103 Assert.assertEquals("should return missing parameter",
104 Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
106 // test empty payload
107 Mockito.doReturn("").when(mockPayload).getValue();
108 resumeServiceAction.validate(mockCommonHeader, Action.ResumeTraffic, mockAI, mockPayload);
109 status = (Status) Whitebox.getInternalState(resumeServiceAction, "status");
110 Assert.assertEquals("should return invalid parameter",
111 Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode());
113 // test space payload
114 Mockito.doReturn(null).when(resumeServiceAction).validateMustHaveParamValue(Mockito.anyString(),
115 Mockito.anyString());
116 Mockito.doReturn(" ").when(mockPayload).getValue();
117 resumeServiceAction.validate(mockCommonHeader, Action.ResumeTraffic, mockAI, mockPayload);
118 status = (Status) Whitebox.getInternalState(resumeServiceAction, "status");
119 Assert.assertEquals("should return invalid parameter",
120 Integer.valueOf(LCMCommandStatus.UNEXPECTED_ERROR.getResponseCode()), status.getCode());