I have an array as follow: [[Disable,Enable,No,Yes][Joe,Bill,Doug,Kevin],[Red,Blue,Pink,Magenta],[One,Two,Three,Four]];
I need a hamcrest matcher that will match with an excel file that has name/value pair data in it. I have Tried: hasItem,hasItems,hasItemInArray.
I have looked at the following links:
Let me know if I am missing any info that would be helpful.
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;
}
Code to try and match with hamcrest, which has nothing for 'Nested Array's which I can see:
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);
The last par with the "hasIteminArray' is where I am trying to utilize Hamcrest to assert on the JSON of a nested array.
AFAIK there is no Excel integration included in Hamcrest. simple-excel offers verification of generated excel files and brings it's own Hamcrest matchers for this.
Otherwise you are most likely to have to roll your own matches using Apache POI or JExcel.