本文整理汇总了Java中org.springframework.test.web.servlet.ResultActions.andExpect方法的典型用法代码示例。如果您正苦于以下问题:Java ResultActions.andExpect方法的具体用法?Java ResultActions.andExpect怎么用?Java ResultActions.andExpect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.test.web.servlet.ResultActions
的用法示例。
在下文中一共展示了ResultActions.andExpect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_runScript
import org.springframework.test.web.servlet.ResultActions; //导入方法依赖的package包/类
@Test
public void test_runScript() throws Exception {
requestAddModule();
String filename = FilenameUtils.getName(testScriptPath);
if (filename == null) {
logger.info("No script found - test escape");
} else {
MockMultipartFile file = new MockMultipartFile(
"file",
filename,
"application/sql",
new FileInputStream(testScriptPath));
String genericModule = NamingUtils.getContainerName(applicationName, module, "johndoe");
ResultActions result = mockMvc.perform(
fileUpload("/module/{moduleName}/run-script", genericModule)
.file(file)
.session(session)
.contentType(MediaType.MULTIPART_FORM_DATA))
.andDo(print());
result.andExpect(status().isOk());
}
}
示例2: test013_CreateAccentNameApplication
import org.springframework.test.web.servlet.ResultActions; //导入方法依赖的package包/类
@Test
public void test013_CreateAccentNameApplication()
throws Exception {
String accentName = "àéèîôù";
String deAccentName = "aeeiou";
logger.info("**************************************");
logger.info("Create application with accent name " + accentName);
logger.info("**************************************");
final String jsonString = "{\"applicationName\":\"" + accentName + "\", \"serverName\":\"" + release + "\"}";
ResultActions resultats =
this.mockMvc.perform(post("/application").session(session).contentType(MediaType.APPLICATION_JSON).content(jsonString));
resultats.andExpect(status().isOk());
logger.info("**************************************");
logger.info("Delete application : " + deAccentName);
logger.info("**************************************");
resultats =
mockMvc.perform(delete("/application/" + deAccentName).session(session).contentType(MediaType.APPLICATION_JSON));
resultats.andExpect(status().isOk());
}
示例3: csarDetails
import org.springframework.test.web.servlet.ResultActions; //导入方法依赖的package包/类
@Test
public void csarDetails() throws Exception {
for (String name : MOCK_CSAR_NAMES) {
ResultActions resultActions = mvc.perform(
get(CSAR_BASE_URL + name).accept(ACCEPTED_MIME_TYPE)
).andDo(print()).andExpect(status().is2xxSuccessful());
resultActions.andExpect(jsonPath("$.name").value(name));
resultActions.andExpect(jsonPath("$.links").isArray());
resultActions.andExpect(jsonPath("$.links[" + relations.size() + "]").doesNotExist());
//Validate String result
MvcResult result = resultActions.andReturn();
JSONObject object = new JSONObject(result.getResponse().getContentAsString());
HALRelationUtils.validateRelations(object.getJSONArray("links"), relations, name);
}
}
示例4: test_changeInvalidJvmMemorySizeApplicationTest
import org.springframework.test.web.servlet.ResultActions; //导入方法依赖的package包/类
@Test(timeout = 30000)
public void test_changeInvalidJvmMemorySizeApplicationTest()
throws Exception {
createApplication(applicationName);
logger.info("Change JVM Memory size with an incorrect value : number not allowed");
String jsonString =
"{\"applicationName\":\"" + applicationName
+ "\",\"jvmMemory\":\"666\",\"jvmOptions\":\"\",\"jvmRelease\":\"\"}";
ResultActions resultats =
mockMvc.perform(put("/server/configuration/jvm").session(session).contentType(MediaType.APPLICATION_JSON).content(jsonString));
resultats.andExpect(status().is4xxClientError());
logger.info("Change JVM Memory size with an empty value");
jsonString =
"{\"applicationName\":\"" + applicationName
+ "\",\"jvmMemory\":\"\",\"jvmOptions\":\"\"}";
resultats =
mockMvc.perform(put("/server/configuration/jvm").session(session).contentType(MediaType.APPLICATION_JSON).content(jsonString));
resultats.andExpect(status().is4xxClientError());
deleteApplication(applicationName);
}
示例5: test_changeJvmOptionsApplicationTest
import org.springframework.test.web.servlet.ResultActions; //导入方法依赖的package包/类
@Test(timeout = 60000)
public void test_changeJvmOptionsApplicationTest()
throws Exception {
createApplication(applicationName);
logger.info("Change JVM Options !");
String jsonString =
"{\"applicationName\":\"" + applicationName
+ "\",\"jvmMemory\":\"512\",\"jvmOptions\":\"-Dkey1=value1\"}";
ResultActions resultats =
mockMvc.perform(put("/server/configuration/jvm").session(session).contentType(MediaType.APPLICATION_JSON).content(jsonString));
resultats.andExpect(status().isOk());
resultats =
mockMvc.perform(get("/application/" + applicationName).session(session).contentType(MediaType.APPLICATION_JSON));
resultats.andExpect(jsonPath("$.server.jvmMemory").value(512))
.andExpect(jsonPath("$.server.jvmOptions").value("-Dkey1=value1"));
deleteApplication(applicationName);
}
示例6: saveContentIntoRemoteFile
import org.springframework.test.web.servlet.ResultActions; //导入方法依赖的package包/类
private void saveContentIntoRemoteFile(String fileName, String path, String content) throws Exception {
String container = applicationName+"-johndoe";
FileRequestBody body = new FileRequestBody();
body.setFileName(fileName);
body.setFilePath(path);
body.setFileContent(content);
ObjectMapper objectMapper = new ObjectMapper();
String jsonString = objectMapper.writeValueAsString(body);
String url = "/file/content/container/"+container+"/application/"+applicationName;
ResultActions resultats = this.mockMvc
.perform(
put(url)
.content(jsonString).contentType(MediaType.APPLICATION_JSON)
.session(session));
resultats.andExpect(status().isOk());
}
示例7: deleteApplication
import org.springframework.test.web.servlet.ResultActions; //导入方法依赖的package包/类
@Test
public void deleteApplication() {
try {
ResultActions resultats =
mockMvc.perform(delete("/application/" + applicationName).session(session).contentType(MediaType.APPLICATION_JSON));
resultats.andExpect(status().isOk());
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
}
}
示例8: createApplication
import org.springframework.test.web.servlet.ResultActions; //导入方法依赖的package包/类
private void createApplication(String accentName) throws Exception {
logger.info("Create application with accent name " + accentName);
final String jsonString = "{\"applicationName\":\"" + accentName + "\", \"serverName\":\"" + release + "\"}";
ResultActions resultats =
this.mockMvc.perform(post("/application").session(session).contentType(MediaType.APPLICATION_JSON)
.content(jsonString));
resultats.andExpect(status().isOk());
}
示例9: createDataInTenant
import org.springframework.test.web.servlet.ResultActions; //导入方法依赖的package包/类
private void createDataInTenant(String costCenter) throws Exception {
final String newCostCenterJson = buildCostCenterJson(costCenter);
ResultActions action = mockMvc
.perform(MockMvcRequestBuilders
.request(HttpMethod.POST, "/cost-center")
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.content(newCostCenterJson));
action.andExpect(MockMvcResultMatchers.status().isOk());
}
示例10: list_files_and_check_presence
import org.springframework.test.web.servlet.ResultActions; //导入方法依赖的package包/类
private void list_files_and_check_presence(String release, String fileToCheck) throws Exception {
String container = applicationName + "-johndoe";
String url = "/logs/sources/" + applicationName + "/container/" + container;
logger.info("url:" + url);
ResultActions resultActions =
mockMvc.perform(get(url).session(session).contentType(MediaType.APPLICATION_JSON));
resultActions.andExpect(status().isOk());
String contentAsString = resultActions.andReturn().getResponse().getContentAsString();
logger.info(contentAsString);
logger.info(fileToCheck);
Assert.assertTrue(contentAsString.contains(fileToCheck));
}
示例11: test_failCreateWrongNameApplication
import org.springframework.test.web.servlet.ResultActions; //导入方法依赖的package包/类
/**
* We cannot create an application with an wrong syntax name.
*
* @throws Exception
*/
@Test(timeout = 30000)
public void test_failCreateWrongNameApplication()
throws Exception {
logger.info("Create application with a wrong syntax name");
final String jsonString = "{\"applicationName\":\"" + " " + "\", \"serverName\":\"" + release + "\"}";
ResultActions resultats =
this.mockMvc.perform(post("/application").session(session).contentType(MediaType.APPLICATION_JSON).content(jsonString));
resultats.andExpect(status().is4xxClientError());
}
示例12: testGenerateBatchPositionResultsWoParametersWithProject
import org.springframework.test.web.servlet.ResultActions; //导入方法依赖的package包/类
@Test
public void testGenerateBatchPositionResultsWoParametersWithProject() throws Exception {
long buildingId = insertNewBuilding();
long radioMapFileId = processRadioMapForBuilding(buildingId);
long evalFileId = processEvaluationFileForBuilding(buildingId);
long projectId = insertNewProjectWithDefaultParameters(buildingId, null);
GenerateBatchPositionResults positionRequestObject = TestHelper
.createDefaultBatchPositionRequestObject(PARAMETERS_DEFAULT_CORRELATION_MODE);
positionRequestObject.setProjectParameters(null);
positionRequestObject.setProjectIdentifier(projectId);
positionRequestObject.setBuildingIdentifier(buildingId);
positionRequestObject.setEvalFileIdentifier(evalFileId);
positionRequestObject.setRadioMapFileIdentifiers(new long[]{radioMapFileId});
ResultActions generateBatchPositionsResultActions = mockMvc.perform(post("/position/generateBatchPositionResults")
.content(TestHelper.jsonify(positionRequestObject))
.contentType(this.contentType));
generateBatchPositionsResultActions.andExpect(status().isOk());
String batchPositionResult = generateBatchPositionsResultActions.andReturn().getResponse().getContentAsString();
List<BatchPositionResult> batchPositionResults = (List<BatchPositionResult>) this.objectMapper.readValue(batchPositionResult,
new TypeReference<List<BatchPositionResult>>() {
});
assertTrue("The backend returned an unexpected number of results.",
batchPositionResults.size() == expectedBatchPositionResultsDefaultScalar.size());
BatchPositionResult currentActual;
BatchPositionResult currentExpected;
for (int i = 0; i < expectedBatchPositionResultsDefaultScalar.size(); i++) {
currentActual = batchPositionResults.get(i);
currentExpected = expectedBatchPositionResultsDefaultScalar.get(i);
assertEquals(currentExpected, currentActual);
}
}
示例13: teardown
import org.springframework.test.web.servlet.ResultActions; //导入方法依赖的package包/类
@After
public void teardown() throws Exception {
logger.info("teardown");
ResultActions resultats =
mockMvc.perform(delete("/application/" + applicationName).session(session).contentType(MediaType.APPLICATION_JSON));
resultats.andExpect(status().isOk());
SecurityContextHolder.clearContext();
session.invalidate();
}
示例14: test03_FailToAddModuleBecauseModuleNonExisting
import org.springframework.test.web.servlet.ResultActions; //导入方法依赖的package包/类
@Test
public void test03_FailToAddModuleBecauseModuleNonExisting() throws Exception {
logger.info("Cannot add a module because module name empty");
String jsonString = "{\"applicationName\":\"" + "REALAPP" + "\", \"imageName\":\"" + "UFO" + "\"}";
ResultActions resultats = mockMvc.perform(post("/module")
.session(session)
.contentType(MediaType.APPLICATION_JSON)
.content(jsonString));
resultats.andExpect(status().is4xxClientError());
}
示例15: testRemoveEvaalFileWithProject
import org.springframework.test.web.servlet.ResultActions; //导入方法依赖的package包/类
@Test
public void testRemoveEvaalFileWithProject() throws Exception {
long buildingId = insertNewBuilding();
long radioMapFileId = processRadioMapForBuilding(buildingId);
long[] radioMapIdArray = {radioMapFileId};
insertNewProjectWithDefaultParameters(buildingId, radioMapIdArray);
ResultActions deleteSelectedEvaalFileResultActions = mockMvc.perform(delete("/position/deleteSelectedEvaalFile?" +
"evaalFileIdentifier=" + radioMapFileId));
deleteSelectedEvaalFileResultActions.andExpect(status().is4xxClientError());
}