RiskUiUtils { public static EffectiveRisk getEffectiveRisk(BpThreat threat) { String riskTreatment = threat.getEntity() .getRawPropertyValue(BpThreat.PROP_RISK_TREATMENT_OPTION); if (StringUtils.isEmpty(riskTreatment)) { return Optional.ofNullable(threat.getRiskWithoutAdditionalSafeguards()) .map(EffectiveRisk::of).orElse(EffectiveRisk.UNKNOWN); } else if (BpThreat.PROP_RISK_TREATMENT_OPTION_RISK_REDUCTION.equals(riskTreatment)) { return Optional.ofNullable(threat.getRiskWithAdditionalSafeguards()) .map(EffectiveRisk::of).orElse(EffectiveRisk.UNKNOWN); } else { return EffectiveRisk.TREATED; } } private  RiskUiUtils(); static Map<String, IHuiControlFactory> createHuiControlFactories(
            CnATreeElement element); static void addSelectionListener(HitroUIComposite huiComposite, CnATreeElement element); static EffectiveRisk getEffectiveRisk(BpThreat threat); static EffectiveRisk getEffectiveRisk(BpThreatGroup threatGroup); static EffectiveRisk getEffectiveRisk(CnATreeElement element);  }
@Test public void no_risk_info_yields_unknown_effective_risk() { BpThreat threat = new BpThreat(null); EffectiveRisk risk = RiskUiUtils.getEffectiveRisk(threat); assertEquals(EffectiveRisk.UNKNOWN, risk); }
@Test public void risk_wo_additional_safeguards_is_used_if_treatment_option_is_unspecified() { BpThreat threat = new BpThreat(null); threat.setRiskWithoutAdditionalSafeguards("risk1"); EffectiveRisk risk = RiskUiUtils.getEffectiveRisk(threat); assertEquals("risk1", risk.getRiskId()); }
@Test public void risk_with_additional_safeguards_is_used_if_treatment_option_is_reduce() { BpThreat threat = new BpThreat(null); threat.setSimpleProperty(BpThreat.PROP_RISK_TREATMENT_OPTION, BpThreat.PROP_RISK_TREATMENT_OPTION_RISK_REDUCTION); threat.setRiskWithAdditionalSafeguards("risk1"); EffectiveRisk risk = RiskUiUtils.getEffectiveRisk(threat); assertEquals("risk1", risk.getRiskId()); }
@Test public void risk_is_unknown_if_treatment_option_is_reduce_and_reduced_risk_is_unspecified() { BpThreat threat = new BpThreat(null); threat.setSimpleProperty(BpThreat.PROP_RISK_TREATMENT_OPTION, BpThreat.PROP_RISK_TREATMENT_OPTION_RISK_REDUCTION); threat.setRiskWithoutAdditionalSafeguards("risk1"); EffectiveRisk risk = RiskUiUtils.getEffectiveRisk(threat); assertEquals(EffectiveRisk.UNKNOWN, risk); }
@Test public void risk_avoidance_yields_treated_effective_risk() { BpThreat threat = new BpThreat(null); threat.setSimpleProperty(BpThreat.PROP_RISK_TREATMENT_OPTION, BpThreat.PROP_RISK_TREATMENT_OPTION_RISK_AVOIDANCE); EffectiveRisk risk = RiskUiUtils.getEffectiveRisk(threat); assertEquals(EffectiveRisk.TREATED, risk); }
@Test public void risk_transfer_yields_treated_effective_risk() { BpThreat threat = new BpThreat(null); threat.setSimpleProperty(BpThreat.PROP_RISK_TREATMENT_OPTION, BpThreat.PROP_RISK_TREATMENT_OPTION_TRANSFER_OF_RISK); EffectiveRisk risk = RiskUiUtils.getEffectiveRisk(threat); assertEquals(EffectiveRisk.TREATED, risk); }
@Test public void risk_acceptance_yields_treated_effective_risk() { BpThreat threat = new BpThreat(null); threat.setSimpleProperty(BpThreat.PROP_RISK_TREATMENT_OPTION, BpThreat.PROP_RISK_TREATMENT_OPTION_RISK_ACCEPTANCE); EffectiveRisk risk = RiskUiUtils.getEffectiveRisk(threat); assertEquals(EffectiveRisk.TREATED, risk); }
@Test public void no_effective_risk_for_empty_group() { BpThreatGroup group = new BpThreatGroup(null); EffectiveRisk risk = RiskUiUtils.getEffectiveRisk(group); assertNull(risk); }
@Test public void highest_specified_risk_is_used() { BpThreatGroup group = new BpThreatGroup(null); BpThreat threat1 = new BpThreat(group); group.addChild(threat1); threat1.setRiskWithoutAdditionalSafeguards("risk1"); assertEquals("risk1", RiskUiUtils.getEffectiveRisk(group).getRiskId()); BpThreat threat2 = new BpThreat(group); group.addChild(threat2); threat2.setRiskWithoutAdditionalSafeguards("risk2"); assertEquals("risk2", RiskUiUtils.getEffectiveRisk(group).getRiskId()); }
@Test public void only_unspecified_children() { BpThreatGroup group = new BpThreatGroup(null); BpThreat threat1 = new BpThreat(group); group.addChild(threat1); assertEquals(EffectiveRisk.UNKNOWN, RiskUiUtils.getEffectiveRisk(group)); }
@Test public void one_specified_and_one_unspecified_child() { BpThreatGroup group = new BpThreatGroup(null); BpThreat threat1 = new BpThreat(group); group.addChild(threat1); BpThreat threat2 = new BpThreat(group); group.addChild(threat2); threat2.setRiskWithoutAdditionalSafeguards("risk2"); assertEquals(EffectiveRisk.UNKNOWN, RiskUiUtils.getEffectiveRisk(group)); }
@Test public void only_acceptance_children() { BpThreatGroup group = new BpThreatGroup(null); BpThreat threat1 = new BpThreat(group); group.addChild(threat1); threat1.setSimpleProperty(BpThreat.PROP_RISK_TREATMENT_OPTION, BpThreat.PROP_RISK_TREATMENT_OPTION_RISK_ACCEPTANCE); assertEquals(EffectiveRisk.TREATED, RiskUiUtils.getEffectiveRisk(group)); }
@Test public void unspecified_and_accepted_children() { BpThreatGroup group = new BpThreatGroup(null); BpThreat threat1 = new BpThreat(group); group.addChild(threat1); threat1.setSimpleProperty(BpThreat.PROP_RISK_TREATMENT_OPTION, BpThreat.PROP_RISK_TREATMENT_OPTION_RISK_ACCEPTANCE); BpThreat threat2 = new BpThreat(group); group.addChild(threat2); assertEquals(EffectiveRisk.UNKNOWN, RiskUiUtils.getEffectiveRisk(group)); }
@Test public void only_contains_group() { BpThreatGroup group = new BpThreatGroup(null); BpThreatGroup subgroup = new BpThreatGroup(group); group.addChild(subgroup); assertNull(RiskUiUtils.getEffectiveRisk(group)); }
@Test public void contains_group_and_child() { BpThreatGroup group = new BpThreatGroup(null); BpThreat threat = new BpThreat(group); group.addChild(threat); threat.setRiskWithAdditionalSafeguards("risk1"); BpThreatGroup subgroup = new BpThreatGroup(group); group.addChild(subgroup); assertNull(RiskUiUtils.getEffectiveRisk(group)); }
@Test public void no_effective_risk_if_risk_analysis_is_not_required() { ItSystem itSystem = new ItSystem(null); EffectiveRisk risk = RiskUiUtils.getEffectiveRisk(itSystem); assertNull(risk); }
@Test public void unknown_effective_risk_if_there_are_no_linked_risks() { ItSystem itSystem = new ItSystem(null); itSystem.getEntity().setFlag(ItSystem.PROP_RISKANALYSIS_NECESSARY, true); EffectiveRisk risk = RiskUiUtils.getEffectiveRisk(itSystem); assertEquals(EffectiveRisk.UNKNOWN, risk); }
@Test public void highest_specified_risk_from_linked_threats_is_used() { ItSystem itSystem = new ItSystem(null); itSystem.getEntity().setFlag(ItSystem.PROP_RISKANALYSIS_NECESSARY, true); BpThreatGroup group = new BpThreatGroup(null); BpThreat threat1 = new BpThreat(group); group.addChild(threat1); threat1.setRiskWithoutAdditionalSafeguards("risk1"); new CnALink(threat1, itSystem, BpThreat.REL_BP_THREAT_BP_ITSYSTEM, null); assertEquals("risk1", RiskUiUtils.getEffectiveRisk(itSystem).getRiskId()); BpThreat threat2 = new BpThreat(group); group.addChild(threat2); threat2.setRiskWithoutAdditionalSafeguards("risk2"); new CnALink(threat2, itSystem, BpThreat.REL_BP_THREAT_BP_ITSYSTEM, null); assertEquals("risk2", RiskUiUtils.getEffectiveRisk(itSystem).getRiskId()); }
@Test public void only_unspecified_risks_in_linked_threats() { ItSystem itSystem = new ItSystem(null); itSystem.getEntity().setFlag(ItSystem.PROP_RISKANALYSIS_NECESSARY, true); BpThreatGroup group = new BpThreatGroup(null); BpThreat threat1 = new BpThreat(group); group.addChild(threat1); new CnALink(threat1, itSystem, BpThreat.REL_BP_THREAT_BP_ITSYSTEM, null); assertEquals(EffectiveRisk.UNKNOWN, RiskUiUtils.getEffectiveRisk(itSystem)); }
@Test public void only_accepted_risks_in_linked_threats() { ItSystem itSystem = new ItSystem(null); itSystem.getEntity().setFlag(ItSystem.PROP_RISKANALYSIS_NECESSARY, true); BpThreatGroup group = new BpThreatGroup(null); BpThreat threat1 = new BpThreat(group); group.addChild(threat1); threat1.setSimpleProperty(BpThreat.PROP_RISK_TREATMENT_OPTION, BpThreat.PROP_RISK_TREATMENT_OPTION_RISK_ACCEPTANCE); new CnALink(threat1, itSystem, BpThreat.REL_BP_THREAT_BP_ITSYSTEM, null); assertEquals(EffectiveRisk.TREATED, RiskUiUtils.getEffectiveRisk(itSystem)); }
@Test public void unspecified_and_accepted_risks_in_linked_threats() { ItSystem itSystem = new ItSystem(null); itSystem.getEntity().setFlag(ItSystem.PROP_RISKANALYSIS_NECESSARY, true); BpThreatGroup group = new BpThreatGroup(null); BpThreat threat1 = new BpThreat(group); group.addChild(threat1); new CnALink(threat1, itSystem, BpThreat.REL_BP_THREAT_BP_ITSYSTEM, null); BpThreat threat2 = new BpThreat(group); group.addChild(threat2); threat2.setSimpleProperty(BpThreat.PROP_RISK_TREATMENT_OPTION, BpThreat.PROP_RISK_TREATMENT_OPTION_RISK_ACCEPTANCE); new CnALink(threat2, itSystem, BpThreat.REL_BP_THREAT_BP_ITSYSTEM, null); assertEquals(EffectiveRisk.UNKNOWN, RiskUiUtils.getEffectiveRisk(itSystem)); }
@Test public void high_and_unspecified_risks_in_linked_threats() { ItSystem itSystem = new ItSystem(null); itSystem.getEntity().setFlag(ItSystem.PROP_RISKANALYSIS_NECESSARY, true); BpThreatGroup group = new BpThreatGroup(null); BpThreat threat1 = new BpThreat(group); threat1.setRiskWithoutAdditionalSafeguards("risk1"); group.addChild(threat1); new CnALink(threat1, itSystem, BpThreat.REL_BP_THREAT_BP_ITSYSTEM, null); BpThreat threat2 = new BpThreat(group); group.addChild(threat2); new CnALink(threat2, itSystem, BpThreat.REL_BP_THREAT_BP_ITSYSTEM, null); assertEquals(EffectiveRisk.UNKNOWN, RiskUiUtils.getEffectiveRisk(itSystem)); }
@Test public void high_and_accepted_risks_in_linked_threats() { ItSystem itSystem = new ItSystem(null); itSystem.getEntity().setFlag(ItSystem.PROP_RISKANALYSIS_NECESSARY, true); BpThreatGroup group = new BpThreatGroup(null); BpThreat threat1 = new BpThreat(group); threat1.setRiskWithoutAdditionalSafeguards("risk1"); group.addChild(threat1); new CnALink(threat1, itSystem, BpThreat.REL_BP_THREAT_BP_ITSYSTEM, null); BpThreat threat2 = new BpThreat(group); group.addChild(threat2); threat2.setSimpleProperty(BpThreat.PROP_RISK_TREATMENT_OPTION, BpThreat.PROP_RISK_TREATMENT_OPTION_RISK_ACCEPTANCE); new CnALink(threat2, itSystem, BpThreat.REL_BP_THREAT_BP_ITSYSTEM, null); assertEquals("risk1", RiskUiUtils.getEffectiveRisk(itSystem).getRiskId()); }