Correted UT Coverage Issues 39/65439/1
authorGuangrongFu <fu.guangrong@zte.com.cn>
Mon, 10 Sep 2018 06:47:40 +0000 (14:47 +0800)
committerGuangrongFu <fu.guangrong@zte.com.cn>
Mon, 10 Sep 2018 06:47:40 +0000 (14:47 +0800)
Change-Id: Id89d4c600683646958e7e0b4b2982506e1bf7db4
Issue-ID: HOLMES-159
Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn>
rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java
rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java
rulemgt/src/test/java/org/onap/holmes/rulemgt/send/RuleAllocatorTest.java
rules/ccvpn-rule.drl [moved from rules/ccvnp-rule.drl with 100% similarity]

index 6c0d732..68314e1 100644 (file)
@@ -14,6 +14,7 @@
 package org.onap.holmes.rulemgt.dcae;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 import com.google.gson.JsonDeserializationContext;
@@ -114,7 +115,7 @@ public class DcaeConfigurationPolling implements Runnable {
             httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT);
             HttpResponse httpResponse = HttpsUtils.get(httpGet, headers, httpClient);
             String response = HttpsUtils.extractResponseEntity(httpResponse);
-            return JSON.parseObject(response, RuleQueryListResponse.class);
+            return JSONObject.parseObject(response, RuleQueryListResponse.class);
         } finally {
             httpGet.releaseConnection();
             closeHttpClient(httpClient);
index 52f1e37..4ad213c 100644 (file)
@@ -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,10 +76,16 @@ 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);
@@ -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();
 
index 1815ebb..5dc8281 100644 (file)
@@ -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;
similarity index 100%
rename from rules/ccvnp-rule.drl
rename to rules/ccvpn-rule.drl