refactor the test

refactor the test
This commit is contained in:
coderfengyun 2014-05-12 14:54:08 +08:00
parent 9fa7b989c8
commit c5f537ee40
8 changed files with 74 additions and 24 deletions

View File

@ -106,7 +106,7 @@ public class Script {
System.out.println(folderPath);
FileHelper.guardFolderExist(folderPath);
if (paramFiles == null) {
return false;
return true;
}
for (MultipartFile multipartFile : paramFiles) {
try {

View File

@ -90,6 +90,9 @@ public class AgentRepository extends AbstractRepositoty {
}
public boolean Update(Collection<Agent> poolToUpdate) {
if (poolToUpdate.size() == 0) {
return true;
}
Session session = this.getSessionHelper().openSession();
Transaction transaction = session.beginTransaction();
try {

View File

@ -27,4 +27,5 @@ public class MarshallerTest {
System.out.println(input.getLoadInUse());
assertTrue(input.getLoadInUse() == output.getLoadInUse());
}
}

View File

@ -77,13 +77,17 @@ public class Test_ScriptService {
@Test
public void testSaveScriptWithDefinedParameters() throws IOException {
User user = this.getUserRepository().getUser("admin");
User user = this.getUserForTest();
String fileSeparator = System.getProperty("file.separator");
this.getScriptService().saveScript(
"HBaseScript",
assertTrue(this.getScriptService().saveScript(
"goodRecord",
user.getId(),
FileUtils.readFileToString(new File("Scripts" + fileSeparator
+ "HBaseScript.xml")), null);
+ "forGoodRecord.xml")), null));
}
private void guardAdminExist() {
this.getUserService().register("admin", "admin", (byte) 1);
}
private boolean doSaveAScript(User user) throws JAXBException {
@ -96,6 +100,7 @@ public class Test_ScriptService {
@Before
public void prepare() {
guardAdminExist();
this.getUserService().register("test1", "test1", (byte) 1);
this.setUserForTest(this.getUserRepository().getUser("test1"));
}

View File

@ -2,8 +2,12 @@ package org.bench4q.master.unitTest.service.auth;
import static org.junit.Assert.*;
import org.bench4q.master.domain.repository.UserRepository;
import org.bench4q.master.domain.service.UserService;
import org.bench4q.master.domain.service.auth.AccessToken;
import org.bench4q.master.domain.service.auth.AuthenticationManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@ -15,6 +19,10 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
public class Test_AuthenticationManager {
private AuthenticationManager authenticationManager;
@Autowired
private UserRepository userRepository;
private UserService userService;
private AuthenticationManager getAuthenticationManager() {
return authenticationManager;
}
@ -25,6 +33,26 @@ public class Test_AuthenticationManager {
this.authenticationManager = authenticationManager;
}
private UserService getUserService() {
return userService;
}
@Autowired
private void setUserService(UserService userService) {
this.userService = userService;
}
@Before
public void prepare() {
assertTrue(this.getUserService().register("test1", "test1", (byte) 1));
this.userRepository.getUser("test1");
}
@After
public void after() {
this.userRepository.detach("test1");
}
@Test
public void test() {
assertNotNull(this.getAuthenticationManager());
@ -33,7 +61,7 @@ public class Test_AuthenticationManager {
@Test
public void testGenerateCredential() {
String generateCredential = this.getAuthenticationManager()
.generateCredential("admin");
.generateCredential("test1");
assertNotNull(generateCredential);
System.out.println(generateCredential);
}
@ -41,7 +69,7 @@ public class Test_AuthenticationManager {
@Test
public void GenerateAccessToken() {
AccessToken accessToken = this.getAuthenticationManager()
.generateAccessToken("chen");
.generateAccessToken("test1");
assertNotNull(accessToken);
System.out.println(accessToken.getExpiresIn());
}

View File

@ -34,7 +34,7 @@ public class Test_PluginHelper {
public String addPlugin(String fileName, PluginRepository pluginRepository) {
try {
PluginUI pluginUI = createPluginUI(fileName);
System.out.println(pluginRepository.attatch(pluginUI));
pluginRepository.attatch(pluginUI);
return pluginUI.getPluginInfo().getName();
} catch (Exception e) {

View File

@ -9,6 +9,7 @@ import org.bench4q.master.domain.RunningAgentInterface;
import org.bench4q.master.domain.entity.Agent;
import org.bench4q.master.domain.entity.TestPlanScript;
import org.bench4q.master.domain.factory.RunningAgentFactory;
import org.bench4q.master.domain.service.AgentService;
import org.bench4q.master.domain.valueobject.transaction.impl.ScriptLoadApplication;
import org.bench4q.master.unitTest.TestBase_MakeUpTestPlan;
import org.junit.After;
@ -19,15 +20,23 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import stubs.Mock_AgentMessenger;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:service-test-context.xml" })
@ContextConfiguration(locations = { "classpath:mockHttpMesseger-context.xml" }, classes = { Mock_AgentMessenger.class })
public class Test_ScriptLoadCommand extends TestBase_MakeUpTestPlan {
private static final String Test_AGENT_HOSTNAME = "127.0.0.1";
private AgentService agentService;
private UUID agentRunId;
@Autowired
private RunningAgentFactory runningAgentFactory;
@Autowired
private void setAgentService(AgentService agentService) {
this.agentService = agentService;
}
private UUID getAgentRunId() {
return agentRunId;
}
@ -52,6 +61,11 @@ public class Test_ScriptLoadCommand extends TestBase_MakeUpTestPlan {
* This need a agent in running
*/
private void buildUpHaPool() {
assertTrue(this.agentService.addAgentToPool(Agent.createAgentWithoutId(
"127.0.0.1", 6565)));
}
@Test
public void testExecuteWithTestPlanScript() {
submitATestPlanWithOneScript();

View File

@ -1,15 +1,14 @@
<!-- <?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:task="http://www.springframework.org/schema/task" 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
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">
<context:component-scan
base-package="org.bench4q.master.helper, org.bench4q.master.domain.repository, org.bench4q.master.domain.entity" />
<mvc:annotation-driven />
<task:annotation-driven />
</beans>
-->
<?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:task="http://www.springframework.org/schema/task" 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
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">
<context:component-scan
base-package="org.bench4q.master.test.testHelper,org.bench4q.master.domain,org.bench4q.master.infrastructure.highavailable,org.bench4q.master.report, org.bench4q.master.helper, org.bench4q.master.testplan, org.bench4q.share, org.bench4q.master.domain.factory, org.bench4q.master.domain.repository" />
<mvc:annotation-driven />
<task:annotation-driven />
</beans>