diff options
Diffstat (limited to 'rulemgt/src/test/java')
-rw-r--r-- | rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java | 24 | ||||
-rw-r--r-- | rulemgt/src/test/java/org/onap/holmes/rulemgt/send/RuleAllocatorTest.java | 10 |
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; |