@Test public void testSave() { final Path path = mock(Path.class); final String content = "content"; final Metadata metadata = mock(Metadata.class); final String comment = "comment"; doReturn(path).when(service).save(path, content, metadata, comment, DeploymentMode.FORCED); service.save(path, content, metadata, comment); verify(service).save(path, content, metadata, comment, DeploymentMode.FORCED); } }
@Test public void testRename() { final Path path = mock(Path.class); final String newFileName = "newFileName"; final String comment = "comment"; service.rename(path, newFileName, comment); verify(renameService).rename(path, newFileName, comment); }
@Test public void testSaveAndRename() { final Path path = mock(Path.class); final String newFileName = "newFileName"; final Metadata metadata = mock(Metadata.class); final String content = "content"; final String comment = "comment"; service.saveAndRename(path, newFileName, metadata, content, comment); verify(saveAndRenameService).saveAndRename(path, newFileName, metadata, content, comment); }
protected WorkspaceProject renameIfNecessary(final OrganizationalUnit ou, final WorkspaceProject project) { String name = project.getName(); Collection<WorkspaceProject> projectsWithSameName = projectService.getAllWorkspaceProjectsByName(ou, name); if (projectsWithSameName.size() > 1) { name = this.projectService.createFreshProjectName(ou, project.getName()); } if (!name.equals(project.getName())) { final Path pomXMLPath = project.getMainModule().getPomXMLPath(); final ProjectScreenModel model = projectScreenService.load(pomXMLPath); model.getPOM().setName(name); projectScreenService.save(pomXMLPath, model, ""); return projectService.resolveProject(pomXMLPath); } return project; }
@Test public void nameIsNotTaken() { service.setupExamples(exampleOrganizationalUnit, importProjects); verify(repositoryCopier).copy(any(OrganizationalUnit.class), eq("example-module1"), any(Path.class)); verify(projectScreenService, never()).save(any(), any(), any()); }
@Test public void testSetupWithOneSectionSetupRejection() { final Section<ProjectScreenModel> section1 = newMockedSection(); final Section<ProjectScreenModel> section2 = newMockedSection(); doReturn(new ArrayList<>(Arrays.asList(section1, section2))).when(sectionManager).getSections(); doReturn(promises.reject("Test")).when(presenter).setupSections(any()); presenter.setupUsingCurrentSection(); verify(view).init(eq(presenter)); verify(view).showBusyIndicator(); verify(projectScreenService).load(any()); verify(presenter).setupSections(any()); // All sections are setup regardless of exceptions/rejections verify(notificationEvent).fire(any()); }
@Test public void testReImport() throws Exception { service.reImport(pathToPom); verify(moduleService).reImport(pathToPom); }
CommandWithFileNameAndCommitMessage getDuplicateCommand() { return details -> { copyPopUpPresenter.getView().hide(); view.showBusyIndicator(view.getLoadingMessage()); promises.promisify(projectScreenService, s -> { s.copy(workspaceProject, details.getNewFileName()); }).then(i -> { view.hideBusyIndicator(); notificationEvent.fire(new NotificationEvent(view.getItemSuccessfullyDuplicatedMessage(), NotificationEvent.NotificationType.SUCCESS)); return promises.resolve(); }).catch_(this::onError); }; }
@Test public void testLoad() { final DefaultEditorContent content = service.loadContent(pomPath); assertNotNull(content); assertEquals(this.content, content); }
@Test public void testDelete() throws Exception { final WorkspaceProject project = mock(WorkspaceProject.class); final Repository repository = mock(Repository.class); final String ouName = "test-realm"; final Space space = new Space(ouName); doReturn(repository).when(project).getRepository(); doReturn("myrepo").when(repository).getAlias(); doReturn(space).when(repository).getSpace(); service.delete(project); verify(repositoryService).removeRepository(eq(space), eq("myrepo")); } }
@Test public void testForceSave() { WorkspaceProject project = mock(WorkspaceProject.class); doReturn(project).when(projectScreenService).save(any(), any(), any(), any()); presenter.concurrentPomUpdateInfo = mock(ObservablePath.OnConcurrentUpdateEvent.class); presenter.forceSave("Test comment", null); assertEquals(null, presenter.concurrentPomUpdateInfo); verify(conflictingRepositoriesPopup).hide(); verify(presenter).saveProjectScreenModel(eq("Test comment"), eq(DeploymentMode.FORCED), any()); }
@Test public void testSaveNonClashingGAV() { presenter.save(comment); verify(service, times(1)).save(any(ObservablePath.class), eq(pomXml), any(Metadata.class), eq(comment), eq(DeploymentMode.VALIDATED)); verify(view, times(1)).showBusyIndicator(eq(CommonConstants.INSTANCE.Saving())); verify(view, times(1)).hideBusyIndicator(); }
public void reimport() { if (this.userCanUpdateProject()) { final Path pomXMLPath = workspaceProject.getMainModule().getPomXMLPath(); view.showBusyIndicator(view.getLoadingMessage()); promises.promisify(projectScreenService, s -> { s.reImport(pomXMLPath); }).then(i -> { view.hideBusyIndicator(); notificationEvent.fire(new NotificationEvent(view.getReimportSuccessfulMessage(), NotificationEvent.NotificationType.SUCCESS)); return promises.resolve(); }).catch_(this::onError); } }
@Test public void testSaveProjectScreenModelThrowingException() { final RuntimeException testException = mock(RuntimeException.class); doThrow(testException).when(projectScreenService).save(any(), any(), any(), any()); presenter.saveProjectScreenModel("Test comment", DeploymentMode.VALIDATED, null).catch_(i -> { fail("Promise should've been resolved!"); return promises.resolve(); }); verify(projectScreenService).save(any(), any(), eq("Test comment"), eq(DeploymentMode.VALIDATED)); verify(presenter, never()).handlePomConcurrentUpdate(any(), any()); }
@Test public void testSaveInvalid() { doThrow(new InvalidPomException(10, 10)) .when(service).save(any(ObservablePath.class), eq(pomXml), any(Metadata.class), eq(comment), eq(DeploymentMode.VALIDATED)); presenter.save(comment); verify(service, times(1)).save(any(ObservablePath.class), eq(pomXml), any(Metadata.class), eq(comment), eq(DeploymentMode.VALIDATED)); verify(view, times(1)).showBusyIndicator(eq(CommonConstants.INSTANCE.Saving())); verify(view, times(1)).hideBusyIndicator(); verify(notificationEvent, times(1)).fire(any()); }
@Test public void testSaveProjectScreenModelWithLocallyDetectedConcurrentUpdate() { presenter.concurrentPomUpdateInfo = mock(ObservablePath.OnConcurrentUpdateEvent.class); doNothing().when(presenter).handlePomConcurrentUpdate(eq("Test comment"), any()); presenter.saveProjectScreenModel("Test comment", DeploymentMode.VALIDATED, null).then(i -> { fail("Promise should've not been resolved!"); return promises.resolve(); }); verify(projectScreenService, never()).save(any(), any(), any(), any()); verify(presenter).handlePomConcurrentUpdate(eq("Test comment"), any()); }
private void doSave(final String commitMessage, final DeploymentMode mode) { //Instantiate a new instance on each "save" operation to pass in commit message view.showBusyIndicator(CommonConstants.INSTANCE.Saving()); pomEditorService.call(getSaveSuccessCallback(view.getContent().hashCode()), new CommandWithThrowableDrivenErrorCallback(busyIndicatorView, saveErrorCallbackConfig(commitMessage))) .save(versionRecordManager.getCurrentPath(), view.getContent(), metadata, commitMessage, mode); }
@Test public void nameIsNotTaken() { String module1 = "module1"; WorkspaceProject project1 = mock(WorkspaceProject.class, Answers.RETURNS_DEEP_STUBS.get()); doReturn(module1).when(project1).getName(); when(project1.getMainModule().getPomXMLPath()).thenReturn(mock(Path.class)); doReturn(project1).when(service).importProject(eq(organizationalUnit), any()); service.importProjects(organizationalUnit, importProjects); verify(projectService, never()).createFreshProjectName(any(), anyString()); verify(projectScreenService, never()).save(any(), any(), any()); }
@Test public void testSaveNonClashingGAVNoChangeToGAV() { when(pom.getGav()).thenReturn(new GAV("groupId", "artifactId", "0.0.1")); service.save(pomPath, pomXml, metaData, comment, DeploymentMode.VALIDATED); verify(moduleService, times(1)).resolveModule(pomPath); verify(moduleRepositoriesService, never()).load(moduleRepositoriesPath); verify(repositoryResolver, never()).getRepositoriesResolvingArtifact(eq(pomXml)); 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(); }
Promise<Void> saveProjectScreenModel(final String comment, final DeploymentMode mode, final Supplier<Promise<Void>> chain) { if (concurrentPomUpdateInfo != null) { handlePomConcurrentUpdate(comment, chain); return promises.reject(sectionManager.getCurrentSection()); } return promises.promisify(projectScreenService, s -> { return s.save(pathToPom, model, comment, mode); }).then(workspaceProject -> { projectContext.updateProjectModule(workspaceProject.getMainModule()); return promises.resolve(); }).catch_(o -> promises.catchOrExecute(o, e -> { if (e instanceof GAVAlreadyExistsException) { return handlePomConcurrentUpdate(comment, chain, (GAVAlreadyExistsException) e); } else { view.hideBusyIndicator(); return promises.resolve(); } }, x -> { view.hideBusyIndicator(); return promises.reject(x); })); }