@Test public void computeQuality_should_set_quality_status_INCOMPLETE_when_one_qualityThreshold_is_missing() throws IOException { Execution execution = new Execution() .withCycleDefinition(new CycleDefinition().withProjectId(PROJECT_ID)) .withQualityThresholds("some") .withRuns(Collections.singleton(new Run().withIncludeInThresholds(Boolean.TRUE))); when(objectMapper.readValue(anyString(), eq(QualityService.TYPE_REFERENCE_TO_MAP_STRING_QUALITY_THRESHOLD))).thenReturn(ImmutableMap.of()); when(objectMapper.writeValueAsString(qualitySeverityListArgument.capture())).thenReturn("any"); when(severityRepository.findAllByProjectIdOrderByPosition(PROJECT_ID)).thenReturn(Collections.singletonList( new Severity().withCode("1").withDefaultOnMissing(true))); cut.computeQuality(execution); assertThat(execution.getQualityStatus()).isEqualTo(QualityStatus.INCOMPLETE); assertThat(qualitySeverityListArgument.getValue().get(1).getStatus()).isEqualTo(QualityStatus.INCOMPLETE); }
public void computeQuality(Execution execution) { QualityStatus globalQualityStatus = QualityStatus.PASSED; Map<String, QualityThreshold> qualityThresholds; try { qualityThresholds = objectMapper.readValue(execution.getQualityThresholds(), TYPE_REFERENCE_TO_MAP_STRING_QUALITY_THRESHOLD); } catch (IOException e) { log.error("Cannot parse qualityThresholds, doing without them but marking the execution as incomplete: {}", execution.getQualityThresholds(), e); qualityThresholds = null; globalQualityStatus = QualityStatus.INCOMPLETE; } List<QualitySeverityDTO> qualitySeverities = new ArrayList<>(); for (Severity severity : getActiveSeverities(execution)) { final QualityThreshold threshold = (qualityThresholds == null ? null : qualityThresholds.get(severity.getCode())); QualitySeverityDTO qualitySeverity = computeQualityOfSeverity(execution, severity, threshold); qualitySeverities.add(qualitySeverity); if (threshold == null) { log.error("No qualityThresholds for {}: doing without them but marking the severity and execution as incomplete", severity.getCode()); qualitySeverity.setStatus(QualityStatus.INCOMPLETE); globalQualityStatus = QualityStatus.INCOMPLETE; } if (globalQualityStatus.ordinal() > qualitySeverity.getStatus().ordinal()) { globalQualityStatus = qualitySeverity.getStatus(); } } QualitySeverityDTO globalQualitySeverity = computeQualityOfSeverity(execution, Severity.ALL, null); globalQualitySeverity.setStatus(globalQualityStatus); qualitySeverities.add(globalQualitySeverity); if (!isComplete(execution)) { globalQualitySeverity.setStatus(QualityStatus.INCOMPLETE); globalQualityStatus = QualityStatus.INCOMPLETE; } try { execution.setQualitySeverities(objectMapper.writeValueAsString(qualitySeverities)); } catch (JsonProcessingException e) { throw new NotGonnaHappenException("JSON serializing should not have failed when serializing to a String", e); } execution.setQualityStatus(globalQualityStatus); }
QualityService { public void computeQuality(Execution execution) { QualityStatus globalQualityStatus = QualityStatus.PASSED; Map<String, QualityThreshold> qualityThresholds; try { qualityThresholds = objectMapper.readValue(execution.getQualityThresholds(), TYPE_REFERENCE_TO_MAP_STRING_QUALITY_THRESHOLD); } catch (IOException e) { log.error("Cannot parse qualityThresholds, doing without them but marking the execution as incomplete: {}", execution.getQualityThresholds(), e); qualityThresholds = null; globalQualityStatus = QualityStatus.INCOMPLETE; } List<QualitySeverityDTO> qualitySeverities = new ArrayList<>(); for (Severity severity : getActiveSeverities(execution)) { final QualityThreshold threshold = (qualityThresholds == null ? null : qualityThresholds.get(severity.getCode())); QualitySeverityDTO qualitySeverity = computeQualityOfSeverity(execution, severity, threshold); qualitySeverities.add(qualitySeverity); if (threshold == null) { log.error("No qualityThresholds for {}: doing without them but marking the severity and execution as incomplete", severity.getCode()); qualitySeverity.setStatus(QualityStatus.INCOMPLETE); globalQualityStatus = QualityStatus.INCOMPLETE; } if (globalQualityStatus.ordinal() > qualitySeverity.getStatus().ordinal()) { globalQualityStatus = qualitySeverity.getStatus(); } } QualitySeverityDTO globalQualitySeverity = computeQualityOfSeverity(execution, Severity.ALL, null); globalQualitySeverity.setStatus(globalQualityStatus); qualitySeverities.add(globalQualitySeverity); if (!isComplete(execution)) { globalQualitySeverity.setStatus(QualityStatus.INCOMPLETE); globalQualityStatus = QualityStatus.INCOMPLETE; } try { execution.setQualitySeverities(objectMapper.writeValueAsString(qualitySeverities)); } catch (JsonProcessingException e) { throw new NotGonnaHappenException("JSON serializing should not have failed when serializing to a String", e); } execution.setQualityStatus(globalQualityStatus); } }
QualityService { public void computeQuality(Execution execution) { QualityStatus globalQualityStatus = QualityStatus.PASSED; Map<String, QualityThreshold> qualityThresholds; try { qualityThresholds = objectMapper.readValue(execution.getQualityThresholds(), TYPE_REFERENCE_TO_MAP_STRING_QUALITY_THRESHOLD); } catch (IOException e) { log.error("Cannot parse qualityThresholds, doing without them but marking the execution as incomplete: {}", execution.getQualityThresholds(), e); qualityThresholds = null; globalQualityStatus = QualityStatus.INCOMPLETE; } List<QualitySeverityDTO> qualitySeverities = new ArrayList<>(); for (Severity severity : getActiveSeverities(execution)) { final QualityThreshold threshold = (qualityThresholds == null ? null : qualityThresholds.get(severity.getCode())); QualitySeverityDTO qualitySeverity = computeQualityOfSeverity(execution, severity, threshold); qualitySeverities.add(qualitySeverity); if (threshold == null) { log.error("No qualityThresholds for {}: doing without them but marking the severity and execution as incomplete", severity.getCode()); qualitySeverity.setStatus(QualityStatus.INCOMPLETE); globalQualityStatus = QualityStatus.INCOMPLETE; } if (globalQualityStatus.ordinal() > qualitySeverity.getStatus().ordinal()) { globalQualityStatus = qualitySeverity.getStatus(); } } QualitySeverityDTO globalQualitySeverity = computeQualityOfSeverity(execution, Severity.ALL, null); globalQualitySeverity.setStatus(globalQualityStatus); qualitySeverities.add(globalQualitySeverity); if (!isComplete(execution)) { globalQualitySeverity.setStatus(QualityStatus.INCOMPLETE); globalQualityStatus = QualityStatus.INCOMPLETE; } try { execution.setQualitySeverities(objectMapper.writeValueAsString(qualitySeverities)); } catch (JsonProcessingException e) { throw new NotGonnaHappenException("JSON serializing should not have failed when serializing to a String", e); } execution.setQualityStatus(globalQualityStatus); }  }
QualityService { public void computeQuality(Execution execution) { QualityStatus globalQualityStatus = QualityStatus.PASSED; Map<String, QualityThreshold> qualityThresholds; try { qualityThresholds = objectMapper.readValue(execution.getQualityThresholds(), TYPE_REFERENCE_TO_MAP_STRING_QUALITY_THRESHOLD); } catch (IOException e) { log.error("Cannot parse qualityThresholds, doing without them but marking the execution as incomplete: {}", execution.getQualityThresholds(), e); qualityThresholds = null; globalQualityStatus = QualityStatus.INCOMPLETE; } List<QualitySeverityDTO> qualitySeverities = new ArrayList<>(); for (Severity severity : getActiveSeverities(execution)) { final QualityThreshold threshold = (qualityThresholds == null ? null : qualityThresholds.get(severity.getCode())); QualitySeverityDTO qualitySeverity = computeQualityOfSeverity(execution, severity, threshold); qualitySeverities.add(qualitySeverity); if (threshold == null) { log.error("No qualityThresholds for {}: doing without them but marking the severity and execution as incomplete", severity.getCode()); qualitySeverity.setStatus(QualityStatus.INCOMPLETE); globalQualityStatus = QualityStatus.INCOMPLETE; } if (globalQualityStatus.ordinal() > qualitySeverity.getStatus().ordinal()) { globalQualityStatus = qualitySeverity.getStatus(); } } QualitySeverityDTO globalQualitySeverity = computeQualityOfSeverity(execution, Severity.ALL, null); globalQualitySeverity.setStatus(globalQualityStatus); qualitySeverities.add(globalQualitySeverity); if (!isComplete(execution)) { globalQualitySeverity.setStatus(QualityStatus.INCOMPLETE); globalQualityStatus = QualityStatus.INCOMPLETE; } try { execution.setQualitySeverities(objectMapper.writeValueAsString(qualitySeverities)); } catch (JsonProcessingException e) { throw new NotGonnaHappenException("JSON serializing should not have failed when serializing to a String", e); } execution.setQualityStatus(globalQualityStatus); }  void computeQuality(Execution execution); }
QualityService { public void computeQuality(Execution execution) { QualityStatus globalQualityStatus = QualityStatus.PASSED; Map<String, QualityThreshold> qualityThresholds; try { qualityThresholds = objectMapper.readValue(execution.getQualityThresholds(), TYPE_REFERENCE_TO_MAP_STRING_QUALITY_THRESHOLD); } catch (IOException e) { log.error("Cannot parse qualityThresholds, doing without them but marking the execution as incomplete: {}", execution.getQualityThresholds(), e); qualityThresholds = null; globalQualityStatus = QualityStatus.INCOMPLETE; } List<QualitySeverityDTO> qualitySeverities = new ArrayList<>(); for (Severity severity : getActiveSeverities(execution)) { final QualityThreshold threshold = (qualityThresholds == null ? null : qualityThresholds.get(severity.getCode())); QualitySeverityDTO qualitySeverity = computeQualityOfSeverity(execution, severity, threshold); qualitySeverities.add(qualitySeverity); if (threshold == null) { log.error("No qualityThresholds for {}: doing without them but marking the severity and execution as incomplete", severity.getCode()); qualitySeverity.setStatus(QualityStatus.INCOMPLETE); globalQualityStatus = QualityStatus.INCOMPLETE; } if (globalQualityStatus.ordinal() > qualitySeverity.getStatus().ordinal()) { globalQualityStatus = qualitySeverity.getStatus(); } } QualitySeverityDTO globalQualitySeverity = computeQualityOfSeverity(execution, Severity.ALL, null); globalQualitySeverity.setStatus(globalQualityStatus); qualitySeverities.add(globalQualitySeverity); if (!isComplete(execution)) { globalQualitySeverity.setStatus(QualityStatus.INCOMPLETE); globalQualityStatus = QualityStatus.INCOMPLETE; } try { execution.setQualitySeverities(objectMapper.writeValueAsString(qualitySeverities)); } catch (JsonProcessingException e) { throw new NotGonnaHappenException("JSON serializing should not have failed when serializing to a String", e); } execution.setQualityStatus(globalQualityStatus); }  void computeQuality(Execution execution);  }