Search in sources :

Example 6 with GAVAlreadyExistsException

use of org.guvnor.common.services.project.service.GAVAlreadyExistsException in project kie-wb-common by kiegroup.

the class ProjectScreenServiceImplTest method testSaveClashingGAVChangeToGAV.

@Test()
public void testSaveClashingGAVChangeToGAV() {
    when(pathToPom.toURI()).thenReturn("default://p0/pom.xml");
    final ProjectScreenModel model = new ProjectScreenModel();
    model.setPOM(new POM(new GAV("groupId", "artifactId", "2.0.0")));
    model.setPOMMetaData(pomMetaData);
    model.setPathToPOM(pathToPom);
    model.setKModule(kmodule);
    model.setKModuleMetaData(kmoduleMetaData);
    model.setPathToKModule(pathToKieModule);
    model.setProjectImports(projectImports);
    model.setProjectImportsMetaData(projectImportsMetaData);
    model.setPathToImports(pathToModuleImports);
    model.setRepositories(moduleRepositories);
    model.setPathToRepositories(pathToModuleRepositories);
    final MavenRepositoryMetadata repositoryMetadata = new MavenRepositoryMetadata("id", "url", MavenRepositorySource.LOCAL);
    moduleRepositories.getRepositories().add(new ModuleRepositories.ModuleRepository(true, repositoryMetadata));
    when(repositoryResolver.getRepositoriesResolvingArtifact(eq(gav), eq(module), eq(repositoryMetadata))).thenReturn(new HashSet<MavenRepositoryMetadata>() {

        {
            add(repositoryMetadata);
        }
    });
    final String comment = "comment";
    try {
        service.save(pathToPom, model, comment);
    } catch (GAVAlreadyExistsException e) {
    // This is expected! We catch here rather than let JUnit handle it with
    // @Test(expected = GAVAlreadyExistsException.class) so we can verify
    // that only the expected methods have been invoked.
    } catch (Exception e) {
        fail(e.getMessage());
    }
    verify(repositoryResolver, times(1)).getRepositoriesResolvingArtifact(eq(model.getPOM().getGav()), eq(module), any(MavenRepositoryMetadata.class));
    verify(pomService, times(1)).save(eq(pathToPom), eq(model.getPOM()), eq(pomMetaData), eq(comment));
    verify(kModuleService, times(1)).save(eq(pathToKieModule), eq(kmodule), eq(kmoduleMetaData), eq(comment));
    verify(importsService, times(1)).save(eq(pathToModuleImports), eq(projectImports), eq(projectImportsMetaData), eq(comment));
    verify(repositoriesService, times(1)).save(eq(pathToModuleRepositories), eq(moduleRepositories), eq(comment));
}
Also used : ModuleRepositories(org.guvnor.common.services.project.model.ModuleRepositories) MavenRepositoryMetadata(org.guvnor.common.services.project.model.MavenRepositoryMetadata) GAVAlreadyExistsException(org.guvnor.common.services.project.service.GAVAlreadyExistsException) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel) GAV(org.guvnor.common.services.project.model.GAV) GAVAlreadyExistsException(org.guvnor.common.services.project.service.GAVAlreadyExistsException) POM(org.guvnor.common.services.project.model.POM) Test(org.junit.Test)

Example 7 with GAVAlreadyExistsException

use of org.guvnor.common.services.project.service.GAVAlreadyExistsException in project kie-wb-common by kiegroup.

the class ProjectScreenServiceImplTest method testSaveClashingGAVNoChangeToGAV.

@Test()
public void testSaveClashingGAVNoChangeToGAV() {
    when(pathToPom.toURI()).thenReturn("default://p0/pom.xml");
    final ProjectScreenModel model = new ProjectScreenModel();
    model.setPOM(pom);
    model.setPOMMetaData(pomMetaData);
    model.setPathToPOM(pathToPom);
    model.setKModule(kmodule);
    model.setKModuleMetaData(kmoduleMetaData);
    model.setPathToKModule(pathToKieModule);
    model.setProjectImports(projectImports);
    model.setProjectImportsMetaData(projectImportsMetaData);
    model.setPathToImports(pathToModuleImports);
    model.setRepositories(moduleRepositories);
    model.setPathToRepositories(pathToModuleRepositories);
    final MavenRepositoryMetadata repositoryMetadata = new MavenRepositoryMetadata("id", "url", MavenRepositorySource.LOCAL);
    moduleRepositories.getRepositories().add(new ModuleRepositories.ModuleRepository(true, repositoryMetadata));
    when(repositoryResolver.getRepositoriesResolvingArtifact(eq(gav), eq(module), eq(repositoryMetadata))).thenReturn(new HashSet<MavenRepositoryMetadata>() {

        {
            add(repositoryMetadata);
        }
    });
    final String comment = "comment";
    try {
        service.save(pathToPom, model, comment);
    } catch (GAVAlreadyExistsException e) {
        fail(e.getMessage());
    }
    verify(repositoryResolver, never()).getRepositoriesResolvingArtifact(eq(model.getPOM().getGav()), eq(module));
    verify(pomService, times(1)).save(eq(pathToPom), eq(model.getPOM()), eq(pomMetaData), eq(comment));
    verify(kModuleService, times(1)).save(eq(pathToKieModule), eq(kmodule), eq(kmoduleMetaData), eq(comment));
    verify(importsService, times(1)).save(eq(pathToModuleImports), eq(projectImports), eq(projectImportsMetaData), eq(comment));
    verify(repositoriesService, times(1)).save(eq(pathToModuleRepositories), eq(moduleRepositories), eq(comment));
}
Also used : ModuleRepositories(org.guvnor.common.services.project.model.ModuleRepositories) MavenRepositoryMetadata(org.guvnor.common.services.project.model.MavenRepositoryMetadata) GAVAlreadyExistsException(org.guvnor.common.services.project.service.GAVAlreadyExistsException) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel) Test(org.junit.Test)

Example 8 with GAVAlreadyExistsException

use of org.guvnor.common.services.project.service.GAVAlreadyExistsException in project kie-wb-common by kiegroup.

the class AddProjectPopUpPresenter method getErrorCallback.

private ErrorCallback<?> getErrorCallback() {
    Map<Class<? extends Throwable>, CommandWithThrowableDrivenErrorCallback.CommandWithThrowable> errors = new HashMap<Class<? extends Throwable>, CommandWithThrowableDrivenErrorCallback.CommandWithThrowable>() {

        {
            put(GAVAlreadyExistsException.class, parameter -> {
                GAVAlreadyExistsException exception = (GAVAlreadyExistsException) parameter;
                view.hideBusyIndicator();
                conflictingRepositoriesPopup.setContent(exception.getGAV(), ((GAVAlreadyExistsException) parameter).getRepositories(), () -> {
                    conflictingRepositoriesPopup.hide();
                    createProject(DeploymentMode.FORCED);
                });
                conflictingRepositoriesPopup.show();
            });
            put(FileAlreadyExistsException.class, parameter -> {
                view.hideBusyIndicator();
                view.showError(view.getDuplicatedProjectMessage());
            });
        }
    };
    return createErrorCallback(errors);
}
Also used : GAVAlreadyExistsException(org.guvnor.common.services.project.service.GAVAlreadyExistsException) HashMap(java.util.HashMap) CommandWithThrowableDrivenErrorCallback(org.kie.workbench.common.widgets.client.callbacks.CommandWithThrowableDrivenErrorCallback)

Example 9 with GAVAlreadyExistsException

use of org.guvnor.common.services.project.service.GAVAlreadyExistsException in project kie-wb-common by kiegroup.

the class SettingsPresenterTest method testHandleSaveProjectScreenModelGavAlreadyExistsException.

@Test
public void testHandleSaveProjectScreenModelGavAlreadyExistsException() {
    doReturn(promises.resolve()).when(settingsPresenter).defaultErrorResolution(any());
    doReturn(promises.resolve()).when(settingsPresenter).handlePomConcurrentUpdate(any(), any(), any());
    final GAVAlreadyExistsException testException = new GAVAlreadyExistsException();
    settingsPresenter.handleSaveProjectScreenModelError("Test comment", null, testException);
    verify(settingsPresenter, never()).defaultErrorResolution(any());
    verify(settingsPresenter).handlePomConcurrentUpdate(eq("Test comment"), any(), eq(testException));
}
Also used : GAVAlreadyExistsException(org.guvnor.common.services.project.service.GAVAlreadyExistsException) Test(org.junit.Test)

Example 10 with GAVAlreadyExistsException

use of org.guvnor.common.services.project.service.GAVAlreadyExistsException in project kie-wb-common by kiegroup.

the class PomEditorServiceImplTest method testSaveClashingGAVNoChangeToGAV.

@Test
public void testSaveClashingGAVNoChangeToGAV() {
    when(pom.getGav()).thenReturn(new GAV("groupId", "artifactId", "0.0.1"));
    try {
        service.save(pomPath, pomXml, metaData, comment, DeploymentMode.VALIDATED);
    } catch (GAVAlreadyExistsException e) {
        // This is should not be thrown if the GAV has not changed.
        fail(e.getMessage());
    }
    verify(moduleService, times(1)).resolveModule(pomPath);
    verify(moduleRepositoriesService, never()).load(moduleRepositoriesPath);
    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();
}
Also used : Path(org.uberfire.backend.vfs.Path) MavenRepositoryMetadata(org.guvnor.common.services.project.model.MavenRepositoryMetadata) GAVAlreadyExistsException(org.guvnor.common.services.project.service.GAVAlreadyExistsException) CommentedOption(org.uberfire.java.nio.base.options.CommentedOption) FileSystem(org.uberfire.java.nio.file.FileSystem) GAV(org.guvnor.common.services.project.model.GAV) Test(org.junit.Test)

Aggregations

GAVAlreadyExistsException (org.guvnor.common.services.project.service.GAVAlreadyExistsException)15 MavenRepositoryMetadata (org.guvnor.common.services.project.model.MavenRepositoryMetadata)12 Test (org.junit.Test)11 ModuleRepositories (org.guvnor.common.services.project.model.ModuleRepositories)10 GAV (org.guvnor.common.services.project.model.GAV)8 ProjectScreenModel (org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel)5 CommentedOption (org.uberfire.java.nio.base.options.CommentedOption)5 FileSystem (org.uberfire.java.nio.file.FileSystem)5 POM (org.guvnor.common.services.project.model.POM)4 Path (org.uberfire.backend.vfs.Path)4 KieModule (org.kie.workbench.common.services.shared.project.KieModule)3 HashSet (java.util.HashSet)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)1 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)1 Branch (org.guvnor.structure.repositories.Branch)1 Repository (org.guvnor.structure.repositories.Repository)1 CommandWithThrowableDrivenErrorCallback (org.kie.workbench.common.widgets.client.callbacks.CommandWithThrowableDrivenErrorCallback)1