Search in sources :

Example 46 with Repository

use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.

the class ModuleServiceImplNewModuleTest method testNewModuleCreationNonClashingGAV.

@Test
public void testNewModuleCreationNonClashingGAV() 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(saver.save(masterBranchRoot, pom, baseURL)).thenReturn(expected);
    final Module project = moduleService.newModule(masterBranchRoot, pom, baseURL);
    assertEquals(expected, project);
}
Also used : Path(org.uberfire.backend.vfs.Path) Repository(org.guvnor.structure.repositories.Repository) Branch(org.guvnor.structure.repositories.Branch) Module(org.guvnor.common.services.project.model.Module) KieModule(org.kie.workbench.common.services.shared.project.KieModule) KieModule(org.kie.workbench.common.services.shared.project.KieModule) POM(org.guvnor.common.services.project.model.POM) Test(org.junit.Test)

Example 47 with Repository

use of org.guvnor.structure.repositories.Repository 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)

Example 48 with Repository

use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.

the class FormsMigrationTool method systemMigrationWasExecuted.

private boolean systemMigrationWasExecuted() {
    final IOService systemIoService = cdiWrapper.getSystemIoService();
    final Repository systemRepository = cdiWrapper.getSystemRepository();
    if (!systemIoService.exists(systemIoService.get(systemRepository.getUri()).resolve("spaces"))) {
        system.err().println(String.format("The SYSTEM CONFIGURATION DIRECTORY STRUCTURE MIGRATION must be ran before this one."));
        return false;
    }
    return true;
}
Also used : Repository(org.guvnor.structure.repositories.Repository) IOService(org.uberfire.io.IOService)

Example 49 with Repository

use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.

the class SourceServiceImplTest method testGetRepositories.

@Test
public void testGetRepositories() {
    List<Repository> repositories = mockRepositories("RepoName.", REPOSITORIES_SIZE);
    OrganizationalUnit organizationalUnit = mock(OrganizationalUnit.class);
    when(organizationalUnit.getName()).thenReturn(OU_NAME);
    // the organizational unit not exists.
    when(organizationalUnitService.getOrganizationalUnit(OU_NAME)).thenReturn(null);
    Collection<String> result = service.getRepositories(OU_NAME);
    // nothing is returned.
    assertTrue(result.isEmpty());
    // there organizational unit exists, but no repository is authorized.
    when(organizationalUnitService.getOrganizationalUnit(OU_NAME)).thenReturn(organizationalUnit);
    when(organizationalUnit.getRepositories()).thenReturn(repositories);
    result = service.getRepositories(OU_NAME);
    // nothing is returned since there are no authorized repository.
    assertTrue(result.isEmpty());
    // finally we authorize some repositories. Take some arbitrary indexes.
    List<Integer> authorizedIndexes = new ArrayList<>();
    List<String> authorizedNames = new ArrayList<>();
    authorizedIndexes.add(1);
    authorizedIndexes.add(4);
    authorizedIndexes.add(6);
    authorizedIndexes.forEach(index -> {
        when(authorizationManager.authorize(repositories.get(index), identity)).thenReturn(true);
        authorizedNames.add(repositories.get(index).getAlias());
    });
    result = service.getRepositories(OU_NAME);
    assertEquals(authorizedNames, result);
}
Also used : Repository(org.guvnor.structure.repositories.Repository) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 50 with Repository

use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.

the class SourceServiceImplTest method mockRepositories.

private List<Repository> mockRepositories(String suffix, int count) {
    List<Repository> result = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        Repository repo = mock(Repository.class);
        when(repo.getAlias()).thenReturn(suffix + i);
        result.add(repo);
    }
    return result;
}
Also used : Repository(org.guvnor.structure.repositories.Repository) ArrayList(java.util.ArrayList)

Aggregations

Repository (org.guvnor.structure.repositories.Repository)51 Test (org.junit.Test)25 OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)21 Branch (org.guvnor.structure.repositories.Branch)21 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)20 GitRepository (org.guvnor.structure.repositories.impl.git.GitRepository)15 Module (org.guvnor.common.services.project.model.Module)14 ArrayList (java.util.ArrayList)13 Path (org.uberfire.backend.vfs.Path)13 ExampleRepository (org.kie.workbench.common.screens.examples.model.ExampleRepository)10 POM (org.guvnor.common.services.project.model.POM)7 KieModule (org.kie.workbench.common.services.shared.project.KieModule)7 ExampleOrganizationalUnit (org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit)5 HashMap (java.util.HashMap)4 MavenRepositoryMetadata (org.guvnor.common.services.project.model.MavenRepositoryMetadata)4 Before (org.junit.Before)4 Metadata (org.guvnor.common.services.shared.metadata.model.Metadata)3 RepositoryEnvironmentConfigurations (org.guvnor.structure.repositories.RepositoryEnvironmentConfigurations)3 ConfigGroup (org.guvnor.structure.server.config.ConfigGroup)3 Space (org.uberfire.spaces.Space)3