2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
26 package org.openecomp.appc.oam.processor;
28 import com.att.eelf.configuration.EELFLogger;
29 import org.junit.Assert;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.mockito.Mockito;
33 import org.opendaylight.yang.gen.v1.org.openecomp.appc.oam.rev170303.status.Status;
34 import org.openecomp.appc.exceptions.InvalidInputException;
35 import org.openecomp.appc.exceptions.InvalidStateException;
36 import org.openecomp.appc.oam.AppcOam;
37 import org.openecomp.appc.oam.OAMCommandStatus;
38 import org.openecomp.appc.oam.util.ConfigurationHelper;
39 import org.openecomp.appc.oam.util.OperationHelper;
40 import org.openecomp.appc.oam.util.StateHelper;
41 import org.openecomp.appc.statemachine.impl.readers.AppcOamStates;
42 import org.powermock.reflect.Whitebox;
44 import static org.mockito.Mockito.mock;
46 public class BaseCommonTest {
47 private class TestAbc extends BaseCommon {
52 * @param eelfLogger for logging
53 * @param configurationHelperIn for property reading
54 * @param stateHelperIn for APP-C OAM state checking
55 * @param operationHelperIn for operational helper
57 TestAbc(EELFLogger eelfLogger,
58 ConfigurationHelper configurationHelperIn,
59 StateHelper stateHelperIn,
60 OperationHelper operationHelperIn) {
61 super(eelfLogger, configurationHelperIn, stateHelperIn, operationHelperIn);
65 private TestAbc testBaseCommon;
66 private ConfigurationHelper mockConfigHelper = mock(ConfigurationHelper.class);
67 private StateHelper mockStateHelper = mock(StateHelper.class);
70 public void setUp() throws Exception {
71 testBaseCommon = new TestAbc(null, mockConfigHelper, mockStateHelper, null);
73 // to avoid operation on logger fail, mock up the logger
74 EELFLogger mockLogger = mock(EELFLogger.class);
75 Whitebox.setInternalState(testBaseCommon, "logger", mockLogger);
79 public void testSetStatus() throws Exception {
80 OAMCommandStatus oamCommandStatus = OAMCommandStatus.ACCEPTED;
81 testBaseCommon.setStatus(oamCommandStatus);
82 Status status = testBaseCommon.status;
83 Assert.assertEquals("Should have code", oamCommandStatus.getResponseCode(), status.getCode().intValue());
84 Assert.assertEquals("Should have message", oamCommandStatus.getResponseMessage(), status.getMessage());
88 public void testSetStatusWithParams() throws Exception {
89 String message = "testing";
90 OAMCommandStatus oamCommandStatus = OAMCommandStatus.REJECTED;
91 testBaseCommon.setStatus(oamCommandStatus, message);
92 Status status = testBaseCommon.status;
93 Assert.assertEquals("Should have code", oamCommandStatus.getResponseCode(), status.getCode().intValue());
94 Assert.assertTrue("Should have message", status.getMessage().endsWith(message));
98 public void testSetErrorStatus() throws Exception {
99 Mockito.doReturn("testName").when(mockConfigHelper).getAppcName();
100 Mockito.doReturn(AppcOamStates.Started).when(mockStateHelper).getCurrentOamState();
101 Whitebox.setInternalState(testBaseCommon, "rpc", AppcOam.RPC.maintenance_mode);
103 String exceptionMessage = "testing";
105 OAMCommandStatus oamCommandStatus = OAMCommandStatus.INVALID_PARAMETER;
106 Throwable t = new InvalidInputException(exceptionMessage);
107 testBaseCommon.setErrorStatus(t);
108 Status status = testBaseCommon.status;
109 Assert.assertEquals("Should have code", oamCommandStatus.getResponseCode(), status.getCode().intValue());
111 oamCommandStatus = OAMCommandStatus.REJECTED;
112 t = new InvalidStateException(exceptionMessage);
113 testBaseCommon.setErrorStatus(t);
114 status = testBaseCommon.status;
115 Assert.assertEquals("Should have code", oamCommandStatus.getResponseCode(), status.getCode().intValue());
117 oamCommandStatus = OAMCommandStatus.UNEXPECTED_ERROR;
118 t = new NullPointerException(exceptionMessage);
119 testBaseCommon.setErrorStatus(t);
120 status = testBaseCommon.status;
121 Assert.assertEquals("Should have code", oamCommandStatus.getResponseCode(), status.getCode().intValue());