This commit is contained in:
coderfengyun 2014-01-06 17:15:53 +08:00
parent 4197027d7e
commit 4902a3a8f0
4 changed files with 209 additions and 0 deletions

View File

@ -0,0 +1,5 @@
package org.bench4q.master.entity;
public interface EntityBase {
public Object extractIdentifier();
}

View File

@ -0,0 +1,39 @@
package org.bench4q.master.test.controller;
import static org.junit.Assert.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.xml.bind.JAXBException;
import org.bench4q.master.test.TestBase_MakeUpTestPlan;
import org.bench4q.share.communication.HttpRequester;
import org.bench4q.share.communication.HttpRequester.HttpResponse;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.master.MonitorMemoryResponseModel;
import org.junit.Test;
public class Test_MonitorController extends TestBase_MakeUpTestPlan {
@Test
public void testMemoryInfo() throws IOException, JAXBException {
Map<String, String> params = new HashMap<String, String>();
params.put("testPlanRunId", "90293f23-581a-40a2-93e3-f47035c06242");
params.put("hostName", "127.0.0.1");
params.put("port", "5556");
params.put("duationBegin", "0");
HttpResponse httpResponse = this.httpRequester.sendGet(BASE_URL
+ "/monitorController/memorySUTInfo", params,
makeAccessTockenMap(this.getAccessTocken()));
System.out.println(httpResponse.getContent());
if (HttpRequester.isInvalidResponse(httpResponse)) {
fail("not valid response!");
}
MonitorMemoryResponseModel memoryResponseModel = (MonitorMemoryResponseModel) MarshalHelper
.unmarshal(MonitorMemoryResponseModel.class,
httpResponse.getContent());
assertEquals(3, memoryResponseModel.getMemoryModels().size());
}
}

View File

@ -0,0 +1,115 @@
package org.bench4q.master.test.service;
import static org.junit.Assert.*;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.xml.bind.JAXBException;
import org.bench4q.master.api.modelfactory.BusinessModelMapFactory;
import org.bench4q.master.domain.TestPlanInBusiness;
import org.bench4q.master.entity.User;
import org.bench4q.master.service.infrastructure.MonitorResultService;
import org.bench4q.master.test.TestBase_MakeUpTestPlan;
import org.bench4q.master.test.testplan.TestPlanTester;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.master.TestPlanBusinessModel;
import org.bench4q.share.models.monitor.LogicalDiskModel;
import org.bench4q.share.models.monitor.MemoryModel;
import org.bench4q.share.models.monitor.NetworkInterfaceModel;
import org.bench4q.share.models.monitor.ProcessorModel;
import org.junit.Before;
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 = { "classpath:service-test-context.xml" })
public class Test_MonitorResultService extends TestBase_MakeUpTestPlan {
private MonitorResultService monitorResultService;
private MonitorResultService getMonitorResultService() {
return monitorResultService;
}
@Autowired
private void setMonitorResultService(
MonitorResultService monitorResultService) {
this.monitorResultService = monitorResultService;
}
@Test
public void test() {
assertNotNull(this.getMonitorResultService());
}
@Before
public void makeUpTestPlanAndTestPlanScriptAndTestPlanScriptResult()
throws JAXBException {
UUID testPlanRunId = UUID.randomUUID();
User user = this.getUserService().getUserByName("admin");
this.setScriptId(this.getScriptService().loadScripts(user).get(0)
.getId());
TestPlanBusinessModel model = TestPlanTester.createATestPlan(this
.getScriptId());
TestPlanInBusiness testPlan = BusinessModelMapFactory.toBusiness(model);
this.getTestPlanService().saveTestPlanToDB(testPlan, user,
testPlanRunId, testPlan.getRunningScripts());
this.setTestPlanRunIdUuid(testPlanRunId);
for (int i = 0; i < 3; i++) {
MemoryModel memoryModel = new MemoryModel();
memoryModel.setAvailableKiloBytes(1009);
NetworkInterfaceModel networkInterfaceModel = new NetworkInterfaceModel();
LogicalDiskModel logicalDiskModel = new LogicalDiskModel();
this.getMonitorResultService().saveMonitorResult(testPlanRunId,
MemoryModel.class.getName(),
MarshalHelper.marshal(MemoryModel.class, memoryModel),
new Date(), "127.0.0.1");
this.getMonitorResultService().saveMonitorResult(
testPlanRunId,
NetworkInterfaceModel.class.getName(),
MarshalHelper.marshal(NetworkInterfaceModel.class,
networkInterfaceModel), new Date(), "127.0.0.1");
this.getMonitorResultService().saveMonitorResult(
testPlanRunId,
LogicalDiskModel.class.getName(),
MarshalHelper.marshal(LogicalDiskModel.class,
logicalDiskModel), new Date(), "127.0.0.1");
this.getMonitorResultService().saveMonitorResult(
testPlanRunId,
ProcessorModel.class.getName(),
MarshalHelper.marshal(ProcessorModel.class,
new ProcessorModel()), new Date(), "127.0.0.1");
}
}
@Test
public void testLoadMemoryResults() throws InterruptedException {
Thread.sleep(3000);
List<LogicalDiskModel> logicalDiskModels = this
.getMonitorResultService()
.loadLogicalDiskResults(this.getTestPlanRunIdUuid(),
"127.0.0.1", 5556, 0).getLogicalDiskModels();
List<MemoryModel> memoryModels = this
.getMonitorResultService()
.loadMemoryModels(this.getTestPlanRunIdUuid(), "127.0.0.1",
5556, 0).getMemoryModels();
List<ProcessorModel> processorModels = this
.getMonitorResultService()
.loadProcessorModels(this.getTestPlanRunIdUuid(), "127.0.0.1",
5556, 0).getProcessorModels();
List<NetworkInterfaceModel> networkInterfaceModels = this
.getMonitorResultService()
.loadNetworkInterfaceModels(this.getTestPlanRunIdUuid(),
"127.0.0.1", 5556, 0).getModels();
assertEquals(3, logicalDiskModels.size());
assertEquals(3, memoryModels.size());
assertEquals(3, processorModels.size());
assertEquals(3, networkInterfaceModels.size());
}
}

View File

@ -0,0 +1,50 @@
package org.bench4q.master.test.service;
import static org.junit.Assert.*;
import java.util.List;
import java.util.UUID;
import org.bench4q.master.entity.TestPlanDB;
import org.bench4q.master.service.infrastructure.UserService;
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 = { "classpath:service-test-context.xml" })
public class Test_UserService {
private UserService userService;
private UserService getUserService() {
return userService;
}
@Autowired
private void setUserService(UserService userService) {
this.userService = userService;
}
@Test
public void test() {
assertNotNull(this.getUserService());
}
@Test
public void testQueryTestPlans() {
List<TestPlanDB> testPlanDBs = this.getUserService().querytestPlans(5);
assertNotNull(testPlanDBs);
assertTrue(testPlanDBs.size() > 0);
}
@Test
public void testQueryTestPlan() {
TestPlanDB testPlan = this.getUserService().queryTestPlan(5,
UUID.fromString("ad10a4be-e6e2-4ffc-9282-3ba5c1a1316b"));
assertNotNull(testPlan);
assertEquals(testPlan.getTestPlanRunId().toString(),
"ad10a4be-e6e2-4ffc-9282-3ba5c1a1316b");
}
}