refactor agent messager test

This commit is contained in:
fanfuxiaoran 2014-05-20 10:43:24 +08:00
parent 2732b9b3dc
commit 4748bac6be
6 changed files with 44 additions and 28 deletions

View File

@ -11,9 +11,7 @@ import org.bench4q.share.models.master.TestScriptConfig;
import org.bench4q.web.model.TestPlanRequestModel;
import org.bench4q.web.model.TestPlanTaskModel;
import org.bench4q.web.model.WebScriptModel;
import org.springframework.stereotype.Component;
@Component
public class TestPlanService {
public TestPlanModel createTestPlan(TestPlanRequestModel testPlan, int port) {

View File

@ -1 +1 @@
masterAddress=127.0.0.1:7979/
masterAddress=133.133.12.1:7979/

View File

@ -32,8 +32,7 @@ Behavior.prototype.loadBehaviorList = function(plugin) {
var behaviors = null;
$.ajax({
type : "POST",
url : "loadBehaviorList",
data : "pluginName=" + plugin,
url : "loadBehaviorList"+"/"+plugin,
dataType : "json",
async : false,
success : function(response) {

View File

@ -1,69 +1,88 @@
package org.bench4q.web.test.masterMessager;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static org.junit.Assert.*;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.master.AgentModel;
import org.bench4q.share.models.master.AgentResponseModel;
import org.bench4q.web.masterMessager.AgentManagerMessager;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "file:src/test/resources/bench4qweb-servlet.xml" })
public class AgentManagerMessagerTest extends MessagerTestBase{
public class AgentManagerMessagerTest extends MessagerTestBase {
private AgentManagerMessager agentManagerMessager;
private String baseUrl="/agentManage";
private String baseUrl = "/agentManage";
public AgentManagerMessager getAgentManagerMessager() {
return agentManagerMessager;
}
@Autowired
public void setAgentManagerMessager(
AgentManagerMessager agentManagerMessager) {
this.agentManagerMessager = agentManagerMessager;
}
@BeforeClass
public static void setUp(){
public static void setUp() {
startServer();
}
@AfterClass
public static void clear(){
public static void clear() {
stopServer();
}
@Test
public void test_addAgent(){
String url=baseUrl+"/addAgentToPool";
public void test_addAgent() {
String url = baseUrl + "/addAgentToPool";
this.getWireMock().register(
post(urlEqualTo(url)).willReturn(
aResponse().withStatus(200)
.withHeader("Content-Type", "text/xml")
.withBody(this.createResponse())));
assertNotNull(this.agentManagerMessager.addAgent(null, ""));
assertTrue(this.agentManagerMessager.addAgent(null, "").isSuccess());
post(urlEqualTo(url))
.withRequestBody(
equalToXml(MarshalHelper
.tryMarshal(createAgentModel())))
.willReturn(
aResponse()
.withStatus(200)
.withHeader("Content-Type",
"application/xml")
.withBody(this.createResponse())));
assertNotNull(this.agentManagerMessager.addAgent(null,
MarshalHelper.tryMarshal(createAgentModel())));
}
private AgentModel createAgentModel() {
AgentModel agentModel = new AgentModel();
agentModel.setMaxLoad(500);
agentModel.setPort(6565);
return agentModel;
}
@Test
public void test_deleteAgent(){
String url=baseUrl+"/removeAgentFromPool?hostName=&agentId=";
public void test_deleteAgent() {
String url = baseUrl + "/removeAgentFromPool?hostName=&agentId=";
this.getWireMock().register(
get(urlEqualTo(url)).willReturn(
aResponse().withStatus(200)
.withHeader("Content-Type", "text/xml")
.withBody(this.createResponse())));
assertNotNull(this.agentManagerMessager.deleteAgent(null, "", ""));
assertTrue(this.agentManagerMessager.deleteAgent(null, "", "").isSuccess());
assertTrue(this.agentManagerMessager.deleteAgent(null, "", "")
.isSuccess());
}
@Test
public void test_loadAgents(){
String url=baseUrl+"/queryAgentList";
public void test_loadAgents() {
String url = baseUrl + "/queryAgentList";
this.getWireMock().register(
get(urlEqualTo(url)).willReturn(
aResponse().withStatus(200)
@ -72,7 +91,7 @@ public class AgentManagerMessagerTest extends MessagerTestBase{
assertNotNull(this.agentManagerMessager.loadAgents(null));
assertTrue(this.agentManagerMessager.loadAgents(null).isSuccess());
}
private String createResponse() {
AgentResponseModel agentResponseModel = new AgentResponseModel();
agentResponseModel.setSuccess(true);

View File

@ -7,7 +7,7 @@ import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
public abstract class MessagerTestBase {
private static WireMockServer wireMockServer;
private static WireMock wireMock;
private static final int port = 7979;
private static final int port = 6000;
protected static void startServer() {
WireMockConfiguration wmc = new WireMockConfiguration();

View File

@ -1 +1 @@
masterAddress=127.0.0.1:7979
masterAddress=127.0.0.1:6000