Search in sources :

Example 1 with RefactoringStatus

use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus in project che by eclipse.

the class RenamePresenterTest method changesShouldNotBeAppliedAndShowErrorMessage.

@Test
public void changesShouldNotBeAppliedAndShowErrorMessage() throws Exception {
    RefactoringStatus refactoringStatus = mock(RefactoringStatus.class);
    when(refactoringStatus.getSeverity()).thenReturn(4);
    when(changeCreationResult.isCanShowPreviewPage()).thenReturn(false);
    when(changeCreationResult.getStatus()).thenReturn(refactoringStatus);
    renamePresenter.show(refactorInfo);
    verify(refactorService).createRenameRefactoring(createRenameRefactoringDto);
    verify(renameRefactoringSessionPromise).then(renameRefactoringSessionCaptor.capture());
    renameRefactoringSessionCaptor.getValue().apply(session);
    renamePresenter.onAcceptButtonClicked();
    verify(refactoringSession).setSessionId(SESSION_ID);
    verifyPreparingRenameSettingsDto();
    verifyPreparingRenameChanges();
    verify(changeCreationResultPromise).then(changeCreationResultCaptor.capture());
    changeCreationResultCaptor.getValue().apply(changeCreationResult);
    verify(view).showErrorMessage(any());
}
Also used : RefactoringStatus(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus) Test(org.junit.Test)

Example 2 with RefactoringStatus

use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus in project che by eclipse.

the class MovePresenter method setMoveDestinationPath.

/** {@inheritDoc} */
@Override
public void setMoveDestinationPath(String path, String projectPath) {
    ReorgDestination destination = dtoFactory.createDto(ReorgDestination.class);
    destination.setType(ReorgDestination.DestinationType.PACKAGE);
    destination.setSessionId(refactoringSessionId);
    destination.setProjectPath(projectPath);
    destination.setDestination(path);
    Promise<RefactoringStatus> promise = refactorService.setDestination(destination);
    promise.then(new Operation<RefactoringStatus>() {

        @Override
        public void apply(RefactoringStatus arg) throws OperationException {
            view.setEnableAcceptButton(true);
            view.setEnablePreviewButton(true);
            switch(arg.getSeverity()) {
                case INFO:
                    view.showStatusMessage(arg);
                    break;
                case WARNING:
                    view.showStatusMessage(arg);
                    break;
                case ERROR:
                    showErrorMessage(arg);
                    break;
                case FATAL:
                    showErrorMessage(arg);
                    break;
                case OK:
                default:
                    view.clearStatusMessage();
                    break;
            }
        }
    });
}
Also used : RefactoringStatus(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus) ReorgDestination(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ReorgDestination) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 3 with RefactoringStatus

use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus in project che by eclipse.

the class RenameRefactoringTest method testApplyLinkedRename.

@Test
public void testApplyLinkedRename() throws Exception {
    StringBuilder b = new StringBuilder();
    b.append("package p;\n");
    b.append("public class A{}\n");
    ICompilationUnit unit = getPackageP().createCompilationUnit("A.java", b.toString(), false, null);
    IType type = unit.getAllTypes()[0];
    RenameRefactoringSession refactoring = manager.createRenameRefactoring(type, unit, b.indexOf("A"), true);
    assertThat(refactoring).isNotNull();
    assertThat(refactoring.getSessionId()).isNotNull().isNotEmpty();
    LinkedRenameRefactoringApply apply = new DtoServerImpls.LinkedRenameRefactoringApplyImpl();
    apply.setSessionId(refactoring.getSessionId());
    apply.setNewName("Test");
    RefactoringStatus status = manager.applyLinkedRename(apply);
    assertThat(status).isNotNull();
    assertThat(status.getSeverity()).isEqualTo(RefactoringStatus.OK);
    assertThat(unit.exists()).isFalse();
    ICompilationUnit newUnit = getPackageP().getCompilationUnit("Test.java");
    assertThat(newUnit.exists()).isTrue();
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) RefactoringStatus(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus) LinkedRenameRefactoringApply(org.eclipse.che.ide.ext.java.shared.dto.refactoring.LinkedRenameRefactoringApply) RenameRefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Example 4 with RefactoringStatus

use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus in project che by eclipse.

the class RenameRefactoringTest method testRenameValidateName.

@Test
public void testRenameValidateName() throws Exception {
    StringBuilder b = new StringBuilder();
    b.append("package p;\n");
    b.append("public class A{}\n");
    ICompilationUnit unit = getPackageP().createCompilationUnit("A.java", b.toString(), false, null);
    IType type = unit.getAllTypes()[0];
    RenameRefactoringSession refactoring = manager.createRenameRefactoring(type, unit, b.indexOf("A"), false);
    DtoServerImpls.ValidateNewNameImpl validateNewName = new DtoServerImpls.ValidateNewNameImpl();
    validateNewName.setSessionId(refactoring.getSessionId());
    validateNewName.setNewName("MyClass");
    RefactoringStatus status = manager.renameValidateNewName(validateNewName);
    assertThat(status).isNotNull();
    assertThat(status.getSeverity()).isEqualTo(RefactoringStatus.OK);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) DtoServerImpls(org.eclipse.che.plugin.java.server.dto.DtoServerImpls) RefactoringStatus(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus) RenameRefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Example 5 with RefactoringStatus

use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus in project che by eclipse.

the class RenameRefactoringTest method testDoRename.

@Test
public void testDoRename() throws Exception {
    StringBuilder b = new StringBuilder();
    b.append("package p;\n");
    b.append("public class A{}\n");
    ICompilationUnit unit = getPackageP().createCompilationUnit("A.java", b.toString(), false, null);
    IType type = unit.getAllTypes()[0];
    RenameRefactoringSession refactoring = manager.createRenameRefactoring(type, unit, b.indexOf("A"), false);
    DtoServerImpls.ValidateNewNameImpl validateNewName = new DtoServerImpls.ValidateNewNameImpl();
    validateNewName.setSessionId(refactoring.getSessionId());
    validateNewName.setNewName("MyClass");
    manager.renameValidateNewName(validateNewName);
    RenameSettings settings = new DtoServerImpls.RenameSettingsImpl();
    settings.setSessionId(refactoring.getSessionId());
    settings.setDeprecateDelegates(true);
    settings.setUpdateReferences(true);
    manager.setRenameSettings(settings);
    ChangeCreationResult change = manager.createChange(refactoring.getSessionId());
    assertThat(change).isNotNull();
    RefactoringStatus applyRefactoring = manager.applyRefactoring(refactoring.getSessionId());
    assertThat(applyRefactoring).isNotNull();
    assertThat(applyRefactoring.getSeverity()).isEqualTo(RefactoringStatus.OK);
    assertThat(unit.exists()).isFalse();
    ICompilationUnit newUnit = getPackageP().getCompilationUnit("MyClass.java");
    assertThat(newUnit.exists()).isTrue();
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) DtoServerImpls(org.eclipse.che.plugin.java.server.dto.DtoServerImpls) RefactoringStatus(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus) RenameSettings(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameSettings) ChangeCreationResult(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult) RenameRefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Aggregations

RefactoringStatus (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus)12 Test (org.junit.Test)9 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)7 IType (org.eclipse.jdt.core.IType)7 RenameRefactoringSession (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession)6 DtoServerImpls (org.eclipse.che.plugin.java.server.dto.DtoServerImpls)5 ReorgDestination (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ReorgDestination)3 OperationException (org.eclipse.che.api.promises.client.OperationException)2 ValidateNewName (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ValidateNewName)2 Operation (org.eclipse.che.api.promises.client.Operation)1 PromiseError (org.eclipse.che.api.promises.client.PromiseError)1 ChangeCreationResult (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult)1 ChangePreview (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangePreview)1 LinkedRenameRefactoringApply (org.eclipse.che.ide.ext.java.shared.dto.refactoring.LinkedRenameRefactoringApply)1 MoveSettings (org.eclipse.che.ide.ext.java.shared.dto.refactoring.MoveSettings)1 RefactoringChange (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringChange)1 RefactoringPreview (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringPreview)1 RenameSettings (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameSettings)1 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1