DMNSimulationUtils { public static DMNModel findDMNModel(List<DMNModel> dmnModels, List<String> pathToFind, int step) { List<DMNModel> result = new ArrayList<>(); String pathToCompare = String.join(delimiter, pathToFind.subList(0, step)); for (DMNModel dmnModel : dmnModels) { String modelPath = new StringBuilder(dmnModel.getResource().getSourcePath()).reverse().toString(); if (modelPath.startsWith(pathToCompare)) { result.add(dmnModel); } } if (result.size() == 0) { throw new ImpossibleToFindDMNException("Retrieving the DMNModel has failed. Make sure the used DMN asset does not " + "produce any compilation errors and that the project does not " + "contain multiple DMN assets with the same name and namespace. " + "In addition, check if the reference to the DMN file is correct " + "in the Settings panel. " + "After addressing the issues, build the project again."); } else if (result.size() == 1) { return result.get(0); } else { return findDMNModel(dmnModels, pathToFind, step + 1); } } private  DMNSimulationUtils(); static DMNModel extractDMNModel(DMNRuntime dmnRuntime, String path); static DMNRuntime extractDMNRuntime(KieContainer kieContainer); static DMNModel findDMNModel(List<DMNModel> dmnModels, List<String> pathToFind, int step);  }
@Test public void findDMNModel() { List<String> pathToFind = Arrays.asList(new StringBuilder("to/find").reverse().toString().split("/")); List<DMNModel> models = Stream.of("this/should/not/match", "find", "something/to/find") .map(this::createDMNModelMock).collect(Collectors.toList()); DMNSimulationUtils.findDMNModel(models, pathToFind, 1); List<String> impossibleToFind = Arrays.asList(new StringBuilder("not/find").reverse().toString().split("/")); Assertions.assertThatThrownBy(() -> DMNSimulationUtils.findDMNModel(models, impossibleToFind, 1)) .isInstanceOf(ImpossibleToFindDMNException.class) .hasMessage("Retrieving the DMNModel has failed. Make sure the used DMN asset does not " + "produce any compilation errors and that the project does not " + "contain multiple DMN assets with the same name and namespace. " + "In addition, check if the reference to the DMN file is correct " + "in the Settings panel. " + "After addressing the issues, build the project again."); }