@Test public void testSaveClashingGAVForced() { final Set<ModuleRepositories.ModuleRepository> moduleRepositoriesMetadata = new HashSet<ModuleRepositories.ModuleRepository>() {{ add(new ModuleRepositories.ModuleRepository(true, new MavenRepositoryMetadata("local-id", "local-url", MavenRepositorySource.LOCAL))); }}; final ModuleRepositories moduleRepositories = new ModuleRepositories(moduleRepositoriesMetadata); when(moduleRepositoriesService.load(moduleRepositoriesPath)).thenReturn(moduleRepositories); final Set<MavenRepositoryMetadata> clashingRepositories = new HashSet<MavenRepositoryMetadata>() {{ add(new MavenRepositoryMetadata("local-id", "local-url", MavenRepositorySource.LOCAL)); }}; when(repositoryResolver.getRepositoriesResolvingArtifact(eq(pomXml), any(MavenRepositoryMetadata.class))).thenReturn(clashingRepositories); when(pom.getGav()).thenReturn(new GAV("groupId", "artifactId", "0.0.1")); try { service.save(pomPath, pomXml, metaData, comment, DeploymentMode.FORCED); } catch (GAVAlreadyExistsException e) { fail(e.getMessage()); } verify(moduleService, never()).resolveModule(pomPath); verify(moduleRepositoriesService, never()).load(pomPath); verify(repositoryResolver, never()).getRepositoriesResolvingArtifact(eq(pomXml), any(MavenRepositoryMetadata.class)); verify(ioService, times(1)).startBatch(any(FileSystem.class)); verify(ioService, times(1)).write(any(org.uberfire.java.nio.file.Path.class), eq(pomXml), eq(attributes), any(CommentedOption.class)); verify(ioService, times(1)).endBatch(); }
@Override public Path save(final Path pomPath, final String pomXml, final Metadata metadata, final String comment, final DeploymentMode mode) { if (DeploymentMode.VALIDATED.equals(mode)) { checkRepositories(pomPath, pomXml); } try { final org.uberfire.java.nio.file.Path nioPomPath = Paths.convert(pomPath); ioService.startBatch(nioPomPath.getFileSystem()); ioService.write(nioPomPath, pomXml, metadataService.setUpAttributes(pomPath, metadata), commentedOptionFactory.makeCommentedOption(comment)); return pomPath; } catch (Exception e) { throw ExceptionUtilities.handleException(e); } finally { ioService.endBatch(); } }
PomEditorServiceImpl implements PomEditorService { @Override public Path save(final Path pomPath, final String pomXml, final Metadata metadata, final String comment, final DeploymentMode mode) { if (DeploymentMode.VALIDATED.equals(mode)) { checkRepositories(pomPath, pomXml); } try { final org.uberfire.java.nio.file.Path nioPomPath = Paths.convert(pomPath); ioService.startBatch(nioPomPath.getFileSystem()); ioService.write(nioPomPath, pomXml, metadataService.setUpAttributes(pomPath, metadata), commentedOptionFactory.makeCommentedOption(comment)); return pomPath; } catch (Exception e) { throw ExceptionUtilities.handleException(e); } finally { ioService.endBatch(); } } }
PomEditorServiceImpl implements PomEditorService { @Override public Path save(final Path pomPath, final String pomXml, final Metadata metadata, final String comment, final DeploymentMode mode) { if (DeploymentMode.VALIDATED.equals(mode)) { checkRepositories(pomPath, pomXml); } try { final org.uberfire.java.nio.file.Path nioPomPath = Paths.convert(pomPath); ioService.startBatch(nioPomPath.getFileSystem()); ioService.write(nioPomPath, pomXml, metadataService.setUpAttributes(pomPath, metadata), commentedOptionFactory.makeCommentedOption(comment)); return pomPath; } catch (Exception e) { throw ExceptionUtilities.handleException(e); } finally { ioService.endBatch(); } } PomEditorServiceImpl(); @Inject  PomEditorServiceImpl(final @Named("ioStrategy") IOService ioService,
                                final DefaultEditorService defaultEditorService,
                                final MetadataServerSideService metadataService,
                                final CommentedOptionFactory commentedOptionFactory,
                                final KieModuleService moduleService,
                                final POMContentHandler pomContentHandler,
                                final ModuleRepositoryResolver repositoryResolver,
                                final ModuleRepositoriesService moduleRepositoriesService,
                                final RenameService renameService,
                                final SaveAndRenameServiceImpl<String, Metadata> saveAndRenameService); }
PomEditorServiceImpl implements PomEditorService { @Override public Path save(final Path pomPath, final String pomXml, final Metadata metadata, final String comment, final DeploymentMode mode) { if (DeploymentMode.VALIDATED.equals(mode)) { checkRepositories(pomPath, pomXml); } try { final org.uberfire.java.nio.file.Path nioPomPath = Paths.convert(pomPath); ioService.startBatch(nioPomPath.getFileSystem()); ioService.write(nioPomPath, pomXml, metadataService.setUpAttributes(pomPath, metadata), commentedOptionFactory.makeCommentedOption(comment)); return pomPath; } catch (Exception e) { throw ExceptionUtilities.handleException(e); } finally { ioService.endBatch(); } } PomEditorServiceImpl(); @Inject  PomEditorServiceImpl(final @Named("ioStrategy") IOService ioService,
                                final DefaultEditorService defaultEditorService,
                                final MetadataServerSideService metadataService,
                                final CommentedOptionFactory commentedOptionFactory,
                                final KieModuleService moduleService,
                                final POMContentHandler pomContentHandler,
                                final ModuleRepositoryResolver repositoryResolver,
                                final ModuleRepositoriesService moduleRepositoriesService,
                                final RenameService renameService,
                                final SaveAndRenameServiceImpl<String, Metadata> saveAndRenameService); @PostConstruct void init(); @Override DefaultEditorContent loadContent(final Path path); @Override Path save(final Path pomPath,
                     final String pomXml,
                     final Metadata metadata,
                     final String comment,
                     final DeploymentMode mode); @Override Path saveAndRename(final Path path,
                              final String newFileName,
                              final Metadata metadata,
                              final String content,
                              final String comment); @Override Path rename(final Path path,
                       final String newName,
                       final String comment); @Override Path save(final Path path,
                     final String content,
                     final Metadata metadata,
                     final String comment); }
PomEditorServiceImpl implements PomEditorService { @Override public Path save(final Path pomPath, final String pomXml, final Metadata metadata, final String comment, final DeploymentMode mode) { if (DeploymentMode.VALIDATED.equals(mode)) { checkRepositories(pomPath, pomXml); } try { final org.uberfire.java.nio.file.Path nioPomPath = Paths.convert(pomPath); ioService.startBatch(nioPomPath.getFileSystem()); ioService.write(nioPomPath, pomXml, metadataService.setUpAttributes(pomPath, metadata), commentedOptionFactory.makeCommentedOption(comment)); return pomPath; } catch (Exception e) { throw ExceptionUtilities.handleException(e); } finally { ioService.endBatch(); } } PomEditorServiceImpl(); @Inject  PomEditorServiceImpl(final @Named("ioStrategy") IOService ioService,
                                final DefaultEditorService defaultEditorService,
                                final MetadataServerSideService metadataService,
                                final CommentedOptionFactory commentedOptionFactory,
                                final KieModuleService moduleService,
                                final POMContentHandler pomContentHandler,
                                final ModuleRepositoryResolver repositoryResolver,
                                final ModuleRepositoriesService moduleRepositoriesService,
                                final RenameService renameService,
                                final SaveAndRenameServiceImpl<String, Metadata> saveAndRenameService); @PostConstruct void init(); @Override DefaultEditorContent loadContent(final Path path); @Override Path save(final Path pomPath,
                     final String pomXml,
                     final Metadata metadata,
                     final String comment,
                     final DeploymentMode mode); @Override Path saveAndRename(final Path path,
                              final String newFileName,
                              final Metadata metadata,
                              final String content,
                              final String comment); @Override Path rename(final Path path,
                       final String newName,
                       final String comment); @Override Path save(final Path path,
                     final String content,
                     final Metadata metadata,
                     final String comment);  }