summaryrefslogtreecommitdiffstats
path: root/appc-oam/appc-oam-bundle/src/test/java/org/openecomp/appc/oam/processor/BaseCommonTest.java
diff options
context:
space:
mode:
authorbeili.zhou <beili.zhou@amdocs.com>2017-08-11 22:55:57 -0400
committerbeili.zhou <beili.zhou@amdocs.com>2017-08-14 13:33:58 -0400
commit891e97b2d53b644b88eb14e2b0cb91d4b3acf930 (patch)
treefc1e3dbfec2bc70bade1bb8e1cab1e44290e71a4 /appc-oam/appc-oam-bundle/src/test/java/org/openecomp/appc/oam/processor/BaseCommonTest.java
parent9adb43f6b764ca4766c43fbdb8afe351f43a24ee (diff)
OAM operations 3 - JUnit tests
OAM operations changes are large, need to be broken down to multiple submission based on size and compilability. This is the third (last) set which covers JUnit test cases. Includes these user stories: APPC-39/41/43/44/45/46/52/77. Issue Id: APPC-38 Change-Id: I2df5e6b371d05030fb18bdd48155e4bb23034997 Signed-off-by: beili.zhou <beili.zhou@amdocs.com>
Diffstat (limited to 'appc-oam/appc-oam-bundle/src/test/java/org/openecomp/appc/oam/processor/BaseCommonTest.java')
-rw-r--r--appc-oam/appc-oam-bundle/src/test/java/org/openecomp/appc/oam/processor/BaseCommonTest.java124
1 files changed, 124 insertions, 0 deletions
diff --git a/appc-oam/appc-oam-bundle/src/test/java/org/openecomp/appc/oam/processor/BaseCommonTest.java b/appc-oam/appc-oam-bundle/src/test/java/org/openecomp/appc/oam/processor/BaseCommonTest.java
new file mode 100644
index 000000000..4e1025781
--- /dev/null
+++ b/appc-oam/appc-oam-bundle/src/test/java/org/openecomp/appc/oam/processor/BaseCommonTest.java
@@ -0,0 +1,124 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+
+package org.openecomp.appc.oam.processor;
+
+import com.att.eelf.configuration.EELFLogger;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.opendaylight.yang.gen.v1.org.openecomp.appc.oam.rev170303.status.Status;
+import org.openecomp.appc.exceptions.InvalidInputException;
+import org.openecomp.appc.exceptions.InvalidStateException;
+import org.openecomp.appc.oam.AppcOam;
+import org.openecomp.appc.oam.OAMCommandStatus;
+import org.openecomp.appc.oam.util.ConfigurationHelper;
+import org.openecomp.appc.oam.util.OperationHelper;
+import org.openecomp.appc.oam.util.StateHelper;
+import org.openecomp.appc.statemachine.impl.readers.AppcOamStates;
+import org.powermock.reflect.Whitebox;
+
+import static org.mockito.Mockito.mock;
+
+public class BaseCommonTest {
+ private class TestAbc extends BaseCommon {
+
+ /**
+ * Constructor
+ *
+ * @param eelfLogger for logging
+ * @param configurationHelperIn for property reading
+ * @param stateHelperIn for APP-C OAM state checking
+ * @param operationHelperIn for operational helper
+ */
+ TestAbc(EELFLogger eelfLogger,
+ ConfigurationHelper configurationHelperIn,
+ StateHelper stateHelperIn,
+ OperationHelper operationHelperIn) {
+ super(eelfLogger, configurationHelperIn, stateHelperIn, operationHelperIn);
+ }
+ }
+
+ private TestAbc testBaseCommon;
+ private ConfigurationHelper mockConfigHelper = mock(ConfigurationHelper.class);
+ private StateHelper mockStateHelper = mock(StateHelper.class);
+
+ @Before
+ public void setUp() throws Exception {
+ testBaseCommon = new TestAbc(null, mockConfigHelper, mockStateHelper, null);
+
+ // to avoid operation on logger fail, mock up the logger
+ EELFLogger mockLogger = mock(EELFLogger.class);
+ Whitebox.setInternalState(testBaseCommon, "logger", mockLogger);
+ }
+
+ @Test
+ public void testSetStatus() throws Exception {
+ OAMCommandStatus oamCommandStatus = OAMCommandStatus.ACCEPTED;
+ testBaseCommon.setStatus(oamCommandStatus);
+ Status status = testBaseCommon.status;
+ Assert.assertEquals("Should have code", oamCommandStatus.getResponseCode(), status.getCode().intValue());
+ Assert.assertEquals("Should have message", oamCommandStatus.getResponseMessage(), status.getMessage());
+ }
+
+ @Test
+ public void testSetStatusWithParams() throws Exception {
+ String message = "testing";
+ OAMCommandStatus oamCommandStatus = OAMCommandStatus.REJECTED;
+ testBaseCommon.setStatus(oamCommandStatus, message);
+ Status status = testBaseCommon.status;
+ Assert.assertEquals("Should have code", oamCommandStatus.getResponseCode(), status.getCode().intValue());
+ Assert.assertTrue("Should have message", status.getMessage().endsWith(message));
+ }
+
+ @Test
+ public void testSetErrorStatus() throws Exception {
+ Mockito.doReturn("testName").when(mockConfigHelper).getAppcName();
+ Mockito.doReturn(AppcOamStates.Started).when(mockStateHelper).getCurrentOamState();
+ Whitebox.setInternalState(testBaseCommon, "rpc", AppcOam.RPC.maintenance_mode);
+
+ String exceptionMessage = "testing";
+
+ OAMCommandStatus oamCommandStatus = OAMCommandStatus.INVALID_PARAMETER;
+ Throwable t = new InvalidInputException(exceptionMessage);
+ testBaseCommon.setErrorStatus(t);
+ Status status = testBaseCommon.status;
+ Assert.assertEquals("Should have code", oamCommandStatus.getResponseCode(), status.getCode().intValue());
+
+ oamCommandStatus = OAMCommandStatus.REJECTED;
+ t = new InvalidStateException(exceptionMessage);
+ testBaseCommon.setErrorStatus(t);
+ status = testBaseCommon.status;
+ Assert.assertEquals("Should have code", oamCommandStatus.getResponseCode(), status.getCode().intValue());
+
+ oamCommandStatus = OAMCommandStatus.UNEXPECTED_ERROR;
+ t = new NullPointerException(exceptionMessage);
+ testBaseCommon.setErrorStatus(t);
+ status = testBaseCommon.status;
+ Assert.assertEquals("Should have code", oamCommandStatus.getResponseCode(), status.getCode().intValue());
+ }
+
+}