added script unit test
This commit is contained in:
parent
2a65e73e10
commit
dd3cfe2453
|
@ -30,9 +30,12 @@ public class ScriptMessager extends MasterMessager {
|
|||
}
|
||||
|
||||
public OperateScriptServerResponseModel stopScriptRecordServer(
|
||||
String accessToken) {
|
||||
String accessToken,String port,String fileNameUUID) {
|
||||
String url = this.getBaseUrl() + "/stopScriptRecordServer";
|
||||
return this.getOperateScriptServerResponseModelByPost(url, null,
|
||||
Map<String,String> params=new HashMap<String,String>();
|
||||
params.put("port", port);
|
||||
params.put("fileNameUUID", fileNameUUID);
|
||||
return this.getOperateScriptServerResponseModelByPost(url, params,
|
||||
accessToken);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
package org.bench4q.web.test.masterMessager;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.OperateScriptServerResponseModel;
|
||||
import org.bench4q.share.models.master.ScriptModel;
|
||||
import org.bench4q.web.masterMessager.RecordPortMessager;
|
||||
import org.bench4q.web.masterMessager.ScriptMessager;
|
||||
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 = { "file:src/test/resources/bench4qweb-servlet.xml" })
|
||||
public class ScriptMessageTest extends MessagerTestBase{
|
||||
private ScriptMessager scriptMessager;
|
||||
private String accessToken;
|
||||
private RecordPortMessager recordPortMessager;
|
||||
private String scriptName="testScript";
|
||||
@Autowired
|
||||
public void setRecordPortMessager(RecordPortMessager recordPortMessager){
|
||||
this.recordPortMessager=recordPortMessager;
|
||||
}
|
||||
public RecordPortMessager getRecordPortMessager(){
|
||||
return this.recordPortMessager;
|
||||
}
|
||||
@Autowired
|
||||
public void setScriptMessager(ScriptMessager scriptMessager){
|
||||
this.scriptMessager=scriptMessager;
|
||||
}
|
||||
public ScriptMessager getScriptMessager(){
|
||||
return this.scriptMessager;
|
||||
}
|
||||
@Before
|
||||
public void SetUp(){
|
||||
this.accessToken=this.login();
|
||||
}
|
||||
@Test
|
||||
public void test_startScriptRecordServer() throws JAXBException{
|
||||
this.scriptMessager.stopScriptRecordServer(accessToken,"8090","");
|
||||
OperateScriptServerResponseModel operateScriptServerResponseModel=this.scriptMessager.startScriptRecordServer(accessToken);
|
||||
String xml=MarshalHelper.marshal(OperateScriptServerResponseModel.class, operateScriptServerResponseModel);
|
||||
System.out.println(xml);
|
||||
assertTrue(operateScriptServerResponseModel.isSuccess());
|
||||
}
|
||||
@Test
|
||||
public void test_stopScriptRecordServer(){
|
||||
OperateScriptServerResponseModel stopOperateScriptServerResponseModel=this.scriptMessager.stopScriptRecordServer(accessToken,"8090","");
|
||||
assertTrue(stopOperateScriptServerResponseModel.isSuccess());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_loadScript(){
|
||||
OperateScriptServerResponseModel beforeSave_operateScriptServerResponseModel=this.scriptMessager.loadScript(accessToken);
|
||||
assertTrue(beforeSave_operateScriptServerResponseModel.isSuccess());
|
||||
}
|
||||
@Test
|
||||
public void test_saveAndDeleteScript(){
|
||||
int countBeforeSave=this.scriptMessager.loadScript(accessToken).getScriptModels().size();
|
||||
this.scriptMessager.stopScriptRecordServer(accessToken,"8090","");
|
||||
OperateScriptServerResponseModel startOperateScriptServerResponseModel=this.scriptMessager.startScriptRecordServer(accessToken);
|
||||
String port=Integer.toString(startOperateScriptServerResponseModel.getPort());
|
||||
String fileNameUUID=startOperateScriptServerResponseModel.getFileName();
|
||||
assertTrue(this.scriptMessager.saveScriptRecorded(accessToken, scriptName, port, fileNameUUID).isSuccess());
|
||||
int countAfterSave=this.scriptMessager.loadScript(accessToken).getScriptModels().size();
|
||||
assertEquals(countBeforeSave+1,countAfterSave);
|
||||
assertTrue(this.scriptMessager.queryScriptByName(accessToken, scriptName).isSuccess());
|
||||
ScriptModel scriptModel=this.scriptMessager.queryScriptByName(accessToken, scriptName).getScriptModels().get(0);
|
||||
String id=Integer.toString(scriptModel.getId());
|
||||
assertTrue(this.scriptMessager.deleteScript(accessToken, id).isSuccess());
|
||||
int countAfterDelete=this.scriptMessager.loadScript(accessToken).getScriptModels().size();
|
||||
assertEquals(countBeforeSave,countAfterDelete);
|
||||
}
|
||||
@Test
|
||||
public void test_updateScript(){
|
||||
this.scriptMessager.stopScriptRecordServer(accessToken,"8090","");
|
||||
OperateScriptServerResponseModel startOperateScriptServerResponseModel=this.scriptMessager.startScriptRecordServer(accessToken);
|
||||
String port=Integer.toString(startOperateScriptServerResponseModel.getPort());
|
||||
String fileNameUUID=startOperateScriptServerResponseModel.getFileName();
|
||||
this.scriptMessager.saveScriptRecorded(accessToken, scriptName, port, fileNameUUID);
|
||||
String id=Integer.toString(this.scriptMessager.queryScriptByName(accessToken, scriptName).getScriptModels().get(0).getId());
|
||||
String scriptContent="testScriptContent";
|
||||
assertTrue(this.scriptMessager.updateScript(accessToken, id, scriptContent).isSuccess());
|
||||
this.scriptMessager.deleteScript(accessToken, id);
|
||||
}
|
||||
@Test
|
||||
public void test_queryScriptById(){
|
||||
this.scriptMessager.stopScriptRecordServer(accessToken,"8090","");
|
||||
OperateScriptServerResponseModel startOperateScriptServerResponseModel=this.scriptMessager.startScriptRecordServer(accessToken);
|
||||
String port=Integer.toString(startOperateScriptServerResponseModel.getPort());
|
||||
String fileNameUUID=startOperateScriptServerResponseModel.getFileName();
|
||||
this.scriptMessager.saveScriptRecorded(accessToken, scriptName, port, fileNameUUID);
|
||||
String id=Integer.toString(this.scriptMessager.queryScriptByName(accessToken, scriptName).getScriptModels().get(0).getId());
|
||||
assertTrue(this.scriptMessager.queryScriptById(accessToken, id).isSuccess());
|
||||
this.scriptMessager.deleteScript(accessToken, id);
|
||||
}
|
||||
|
||||
}
|
|
@ -1 +1 @@
|
|||
masterAddress=127.0.0.1:7979
|
||||
masterAddress=133.133.12.1:7979
|
Loading…
Reference in New Issue