gpt4 book ai didi

java - Hamcrest.Matchers : JSON Nested Array

转载 作者:行者123 更新时间:2023-11-30 04:31:12 24 4
gpt4 key购买 nike

我有一个数组如下:[[Disable,Enable,No,Yes][Joe,Bill,Doug,Kevin],[Red,Blue,Pink,Magenta],[One,Two,Three,Four]] ;

我需要一个 hamcrest 匹配器,它将与其中包含名称/值对数据的 Excel 文件匹配。我尝试过:hasItem、hasItems、hasItemInArray。

我查看了以下链接:

Hamcrest Link

如果我遗漏了任何有用的信息,请告诉我。

private String[][] getExcelSheetData(String excelFile)
throws NoExcelValidationDataFoundException {
String[][] excelValidationData = null;

try {
ExcelDAOFactory excelDAOFactory = (ExcelDAOFactory) DAOFactory
.getFactory(DAOFactory.EXCEL);
excelDAOFactory.setExcelFile(excelFile);
excelValidationData = excelDAOFactory.fetchData();
TAFLogger.logTAFActivity("Finished retrieving data from "
+ excelFile);
} catch (InvalidFormatException | IOException | UnsupportedDAOException e) {
TAFLogger.logTAFActivity(
"Error retrieving data from ExcelDAOFactory: "
+ e.getMessage(), logger.WARN);
throw new NoExcelValidationDataFoundException(
"Could not retireve validation " + "data from " + excelFile
+ e.getMessage());
}
return excelValidationData;
}

尝试与 hamcrest 匹配的代码,其中没有任何我可以看到的“嵌套数组”:

 requestBuilder = new RequestSpecBuilder();
requestBuilder.addCookie().setContentType(ContentType.JSON);
requestSpecification = requestBuilder.build();


responseBuilder = new ResponseSpecBuilder();
responseBuilder.expectStatusCode(Integer.parseInt(xmlTest
.getParameter("http-status-code-200")));
//responseBuilder.expectContentType(ContentType.JSON);
responseSpecification = responseBuilder.build();

try {
validationData = getExcelSheetData(excelFile);
} catch (NoExcelValidationDataFoundException e) {
Logger.logActivity("Could not retrieve Excel sheet data: "
+ e.getMessage(), Logger.ERROR);
Assert.fail("Could not retrieve Excel sheet data: "
+ e.getMessage());

for (int i = 0; i < validationData.length; i++) {
responseBuilder.expectBody(validationData[i][0],
hasItemInArray(validationData[i][1]));

responseSpecification = responseBuilder.build();

try {
//Response res = given().getValue()).get("data/roles");

String data = given().spec(requestSpecification).
.expect().spec(responseSpecification).when().get("data/roles").asString();
System.out.println(data);

logger.logTestActivity("Completed testing JSON payload using Excel file");
} catch (AssertionError e) {
logger.logTestActivity(
"Error testing JSON payload: " + e.getMessage(),
logger.ERROR);
throw new Exception(e);

与“hasIteminArray”的最后一个部分是我尝试利用 Hamcrest 对嵌套数组的 JSON 进行断言。

最佳答案

据我所知,Hamcrest 中不包含 Excel 集成。 simple-excel提供对生成的 excel 文件的验证,并为此带来自己的 Hamcrest 匹配器。

否则您很可能必须使用 Apache POI 来进行自己的匹配或JExcel .

关于java - Hamcrest.Matchers : JSON Nested Array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14615496/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com