Search in sources :

Example 16 with MavenRepositoryMetadata

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

the class ModuleRepositoriesSynchronizerTest method testAddModuleRepository.

@Test
public void testAddModuleRepository() {
    final ResourceUpdatedEvent event = new ResourceUpdatedEvent(pomPath, "", sessionInfo);
    final ModuleRepositories moduleRepositories = new ModuleRepositories();
    when(moduleRepositoriesService.load(moduleRepositoriesPath)).thenReturn(moduleRepositories);
    when(repositoryResolver.getRemoteRepositoriesMetaData(module)).thenReturn(new HashSet<MavenRepositoryMetadata>() {

        {
            add(new MavenRepositoryMetadata("local-id", "local-url", MavenRepositorySource.LOCAL));
        }
    });
    synchronizer.onResourceUpdated(event);
    final ArgumentCaptor<ModuleRepositories> moduleRepositoriesArgumentCaptor = ArgumentCaptor.forClass(ModuleRepositories.class);
    verify(moduleRepositoriesService, times(1)).save(eq(moduleRepositoriesPath), moduleRepositoriesArgumentCaptor.capture(), any(String.class));
    final ModuleRepositories saved = moduleRepositoriesArgumentCaptor.getValue();
    assertNotNull(saved);
    assertEquals(1, saved.getRepositories().size());
    final ModuleRepositories.ModuleRepository repository = saved.getRepositories().iterator().next();
    assertTrue(repository.isIncluded());
    assertEquals("local-id", repository.getMetadata().getId());
    assertEquals("local-url", repository.getMetadata().getUrl());
    assertEquals(MavenRepositorySource.LOCAL, repository.getMetadata().getSource());
}
Also used : ModuleRepositories(org.guvnor.common.services.project.model.ModuleRepositories) MavenRepositoryMetadata(org.guvnor.common.services.project.model.MavenRepositoryMetadata) ResourceUpdatedEvent(org.uberfire.workbench.events.ResourceUpdatedEvent) Test(org.junit.Test)

Example 17 with MavenRepositoryMetadata

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

the class ModuleRepositoriesSynchronizerTest method testRemoveModuleRepository.

@Test
public void testRemoveModuleRepository() {
    final ResourceUpdatedEvent event = new ResourceUpdatedEvent(pomPath, "", sessionInfo);
    final Set<ModuleRepositories.ModuleRepository> repositories = new HashSet<ModuleRepositories.ModuleRepository>() {

        {
            add(new ModuleRepositories.ModuleRepository(true, new MavenRepositoryMetadata("local-id", "local-url", MavenRepositorySource.LOCAL)));
        }
    };
    final ModuleRepositories moduleRepositories = new ModuleRepositories(repositories);
    when(moduleRepositoriesService.load(moduleRepositoriesPath)).thenReturn(moduleRepositories);
    synchronizer.onResourceUpdated(event);
    final ArgumentCaptor<ModuleRepositories> moduleRepositoriesArgumentCaptor = ArgumentCaptor.forClass(ModuleRepositories.class);
    verify(moduleRepositoriesService, times(1)).save(eq(moduleRepositoriesPath), moduleRepositoriesArgumentCaptor.capture(), any(String.class));
    final ModuleRepositories saved = moduleRepositoriesArgumentCaptor.getValue();
    assertNotNull(saved);
    assertEquals(0, saved.getRepositories().size());
}
Also used : ModuleRepositories(org.guvnor.common.services.project.model.ModuleRepositories) MavenRepositoryMetadata(org.guvnor.common.services.project.model.MavenRepositoryMetadata) ResourceUpdatedEvent(org.uberfire.workbench.events.ResourceUpdatedEvent) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 18 with MavenRepositoryMetadata

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

the class ModuleServiceImplNewModuleTest method testNewModuleCreationClashingGAVForced.

@Test()
public void testNewModuleCreationClashingGAVForced() throws URISyntaxException {
    final Repository repository = mock(Repository.class);
    final Path masterBranchRoot = mock(Path.class);
    doReturn(Optional.of(new Branch("master", masterBranchRoot))).when(repository).getDefaultBranch();
    final POM pom = new POM();
    final String baseURL = "/";
    final KieModule expected = new KieModule();
    when(moduleRepositoryResolver.getRepositoriesResolvingArtifact(eq(pom.getGav()))).thenReturn(new HashSet<MavenRepositoryMetadata>() {

        {
            add(new MavenRepositoryMetadata("id", "url", MavenRepositorySource.SETTINGS));
        }
    });
    when(saver.save(masterBranchRoot, pom, baseURL)).thenReturn(expected);
    try {
        moduleService.newModule(masterBranchRoot, pom, baseURL, DeploymentMode.FORCED);
    } catch (GAVAlreadyExistsException e) {
        fail("Unexpected exception thrown: " + e.getMessage());
    }
}
Also used : Path(org.uberfire.backend.vfs.Path) Repository(org.guvnor.structure.repositories.Repository) MavenRepositoryMetadata(org.guvnor.common.services.project.model.MavenRepositoryMetadata) GAVAlreadyExistsException(org.guvnor.common.services.project.service.GAVAlreadyExistsException) Branch(org.guvnor.structure.repositories.Branch) KieModule(org.kie.workbench.common.services.shared.project.KieModule) POM(org.guvnor.common.services.project.model.POM) Test(org.junit.Test)

Example 19 with MavenRepositoryMetadata

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

the class ModuleServiceImplNewModuleTest method testNewModuleCreationClashingGAV.

@Test(expected = GAVAlreadyExistsException.class)
public void testNewModuleCreationClashingGAV() throws URISyntaxException {
    final Repository repository = mock(Repository.class);
    final Path masterBranchRoot = mock(Path.class);
    doReturn(Optional.of(new Branch("master", masterBranchRoot))).when(repository).getDefaultBranch();
    final POM pom = new POM();
    final String baseURL = "/";
    final KieModule expected = new KieModule();
    when(moduleRepositoryResolver.getRepositoriesResolvingArtifact(eq(pom.getGav()))).thenReturn(new HashSet<MavenRepositoryMetadata>() {

        {
            add(new MavenRepositoryMetadata("id", "url", MavenRepositorySource.SETTINGS));
        }
    });
    when(saver.save(masterBranchRoot, pom, baseURL)).thenReturn(expected);
    moduleService.newModule(masterBranchRoot, pom, baseURL);
}
Also used : Path(org.uberfire.backend.vfs.Path) Repository(org.guvnor.structure.repositories.Repository) MavenRepositoryMetadata(org.guvnor.common.services.project.model.MavenRepositoryMetadata) Branch(org.guvnor.structure.repositories.Branch) KieModule(org.kie.workbench.common.services.shared.project.KieModule) POM(org.guvnor.common.services.project.model.POM) 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