PlanningSolutionCopyHelper implements CopyHelper { @Override public void postProcess(Path sourcePath, Path destinationPath) { String dataObjectSource = ioService.readAllString(Paths.convert(sourcePath)); GenerationResult generationResult = dataModelerService.loadDataObject(sourcePath, dataObjectSource, sourcePath); if (generationResult.hasErrors()) { LOGGER.warn("Path " + sourcePath + " 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(sourcePath).getPackageMainResourcesPath()); org.uberfire.java.nio.file.Path sourcePackage = Files.isDirectory(source) ? source : source.getParent(); String sourceDataObjectFileName = sourcePath.getFileName().substring(0, sourcePath.getFileName().indexOf(".")); org.uberfire.java.nio.file.Path destination = Paths.convert(kieModuleService.resolvePackage(destinationPath).getPackageMainResourcesPath()); org.uberfire.java.nio.file.Path destinationPackage = Files.isDirectory(destination) ? destination : destination.getParent(); String destinationDataObjectFileName = destinationPath.getFileName().substring(0, destinationPath.getFileName().indexOf(".")); boolean scoreHolderGlobalFileExists = ioService.exists(sourcePackage.resolve(sourceDataObjectFileName + SCORE_HOLDER_GLOBAL_FILE_SUFFIX)); if (scoreHolderGlobalFileExists) { ioService.copy(sourcePackage.resolve(sourceDataObjectFileName + SCORE_HOLDER_GLOBAL_FILE_SUFFIX), destinationPackage.resolve(destinationDataObjectFileName + SCORE_HOLDER_GLOBAL_FILE_SUFFIX)); } } } } PlanningSolutionCopyHelper(); @Inject  PlanningSolutionCopyHelper(@Named("ioStrategy") final IOService ioService,
                                      final DataModelerService dataModelerService,
                                      final KieModuleService kieModuleService); @Override boolean supports(Path path); @Override void postProcess(Path sourcePath,
                            Path destinationPath);  }
@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); copyHelper.postProcess(sourcePath, destinationPath); verify(ioService, times(1)).copy(any(org.uberfire.java.nio.file.Path.class), any(org.uberfire.java.nio.file.Path.class)); }
@Test public void sourceDataObjectIsNull() { generationResult.setDataObject(null); copyHelper.postProcess(sourcePath, destinationPath); verify(ioService, never()).exists(any()); }
@Test public void sourceDataObjectIsNotPlanningSolution() { DataObject dataObject = new DataObjectImpl("test", "TestSource"); generationResult.setDataObject(dataObject); copyHelper.postProcess(sourcePath, destinationPath); verify(ioService, never()).exists(any()); }