Search in sources :

Example 6 with MavenRepositoryMetadata

use of org.guvnor.common.services.project.model.MavenRepositoryMetadata in project kie-wb-common by kiegroup.

the class ProjectScreenServiceImplTest method testSaveClashingGAVFilteredRepositoryChangeToGAV.

@Test()
public void testSaveClashingGAVFilteredRepositoryChangeToGAV() {
    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(false, repositoryMetadata));
    final ArgumentCaptor<MavenRepositoryMetadata> filterCaptor = ArgumentCaptor.forClass(MavenRepositoryMetadata.class);
    when(repositoryResolver.getRepositoriesResolvingArtifact(eq(gav), eq(module), filterCaptor.capture())).thenReturn(new HashSet<MavenRepositoryMetadata>());
    final String comment = "comment";
    try {
        service.save(pathToPom, model, comment);
    } catch (GAVAlreadyExistsException e) {
        // This should not be thrown if we're filtering out the Repository from the check
        fail(e.getMessage());
    }
    final List<MavenRepositoryMetadata> filter = filterCaptor.getAllValues();
    assertEquals(0, filter.size());
    verify(repositoryResolver, times(1)).getRepositoriesResolvingArtifact(eq(model.getPOM().getGav()), eq(module));
    verify(ioService, times(1)).startBatch(any(FileSystem.class), any(CommentedOption.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));
    verify(ioService, times(1)).endBatch();
}
Also used : ModuleRepositories(org.guvnor.common.services.project.model.ModuleRepositories) GAVAlreadyExistsException(org.guvnor.common.services.project.service.GAVAlreadyExistsException) POM(org.guvnor.common.services.project.model.POM) MavenRepositoryMetadata(org.guvnor.common.services.project.model.MavenRepositoryMetadata) CommentedOption(org.uberfire.java.nio.base.options.CommentedOption) FileSystem(org.uberfire.java.nio.file.FileSystem) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel) GAV(org.guvnor.common.services.project.model.GAV) Test(org.junit.Test)

Example 7 with MavenRepositoryMetadata

use of org.guvnor.common.services.project.model.MavenRepositoryMetadata 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 8 with MavenRepositoryMetadata

use of org.guvnor.common.services.project.model.MavenRepositoryMetadata 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 9 with MavenRepositoryMetadata

use of org.guvnor.common.services.project.model.MavenRepositoryMetadata in project kie-wb-common by kiegroup.

the class ValidationItemPresenterTest method testSetup.

@Test
public void testSetup() {
    final ModuleRepositories.ModuleRepository projectRepository = mock(ModuleRepositories.ModuleRepository.class);
    final ValidationPresenter parentPresenter = mock(ValidationPresenter.class);
    doReturn(new MavenRepositoryMetadata("test", "https://test.url", MavenRepositorySource.LOCAL)).when(projectRepository).getMetadata();
    validationItemPresenter.setup(projectRepository, parentPresenter);
    verify(view).init(eq(validationItemPresenter));
    verify(view).setInclude(anyBoolean());
    verify(view).setId(any());
    verify(view).setUrl(any());
    verify(view).setSource(any());
}
Also used : ModuleRepositories(org.guvnor.common.services.project.model.ModuleRepositories) MavenRepositoryMetadata(org.guvnor.common.services.project.model.MavenRepositoryMetadata) Test(org.junit.Test)

Example 10 with MavenRepositoryMetadata

use of org.guvnor.common.services.project.model.MavenRepositoryMetadata in project kie-wb-common by kiegroup.

the class PomEditorServiceImplTest method testSaveNonClashingGAVChangeToGAV.

@Test
public void testSaveNonClashingGAVChangeToGAV() {
    final Set<ModuleRepositories.ModuleRepository> moduleRepositoriesMetadata = new HashSet<ModuleRepositories.ModuleRepository>();
    final ModuleRepositories moduleRepositories = new ModuleRepositories(moduleRepositoriesMetadata);
    when(moduleRepositoriesService.load(moduleRepositoriesPath)).thenReturn(moduleRepositories);
    final ArgumentCaptor<MavenRepositoryMetadata> resolvedRepositoriesCaptor = ArgumentCaptor.forClass(MavenRepositoryMetadata.class);
    when(repositoryResolver.getRepositoriesResolvingArtifact(eq(pomXml), resolvedRepositoriesCaptor.capture())).thenReturn(Collections.EMPTY_SET);
    when(pom.getGav()).thenReturn(new GAV("groupId", "artifactId", "0.0.2"));
    service.save(pomPath, pomXml, metaData, comment, DeploymentMode.VALIDATED);
    verify(moduleService, times(1)).resolveModule(pomPath);
    verify(moduleRepositoriesService, times(1)).load(moduleRepositoriesPath);
    verify(repositoryResolver, times(1)).getRepositoriesResolvingArtifact(eq(pomXml));
    final List<MavenRepositoryMetadata> resolvedRepositories = resolvedRepositoriesCaptor.getAllValues();
    assertNotNull(resolvedRepositories);
    assertEquals(0, resolvedRepositories.size());
    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) ModuleRepositories(org.guvnor.common.services.project.model.ModuleRepositories) MavenRepositoryMetadata(org.guvnor.common.services.project.model.MavenRepositoryMetadata) CommentedOption(org.uberfire.java.nio.base.options.CommentedOption) FileSystem(org.uberfire.java.nio.file.FileSystem) GAV(org.guvnor.common.services.project.model.GAV) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

MavenRepositoryMetadata (org.guvnor.common.services.project.model.MavenRepositoryMetadata)19 ModuleRepositories (org.guvnor.common.services.project.model.ModuleRepositories)17 Test (org.junit.Test)15 GAVAlreadyExistsException (org.guvnor.common.services.project.service.GAVAlreadyExistsException)11 GAV (org.guvnor.common.services.project.model.GAV)8 HashSet (java.util.HashSet)7 Path (org.uberfire.backend.vfs.Path)6 CommentedOption (org.uberfire.java.nio.base.options.CommentedOption)6 FileSystem (org.uberfire.java.nio.file.FileSystem)6 POM (org.guvnor.common.services.project.model.POM)5 ProjectScreenModel (org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel)5 KieModule (org.kie.workbench.common.services.shared.project.KieModule)5 ResourceUpdatedEvent (org.uberfire.workbench.events.ResourceUpdatedEvent)3 Branch (org.guvnor.structure.repositories.Branch)2 Repository (org.guvnor.structure.repositories.Repository)2 IOException (java.io.IOException)1 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)1 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)1 Path (org.uberfire.java.nio.file.Path)1