Search in sources :

Example 6 with ModuleRepositories

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

the class ProjectScreenModelSaverTest method testRepositoriesSave.

@Test
public void testRepositoriesSave() throws Exception {
    final ProjectScreenModel model = new ProjectScreenModel();
    final ModuleRepositories moduleRepositories = new ModuleRepositories();
    model.setRepositories(moduleRepositories);
    final Path pathToRepositories = mock(Path.class);
    model.setPathToRepositories(pathToRepositories);
    saver.save(pathToPom, model, DeploymentMode.FORCED, "message repositories");
    verify(repositoriesService).save(eq(pathToRepositories), eq(moduleRepositories), eq("message repositories"));
}
Also used : Path(org.uberfire.backend.vfs.Path) ModuleRepositories(org.guvnor.common.services.project.model.ModuleRepositories) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel) Test(org.junit.Test)

Example 7 with ModuleRepositories

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

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

the class ProjectScreenServiceImplTest method setup.

@Before
public void setup() {
    projectImports = new ProjectImports();
    moduleRepositories = new ModuleRepositories();
    loader = new ProjectScreenModelLoader(moduleService, pomService, metadataService, kModuleService, importsService, repositoriesService, whiteListService) {

        @Override
        protected boolean fileExists(final Path path) {
            return true;
        }
    };
    saver = new ProjectScreenModelSaver(pomService, kModuleService, importsService, repositoriesService, whiteListService, ioService, moduleService, repositoryResolver, commentedOptionFactory, pomModelCache);
    service = new ProjectScreenServiceImpl(projectService, repositoryService, moduleService, loader, saver, repositoryCopier, pomService, metadataService);
    when(module.getKModuleXMLPath()).thenReturn(pathToKieModule);
    when(module.getImportsPath()).thenReturn(pathToModuleImports);
    when(module.getRepositoriesPath()).thenReturn(pathToModuleRepositories);
    when(module.getPom()).thenReturn(pom);
    when(pathToPom.toURI()).thenReturn("default://pom.xml");
    when(pomService.load(eq(pathToPom))).thenReturn(pom);
    when(kModuleService.load(eq(pathToKieModule))).thenReturn(kmodule);
    when(importsService.load(eq(pathToModuleImports))).thenReturn(projectImports);
    when(repositoriesService.load(eq(pathToModuleRepositories))).thenReturn(moduleRepositories);
    when(moduleService.resolveModule(eq(pathToPom))).thenReturn(module);
    when(metadataService.getMetadata(eq(pathToPom))).thenReturn(pomMetaData);
    when(metadataService.getMetadata(eq(pathToKieModule))).thenReturn(kmoduleMetaData);
    when(metadataService.getMetadata(eq(pathToModuleImports))).thenReturn(projectImportsMetaData);
}
Also used : Path(org.uberfire.backend.vfs.Path) ModuleRepositories(org.guvnor.common.services.project.model.ModuleRepositories) ProjectImports(org.guvnor.common.services.project.model.ProjectImports) Before(org.junit.Before)

Example 9 with ModuleRepositories

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

use of org.guvnor.common.services.project.model.ModuleRepositories 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)

Aggregations

ModuleRepositories (org.guvnor.common.services.project.model.ModuleRepositories)21 MavenRepositoryMetadata (org.guvnor.common.services.project.model.MavenRepositoryMetadata)16 Test (org.junit.Test)16 GAVAlreadyExistsException (org.guvnor.common.services.project.service.GAVAlreadyExistsException)10 ProjectScreenModel (org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel)9 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)3 KieModule (org.kie.workbench.common.services.shared.project.KieModule)3 ResourceUpdatedEvent (org.uberfire.workbench.events.ResourceUpdatedEvent)3 IOException (java.io.IOException)1 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)1 ProjectImports (org.guvnor.common.services.project.model.ProjectImports)1 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)1 Before (org.junit.Before)1 Path (org.uberfire.java.nio.file.Path)1