parent
53af4aeecc
commit
0bbe091762
|
@ -42,6 +42,7 @@
|
|||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>3.2.5.RELEASE</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- for spring end -->
|
||||
<dependency>
|
||||
|
|
|
@ -13,7 +13,7 @@ import org.springframework.test.context.ContextConfiguration;
|
|||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "classpath*:/org/bench4q/agent/config/application-context.xml" })
|
||||
@ContextConfiguration(locations = { "classpath:application-context.xml" })
|
||||
public class Test_ScenarioContext {
|
||||
|
||||
@Test
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
package org.bench4q.agent.test.scenario;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.bench4q.agent.parameterization.SessionObject;
|
||||
import org.bench4q.agent.plugin.basic.PluginReturn;
|
||||
import org.bench4q.agent.plugin.basic.http.HttpReturn;
|
||||
import org.bench4q.agent.scenario.Worker;
|
||||
import org.bench4q.share.helper.TestHelper;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "classpath:application-context.xml" })
|
||||
public class Test_Worker {
|
||||
private SessionObject sessionObject = new SessionObject() {
|
||||
private Map<String, String> runTimeParams = new HashMap<String, String>();
|
||||
|
||||
public String getParam(String name) {
|
||||
return this.runTimeParams.get(name);
|
||||
}
|
||||
|
||||
public void saveRuntimeParam(String name, String value) {
|
||||
}
|
||||
|
||||
public void doCleanUp() {
|
||||
}
|
||||
|
||||
public void saveRuntimeParams(Map<String, String> runTimeParams) {
|
||||
this.runTimeParams.putAll(runTimeParams);
|
||||
}
|
||||
};
|
||||
|
||||
@Test
|
||||
public void testExtractRunTimeParamsWithiNullPluginReturn() {
|
||||
Worker testWorker = createAWorker();
|
||||
try {
|
||||
TestHelper.invokePrivate(testWorker, "extractRunTimeParams",
|
||||
new Class[] { PluginReturn.class }, new Object[] { null });
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtractRunTimeParamsWithNullRunTimeParams() {
|
||||
Worker testWorker = createAWorker();
|
||||
try {
|
||||
HttpReturn httpReturn = new HttpReturn(true, 200, 100, "text/html");
|
||||
httpReturn.setRunTimeParams(null);
|
||||
TestHelper.invokePrivate(testWorker, "extractRunTimeParams",
|
||||
new Class[] { PluginReturn.class },
|
||||
new Object[] { httpReturn });
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtractRunTimeParamsWithZeroRunTimeParams() {
|
||||
Worker testWorker = createAWorker();
|
||||
try {
|
||||
HttpReturn httpReturn = new HttpReturn(true, 200, 100, "text/html");
|
||||
httpReturn.setRunTimeParams(new HashMap<String, String>());
|
||||
TestHelper.invokePrivate(testWorker, "extractRunTimeParams",
|
||||
new Class[] { PluginReturn.class },
|
||||
new Object[] { httpReturn });
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtractRunTimeParamsWithOneRunTimeParams() {
|
||||
Worker testWorker = createAWorker();
|
||||
try {
|
||||
HttpReturn httpReturn = new HttpReturn(true, 200, 100, "text/html");
|
||||
httpReturn.setRunTimeParams(new HashMap<String, String>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
{
|
||||
put("key", "value");
|
||||
}
|
||||
});
|
||||
TestHelper.invokePrivate(testWorker, "extractRunTimeParams",
|
||||
new Class[] { PluginReturn.class },
|
||||
new Object[] { httpReturn });
|
||||
assertEquals("value", this.sessionObject.getParam("key"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
private Worker createAWorker() {
|
||||
return new Worker(null, this.sessionObject);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||
|
||||
<context:component-scan
|
||||
base-package="org.bench4q.agent.helper, org.bench4q.agent.plugin" />
|
||||
<mvc:annotation-driven />
|
||||
|
||||
</beans>
|
Loading…
Reference in New Issue