diff options
author | youbowu <wu.youbo@zte.com.cn> | 2017-03-13 15:54:30 +0800 |
---|---|---|
committer | 6092002067 <wu.youbo@zte.com.cn> | 2017-03-13 15:54:30 +0800 |
commit | aac5a54d21387217b99285d46cd6dcd9bdef1555 (patch) | |
tree | 69484180cb53cebd63f550ef2ffefcefdd8360f4 /rulemgt/src/test/java/org | |
parent | 4c39f7390aebf3f8c6ca3b072dce0514a6cf8f99 (diff) |
Change the Way to Invoke HTTP Requests
Change-Id: Ide3962f548e619c4cdeee416b02c1cda2b2d9b9a
Issue-ID: HOLMES-50
Signed-off-by: youbowu <wu.youbo@zte.com.cn>
Diffstat (limited to 'rulemgt/src/test/java/org')
-rw-r--r-- | rulemgt/src/test/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineServiceTest.java | 39 | ||||
-rw-r--r-- | rulemgt/src/test/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java | 44 |
2 files changed, 17 insertions, 66 deletions
diff --git a/rulemgt/src/test/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineServiceTest.java b/rulemgt/src/test/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineServiceTest.java index 3b1c9bd..f4275eb 100644 --- a/rulemgt/src/test/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineServiceTest.java +++ b/rulemgt/src/test/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineServiceTest.java @@ -20,15 +20,11 @@ package org.openo.holmes.rulemgt.bolt.enginebolt; import org.apache.http.HttpResponse;
import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpPut;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
-import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Rule;
-import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.openo.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;
import org.openo.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
@@ -57,39 +53,4 @@ public class EngineServiceTest { correlationDeployRule4Engine.setContent("{\"package\":\"test\"}");
correlationDeployRule4Engine.setEngineId("engine_id");
}
-
- @Test
- public void getResponseContent_http_entity_is_null() throws Exception {
- EasyMock.expect(httpResponseMock.getEntity()).andReturn(null);
- PowerMock.replayAll();
-
- engineService.getResponseContent(httpResponseMock);
-
- PowerMock.verifyAll();
- }
-
- @Test
- public void delete_exception() throws Exception {
- thrown.expect(Exception.class);
-
- engineService.delete("test");
-
- }
-
- @Test
- public void deploy_exception() throws Exception {
-
- thrown.expect(Exception.class);
-
- engineService.deploy(correlationDeployRule4Engine);
-
- }
-
- @Test
- public void check_normal() throws Exception {
- thrown.expect(Exception.class);
-
- engineService.check(new CorrelationCheckRule4Engine());
-
- }
}
\ No newline at end of file diff --git a/rulemgt/src/test/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java b/rulemgt/src/test/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java index 7746394..fe7696b 100644 --- a/rulemgt/src/test/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java +++ b/rulemgt/src/test/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java @@ -20,7 +20,7 @@ package org.openo.holmes.rulemgt.bolt.enginebolt; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
-import org.apache.http.HttpResponse;
+import javax.ws.rs.core.Response;
import org.apache.http.StatusLine;
import org.easymock.EasyMock;
import org.junit.Before;
@@ -40,13 +40,13 @@ public class EngineWrapperTest { public ExpectedException thrown = ExpectedException.none();
private EngineWrapper engineWrapper = new EngineWrapper();
private EngineService engineServiceMock;
- private HttpResponse httpResponseMock;
+ private Response response;
private StatusLine statusLineMock;
@Before
public void setUp() throws Exception {
engineServiceMock = PowerMock.createMock(EngineService.class);
- httpResponseMock = PowerMock.createMock(HttpResponse.class);
+ response = PowerMock.createMock(Response.class);
statusLineMock = PowerMock.createMock(StatusLine.class);
Whitebox.setInternalState(engineWrapper, "engineService", engineServiceMock);
}
@@ -71,10 +71,8 @@ public class EngineWrapperTest { thrown.expectMessage(I18nProxy.ENGINE_DEPLOY_RULE_FAILED);
EasyMock.expect(engineServiceMock.deploy(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))
- .andReturn(httpResponseMock);
- EasyMock.expect(httpResponseMock.getStatusLine()).andReturn(statusLineMock);
- EasyMock.expect(statusLineMock.getStatusCode()).andReturn(400);
-
+ .andReturn(response);
+ EasyMock.expect(response.getStatus()).andReturn(400);
PowerMock.replayAll();
engineWrapper.deployEngine(new CorrelationDeployRule4Engine());
@@ -89,12 +87,9 @@ public class EngineWrapperTest { thrown.expect(CorrelationException.class);
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_PARSE_DEPLOY_RESULT_ERROR);
EasyMock.expect(engineServiceMock.deploy(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))
- .andReturn(httpResponseMock);
- EasyMock.expect(httpResponseMock.getStatusLine()).andReturn(statusLineMock);
- EasyMock.expect(statusLineMock.getStatusCode()).andReturn(200);
- EasyMock.expect(engineServiceMock.getResponseContent(EasyMock.anyObject(HttpResponse.class)))
- .andReturn(content);
-
+ .andReturn(response);
+ EasyMock.expect(response.getStatus()).andReturn(200);
+ EasyMock.expect(response.readEntity(String.class)).andReturn(content);
PowerMock.replayAll();
engineWrapper.deployEngine(new CorrelationDeployRule4Engine());
@@ -106,11 +101,9 @@ public class EngineWrapperTest { public void deployEngine_success() throws Exception {
String content = "{\"package\":\"test\"}";
EasyMock.expect(engineServiceMock.deploy(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))
- .andReturn(httpResponseMock);
- EasyMock.expect(httpResponseMock.getStatusLine()).andReturn(statusLineMock);
- EasyMock.expect(statusLineMock.getStatusCode()).andReturn(200);
- EasyMock.expect(engineServiceMock.getResponseContent(EasyMock.anyObject(HttpResponse.class)))
- .andReturn(content);
+ .andReturn(response);
+ EasyMock.expect(response.getStatus()).andReturn(200);
+ EasyMock.expect(response.readEntity(String.class)).andReturn(content);
PowerMock.replayAll();
String result = engineWrapper.deployEngine(new CorrelationDeployRule4Engine());
@@ -139,9 +132,8 @@ public class EngineWrapperTest { thrown.expectMessage(I18nProxy.ENGINE_DELETE_RULE_FAILED);
EasyMock.expect(engineServiceMock.delete(EasyMock.anyObject(String.class)))
- .andReturn(httpResponseMock);
- EasyMock.expect(httpResponseMock.getStatusLine()).andReturn(statusLineMock);
- EasyMock.expect(statusLineMock.getStatusCode()).andReturn(400);
+ .andReturn(response);
+ EasyMock.expect(response.getStatus()).andReturn(400);
PowerMock.replayAll();
@@ -153,9 +145,8 @@ public class EngineWrapperTest { @Test
public void deleteRuleFromEngine_success() throws Exception {
EasyMock.expect(engineServiceMock.delete(EasyMock.anyObject(String.class)))
- .andReturn(httpResponseMock);
- EasyMock.expect(httpResponseMock.getStatusLine()).andReturn(statusLineMock);
- EasyMock.expect(statusLineMock.getStatusCode()).andReturn(200);
+ .andReturn(response);
+ EasyMock.expect(response.getStatus()).andReturn(200);
PowerMock.replayAll();
@@ -181,9 +172,8 @@ public class EngineWrapperTest { @Test
public void checkRuleFromEngine_success() throws Exception {
EasyMock.expect(engineServiceMock.check(EasyMock.anyObject(CorrelationCheckRule4Engine.class)))
- .andReturn(httpResponseMock);
- EasyMock.expect(httpResponseMock.getStatusLine()).andReturn(statusLineMock);
- EasyMock.expect(statusLineMock.getStatusCode()).andReturn(200);
+ .andReturn(response);
+ EasyMock.expect(response.getStatus()).andReturn(200);
PowerMock.replayAll();
|