aboutsummaryrefslogtreecommitdiffstats
path: root/appc-oam
diff options
context:
space:
mode:
authorJoss Armstrong <joss.armstrong@ericsson.com>2018-12-18 14:59:41 +0000
committerJoss Armstrong <joss.armstrong@ericsson.com>2018-12-18 15:00:42 +0000
commit6feb765e31634cb1041df521b3e8a034223cabab (patch)
treefb941daf92c7de8fc95b1d3080b42014e8d5913c /appc-oam
parent74553eb3428822f57b868e3769ac23d2e7394df4 (diff)
Fix for APPC-1286
Increased test coverage from 49% to 73% for package. Added coverage for 4 classes that were previously at 0% coverage. Refactored slow running code into a method that can be mocked to speed up execution of unit tests. Issue-ID: APPC-1286 Change-Id: I3ebe5f6bfbc59228b57d20a3c45081e40ee8e31e Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
Diffstat (limited to 'appc-oam')
-rw-r--r--appc-oam/appc-oam-bundle/src/main/java/org/onap/appc/oam/processor/BaseCommon.java25
-rw-r--r--appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/BaseActionRunnableTest.java164
-rw-r--r--appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/BaseCommonTest.java6
-rw-r--r--appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/BaseProcessorTest.java4
-rw-r--r--appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/OamMmodeProcessorTest.java116
-rw-r--r--appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/OamRestartProcessorTest.java121
-rw-r--r--appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/OamStartProcessorTest.java121
-rw-r--r--appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/OamStopProcessorTest.java121
8 files changed, 593 insertions, 85 deletions
diff --git a/appc-oam/appc-oam-bundle/src/main/java/org/onap/appc/oam/processor/BaseCommon.java b/appc-oam/appc-oam-bundle/src/main/java/org/onap/appc/oam/processor/BaseCommon.java
index 47f9c9e49..735116d09 100644
--- a/appc-oam/appc-oam-bundle/src/main/java/org/onap/appc/oam/processor/BaseCommon.java
+++ b/appc-oam/appc-oam-bundle/src/main/java/org/onap/appc/oam/processor/BaseCommon.java
@@ -5,6 +5,8 @@
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications (C) 2018 Ericsson
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,6 +44,7 @@ import org.onap.appc.oam.util.StateHelper;
import org.slf4j.MDC;
import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.time.Instant;
import java.util.Arrays;
import java.util.Date;
@@ -129,9 +132,9 @@ public abstract class BaseCommon {
try {
//!!!Don't change the following to a .getHostName() again please. It's wrong!MDC.put(MDC_SERVER_FQDN,
// InetAddress.getLocalHost().getCanonicalHostName());
- MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getCanonicalHostName());
- MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
- MDC.put(LoggingConstants.MDCKeys.SERVER_NAME, InetAddress.getLocalHost().getHostName());
+ MDC.put(MDC_SERVER_FQDN, getHostInfo("canonicalHostName"));
+ MDC.put(MDC_SERVER_IP_ADDRESS, getHostInfo("hostName"));
+ MDC.put(LoggingConstants.MDCKeys.SERVER_NAME, getHostInfo("hostName"));
} catch (Exception e) {
logger.error("MDC constant error", e);
}
@@ -261,4 +264,20 @@ public abstract class BaseCommon {
logger.debug(String.format(message, args));
}
}
+
+ protected String getHostInfo(String type) throws UnknownHostException {
+ InetAddress inetAddress = InetAddress.getLocalHost();
+ String returnValue = "";
+ switch(type) {
+ case "canonicalHostName": returnValue = inetAddress.getCanonicalHostName();
+ break;
+ case "hostName": returnValue = inetAddress.getHostName();
+ break;
+ case "hostAddress": returnValue = inetAddress.getHostAddress();
+ break;
+ default: returnValue = "Invalid operation";
+ break;
+ }
+ return returnValue;
+ }
}
diff --git a/appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/BaseActionRunnableTest.java b/appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/BaseActionRunnableTest.java
index 07bb12ed9..a378638a8 100644
--- a/appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/BaseActionRunnableTest.java
+++ b/appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/BaseActionRunnableTest.java
@@ -5,6 +5,8 @@
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications (C) 2018 Ericsson
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -93,7 +95,7 @@ public class BaseActionRunnableTest {
}
}
- private TestAbc testBaseAcionRunnable;
+ private TestAbc testBaseActionRunnable;
private BaseProcessor testProcessor;
private StateHelper mockStateHelper = mock(StateHelper.class);
private OperationHelper mockOperHelper = mock(OperationHelper.class);
@@ -110,126 +112,127 @@ public class BaseActionRunnableTest {
new TestProcessor(mockLogger, mockConfigHelper, mockStateHelper, null, mockOperHelper));
Whitebox.setInternalState(testProcessor, "bundleHelper", mockBundleHelper);
- testBaseAcionRunnable = spy(new TestAbc(testProcessor));
- Whitebox.setInternalState(testBaseAcionRunnable, "commonHeader", mock(CommonHeader.class));
+ testBaseActionRunnable = spy(new TestAbc(testProcessor));
+ Whitebox.setInternalState(testBaseActionRunnable, "commonHeader", mock(CommonHeader.class));
}
@Test
public void testSetTimeoutValues() throws Exception {
- Whitebox.setInternalState(testBaseAcionRunnable, "timeoutMs", 0);
- Whitebox.setInternalState(testBaseAcionRunnable, "startTimeMs", 0);
- Whitebox.setInternalState(testBaseAcionRunnable, "doTimeoutChecking", false);
+ Whitebox.setInternalState(testBaseActionRunnable, "timeoutMs", 0);
+ Whitebox.setInternalState(testBaseActionRunnable, "startTimeMs", 0);
+ Whitebox.setInternalState(testBaseActionRunnable, "doTimeoutChecking", false);
long expectedTimeout = 10000L;
Mockito.doReturn(expectedTimeout).when(mockConfigHelper).getOAMOperationTimeoutValue(any());
- testBaseAcionRunnable.setTimeoutValues();
- Assert.assertEquals("Should set timeoutMs", expectedTimeout, testBaseAcionRunnable.timeoutMs);
- Assert.assertTrue("Should set start time MS", testBaseAcionRunnable.startTimeMs != 0);
- Assert.assertTrue("Should do check", testBaseAcionRunnable.doTimeoutChecking);
-
- Whitebox.setInternalState(testBaseAcionRunnable, "timeoutMs", 0);
- Whitebox.setInternalState(testBaseAcionRunnable, "startTimeMs", 0);
- Whitebox.setInternalState(testBaseAcionRunnable, "doTimeoutChecking", false);
+ testBaseActionRunnable.setTimeoutValues();
+ Assert.assertEquals("Should set timeoutMs", expectedTimeout, testBaseActionRunnable.timeoutMs);
+ Assert.assertTrue("Should set start time MS", testBaseActionRunnable.startTimeMs != 0);
+ Assert.assertTrue("Should do check", testBaseActionRunnable.doTimeoutChecking);
+
+ Whitebox.setInternalState(testBaseActionRunnable, "timeoutMs", 0);
+ Whitebox.setInternalState(testBaseActionRunnable, "startTimeMs", 0);
+ Whitebox.setInternalState(testBaseActionRunnable, "doTimeoutChecking", false);
expectedTimeout = 20000L;
Mockito.doReturn(expectedTimeout).when(mockConfigHelper).getOAMOperationTimeoutValue(any());
- testBaseAcionRunnable.setTimeoutValues();
- Assert.assertEquals("Should set timeoutMs", expectedTimeout, testBaseAcionRunnable.timeoutMs);
- Assert.assertTrue("Should set start time MS", testBaseAcionRunnable.startTimeMs != 0);
- Assert.assertTrue("Should do check", testBaseAcionRunnable.doTimeoutChecking);
-
- Whitebox.setInternalState(testBaseAcionRunnable, "timeoutMs", 0);
- Whitebox.setInternalState(testBaseAcionRunnable, "startTimeMs", 0);
- Whitebox.setInternalState(testBaseAcionRunnable, "doTimeoutChecking", false);
+ testBaseActionRunnable.setTimeoutValues();
+ Assert.assertEquals("Should set timeoutMs", expectedTimeout, testBaseActionRunnable.timeoutMs);
+ Assert.assertTrue("Should set start time MS", testBaseActionRunnable.startTimeMs != 0);
+ Assert.assertTrue("Should do check", testBaseActionRunnable.doTimeoutChecking);
+
+ Whitebox.setInternalState(testBaseActionRunnable, "timeoutMs", 0);
+ Whitebox.setInternalState(testBaseActionRunnable, "startTimeMs", 0);
+ Whitebox.setInternalState(testBaseActionRunnable, "doTimeoutChecking", false);
expectedTimeout = 0L;
Mockito.doReturn(expectedTimeout).when(mockConfigHelper).getOAMOperationTimeoutValue(any());
- testBaseAcionRunnable.setTimeoutValues();
- Assert.assertEquals("Should set timeoutMs", expectedTimeout, testBaseAcionRunnable.timeoutMs);
- Assert.assertTrue("Should not set start time MS", testBaseAcionRunnable.startTimeMs == 0);
- Assert.assertFalse("Should not do check", testBaseAcionRunnable.doTimeoutChecking);
+ testBaseActionRunnable.setTimeoutValues();
+ Assert.assertEquals("Should set timeoutMs", expectedTimeout, testBaseActionRunnable.timeoutMs);
+ Assert.assertTrue("Should not set start time MS", testBaseActionRunnable.startTimeMs == 0);
+ Assert.assertFalse("Should not do check", testBaseActionRunnable.doTimeoutChecking);
}
@Test
public void testRun() throws Exception {
// test doAction failed
- Whitebox.setInternalState(testBaseAcionRunnable, "doActionResult", false);
- testBaseAcionRunnable.run();
+ Whitebox.setInternalState(testBaseActionRunnable, "doActionResult", false);
+ Mockito.doReturn("SOME HOST NAME").when(testBaseActionRunnable).getHostInfo(Mockito.anyString());
+ testBaseActionRunnable.run();
Assert.assertFalse("isWaiting should still be false",
- Whitebox.getInternalState(testBaseAcionRunnable, "isWaiting"));
+ Whitebox.getInternalState(testBaseActionRunnable, "isWaiting"));
// test doAction success
- Whitebox.setInternalState(testBaseAcionRunnable, "doActionResult", true);
+ Whitebox.setInternalState(testBaseActionRunnable, "doActionResult", true);
// with checkState return true
- Mockito.doReturn(true).when(testBaseAcionRunnable).checkState();
- testBaseAcionRunnable.run();
+ Mockito.doReturn(true).when(testBaseActionRunnable).checkState();
+ testBaseActionRunnable.run();
Assert.assertFalse("isWaiting should still be false",
- Whitebox.getInternalState(testBaseAcionRunnable, "isWaiting"));
+ Whitebox.getInternalState(testBaseActionRunnable, "isWaiting"));
// with checkState return false
- Mockito.doReturn(false).when(testBaseAcionRunnable).checkState();
- testBaseAcionRunnable.run();
+ Mockito.doReturn(false).when(testBaseActionRunnable).checkState();
+ testBaseActionRunnable.run();
Assert.assertTrue("isWaiting should still be true",
- Whitebox.getInternalState(testBaseAcionRunnable, "isWaiting"));
+ Whitebox.getInternalState(testBaseActionRunnable, "isWaiting"));
// should stay
- testBaseAcionRunnable.run();
- Mockito.verify(testBaseAcionRunnable, times(1)).keepWaiting();
+ testBaseActionRunnable.run();
+ Mockito.verify(testBaseActionRunnable, times(1)).keepWaiting();
}
@Test
public void testSetAbortStatus() throws Exception {
- testBaseAcionRunnable.setAbortStatus();
+ testBaseActionRunnable.setAbortStatus();
Assert.assertEquals("Should return abort code", OAMCommandStatus.ABORT.getResponseCode(),
- testBaseAcionRunnable.status.getCode().intValue());
+ testBaseActionRunnable.status.getCode().intValue());
Assert.assertTrue("Should set abort due to execution error message",
- testBaseAcionRunnable.status.getMessage().endsWith(
- String.format(testBaseAcionRunnable.ABORT_MESSAGE_FORMAT,
- testRpc.name(), testBaseAcionRunnable.DUE_TO_EXECUTION_ERROR)));
+ testBaseActionRunnable.status.getMessage().endsWith(
+ String.format(testBaseActionRunnable.ABORT_MESSAGE_FORMAT,
+ testRpc.name(), testBaseActionRunnable.DUE_TO_EXECUTION_ERROR)));
}
@Test
public void testCheckState() throws Exception {
// 1. with isTimeout true
- Mockito.doReturn(true).when(testBaseAcionRunnable).isTimeout("checkState");
- Assert.assertTrue("Should return true", testBaseAcionRunnable.checkState());
+ Mockito.doReturn(true).when(testBaseActionRunnable).isTimeout("checkState");
+ Assert.assertTrue("Should return true", testBaseActionRunnable.checkState());
// 2. with isTimeout false and
- Mockito.doReturn(false).when(testBaseAcionRunnable).isTimeout("checkState");
+ Mockito.doReturn(false).when(testBaseActionRunnable).isTimeout("checkState");
// 2.1 with task not all done
Mockito.doReturn(false).when(mockBundleHelper).isAllTaskDone(any());
- Assert.assertFalse("Should return false", testBaseAcionRunnable.checkState());
+ Assert.assertFalse("Should return false", testBaseActionRunnable.checkState());
// 2. 2 with task all done
Mockito.doReturn(true).when(mockBundleHelper).isAllTaskDone(any());
// 2.2.1 with has bundle failure
- Mockito.doReturn(true).when(testBaseAcionRunnable).hasBundleOperationFailure();
- Assert.assertTrue("Should return true", testBaseAcionRunnable.checkState());
+ Mockito.doReturn(true).when(testBaseActionRunnable).hasBundleOperationFailure();
+ Assert.assertTrue("Should return true", testBaseActionRunnable.checkState());
// 2.2.2 with no bundle failure
- Mockito.doReturn(false).when(testBaseAcionRunnable).hasBundleOperationFailure();
+ Mockito.doReturn(false).when(testBaseActionRunnable).hasBundleOperationFailure();
Mockito.doReturn(targetState).when(mockStateHelper).getBundlesState();
- Assert.assertTrue("Should return true", testBaseAcionRunnable.checkState());
+ Assert.assertTrue("Should return true", testBaseActionRunnable.checkState());
Mockito.doReturn(AppcOamStates.Started).when(mockStateHelper).getBundlesState();
- Assert.assertFalse("Should return false", testBaseAcionRunnable.checkState());
+ Assert.assertFalse("Should return false", testBaseActionRunnable.checkState());
}
@Test
public void testPostAction() throws Exception {
Mockito.doReturn(AppcOamStates.Started).when(mockStateHelper).getCurrentOamState();
// set status to avoid NPE when using status
- testBaseAcionRunnable.setAbortStatus();
+ testBaseActionRunnable.setAbortStatus();
// test no parameter
- testBaseAcionRunnable.postAction(null);
+ testBaseActionRunnable.postAction(null);
Mockito.verify(mockOperHelper, times(1)).sendNotificationMessage(any(), any(), any());
Mockito.verify(mockStateHelper, times(0)).setState(any());
Mockito.verify(testProcessor, times(1)).cancelAsyncTask();
// test with parameter
- testBaseAcionRunnable.postAction(AppcOamStates.Error);
+ testBaseActionRunnable.postAction(AppcOamStates.Error);
Mockito.verify(mockOperHelper, times(2)).sendNotificationMessage(any(), any(), any());
Mockito.verify(mockStateHelper, times(1)).setState(any());
Mockito.verify(testProcessor, times(2)).cancelAsyncTask();
@@ -238,55 +241,56 @@ public class BaseActionRunnableTest {
@Test
public void testIsTimeout() throws Exception {
String parentName = "testing";
- Whitebox.setInternalState(testBaseAcionRunnable, "doTimeoutChecking", false);
- Assert.assertFalse("Should not be timeout", testBaseAcionRunnable.isTimeout(parentName));
+ Whitebox.setInternalState(testBaseActionRunnable, "doTimeoutChecking", false);
+ Assert.assertFalse("Should not be timeout", testBaseActionRunnable.isTimeout(parentName));
Mockito.doReturn(AppcOamStates.Started).when(mockStateHelper).getCurrentOamState();
- Whitebox.setInternalState(testBaseAcionRunnable, "doTimeoutChecking", true);
- Whitebox.setInternalState(testBaseAcionRunnable, "timeoutMs", System.currentTimeMillis() + 100);
- Whitebox.setInternalState(testBaseAcionRunnable, "startTimeMs", 2);
- Assert.assertFalse("Should not be timeout", testBaseAcionRunnable.isTimeout(parentName));
+ Whitebox.setInternalState(testBaseActionRunnable, "doTimeoutChecking", true);
+ Whitebox.setInternalState(testBaseActionRunnable, "timeoutMs", System.currentTimeMillis() + 100);
+ Whitebox.setInternalState(testBaseActionRunnable, "startTimeMs", 2);
+ Assert.assertFalse("Should not be timeout", testBaseActionRunnable.isTimeout(parentName));
long timeoutMs = 1;
- Whitebox.setInternalState(testBaseAcionRunnable, "timeoutMs", timeoutMs);
- Whitebox.setInternalState(testBaseAcionRunnable, "startTimeMs", 2);
- Assert.assertTrue("Should be timeout", testBaseAcionRunnable.isTimeout(parentName));
- Mockito.verify(testBaseAcionRunnable, times(1)).postAction(any());
+ Whitebox.setInternalState(testBaseActionRunnable, "timeoutMs", timeoutMs);
+ Whitebox.setInternalState(testBaseActionRunnable, "startTimeMs", 2);
+ Assert.assertTrue("Should be timeout", testBaseActionRunnable.isTimeout(parentName));
+ Mockito.verify(testBaseActionRunnable, times(1)).postAction(any());
Assert.assertEquals("Should return timeout code", OAMCommandStatus.TIMEOUT.getResponseCode(),
- testBaseAcionRunnable.status.getCode().intValue());
+ testBaseActionRunnable.status.getCode().intValue());
Assert.assertTrue("Should set timeout message",
- testBaseAcionRunnable.status.getMessage().endsWith(
- String.format(testBaseAcionRunnable.TIMEOUT_MESSAGE_FORMAT, testRpc.name(), timeoutMs)));
+ testBaseActionRunnable.status.getMessage().endsWith(
+ String.format(testBaseActionRunnable.TIMEOUT_MESSAGE_FORMAT, testRpc.name(), timeoutMs)));
}
@SuppressWarnings("unchecked")
@Test
public void testHasBundleOperationFailure() throws Exception {
Mockito.when(mockBundleHelper.getFailedMetrics(anyMap())).thenReturn(Long.valueOf("0"));
- Assert.assertFalse("should return false", testBaseAcionRunnable.hasBundleOperationFailure());
+ Assert.assertFalse("should return false", testBaseActionRunnable.hasBundleOperationFailure());
Mockito.when(mockStateHelper.getCurrentOamState()).thenReturn(AppcOamStates.Restarting);
long failedNumber = 1;
Mockito.doReturn(failedNumber).when(mockBundleHelper).getFailedMetrics(anyMap());
- Assert.assertTrue("should return true", testBaseAcionRunnable.hasBundleOperationFailure());
- Mockito.verify(testBaseAcionRunnable, times(1)).setStatus(OAMCommandStatus.UNEXPECTED_ERROR,
- String.format(testBaseAcionRunnable.BUNDLE_OPERATION_FAILED_FORMAT, failedNumber));
- Mockito.verify(testBaseAcionRunnable, times(1)).postAction(AppcOamStates.Error);
+ Assert.assertTrue("should return true", testBaseActionRunnable.hasBundleOperationFailure());
+ Mockito.verify(testBaseActionRunnable, times(1)).setStatus(OAMCommandStatus.UNEXPECTED_ERROR,
+ String.format(testBaseActionRunnable.BUNDLE_OPERATION_FAILED_FORMAT, failedNumber));
+ Mockito.verify(testBaseActionRunnable, times(1)).postAction(AppcOamStates.Error);
}
@Test
public void testAbortRunnable() throws Exception {
Mockito.doReturn(AppcOamStates.Restarting).when(mockStateHelper).getCurrentOamState();
+ Mockito.doReturn("SOME HOST NAME").when(testBaseActionRunnable).getHostInfo(Mockito.anyString());
AppcOam.RPC newRpc = AppcOam.RPC.restart;
- testBaseAcionRunnable.abortRunnable(newRpc);
+ testBaseActionRunnable.abortRunnable(newRpc);
Assert.assertEquals("Should return abort code", OAMCommandStatus.ABORT.getResponseCode(),
- testBaseAcionRunnable.status.getCode().intValue());
+ testBaseActionRunnable.status.getCode().intValue());
Assert.assertTrue("Should set abort due to new request message",
- testBaseAcionRunnable.status.getMessage().endsWith(
- String.format(testBaseAcionRunnable.ABORT_MESSAGE_FORMAT, testRpc.name(),
- String.format(testBaseAcionRunnable.NEW_RPC_OPERATION_REQUEST, newRpc.name()))));
+ testBaseActionRunnable.status.getMessage().endsWith(
+ String.format(testBaseActionRunnable.ABORT_MESSAGE_FORMAT, testRpc.name(),
+ String.format(testBaseActionRunnable.NEW_RPC_OPERATION_REQUEST, newRpc.name()))));
Mockito.verify(mockOperHelper, times(1)).sendNotificationMessage(any(), any(), any());
- Mockito.verify(testBaseAcionRunnable, times(1)).resetLogProperties(false);
- Mockito.verify(testBaseAcionRunnable, times(1)).resetLogProperties(true);
+ Mockito.verify(testBaseActionRunnable, times(1)).resetLogProperties(false);
+ Mockito.verify(testBaseActionRunnable, times(1)).resetLogProperties(true);
}
}
diff --git a/appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/BaseCommonTest.java b/appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/BaseCommonTest.java
index 7b811e9e2..60d9e3c92 100644
--- a/appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/BaseCommonTest.java
+++ b/appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/BaseCommonTest.java
@@ -5,6 +5,8 @@
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications (C) 2018 Ericsson
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,7 +46,6 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
import org.slf4j.MDC;
-
import java.util.Map;
import static org.mockito.Mockito.mock;
@@ -115,6 +116,7 @@ public class BaseCommonTest {
Mockito.doReturn(AppcOamStates.Started).when(mockStateHelper).getCurrentOamState();
Mockito.doReturn("testRequestId").when(mockCommonHeader).getRequestId();
Mockito.doReturn("testOrigId").when(mockCommonHeader).getOriginatorId();
+ Mockito.doReturn("SOME HOST NAME").when(testBaseCommon).getHostInfo(Mockito.anyString());
String exceptionMessage = "testing";
@@ -146,6 +148,7 @@ public class BaseCommonTest {
@Test
public void testSetInitialLogProperties() throws Exception {
mockStatic(MDC.class);
+ Mockito.doReturn("SOME HOST NAME").when(testBaseCommon).getHostInfo(Mockito.anyString());
testBaseCommon.setInitialLogProperties();
PowerMockito.verifyStatic(times(5));
}
@@ -159,6 +162,7 @@ public class BaseCommonTest {
@Test
public void testResetLogProperties() throws Exception {
+ Mockito.doReturn("SOME HOST NAME").when(testBaseCommon).getHostInfo(Mockito.anyString());
testBaseCommon.setInitialLogProperties();
testBaseCommon.resetLogProperties(false);
diff --git a/appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/BaseProcessorTest.java b/appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/BaseProcessorTest.java
index f51541841..55ae11b8d 100644
--- a/appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/BaseProcessorTest.java
+++ b/appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/BaseProcessorTest.java
@@ -5,6 +5,8 @@
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications (C) 2018 Ericsson
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -94,7 +96,7 @@ public class BaseProcessorTest {
testBaseProcessor = spy(
new TestAbc(null, mockConfigHelper, mockStateHelper, mockTaskHelper, mockOperHelper));
-
+ Mockito.doReturn("SOME HOST NAME").when(testBaseProcessor).getHostInfo(Mockito.anyString());
Whitebox.setInternalState(testBaseProcessor, "commonHeader", mockCommonHeader);
// to avoid operation on logger fail, mock up the logger
diff --git a/appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/OamMmodeProcessorTest.java b/appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/OamMmodeProcessorTest.java
new file mode 100644
index 000000000..73b2db975
--- /dev/null
+++ b/appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/OamMmodeProcessorTest.java
@@ -0,0 +1,116 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018 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
+ *
+ * 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=========================================================
+ */
+
+package org.onap.appc.oam.processor;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import java.net.UnknownHostException;
+import java.util.concurrent.TimeoutException;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.appc.exceptions.APPCException;
+import org.onap.appc.exceptions.InvalidInputException;
+import org.onap.appc.exceptions.InvalidStateException;
+import org.onap.appc.i18n.Msg;
+import org.onap.appc.oam.AppcOam;
+import org.onap.appc.oam.util.AsyncTaskHelper;
+import org.onap.appc.oam.util.ConfigurationHelper;
+import org.onap.appc.oam.util.OperationHelper;
+import org.onap.appc.oam.util.StateHelper;
+import org.onap.appc.statemachine.impl.readers.AppcOamStates;
+import org.opendaylight.yang.gen.v1.org.onap.appc.oam.rev170303.StartInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.oam.rev170303.common.header.CommonHeader;
+import org.powermock.reflect.Whitebox;
+import org.onap.appc.requesthandler.LCMStateManager;
+import com.att.eelf.configuration.EELFLogger;
+
+public class OamMmodeProcessorTest {
+
+ private class TestAbc extends OamMmodeProcessor {
+
+ /**
+ * Constructor
+ *
+ * @param eelfLogger for logging
+ * @param configurationHelperIn for property reading
+ * @param stateHelperIn for APP-C OAM state checking
+ * @param asyncTaskHelperIn for scheduling async task
+ * @param operationHelperIn for operational helper
+ */
+ TestAbc(EELFLogger eelfLogger,
+ ConfigurationHelper configurationHelperIn,
+ StateHelper stateHelperIn,
+ AsyncTaskHelper asyncTaskHelperIn,
+ OperationHelper operationHelperIn) {
+ super(eelfLogger, configurationHelperIn, stateHelperIn, asyncTaskHelperIn, operationHelperIn);
+
+ // must set rpc and auditMsg
+ rpc = testRpc;
+ auditMsg = Msg.OAM_OPERATION_STARTING;
+ }
+ }
+
+ private ConfigurationHelper mockConfigHelper = mock(ConfigurationHelper.class);
+ private StateHelper mockStateHelper = mock(StateHelper.class);
+ private AsyncTaskHelper mockTaskHelper = mock(AsyncTaskHelper.class);
+ private OperationHelper mockOperHelper = mock(OperationHelper.class);
+ private AppcOam.RPC testRpc = AppcOam.RPC.start;
+ private AppcOamStates currentState = AppcOamStates.Stopped;
+ private StartInput mockInput = mock(StartInput.class);
+ private CommonHeader mockCommonHeader = mock(CommonHeader.class);
+ private LCMStateManager mockLCMStateManager = mock(LCMStateManager.class);
+
+
+ // to avoid operation on logger fail, mock up the logger
+ EELFLogger mockLogger = mock(EELFLogger.class);
+ private OamMmodeProcessor oamMmodeProcessor = Mockito.spy(new TestAbc(mockLogger, mockConfigHelper, mockStateHelper, mockTaskHelper, mockOperHelper));
+
+ @Before
+ public void setup() throws UnknownHostException, APPCException {
+ Mockito.doReturn("SOME HOST NAME").when(oamMmodeProcessor).getHostInfo(Mockito.anyString());
+ Mockito.doReturn(mockCommonHeader).when(mockOperHelper).getCommonHeader(mockInput);
+ Mockito.doReturn(mockCommonHeader).when(mockInput).getCommonHeader();
+ Mockito.doReturn(mockLCMStateManager).when(mockOperHelper).getService(LCMStateManager.class);
+ Whitebox.setInternalState(oamMmodeProcessor, "commonHeader", mockCommonHeader);
+ }
+
+ @Test
+ public void testPreProcess() throws InvalidInputException, InvalidStateException, APPCException, InterruptedException, TimeoutException {
+ Mockito.doReturn(currentState).when(mockStateHelper).getCurrentOamState();
+ AppcOamStates nextState = AppcOamStates.Starting;
+ Mockito.doReturn(nextState)
+ .when(mockOperHelper).getNextState(testRpc.getAppcOperation(), currentState);
+ oamMmodeProcessor.preProcess(mockInput);
+ Mockito.verify(mockOperHelper, times(1)).isInputValid(mockInput);
+ Mockito.verify(mockOperHelper, times(1)).getNextState(testRpc.getAppcOperation(), currentState);
+ Mockito.verify(mockStateHelper, times(1)).setState(nextState);
+ }
+
+ @Test
+ public void testScheduleAsyncTask() throws Exception {
+ oamMmodeProcessor.scheduleAsyncTask();
+ BaseActionRunnable runnable = Whitebox.getInternalState(oamMmodeProcessor, "runnable");
+ assertTrue(runnable != null);
+ }
+}
diff --git a/appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/OamRestartProcessorTest.java b/appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/OamRestartProcessorTest.java
new file mode 100644
index 000000000..880f466f4
--- /dev/null
+++ b/appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/OamRestartProcessorTest.java
@@ -0,0 +1,121 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018 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
+ *
+ * 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=========================================================
+ */
+
+package org.onap.appc.oam.processor;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import java.net.UnknownHostException;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.appc.exceptions.APPCException;
+import org.onap.appc.i18n.Msg;
+import org.onap.appc.oam.AppcOam;
+import org.onap.appc.oam.AppcOam.RPC;
+import org.onap.appc.oam.util.AsyncTaskHelper;
+import org.onap.appc.oam.util.BundleHelper;
+import org.onap.appc.oam.util.ConfigurationHelper;
+import org.onap.appc.oam.util.OperationHelper;
+import org.onap.appc.oam.util.StateHelper;
+import org.onap.appc.requesthandler.LCMStateManager;
+import org.opendaylight.yang.gen.v1.org.onap.appc.oam.rev170303.RestartInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.oam.rev170303.common.header.CommonHeader;
+import org.powermock.reflect.Whitebox;
+import com.att.eelf.configuration.EELFLogger;
+
+public class OamRestartProcessorTest {
+
+ private class TestAbc extends OamRestartProcessor {
+
+ /**
+ * Constructor
+ *
+ * @param eelfLogger for logging
+ * @param configurationHelperIn for property reading
+ * @param stateHelperIn for APP-C OAM state checking
+ * @param asyncTaskHelperIn for scheduling async task
+ * @param operationHelperIn for operational helper
+ */
+ TestAbc(EELFLogger eelfLogger,
+ ConfigurationHelper configurationHelperIn,
+ StateHelper stateHelperIn,
+ AsyncTaskHelper asyncTaskHelperIn,
+ OperationHelper operationHelperIn) {
+ super(eelfLogger, configurationHelperIn, stateHelperIn, asyncTaskHelperIn, operationHelperIn);
+
+ // must set rpc and auditMsg
+ rpc = testRpc;
+ auditMsg = Msg.OAM_OPERATION_STARTING;
+ }
+ }
+
+ private ConfigurationHelper mockConfigHelper = mock(ConfigurationHelper.class);
+ private StateHelper mockStateHelper = mock(StateHelper.class);
+ private AsyncTaskHelper mockTaskHelper = mock(AsyncTaskHelper.class);
+ private OperationHelper mockOperHelper = mock(OperationHelper.class);
+ private AppcOam.RPC testRpc = AppcOam.RPC.start;
+ private RestartInput mockInput = mock(RestartInput.class);
+ private CommonHeader mockCommonHeader = mock(CommonHeader.class);
+ private LCMStateManager mockLCMStateManager = mock(LCMStateManager.class);
+
+ // to avoid operation on logger fail, mock up the logger
+ EELFLogger mockLogger = mock(EELFLogger.class);
+ private TestAbc oamRestartProcessor;
+
+ @Before
+ public void setup() throws UnknownHostException, APPCException {
+ oamRestartProcessor = Mockito.spy(new TestAbc(mockLogger, mockConfigHelper, mockStateHelper, mockTaskHelper, mockOperHelper));
+ Mockito.doReturn("SOME HOST NAME").when(oamRestartProcessor).getHostInfo(Mockito.anyString());
+ Mockito.doReturn(mockCommonHeader).when(mockOperHelper).getCommonHeader(mockInput);
+ Mockito.doReturn(mockCommonHeader).when(mockInput).getCommonHeader();
+ Mockito.doReturn(mockLCMStateManager).when(mockOperHelper).getService(LCMStateManager.class);
+ Whitebox.setInternalState(oamRestartProcessor, "commonHeader", mockCommonHeader);
+ }
+
+ @Test
+ public void testScheduleAsyncTask() throws Exception {
+ oamRestartProcessor.scheduleAsyncTask();
+ BaseActionRunnable runnable = Whitebox.getInternalState(oamRestartProcessor, "runnable");
+ Whitebox.setInternalState(runnable, "isWaiting", true);
+ assertTrue(runnable != null);
+ }
+
+ @Test
+ public void testDoAction() throws Exception {
+ oamRestartProcessor.scheduleAsyncTask();
+ BaseActionRunnable runnable = Whitebox.getInternalState(oamRestartProcessor, "runnable");
+ Whitebox.setInternalState(runnable, "isWaiting", true);
+ BundleHelper mockBundleHelper = mock(BundleHelper.class);
+ Mockito.doReturn(true).when(mockBundleHelper).bundleOperations(Mockito.any(RPC.class), Mockito.anyMap(), Mockito.any(AsyncTaskHelper.class), Mockito.any(BaseCommon.class));
+ Whitebox.setInternalState(oamRestartProcessor, "bundleHelper", mockBundleHelper);
+ assertTrue(runnable.doAction());
+ Mockito.verify(oamRestartProcessor).getInitialDelayMillis();
+ }
+
+ @Test
+ public void testCheckState() throws Exception {
+ oamRestartProcessor.scheduleAsyncTask();
+ BaseActionRunnable runnable = Whitebox.getInternalState(oamRestartProcessor, "runnable");
+ assertTrue(runnable.checkState());
+ }
+}
+
diff --git a/appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/OamStartProcessorTest.java b/appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/OamStartProcessorTest.java
new file mode 100644
index 000000000..5dc8fab8f
--- /dev/null
+++ b/appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/OamStartProcessorTest.java
@@ -0,0 +1,121 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018 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
+ *
+ * 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=========================================================
+ */
+
+package org.onap.appc.oam.processor;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import java.net.UnknownHostException;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.appc.exceptions.APPCException;
+import org.onap.appc.i18n.Msg;
+import org.onap.appc.oam.AppcOam;
+import org.onap.appc.oam.AppcOam.RPC;
+import org.onap.appc.oam.util.AsyncTaskHelper;
+import org.onap.appc.oam.util.BundleHelper;
+import org.onap.appc.oam.util.ConfigurationHelper;
+import org.onap.appc.oam.util.OperationHelper;
+import org.onap.appc.oam.util.StateHelper;
+import org.onap.appc.requesthandler.LCMStateManager;
+import org.opendaylight.yang.gen.v1.org.onap.appc.oam.rev170303.StartInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.oam.rev170303.common.header.CommonHeader;
+import org.powermock.reflect.Whitebox;
+import com.att.eelf.configuration.EELFLogger;
+
+public class OamStartProcessorTest {
+
+ private class TestAbc extends OamStartProcessor {
+
+ /**
+ * Constructor
+ *
+ * @param eelfLogger for logging
+ * @param configurationHelperIn for property reading
+ * @param stateHelperIn for APP-C OAM state checking
+ * @param asyncTaskHelperIn for scheduling async task
+ * @param operationHelperIn for operational helper
+ */
+ TestAbc(EELFLogger eelfLogger,
+ ConfigurationHelper configurationHelperIn,
+ StateHelper stateHelperIn,
+ AsyncTaskHelper asyncTaskHelperIn,
+ OperationHelper operationHelperIn) {
+ super(eelfLogger, configurationHelperIn, stateHelperIn, asyncTaskHelperIn, operationHelperIn);
+
+ // must set rpc and auditMsg
+ rpc = testRpc;
+ auditMsg = Msg.OAM_OPERATION_STARTING;
+ }
+ }
+
+ private ConfigurationHelper mockConfigHelper = mock(ConfigurationHelper.class);
+ private StateHelper mockStateHelper = mock(StateHelper.class);
+ private AsyncTaskHelper mockTaskHelper = mock(AsyncTaskHelper.class);
+ private OperationHelper mockOperHelper = mock(OperationHelper.class);
+ private AppcOam.RPC testRpc = AppcOam.RPC.start;
+ private StartInput mockInput = mock(StartInput.class);
+ private CommonHeader mockCommonHeader = mock(CommonHeader.class);
+ private LCMStateManager mockLCMStateManager = mock(LCMStateManager.class);
+
+ // to avoid operation on logger fail, mock up the logger
+ EELFLogger mockLogger = mock(EELFLogger.class);
+ private TestAbc oamStartProcessor;
+
+ @Before
+ public void setup() throws UnknownHostException, APPCException {
+ oamStartProcessor = Mockito.spy(new TestAbc(mockLogger, mockConfigHelper, mockStateHelper, mockTaskHelper, mockOperHelper));
+ Mockito.doReturn("SOME HOST NAME").when(oamStartProcessor).getHostInfo(Mockito.anyString());
+ Mockito.doReturn(mockCommonHeader).when(mockOperHelper).getCommonHeader(mockInput);
+ Mockito.doReturn(mockCommonHeader).when(mockInput).getCommonHeader();
+ Mockito.doReturn(mockLCMStateManager).when(mockOperHelper).getService(LCMStateManager.class);
+ Whitebox.setInternalState(oamStartProcessor, "commonHeader", mockCommonHeader);
+ }
+
+ @Test
+ public void testScheduleAsyncTask() throws Exception {
+ oamStartProcessor.scheduleAsyncTask();
+ BaseActionRunnable runnable = Whitebox.getInternalState(oamStartProcessor, "runnable");
+ Whitebox.setInternalState(runnable, "isWaiting", true);
+ assertTrue(runnable != null);
+ }
+
+ @Test
+ public void testDoAction() throws Exception {
+ oamStartProcessor.scheduleAsyncTask();
+ BaseActionRunnable runnable = Whitebox.getInternalState(oamStartProcessor, "runnable");
+ Whitebox.setInternalState(runnable, "isWaiting", true);
+ BundleHelper mockBundleHelper = mock(BundleHelper.class);
+ Mockito.doReturn(true).when(mockBundleHelper).bundleOperations(Mockito.any(RPC.class), Mockito.anyMap(), Mockito.any(AsyncTaskHelper.class), Mockito.any(BaseCommon.class));
+ Whitebox.setInternalState(oamStartProcessor, "bundleHelper", mockBundleHelper);
+ assertTrue(runnable.doAction());
+ Mockito.verify(oamStartProcessor).getInitialDelayMillis();
+ }
+
+ @Test
+ public void testCheckState() throws Exception {
+ oamStartProcessor.scheduleAsyncTask();
+ BaseActionRunnable runnable = Whitebox.getInternalState(oamStartProcessor, "runnable");
+ assertFalse(runnable.checkState());
+ }
+}
diff --git a/appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/OamStopProcessorTest.java b/appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/OamStopProcessorTest.java
new file mode 100644
index 000000000..562dd155c
--- /dev/null
+++ b/appc-oam/appc-oam-bundle/src/test/java/org/onap/appc/oam/processor/OamStopProcessorTest.java
@@ -0,0 +1,121 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018 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
+ *
+ * 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=========================================================
+ */
+
+package org.onap.appc.oam.processor;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import java.net.UnknownHostException;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.appc.exceptions.APPCException;
+import org.onap.appc.i18n.Msg;
+import org.onap.appc.oam.AppcOam;
+import org.onap.appc.oam.AppcOam.RPC;
+import org.onap.appc.oam.util.AsyncTaskHelper;
+import org.onap.appc.oam.util.BundleHelper;
+import org.onap.appc.oam.util.ConfigurationHelper;
+import org.onap.appc.oam.util.OperationHelper;
+import org.onap.appc.oam.util.StateHelper;
+import org.onap.appc.requesthandler.LCMStateManager;
+import org.opendaylight.yang.gen.v1.org.onap.appc.oam.rev170303.StopInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.oam.rev170303.common.header.CommonHeader;
+import org.powermock.reflect.Whitebox;
+import com.att.eelf.configuration.EELFLogger;
+
+public class OamStopProcessorTest {
+
+ private class TestAbc extends OamStopProcessor {
+
+ /**
+ * Constructor
+ *
+ * @param eelfLogger for logging
+ * @param configurationHelperIn for property reading
+ * @param stateHelperIn for APP-C OAM state checking
+ * @param asyncTaskHelperIn for scheduling async task
+ * @param operationHelperIn for operational helper
+ */
+ TestAbc(EELFLogger eelfLogger,
+ ConfigurationHelper configurationHelperIn,
+ StateHelper stateHelperIn,
+ AsyncTaskHelper asyncTaskHelperIn,
+ OperationHelper operationHelperIn) {
+ super(eelfLogger, configurationHelperIn, stateHelperIn, asyncTaskHelperIn, operationHelperIn);
+
+ // must set rpc and auditMsg
+ rpc = testRpc;
+ auditMsg = Msg.OAM_OPERATION_STARTING;
+ }
+ }
+
+ private ConfigurationHelper mockConfigHelper = mock(ConfigurationHelper.class);
+ private StateHelper mockStateHelper = mock(StateHelper.class);
+ private AsyncTaskHelper mockTaskHelper = mock(AsyncTaskHelper.class);
+ private OperationHelper mockOperHelper = mock(OperationHelper.class);
+ private AppcOam.RPC testRpc = AppcOam.RPC.start;
+ private StopInput mockInput = mock(StopInput.class);
+ private CommonHeader mockCommonHeader = mock(CommonHeader.class);
+ private LCMStateManager mockLCMStateManager = mock(LCMStateManager.class);
+
+ // to avoid operation on logger fail, mock up the logger
+ EELFLogger mockLogger = mock(EELFLogger.class);
+ private TestAbc oamStopProcessor;
+
+ @Before
+ public void setup() throws UnknownHostException, APPCException {
+ oamStopProcessor = Mockito.spy(new TestAbc(mockLogger, mockConfigHelper, mockStateHelper, mockTaskHelper, mockOperHelper));
+ Mockito.doReturn("SOME HOST NAME").when(oamStopProcessor).getHostInfo(Mockito.anyString());
+ Mockito.doReturn(mockCommonHeader).when(mockOperHelper).getCommonHeader(mockInput);
+ Mockito.doReturn(mockCommonHeader).when(mockInput).getCommonHeader();
+ Mockito.doReturn(mockLCMStateManager).when(mockOperHelper).getService(LCMStateManager.class);
+ Whitebox.setInternalState(oamStopProcessor, "commonHeader", mockCommonHeader);
+ }
+
+ @Test
+ public void testScheduleAsyncTask() throws Exception {
+ oamStopProcessor.scheduleAsyncTask();
+ BaseActionRunnable runnable = Whitebox.getInternalState(oamStopProcessor, "runnable");
+ Whitebox.setInternalState(runnable, "isWaiting", true);
+ assertTrue(runnable != null);
+ }
+
+ @Test
+ public void testDoAction() throws Exception {
+ oamStopProcessor.scheduleAsyncTask();
+ BaseActionRunnable runnable = Whitebox.getInternalState(oamStopProcessor, "runnable");
+ Whitebox.setInternalState(runnable, "isWaiting", true);
+ BundleHelper mockBundleHelper = mock(BundleHelper.class);
+ Mockito.doReturn(true).when(mockBundleHelper).bundleOperations(Mockito.any(RPC.class), Mockito.anyMap(), Mockito.any(AsyncTaskHelper.class), Mockito.any(BaseCommon.class));
+ Whitebox.setInternalState(oamStopProcessor, "bundleHelper", mockBundleHelper);
+ assertTrue(runnable.doAction());
+ Mockito.verify(oamStopProcessor).getInitialDelayMillis();
+ }
+
+ @Test
+ public void testCheckState() throws Exception {
+ oamStopProcessor.scheduleAsyncTask();
+ BaseActionRunnable runnable = Whitebox.getInternalState(oamStopProcessor, "runnable");
+ assertFalse(runnable.checkState());
+ }
+}