PlanningSolutionDeleteHelper implements DeleteHelper { @Override public void postProcess(final Path path) { String dataObjectSource = ioService.readAllString(Paths.convert(path)); GenerationResult generationResult = dataModelerService.loadDataObject(path, dataObjectSource, path); if (generationResult.hasErrors()) { LOGGER.warn("Path " + path + " parsing as a data object has failed. Score holder global generation will be skipped."); } else { DataObject dataObject = generationResult.getDataObject(); if (dataObject != null && dataObject.getAnnotation(PLANNING_SOLUTION_ANNOTATION) != null) { org.uberfire.java.nio.file.Path source = Paths.convert(kieModuleService.resolvePackage(path).getPackageMainResourcesPath()); org.uberfire.java.nio.file.Path sourcePackage = Files.isDirectory(source) ? source : source.getParent(); String dataObjectFileName = path.getFileName().substring(0, path.getFileName().indexOf(".")); ioService.deleteIfExists(sourcePackage.resolve(dataObjectFileName + SCORE_HOLDER_GLOBAL_FILE_SUFFIX)); } } } PlanningSolutionDeleteHelper(); @Inject  PlanningSolutionDeleteHelper(@Named("ioStrategy") final IOService ioService,
                                        final DataModelerService dataModelerService,
                                        final KieModuleService kieModuleService); @Override boolean supports(final Path path); @Override void postProcess(final Path path);  }
@Test public void postProcess() { DataObject dataObject = new DataObjectImpl("test", "TestSource"); dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); generationResult.setDataObject(dataObject); Package _package = mock(Package.class); when(_package.getPackageMainResourcesPath()).thenReturn(PathFactory.newPath("dataObjects", "file: when(kieModuleService.resolvePackage(sourcePath)).thenReturn(_package); when(ioService.exists(any())).thenReturn(true); deleteHelper.postProcess(sourcePath); verify(ioService, times(1)).deleteIfExists(any(org.uberfire.java.nio.file.Path.class)); }
@Test public void sourceDataObjectIsNull() { generationResult.setDataObject(null); deleteHelper.postProcess(sourcePath); verify(ioService, never()).exists(any()); }
@Test public void sourceDataObjectIsNotPlanningSolution() { DataObject dataObject = new DataObjectImpl("test", "TestSource"); generationResult.setDataObject(dataObject); deleteHelper.postProcess(sourcePath); verify(ioService, never()).exists(any()); }