@Test public void testCopy() throws Exception { when(projectService.createFreshProjectName(any(), any())).thenCallRealMethod(); doReturn(Arrays.asList(mock(WorkspaceProject.class))).when(projectService).getAllWorkspaceProjectsByName(any(), eq("newName"), anyBoolean()); final WorkspaceProject project = mock(WorkspaceProject.class); final OrganizationalUnit ou = mock(OrganizationalUnit.class); final Path projectRoot = mock(Path.class); doReturn(ou).when(project).getOrganizationalUnit(); doReturn(projectRoot).when(project).getRootPath(); final Repository newRepository = mock(Repository.class); final Path newRepositoryRoot = PathFactory.newPath("root", "file: doReturn(Optional.of(new Branch("master", newRepositoryRoot))).when(newRepository).getDefaultBranch(); doReturn(newRepository).when(repositoryCopier).copy(ou, "newName", projectRoot); final ArgumentCaptor<POM> pomArgumentCaptor = ArgumentCaptor.forClass(POM.class); final POM pom = new POM(); doReturn(pom).when(pomService).load(any(Path.class)); final Metadata metadata = mock(Metadata.class); doReturn(metadata).when(metadataService).getMetadata(any(Path.class)); service.copy(project, "newName"); verify(pomService).save(any(Path.class), pomArgumentCaptor.capture(), eq(metadata), eq("Renaming the project."), eq(true)); final POM updatedPom = pomArgumentCaptor.getValue(); assertEquals("newName-1", updatedPom.getName()); assertEquals("newName", updatedPom.getGav().getArtifactId()); verify(newProjectEvent).fire(any()); }
@Override public void copy(final WorkspaceProject project, final String newName) { String newUniqueName = projectService.createFreshProjectName(project.getOrganizationalUnit(), newName); final Repository copy = repositoryCopier.copy(project.getOrganizationalUnit(), newName, project.getRootPath()); if (!copy.getDefaultBranch().isPresent()) { throw new IllegalStateException("Copy should have at least one branch."); } final Path newPomPath = Paths.convert(Paths.convert(copy.getDefaultBranch().get().getPath()).resolve("pom.xml")); final POM pom = pomService.load(newPomPath); if (pom != null) { pom.setName(newUniqueName); pom.getGav().setArtifactId(newName); pomService.save(newPomPath, pom, metadataService.getMetadata(newPomPath), "Renaming the project.", true); WorkspaceProject newProject = projectService.resolveProject(copy); newProjectEvent.fire(new NewProjectEvent(newProject)); } }
ProjectScreenServiceImpl implements ProjectScreenService { @Override public void copy(final WorkspaceProject project, final String newName) { String newUniqueName = projectService.createFreshProjectName(project.getOrganizationalUnit(), newName); final Repository copy = repositoryCopier.copy(project.getOrganizationalUnit(), newName, project.getRootPath()); if (!copy.getDefaultBranch().isPresent()) { throw new IllegalStateException("Copy should have at least one branch."); } final Path newPomPath = Paths.convert(Paths.convert(copy.getDefaultBranch().get().getPath()).resolve("pom.xml")); final POM pom = pomService.load(newPomPath); if (pom != null) { pom.setName(newUniqueName); pom.getGav().setArtifactId(newName); pomService.save(newPomPath, pom, metadataService.getMetadata(newPomPath), "Renaming the project.", true); WorkspaceProject newProject = projectService.resolveProject(copy); newProjectEvent.fire(new NewProjectEvent(newProject)); } } }
ProjectScreenServiceImpl implements ProjectScreenService { @Override public void copy(final WorkspaceProject project, final String newName) { String newUniqueName = projectService.createFreshProjectName(project.getOrganizationalUnit(), newName); final Repository copy = repositoryCopier.copy(project.getOrganizationalUnit(), newName, project.getRootPath()); if (!copy.getDefaultBranch().isPresent()) { throw new IllegalStateException("Copy should have at least one branch."); } final Path newPomPath = Paths.convert(Paths.convert(copy.getDefaultBranch().get().getPath()).resolve("pom.xml")); final POM pom = pomService.load(newPomPath); if (pom != null) { pom.setName(newUniqueName); pom.getGav().setArtifactId(newName); pomService.save(newPomPath, pom, metadataService.getMetadata(newPomPath), "Renaming the project.", true); WorkspaceProject newProject = projectService.resolveProject(copy); newProjectEvent.fire(new NewProjectEvent(newProject)); } } ProjectScreenServiceImpl(); @Inject  ProjectScreenServiceImpl(final WorkspaceProjectService projectService,
                                    final RepositoryService repositoryService,
                                    final KieModuleService moduleService,
                                    final ProjectScreenModelLoader loader,
                                    final ProjectScreenModelSaver saver,
                                    final RepositoryCopier repositoryCopier,
                                    final POMService pomService,
                                    final MetadataService metadataService,
                                    final Event<NewProjectEvent> newProjectEvent); }
ProjectScreenServiceImpl implements ProjectScreenService { @Override public void copy(final WorkspaceProject project, final String newName) { String newUniqueName = projectService.createFreshProjectName(project.getOrganizationalUnit(), newName); final Repository copy = repositoryCopier.copy(project.getOrganizationalUnit(), newName, project.getRootPath()); if (!copy.getDefaultBranch().isPresent()) { throw new IllegalStateException("Copy should have at least one branch."); } final Path newPomPath = Paths.convert(Paths.convert(copy.getDefaultBranch().get().getPath()).resolve("pom.xml")); final POM pom = pomService.load(newPomPath); if (pom != null) { pom.setName(newUniqueName); pom.getGav().setArtifactId(newName); pomService.save(newPomPath, pom, metadataService.getMetadata(newPomPath), "Renaming the project.", true); WorkspaceProject newProject = projectService.resolveProject(copy); newProjectEvent.fire(new NewProjectEvent(newProject)); } } ProjectScreenServiceImpl(); @Inject  ProjectScreenServiceImpl(final WorkspaceProjectService projectService,
                                    final RepositoryService repositoryService,
                                    final KieModuleService moduleService,
                                    final ProjectScreenModelLoader loader,
                                    final ProjectScreenModelSaver saver,
                                    final RepositoryCopier repositoryCopier,
                                    final POMService pomService,
                                    final MetadataService metadataService,
                                    final Event<NewProjectEvent> newProjectEvent); @Override ProjectScreenModel load(final Path pathToPom); @Override void save(final Path pathToPomXML,
                     final ProjectScreenModel model,
                     final String comment); @Override WorkspaceProject save(final Path pathToPomXML,
                                 final ProjectScreenModel model,
                                 final String comment,
                                 final DeploymentMode mode); @Override void delete(final WorkspaceProject project); @Override void copy(final WorkspaceProject project,
                     final String newName); @Override void reImport(final Path pathToPomXML); }
ProjectScreenServiceImpl implements ProjectScreenService { @Override public void copy(final WorkspaceProject project, final String newName) { String newUniqueName = projectService.createFreshProjectName(project.getOrganizationalUnit(), newName); final Repository copy = repositoryCopier.copy(project.getOrganizationalUnit(), newName, project.getRootPath()); if (!copy.getDefaultBranch().isPresent()) { throw new IllegalStateException("Copy should have at least one branch."); } final Path newPomPath = Paths.convert(Paths.convert(copy.getDefaultBranch().get().getPath()).resolve("pom.xml")); final POM pom = pomService.load(newPomPath); if (pom != null) { pom.setName(newUniqueName); pom.getGav().setArtifactId(newName); pomService.save(newPomPath, pom, metadataService.getMetadata(newPomPath), "Renaming the project.", true); WorkspaceProject newProject = projectService.resolveProject(copy); newProjectEvent.fire(new NewProjectEvent(newProject)); } } ProjectScreenServiceImpl(); @Inject  ProjectScreenServiceImpl(final WorkspaceProjectService projectService,
                                    final RepositoryService repositoryService,
                                    final KieModuleService moduleService,
                                    final ProjectScreenModelLoader loader,
                                    final ProjectScreenModelSaver saver,
                                    final RepositoryCopier repositoryCopier,
                                    final POMService pomService,
                                    final MetadataService metadataService,
                                    final Event<NewProjectEvent> newProjectEvent); @Override ProjectScreenModel load(final Path pathToPom); @Override void save(final Path pathToPomXML,
                     final ProjectScreenModel model,
                     final String comment); @Override WorkspaceProject save(final Path pathToPomXML,
                                 final ProjectScreenModel model,
                                 final String comment,
                                 final DeploymentMode mode); @Override void delete(final WorkspaceProject project); @Override void copy(final WorkspaceProject project,
                     final String newName); @Override void reImport(final Path pathToPomXML);  }