summaryrefslogtreecommitdiffstats
path: root/rulemgt/src/test
diff options
context:
space:
mode:
authortang peng <tang.peng5@zte.com.cn>2021-06-02 17:14:36 +0800
committertang peng <tang.peng5@zte.com.cn>2021-06-03 19:45:36 +0800
commit8182df37f0308ad04433a47570e7ca9612fcfd84 (patch)
tree384e0319e8be5c6578192c657f2fb32e9df0517a /rulemgt/src/test
parentc2a7c78225a54445098d666d72c6e84c21ca70ca (diff)
Removed Dependency: httpclient
Issue-ID: HOLMES-414 Signed-off-by: tang peng <tang.peng5@zte.com.cn> Change-Id: I3d7771d25d4bd0f67a2e02373ceb2ec392ad4f40
Diffstat (limited to 'rulemgt/src/test')
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/InitializerTest.java4
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineServiceTest.java91
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java184
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java134
4 files changed, 143 insertions, 270 deletions
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/InitializerTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/InitializerTest.java
index 3f071b3..120aba2 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/InitializerTest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/InitializerTest.java
@@ -28,7 +28,7 @@ import org.powermock.reflect.internal.WhiteboxImpl;
@RunWith(PowerMockRunner.class)
@PrepareForTest(MicroServiceConfig.class)
-@SuppressStaticInitializationFor("org.onap.holmes.common.utils.HttpsUtils")
+@SuppressStaticInitializationFor("org.onap.holmes.common.utils.CommonUtils")
public class InitializerTest {
@Test
@@ -38,7 +38,7 @@ public class InitializerTest {
PowerMock.mockStaticPartial(MicroServiceConfig.class, "getMicroServiceIpAndPort", "getEnv");
EasyMock.expect(MicroServiceConfig.getMicroServiceIpAndPort()).andReturn(new String[]{"127.0.0.1", "443"});
- EasyMock.expect(MicroServiceConfig.getEnv("ENABLE_ENCRYPT")).andReturn("true");
+ System.setProperty("ENABLE_ENCRYPT", "true");
mockedMsbRegister.register2Msb(EasyMock.anyObject(MicroServiceInfo.class));
EasyMock.expectLastCall();
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineServiceTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineServiceTest.java
index e581699..aae62aa 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineServiceTest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineServiceTest.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017 - 2021 ZTE Corporation.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,67 +17,74 @@
package org.onap.holmes.rulemgt.bolt.enginebolt;
-
-import org.apache.http.HttpResponse;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
-import org.onap.holmes.common.utils.HttpsUtils;
+import org.onap.holmes.common.utils.JerseyClient;
+import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;
import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
-import org.powermock.api.easymock.PowerMock;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.reflect.Whitebox;
-
-import java.util.HashMap;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.easymock.EasyMock.*;
import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import static org.powermock.api.easymock.PowerMock.createMock;
+import static org.powermock.api.easymock.PowerMock.*;
-@PrepareForTest({HttpClients.class, CloseableHttpClient.class, HttpsUtils.class})
-@PowerMockIgnore("javax.net.ssl.*")
@RunWith(PowerMockRunner.class)
+@PrepareForTest(EngineService.class)
+@SuppressStaticInitializationFor({"org.onap.holmes.common.utils.JerseyClient"})
public class EngineServiceTest {
- @Rule
- public ExpectedException thrown = ExpectedException.none();
- private EngineService engineService;
- private HttpResponse httpResponseMock;
- private CloseableHttpClient closeableHttpClient;
- private CorrelationDeployRule4Engine correlationDeployRule4Engine;
- private CloseableHttpResponse closeableHttpResponseMock;
+ private EngineService engineService = new EngineService();
+ ;
@Before
- public void setUp() {
- engineService = new EngineService();
- closeableHttpClient = PowerMock.createMock(CloseableHttpClient.class);
- httpResponseMock = PowerMock.createMock(HttpResponse.class);
- closeableHttpResponseMock = PowerMock.createMock(CloseableHttpResponse.class);
- correlationDeployRule4Engine = new CorrelationDeployRule4Engine();
- correlationDeployRule4Engine.setContent("{\"package\":\"test\"}");
- correlationDeployRule4Engine.setEngineId("engine_id");
+ public void setUp() throws Exception {
+ System.setProperty("ENABLE_ENCRYPT", "false");
}
@Test
- public void testEngineService_createHeaders_ok() throws Exception {
- PowerMock.resetAll();
- HashMap<String, String> headers = Whitebox.invokeMethod(engineService, "createHeaders");
- assertThat(headers.get("Content-Type"), equalTo("application/json"));
- assertThat(headers.get("Accept"), equalTo("application/json"));
+ public void delete() throws Exception {
+ JerseyClient client = createMock(JerseyClient.class);
+ expectNew(JerseyClient.class).andReturn(client);
+ expect(client.path(anyString())).andReturn(client);
+ expect(client.delete(anyString())).andReturn("true");
+ replayAll();
+ assertThat(engineService.delete("test", "127.0.0.1"), is(true));
+ verifyAll();
}
@Test
- public void testEngineService_closeHttpClient_ok() throws Exception {
- PowerMock.resetAll();
- CloseableHttpClient closeableHttpClient = HttpsUtils
- .getConditionalHttpsClient(HttpsUtils.DEFUALT_TIMEOUT);
- Whitebox.invokeMethod(engineService, "closeHttpClient", closeableHttpClient);
+ public void check() throws Exception {
+ JerseyClient client = createMock(JerseyClient.class);
+ expectNew(JerseyClient.class).andReturn(client);
+ expect(client.header(anyString(), anyString())).andReturn(client);
+ expect(client.post(anyString(), anyObject())).andReturn("true");
+
+ CorrelationCheckRule4Engine correlationCheckRule4Engine = new CorrelationCheckRule4Engine();
+ correlationCheckRule4Engine.setContent("{\"package\":\"test\"}");
+
+ replayAll();
+ assertThat(engineService.check(correlationCheckRule4Engine, "127.0.0.1"), is(true));
+ verifyAll();
}
+ @Test
+ public void deploy() throws Exception {
+ JerseyClient client = createMock(JerseyClient.class);
+ expectNew(JerseyClient.class).andReturn(client);
+ expect(client.header(anyString(), anyString())).andReturn(client);
+ expect(client.put(anyString(), anyObject())).andReturn("true");
+
+ CorrelationDeployRule4Engine correlationDeployRule4Engine = new CorrelationDeployRule4Engine();
+ correlationDeployRule4Engine.setContent("{\"package\":\"test\"}");
+
+ replayAll();
+ assertThat(engineService.deploy(correlationDeployRule4Engine, "127.0.0.1"), equalTo("true"));
+ verifyAll();
+ }
} \ No newline at end of file
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java
index 7296824..6bfb387 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java
@@ -1,12 +1,12 @@
/**
- * Copyright 2017 ZTE Corporation.
- *
+ * Copyright 2017 - 2021 ZTE Corporation.
+ * <p>
* 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
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* 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.
@@ -17,201 +17,141 @@
package org.onap.holmes.rulemgt.bolt.enginebolt;
-import org.apache.http.HttpResponse;
-import org.apache.http.StatusLine;
-import org.easymock.EasyMock;
+import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.onap.holmes.common.exception.CorrelationException;
-import org.onap.holmes.common.utils.HttpsUtils;
import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;
import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
-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 static org.easymock.EasyMock.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
+import static org.powermock.api.easymock.PowerMock.*;
-@PrepareForTest({EngineWrapper.class, EngineService.class, HttpsUtils.class, HttpResponse.class,
- StatusLine.class})
@RunWith(PowerMockRunner.class)
public class EngineWrapperTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
+
private EngineWrapper engineWrapper = new EngineWrapper();
- private EngineService engineServiceMock;
- private HttpResponse httpResponse;
- private StatusLine statusLineMock;
+
+ private EngineService mockedEngineService;
@Before
- public void setUp() throws Exception {
- engineServiceMock = PowerMock.createMock(EngineService.class);
- httpResponse = PowerMock.createMock(HttpResponse.class);
- statusLineMock = PowerMock.createMock(StatusLine.class);
- Whitebox.setInternalState(engineWrapper, "engineService", engineServiceMock);
+ public void before() {
+ mockedEngineService = createMock(EngineService.class);
+ Whitebox.setInternalState(engineWrapper, "engineService", mockedEngineService);
}
- @Test
- public void deployEngine_invoke_rule_deploy_exception() throws Exception {
- thrown.expect(CorrelationException.class);
- thrown.expectMessage("Failed to call the rule deployment RESTful API.");
-
- EasyMock.expect(
- engineServiceMock.deploy(EasyMock.anyObject(CorrelationDeployRule4Engine.class),
- EasyMock.anyObject(String.class)))
- .andThrow(
- new RuntimeException(""));
- PowerMock.replayAll();
-
- engineWrapper.deployEngine(new CorrelationDeployRule4Engine(),"127.0.0.1");
-
- PowerMock.verifyAll();
+ @After
+ public void after() {
+ resetAll();
}
@Test
- public void deployEngine_http_status_not_ok() throws Exception {
+ public void deployEngine_fail() throws Exception {
thrown.expect(CorrelationException.class);
thrown.expectMessage("Failed to deploy the rule!");
- EasyMock.expect(
- engineServiceMock.deploy(EasyMock.anyObject(CorrelationDeployRule4Engine.class),
- EasyMock.anyObject(String.class)))
- .andReturn(httpResponse);
- EasyMock.expect(httpResponse.getStatusLine()).andReturn(statusLineMock);
- EasyMock.expect(statusLineMock.getStatusCode()).andReturn(400);
- PowerMock.replayAll();
+ expect(mockedEngineService.deploy(anyObject(CorrelationDeployRule4Engine.class),
+ anyObject(String.class))).andReturn(null);
+
+ replayAll();
- engineWrapper.deployEngine(new CorrelationDeployRule4Engine(),"127.0.0.1");
+ engineWrapper.deployEngine(new CorrelationDeployRule4Engine(), "127.0.0.1");
- PowerMock.verifyAll();
+ verifyAll();
}
@Test
public void deployEngine_parse_content_exception() throws Exception {
- PowerMock.resetAll();
- String content = "";
- PowerMock.mockStatic(HttpsUtils.class);
thrown.expect(CorrelationException.class);
thrown.expectMessage(
"Failed to parse the value returned by the engine management service.");
- EasyMock.expect(
- engineServiceMock.deploy(EasyMock.anyObject(CorrelationDeployRule4Engine.class),
- EasyMock.anyObject(String.class)))
- .andReturn(httpResponse);
- EasyMock.expect(httpResponse.getStatusLine()).andReturn(statusLineMock);
- EasyMock.expect(statusLineMock.getStatusCode()).andReturn(200);
- EasyMock.expect(HttpsUtils.extractResponseEntity(httpResponse)).andReturn(content);
- PowerMock.replayAll();
-
- engineWrapper.deployEngine(new CorrelationDeployRule4Engine(),"127.0.0.1");
-
- PowerMock.verifyAll();
- }
+ expect(mockedEngineService.deploy(anyObject(CorrelationDeployRule4Engine.class),
+ anyObject(String.class))).andReturn("");
- @Test
- public void deployEngine_success() throws Exception {
- PowerMock.resetAll();
- String content = "{\"packageName\":\"test\"}";
- PowerMock.mockStatic(HttpsUtils.class);
- EasyMock.expect(
- engineServiceMock.deploy(EasyMock.anyObject(CorrelationDeployRule4Engine.class),
- EasyMock.anyObject(String.class)))
- .andReturn(httpResponse);
- EasyMock.expect(httpResponse.getStatusLine()).andReturn(statusLineMock);
- EasyMock.expect(statusLineMock.getStatusCode()).andReturn(200);
- EasyMock.expect(HttpsUtils.extractResponseEntity(httpResponse)).andReturn(content);
- PowerMock.replayAll();
-
- String result = engineWrapper.deployEngine(new CorrelationDeployRule4Engine(),"127.0.0.1");
+ replayAll();
- assertThat(result, equalTo("test"));
+ engineWrapper.deployEngine(new CorrelationDeployRule4Engine(), "127.0.0.1");
+ verifyAll();
}
@Test
- public void deleteRuleFromEngine_invoke_rule_delete_exception() throws Exception {
- thrown.expect(CorrelationException.class);
- thrown.expectMessage("Failed to call the rule deleting RESTful API.");
+ public void deployEngine_success() throws Exception {
+ String content = "{\"packageName\":\"test\"}";
+ expect(mockedEngineService.deploy(anyObject(CorrelationDeployRule4Engine.class),
+ anyObject(String.class))).andReturn(content);
+
+ replayAll();
- EasyMock.expect(engineServiceMock.delete(EasyMock.anyObject(String.class),
- EasyMock.anyObject(String.class))).andThrow(
- new RuntimeException(""));
- PowerMock.replayAll();
+ String result = engineWrapper.deployEngine(new CorrelationDeployRule4Engine(), "127.0.0.1");
- engineWrapper.deleteRuleFromEngine("","127.0.0.1");
+ assertThat(result, equalTo("test"));
- PowerMock.verifyAll();
}
@Test
- public void deleteRuleFromEngine_http_status_not_ok() throws Exception {
+ public void deleteRuleFromEngine_fail() throws Exception {
thrown.expect(CorrelationException.class);
thrown.expectMessage("Failed to delete the rule!");
- EasyMock.expect(engineServiceMock.delete(EasyMock.anyObject(String.class),
- EasyMock.anyObject(String.class)))
- .andReturn(httpResponse);
- EasyMock.expect(httpResponse.getStatusLine()).andReturn(statusLineMock);
- EasyMock.expect(statusLineMock.getStatusCode()).andReturn(400);
+ expect(mockedEngineService.delete(anyObject(String.class),
+ anyObject(String.class)))
+ .andReturn(false);
- PowerMock.replayAll();
+ replayAll();
- engineWrapper.deleteRuleFromEngine("","127.0.0.1");
+ engineWrapper.deleteRuleFromEngine("", "127.0.0.1");
- PowerMock.verifyAll();
+ verifyAll();
}
@Test
public void deleteRuleFromEngine_success() throws Exception {
- EasyMock.expect(engineServiceMock.delete(EasyMock.anyObject(String.class),
- EasyMock.anyObject(String.class)))
- .andReturn(httpResponse);
- EasyMock.expect(httpResponse.getStatusLine()).andReturn(statusLineMock);
- EasyMock.expect(statusLineMock.getStatusCode()).andReturn(200);
+ expect(mockedEngineService.delete(anyObject(String.class),
+ anyObject(String.class)))
+ .andReturn(true);
- PowerMock.replayAll();
+ replayAll();
- boolean result = engineWrapper.deleteRuleFromEngine("","127.0.0.1");
+ boolean result = engineWrapper.deleteRuleFromEngine("", "127.0.0.1");
assertThat(result, equalTo(true));
}
@Test
- public void checkRuleFromEngine_rule_delete_exception() throws Exception {
+ public void checkRuleFromEngine_fail() throws Exception {
thrown.expect(CorrelationException.class);
- thrown.expectMessage("Failed to call the rule verification RESTful API.");
+ thrown.expectMessage("Failed to verify the rule. The contents of the rule are invalid.");
- EasyMock.expect(
- engineServiceMock.check(EasyMock.anyObject(CorrelationCheckRule4Engine.class),
- EasyMock.anyObject(String.class)))
- .andThrow(
- new RuntimeException(""));
- PowerMock.replayAll();
+ expect(
+ mockedEngineService.check(anyObject(CorrelationCheckRule4Engine.class),
+ anyObject(String.class))).andReturn(false);
+ replayAll();
- engineWrapper.checkRuleFromEngine(new CorrelationCheckRule4Engine(),"127.0.0.1");
+ engineWrapper.checkRuleFromEngine(new CorrelationCheckRule4Engine(), "127.0.0.1");
- PowerMock.verifyAll();
+ verifyAll();
}
@Test
public void checkRuleFromEngine_success() throws Exception {
- EasyMock.expect(
- engineServiceMock.check(EasyMock.anyObject(CorrelationCheckRule4Engine.class),
- EasyMock.anyObject(String.class)))
- .andReturn(httpResponse);
- EasyMock.expect(httpResponse.getStatusLine()).andReturn(statusLineMock);
- EasyMock.expect(statusLineMock.getStatusCode()).andReturn(200);
+ expect(mockedEngineService.check(anyObject(CorrelationCheckRule4Engine.class),anyString())).andReturn(true);
- PowerMock.replayAll();
+ replayAll();
- boolean result = engineWrapper.checkRuleFromEngine(new CorrelationCheckRule4Engine(),"127.0.0.1");
+ boolean result = engineWrapper.checkRuleFromEngine(new CorrelationCheckRule4Engine(), "127.0.0.1");
- assertThat(result, equalTo(true));
+ assertThat(result, is(true));
}
} \ No newline at end of file
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 6b640b2..b6e7149 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
@@ -1,5 +1,5 @@
/**
- * Copyright 2017-2020 ZTE Corporation.
+ * Copyright 2017-2021 ZTE Corporation.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,49 +15,31 @@
*/
package org.onap.holmes.rulemgt.dcae;
-import org.apache.http.HttpResponse;
-import org.apache.http.StatusLine;
-import org.apache.http.client.methods.HttpDelete;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPut;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.junit.After;
-import org.junit.Before;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.onap.holmes.common.dcae.DcaeConfigurationQuery;
import org.onap.holmes.common.dcae.entity.DcaeConfigurations;
import org.onap.holmes.common.dcae.entity.Rule;
-import org.onap.holmes.common.utils.GsonUtil;
-import org.onap.holmes.common.utils.HttpsUtils;
+import org.onap.holmes.common.utils.JerseyClient;
import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse;
import org.onap.holmes.rulemgt.bean.response.RuleResult4API;
+import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.expect;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.easymock.EasyMock.*;
import static org.powermock.api.easymock.PowerMock.*;
-@PrepareForTest({HttpsUtils.class, DcaeConfigurationQuery.class})
-@SuppressStaticInitializationFor("org.onap.holmes.common.utils.HttpsUtils")
@RunWith(PowerMockRunner.class)
+@SuppressStaticInitializationFor("org.onap.holmes.common.utils.JerseyClient")
+@PrepareForTest({DcaeConfigurationPolling.class, DcaeConfigurationQuery.class})
public class DcaeConfigurationPollingTest {
- @org.junit.Rule
- public ExpectedException thrown = ExpectedException.none();
-
-
@Test
public void run() throws Exception {
DcaeConfigurations dcaeConfigurations = new DcaeConfigurations();
@@ -69,7 +51,7 @@ public class DcaeConfigurationPollingTest {
Whitebox.setInternalState(dcaeConfigurationPolling, "url", "http://127.0.0.1");
RuleQueryListResponse ruleQueryListResponse = new RuleQueryListResponse();
- List<RuleResult4API> ruleResult4APIList = new ArrayList<RuleResult4API>(){
+ List<RuleResult4API> ruleResult4APIList = new ArrayList<RuleResult4API>() {
{
add(new RuleResult4API());
}
@@ -77,31 +59,16 @@ public class DcaeConfigurationPollingTest {
ruleQueryListResponse.setCorrelationRules(ruleResult4APIList);
ruleQueryListResponse.setTotalCount(ruleResult4APIList.size());
- CloseableHttpClient clientMock = createMock(CloseableHttpClient.class);
- HttpResponse httpResponseMock = createMock(HttpResponse.class);
- expect(HttpsUtils.getConditionalHttpsClient(30000)).andReturn(clientMock);
- expect(HttpsUtils.get(anyObject(HttpGet.class), anyObject(HashMap.class), anyObject(CloseableHttpClient.class)))
- .andReturn(httpResponseMock);
- expect(HttpsUtils.extractResponseEntity(httpResponseMock)).andReturn(GsonUtil.beanToJson(ruleQueryListResponse));
- clientMock.close();
- expectLastCall();
-
- expect(HttpsUtils.getConditionalHttpsClient(30000)).andReturn(clientMock);
- expect(HttpsUtils.delete(anyObject(HttpDelete.class), anyObject(HashMap.class), anyObject(CloseableHttpClient.class)))
- .andReturn(httpResponseMock);
- clientMock.close();
- expectLastCall();
-
- expect(HttpsUtils.getConditionalHttpsClient(30000)).andReturn(clientMock);
- expect(HttpsUtils.put(anyObject(HttpPut.class), anyObject(HashMap.class), anyObject(HashMap.class),
- anyObject(StringEntity.class), anyObject(CloseableHttpClient.class)))
- .andReturn(httpResponseMock);
- clientMock.close();
- expectLastCall();
-
- StatusLine sl = createMock(StatusLine.class);
- expect(httpResponseMock.getStatusLine()).andReturn(sl);
- expect(sl.getStatusCode()).andReturn(200);
+ JerseyClient mockedJerseyClient = PowerMock.createMock(JerseyClient.class);
+ PowerMock.expectNew(JerseyClient.class).andReturn(mockedJerseyClient);
+ expect(mockedJerseyClient.get(anyString(), anyObject())).andReturn(ruleQueryListResponse);
+
+ PowerMock.expectNew(JerseyClient.class).andReturn(mockedJerseyClient);
+ expect(mockedJerseyClient.delete(anyString())).andReturn("true");
+
+ PowerMock.expectNew(JerseyClient.class).andReturn(mockedJerseyClient);
+ expect(mockedJerseyClient.header(anyString(), anyString())).andReturn(mockedJerseyClient);
+ expect(mockedJerseyClient.put(anyString(), anyObject())).andReturn("true");
replayAll();
@@ -116,38 +83,28 @@ public class DcaeConfigurationPollingTest {
dcaeConfigurations.addDefaultRule(new Rule("test", "clName", "contents", 1));
mockStatic(DcaeConfigurationQuery.class);
expect(DcaeConfigurationQuery.getDcaeConfigurations(anyObject(String.class))).andReturn(dcaeConfigurations).times(2);
- DcaeConfigurationPolling dcaeConfigurationPolling = createPartialMock(DcaeConfigurationPolling.class,
- "getAllCorrelationRules");
+ DcaeConfigurationPolling dcaeConfigurationPolling = new DcaeConfigurationPolling("localhost");
+
Whitebox.setInternalState(dcaeConfigurationPolling, "url", "http://127.0.0.1");
RuleQueryListResponse ruleQueryListResponse = new RuleQueryListResponse();
- List<RuleResult4API> ruleResult4APIList = new ArrayList<RuleResult4API>(){
+ List<RuleResult4API> ruleResult4APIList = new ArrayList<RuleResult4API>() {
{
add(new RuleResult4API());
}
};
ruleQueryListResponse.setCorrelationRules(ruleResult4APIList);
ruleQueryListResponse.setTotalCount(ruleResult4APIList.size());
- expect(dcaeConfigurationPolling.getAllCorrelationRules()).andReturn(ruleQueryListResponse);
-
- CloseableHttpClient clientMock = createMock(CloseableHttpClient.class);
- HttpResponse httpResponseMock = createMock(HttpResponse.class);
- expect(HttpsUtils.getConditionalHttpsClient(30000)).andReturn(clientMock);
- expect(HttpsUtils.delete(anyObject(HttpDelete.class), anyObject(HashMap.class), anyObject(CloseableHttpClient.class)))
- .andReturn(httpResponseMock);
- clientMock.close();
- expectLastCall();
-
- expect(HttpsUtils.getConditionalHttpsClient(30000)).andReturn(clientMock);
- expect(HttpsUtils.put(anyObject(HttpPut.class), anyObject(HashMap.class), anyObject(HashMap.class),
- anyObject(StringEntity.class), anyObject(CloseableHttpClient.class)))
- .andReturn(httpResponseMock);
- clientMock.close();
- expectLastCall();
-
- StatusLine sl = createMock(StatusLine.class);
- expect(httpResponseMock.getStatusLine()).andReturn(sl);
- expect(sl.getStatusCode()).andReturn(200);
+ JerseyClient mockedJerseyClient = PowerMock.createMock(JerseyClient.class);
+ PowerMock.expectNew(JerseyClient.class).andReturn(mockedJerseyClient);
+ expect(mockedJerseyClient.get(anyString(), anyObject())).andReturn(ruleQueryListResponse);
+
+ PowerMock.expectNew(JerseyClient.class).andReturn(mockedJerseyClient);
+ expect(mockedJerseyClient.delete(anyString())).andReturn("true");
+
+ PowerMock.expectNew(JerseyClient.class).andReturn(mockedJerseyClient);
+ expect(mockedJerseyClient.header(anyString(), anyString())).andReturn(mockedJerseyClient);
+ expect(mockedJerseyClient.put(anyString(), anyObject())).andReturn("true");
replayAll();
@@ -156,35 +113,4 @@ public class DcaeConfigurationPollingTest {
verifyAll();
}
-
-
-
- @Test
- public void getAllCorrelationRules() throws Exception {
-
- CloseableHttpClient clientMock = createMock(CloseableHttpClient.class);
- HttpResponse httpResponseMock = createMock(HttpResponse.class);
- expect(HttpsUtils.getConditionalHttpsClient(30000)).andReturn(clientMock);
- expect(HttpsUtils.get(anyObject(HttpGet.class), anyObject(HashMap.class), anyObject(CloseableHttpClient.class)))
- .andReturn(httpResponseMock);
- expect(HttpsUtils.extractResponseEntity(httpResponseMock)).andReturn("{\"correlationRules\": [], \"totalCount\": 0}");
- clientMock.close();
- expectLastCall();
-
- replayAll();
- DcaeConfigurationPolling daceConfigurationPolling = new DcaeConfigurationPolling("holmes-rule-mgmt");
- RuleQueryListResponse response = daceConfigurationPolling.getAllCorrelationRules();
- assertThat(response.getTotalCount(), is(0));
- verifyAll();
- }
-
- @Before
- public void setUp() {
- mockStatic(HttpsUtils.class);
- }
-
- @After
- public void tearDown() {
- resetAll();
- }
} \ No newline at end of file