StatusCodesComparator implements ComparatorJob { @Override @SuppressWarnings("unchecked") public ComparatorStepResult compare() throws ProcessingException { final ComparatorStepResult result; LOGGER.info("Starting comparison phase for status codes for Company: {} Project: {}", properties.getCompany(), properties.getProject()); try { StatusCodesCollectorResult dataResult = artifactsDAO.getJsonFormatArtifact(properties, properties.getCollectedId(), RESULT_TYPE); for (DataFilterJob<StatusCodesCollectorResult> dataFilterJob : dataFilterJobs) { dataResult = dataFilterJob.modifyData(dataResult); } List<StatusCode> statusCodes = dataResult.getStatusCodes(); StatusCodesFilter statusCodesFilter = new StatusCodesFilter(filterRangeLowerBound, filterRangeUpperBound, filterCodes); Map<String, StatusCode> deduplicatedStatusCodes = new LinkedHashMap<>(); for (StatusCode code : statusCodes) { deduplicatedStatusCodes.put(code.getUrl(), code); } List<StatusCode> filteredStatusCodes = statusCodesFilter.filter(Lists .newArrayList(deduplicatedStatusCodes.values())); List<StatusCode> notExcludedStatusCodes = Lists.newLinkedList(); notExcludedStatusCodes.addAll(Collections2.filter(filteredStatusCodes, new Excludable.NonExcludedPredicate())); List<StatusCode> excludedStatusCodes = Lists.newLinkedList(); if (showExcluded) { excludedStatusCodes.addAll(Collections2.filter(filteredStatusCodes, new Excludable.ExcludedPredicate())); } Boolean isSuccess = notExcludedStatusCodes.isEmpty(); StatusCodesComparatorResult comparatorResult = new StatusCodesComparatorResult(statusCodes, notExcludedStatusCodes, excludedStatusCodes); String resultId = artifactsDAO.saveArtifactInJsonFormat(properties, comparatorResult); result = new ComparatorStepResult(resultId, isSuccess ? ComparatorStepResult.Status.PASSED : ComparatorStepResult.Status.FAILED); } catch (Exception e) { throw new ProcessingException(e.getMessage(), e); } return result; } StatusCodesComparator(ArtifactsDAO artifactsDAO, ComparatorProperties comparatorProperties,
      List<DataFilterJob> dataFilterJobs); @Override @SuppressWarnings("unchecked") ComparatorStepResult compare(); @Override void setParameters(Map<String, String> params); static final String COMPARATOR_TYPE; static final String COMPARATOR_NAME; }
@Test public void compareTest_expectPassed() throws ProcessingException { tested = createNewStatusCodesComparator("expected-data-200-result.json"); result = tested.compare(); assertEquals(ComparatorStepResult.Status.PASSED, result.getStatus()); }
@Test public void compareTest_defaultRange_expectPassed() throws ProcessingException { tested = createNewStatusCodesComparator("default-range-399-601-errors-result.json"); result = tested.compare(); assertEquals(ComparatorStepResult.Status.PASSED, result.getStatus()); }
@Test public void compareTest_defaultRange_expectFailed() throws ProcessingException { tested = createNewStatusCodesComparator("default-range-400-600-errors-result.json"); result = tested.compare(); assertEquals(ComparatorStepResult.Status.FAILED, result.getStatus()); }