ScenarioValidationService extends AbstractKieContainerService { public List<FactMappingValidationError> validateSimulationStructure(Simulation simulation, Settings settings, Path path) { List<FactMapping> factMappings = simulation.getScesimModelDescriptor().getFactMappings(); if (factMappings.stream().allMatch(AbstractScenarioValidation::isToSkip)) { return Collections.emptyList(); } KieContainer kieContainer = getKieContainer(path); ScenarioSimulationModel.Type type = settings.getType(); if (DMN.equals(type)) { return validateDMN(simulation, settings, kieContainer); } else if (RULE.equals(type)) { return validateRULE(simulation, settings, kieContainer); } else { throw new IllegalArgumentException("Only DMN and RULE test scenarios can be validated"); } }  List<FactMappingValidationError> validateSimulationStructure(Simulation simulation, Settings settings, Path path);  }
@Test public void validateSimulationStructure() { Simulation simulation = new Simulation(); Settings settings = new Settings(); ScenarioValidationService scenarioValidationServiceSpy = spy(new ScenarioValidationService() { @Override protected List<FactMappingValidationError> validateDMN(Simulation simulation, Settings settings, KieContainer kieContainer) { return Collections.emptyList(); } @Override protected List<FactMappingValidationError> validateRULE(Simulation simulation, Settings settings, KieContainer kieContainer) { return Collections.emptyList(); } @Override protected KieContainer getKieContainer(Path path) { return kieContainerMock; } }); settings.setType(ScenarioSimulationModel.Type.DMN); scenarioValidationServiceSpy.validateSimulationStructure(simulation, settings, pathMock); verify(scenarioValidationServiceSpy, never()).validateDMN(eq(simulation), eq(settings), eq(kieContainerMock)); verify(scenarioValidationServiceSpy, never()).validateRULE(eq(simulation), eq(settings), eq(kieContainerMock)); reset(scenarioValidationServiceSpy); FactMapping sampleFactMapping = simulation.getScesimModelDescriptor() .addFactMapping(FactIdentifier.create("sample", String.class.getCanonicalName()), ExpressionIdentifier.create("sample", FactMappingType.GIVEN)); sampleFactMapping.addExpressionElement("sample", String.class.getCanonicalName()); settings.setType(ScenarioSimulationModel.Type.DMN); scenarioValidationServiceSpy.validateSimulationStructure(simulation, settings, pathMock); verify(scenarioValidationServiceSpy, timeout(1)).validateDMN(eq(simulation), eq(settings), eq(kieContainerMock)); reset(scenarioValidationServiceSpy); settings.setType(ScenarioSimulationModel.Type.RULE); scenarioValidationServiceSpy.validateSimulationStructure(simulation, settings, pathMock); verify(scenarioValidationServiceSpy, timeout(1)).validateRULE(eq(simulation), eq(settings), eq(kieContainerMock)); settings.setType(null); assertThatThrownBy(() -> scenarioValidationServiceSpy.validateSimulationStructure(simulation, settings, pathMock)) .isInstanceOf(IllegalArgumentException.class); }