summaryrefslogtreecommitdiffstats
path: root/rulemgt/src/test/java/org/onap
diff options
context:
space:
mode:
authorGuangrongFu <fu.guangrong@zte.com.cn>2018-09-10 14:47:40 +0800
committerGuangrongFu <fu.guangrong@zte.com.cn>2018-09-10 14:47:40 +0800
commitcc95aa4f9966f014f45e32f177bf622b3ef7a8b7 (patch)
tree55497c4b468736e529ac2c2fd7e5800a09af5e38 /rulemgt/src/test/java/org/onap
parentb8651a1e20797576bb4af8ec672b60a65c215549 (diff)
Correted UT Coverage Issues
Change-Id: Id89d4c600683646958e7e0b4b2982506e1bf7db4 Issue-ID: HOLMES-159 Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn>
Diffstat (limited to 'rulemgt/src/test/java/org/onap')
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java24
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/send/RuleAllocatorTest.java10
2 files changed, 17 insertions, 17 deletions
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java
index 52f1e37..4ad213c 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java
@@ -42,7 +42,6 @@ import org.powermock.reflect.Whitebox;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.expect;
@@ -50,7 +49,7 @@ import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.powermock.api.easymock.PowerMock.*;
-@PrepareForTest({HttpsUtils.class, DcaeConfigurationQuery.class, DcaeConfigurationPolling.class})
+@PrepareForTest({HttpsUtils.class, DcaeConfigurationQuery.class})
@SuppressStaticInitializationFor("org.onap.holmes.common.utils.HttpsUtils")
@RunWith(PowerMockRunner.class)
public class DcaeConfigurationPollingTest {
@@ -58,14 +57,15 @@ public class DcaeConfigurationPollingTest {
@org.junit.Rule
public ExpectedException thrown = ExpectedException.none();
+
@Test
public void run() throws Exception {
DcaeConfigurations dcaeConfigurations = new DcaeConfigurations();
dcaeConfigurations.addDefaultRule(new Rule("test", "clName", "contents", 1));
mockStatic(DcaeConfigurationQuery.class);
expect(DcaeConfigurationQuery.getDcaeConfigurations(anyObject(String.class))).andReturn(dcaeConfigurations);
- DcaeConfigurationPolling dcaeConfigurationPolling = createPartialMock(DcaeConfigurationPolling.class,
- "getAllCorrelationRules");
+ DcaeConfigurationPolling dcaeConfigurationPolling = new DcaeConfigurationPolling("localhost");
+
Whitebox.setInternalState(dcaeConfigurationPolling, "url", "http://127.0.0.1");
RuleQueryListResponse ruleQueryListResponse = new RuleQueryListResponse();
@@ -76,11 +76,17 @@ public class DcaeConfigurationPollingTest {
};
ruleQueryListResponse.setCorrelationRules(ruleResult4APIList);
ruleQueryListResponse.setTotalCount(ruleResult4APIList.size());
- expect(dcaeConfigurationPolling.getAllCorrelationRules()).andReturn(ruleQueryListResponse);
CloseableHttpClient clientMock = createMock(CloseableHttpClient.class);
HttpResponse httpResponseMock = createMock(HttpResponse.class);
expect(HttpsUtils.getHttpClient(30000)).andReturn(clientMock);
+ expect(HttpsUtils.get(anyObject(HttpGet.class), anyObject(HashMap.class), anyObject(CloseableHttpClient.class)))
+ .andReturn(httpResponseMock);
+ expect(HttpsUtils.extractResponseEntity(httpResponseMock)).andReturn(JSONObject.toJSONString(ruleQueryListResponse));
+ clientMock.close();
+ expectLastCall();
+
+ expect(HttpsUtils.getHttpClient(30000)).andReturn(clientMock);
expect(HttpsUtils.delete(anyObject(HttpDelete.class), anyObject(HashMap.class), anyObject(CloseableHttpClient.class)))
.andReturn(httpResponseMock);
clientMock.close();
@@ -155,19 +161,13 @@ public class DcaeConfigurationPollingTest {
@Test
public void getAllCorrelationRules() throws Exception {
- Map<String, Object> responseObj = new HashMap(){
- {
- put("correlationRules", new ArrayList<String>());
- put("totalCount", 0);
- }
- };
CloseableHttpClient clientMock = createMock(CloseableHttpClient.class);
HttpResponse httpResponseMock = createMock(HttpResponse.class);
expect(HttpsUtils.getHttpClient(30000)).andReturn(clientMock);
expect(HttpsUtils.get(anyObject(HttpGet.class), anyObject(HashMap.class), anyObject(CloseableHttpClient.class)))
.andReturn(httpResponseMock);
- expect(HttpsUtils.extractResponseEntity(httpResponseMock)).andReturn(JSONObject.toJSONString(responseObj));
+ expect(HttpsUtils.extractResponseEntity(httpResponseMock)).andReturn("{\"correlationRules\": [], \"totalCount\": 0}");
clientMock.close();
expectLastCall();
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/send/RuleAllocatorTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/send/RuleAllocatorTest.java
index 1815ebb..5dc8281 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/send/RuleAllocatorTest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/send/RuleAllocatorTest.java
@@ -36,7 +36,7 @@ import org.onap.holmes.rulemgt.wrapper.RuleQueryWrapper;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.reflect.Whitebox;
+import org.powermock.modules.junit4.rule.PowerMockRule;
import java.util.ArrayList;
import java.util.Calendar;
@@ -44,18 +44,18 @@ import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.assertThat;
import static org.onap.holmes.rulemgt.send.RuleAllocator.ENABLE;
-@RunWith(PowerMockRunner.class)
@PrepareForTest({ServiceLocator.class, RuleMgtWrapper.class, RuleQueryWrapper.class, EngineWrapper.class,
- EngineInsQueryTool.class, DbDaoUtil.class, RuleAllocator.class, ServiceLocatorHolder.class})
+ EngineInsQueryTool.class, DbDaoUtil.class, ServiceLocatorHolder.class})
public class RuleAllocatorTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
+ @Rule
+ public PowerMockRule rule = new PowerMockRule();
+
private RuleMgtWrapper ruleMgtWrapperMock;
private RuleQueryWrapper ruleQueryWrapperMock;
private EngineWrapper engineWrapperMock;