private int getFieldWidth(List<FieldDescriptor> fields) { int colNum = 0; for (FieldDescriptor fieldDescriptor : fields) { colNum += fieldDescriptor.getLeafNodeCount(); } return colNum == 0 ? 1 : colNum; }
@Override public void write(OutputStream output) throws IOException { new TestResultExport().export(output, testsPerPage, results); } };
private int addHeaderTasks(TreeSet<WriteTask> tasks, Cursor cursor, List<FieldDescriptor> fields, String prefix) { int colNum = cursor.getColNum(); int rowNum = cursor.getRowNum(); for (FieldDescriptor fieldDescriptor : fields) { String fieldName = fieldDescriptor.getField().getName(); int width = fieldDescriptor.getLeafNodeCount(); if (fieldDescriptor.getChildren() == null) { tasks.add(new WriteTask(new Cursor(rowNum, colNum), prefix + fieldName, styles.header)); } else { addHeaderTasks(tasks, new Cursor(rowNum, colNum), fieldDescriptor.getChildren(), prefix + fieldName + "."); } colNum += width; } return colNum; }
private int write(Sheet sheet, TestUnitsResults result, int startRow) { int rowNum = writeInfo(sheet, result, startRow); rowNum = writeHeader(sheet, result, rowNum); rowNum = writeResults(sheet, result, rowNum); return rowNum; }
Styles(SXSSFWorkbook wb) { testNameSuccess = textStyle(wb, createFont(wb, GREEN.getIndex())); testNameFailure = textStyle(wb, createFont(wb, RED.getIndex())); testInfo = textStyle(wb, createFont(wb, GREY_50_PERCENT.getIndex())); header = backgroundStyle(wb, HEADER); resultSuccessId = backgroundStyle(wb, GREEN_MAIN); resultFailureId = backgroundStyle(wb, RED_MAIN); resultSuccessStatus = backgroundStyle(wb, GREEN_MAIN, createFont(wb, GREEN.getIndex())); resultFailureStatus = backgroundStyle(wb, RED_MAIN, createFont(wb, RED.getIndex())); resultSuccess = backgroundStyle(wb, GREEN_FIELDS); resultFailure = backgroundStyle(wb, RED_FIELDS); resultOther = backgroundStyle(wb, null); parametersInfo = textStyle(wb, createFont(wb, BLACK.getIndex())); parameterValue = backgroundStyle(wb, null); parameterAbsent = backgroundStyle(wb, ABSENT_VALUE); }
@Override public void write(OutputStream output) throws IOException { new RulesResultExport().export(output, -1, results); } };
/** * Find all non empty fields from all test results. * If some field of any test result is not null, it will be included in result. * If some field is null in all test results, it will not be included in result. * WARNING: This method is very expensive! Don't invoke it too often. * * @param type Type of a checking object * @param values All possible values for a given type. Is got from test result. * @return all non empty fields from all test results (values). */ static List<FieldDescriptor> nonEmptyFields(IOpenClass type, List<?> values) { return nonEmptyFieldsForFlatten(type, ExportUtils.flatten(values)); }
protected Object getSimpleValue(Object value) { if (value == null) { return null; } if (value instanceof ParameterWithValueDeclaration) { ParameterWithValueDeclaration parameter = (ParameterWithValueDeclaration) value; Object simpleValue = parameter.getValue(); // Return key field for complex objects IOpenField keyField = parameter.getKeyField(); if (keyField != null) { // If key can't be found, return the object itself Object key = ExportUtils.fieldValue(simpleValue, keyField); simpleValue = key == null ? simpleValue : key; } return getSimpleValue(simpleValue); } return value; } }
private List<List<FieldDescriptor>> getAllNonEmptyFields(TestDescription[] descriptions) { TestDescription description = descriptions[0]; ParameterWithValueDeclaration[] executionParams = description.getExecutionParams(); List<List<FieldDescriptor>> result = new ArrayList<>(executionParams.length); for (int i = 0; i < executionParams.length; i++) { ParameterWithValueDeclaration param = executionParams[i]; result.add(FieldDescriptor.nonEmptyFields(param.getType(), valuesForAllCases(descriptions, i))); } return result; }
protected Cell createCell(Row row, int cellNum, Object value, CellStyle style) { Cell cell = row.createCell(cellNum); Object simpleValue = getSimpleValue(value); if (simpleValue != null) { if (simpleValue instanceof Date) { style = styles.getDateStyle(row.getSheet().getWorkbook(), style); cell.setCellValue((Date) simpleValue); } else { cell.setCellValue(FormattersManager.format(simpleValue)); } } cell.setCellStyle(style); return cell; }
@Override protected void writeResultHeader(TestUnitsResults result, Row row, int colNum) { createCell(row, colNum, "Result", styles.header); }
private CellStyle backgroundStyle(SXSSFWorkbook workbook, Integer rgb) { return backgroundStyle(workbook, rgb, null); }
private void styleEmptyCells(Row row, int firstCellNum, int lastCellNum) { for (int i = firstCellNum; i <= lastCellNum; i++) { Cell cell = row.getCell(i); if (cell == null) { createCell(row, i, null, styles.parameterAbsent); } } }
@Override protected void writeResultHeader(TestUnitsResults result, Row row, int colNum) { for (String name : result.getTestResultColumnDisplayNames()) { createCell(row, colNum++, name, styles.header); } }
@Override public void write(OutputStream output) throws IOException { new TestResultExport().export(output, testsPerPage, results); } };
@Override public void write(OutputStream output) throws IOException { new RulesResultExport().export(output, -1, results); } };
/** * Returns leaf node count * * @return the count of leaf node or 1 if the node doesn't contain children */ public int getLeafNodeCount() { if (children == null) { return 1; } int width = 0; for (FieldDescriptor child : children) { width += child.getLeafNodeCount(); } return width; }
@Override protected void writeResult(Row row, int colNum, ITestUnit testUnit) { createCell(row, colNum, testUnit.getActualParam(), styles.resultSuccess); } }