Search in sources :

Example 6 with GitRepository

use of org.guvnor.structure.repositories.impl.git.GitRepository in project kie-wb-common by kiegroup.

the class ExamplesServiceImplTest method makeGitRepository.

private GitRepository makeGitRepository() {
    final GitRepository repository = new GitRepository("guvnorng-playground", new Space("space"));
    final HashMap<String, Branch> branches = new HashMap<>();
    branches.put("master", new Branch("master", mock(Path.class)));
    repository.setBranches(branches);
    return repository;
}
Also used : Space(org.uberfire.spaces.Space) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) HashMap(java.util.HashMap) Branch(org.guvnor.structure.repositories.Branch)

Example 7 with GitRepository

use of org.guvnor.structure.repositories.impl.git.GitRepository in project kie-wb-common by kiegroup.

the class ExamplesServiceImplTest method testSetupExamples_NewOrganizationalUnitNewRepository.

@Test
public void testSetupExamples_NewOrganizationalUnitNewRepository() {
    final ExampleOrganizationalUnit exOU = mock(ExampleOrganizationalUnit.class);
    final ExampleProject exModule = mock(ExampleProject.class);
    doReturn("module").when(exModule).getName();
    final List<ExampleProject> exModules = new ArrayList<ExampleProject>() {

        {
            add(exModule);
        }
    };
    final OrganizationalUnit ou = mock(OrganizationalUnit.class);
    doReturn("ou").when(ou).getName();
    final GitRepository repository = mock(GitRepository.class);
    final Path repositoryRoot = mock(Path.class);
    final Path moduleRoot = mock(Path.class);
    when(exOU.getName()).thenReturn("ou");
    when(exModule.getName()).thenReturn("module");
    when(exModule.getRoot()).thenReturn(moduleRoot);
    when(repository.getDefaultBranch()).thenReturn(Optional.of(new Branch("master", repositoryRoot)));
    when(repositoryRoot.toURI()).thenReturn("default:///");
    when(moduleRoot.toURI()).thenReturn("default:///module");
    when(ouService.getOrganizationalUnit(eq("ou"))).thenReturn(null);
    when(ouService.createOrganizationalUnit(eq("ou"), eq(""), eq(""))).thenReturn(ou);
    when(repositoryCopier.copy(eq(ou), anyString(), eq(moduleRoot))).thenReturn(repository);
    final WorkspaceProject project = spy(new WorkspaceProject());
    doReturn("project").when(project).getName();
    doReturn(project).when(projectService).resolveProject(repository);
    final WorkspaceProjectContextChangeEvent event = service.setupExamples(exOU, exModules);
    assertNull(event.getOrganizationalUnit());
    assertEquals(project, event.getWorkspaceProject());
    verify(ouService, times(1)).createOrganizationalUnit(eq("ou"), eq(""), eq(""));
    verify(repositoryCopier, times(1)).copy(eq(ou), anyString(), eq(moduleRoot));
    verify(newProjectEvent, times(1)).fire(any(NewProjectEvent.class));
}
Also used : Path(org.uberfire.backend.vfs.Path) NewProjectEvent(org.guvnor.common.services.project.events.NewProjectEvent) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) Branch(org.guvnor.structure.repositories.Branch) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) ArrayList(java.util.ArrayList) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) WorkspaceProjectContextChangeEvent(org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent) ExampleProject(org.kie.workbench.common.screens.examples.model.ExampleProject) Test(org.junit.Test)

Example 8 with GitRepository

use of org.guvnor.structure.repositories.impl.git.GitRepository in project kie-wb-common by kiegroup.

the class ExamplesServiceImplTest method testSetupExamples_ProjectCopy.

@Test
public void testSetupExamples_ProjectCopy() {
    final ExampleOrganizationalUnit exOU = mock(ExampleOrganizationalUnit.class);
    final ExampleProject exProject1 = mock(ExampleProject.class);
    doReturn("project 1").when(exProject1).getName();
    final ExampleProject exProject2 = mock(ExampleProject.class);
    doReturn("project 2").when(exProject1).getName();
    final List<ExampleProject> exProjects = new ArrayList<ExampleProject>() {

        {
            add(exProject1);
            add(exProject2);
        }
    };
    final OrganizationalUnit ou = mock(OrganizationalUnit.class);
    doReturn("ou").when(ou).getName();
    final GitRepository repository1 = mock(GitRepository.class);
    final Path repositoryRoot = mock(Path.class);
    final Path module1Root = mock(Path.class);
    final Path module2Root = mock(Path.class);
    when(exOU.getName()).thenReturn("ou");
    when(exProject1.getName()).thenReturn("module1");
    when(exProject1.getRoot()).thenReturn(module1Root);
    when(exProject2.getName()).thenReturn("module2");
    when(exProject2.getRoot()).thenReturn(module2Root);
    when(repository1.getBranch("dev_branch")).thenReturn(Optional.of(new Branch("dev_branch", repositoryRoot)));
    final Optional<Branch> master = Optional.of(new Branch("master", PathFactory.newPath("testFile", "file:///")));
    when(repository1.getDefaultBranch()).thenReturn(master);
    when(repositoryRoot.toURI()).thenReturn("default:///");
    when(module1Root.toURI()).thenReturn("default:///module1");
    when(module2Root.toURI()).thenReturn("default:///module2");
    when(ouService.getOrganizationalUnit(eq("ou"))).thenReturn(ou);
    doReturn(repository1).when(repositoryCopier).copy(eq(ou), anyString(), eq(module1Root));
    doReturn(repository1).when(repositoryCopier).copy(eq(ou), anyString(), eq(module2Root));
    final WorkspaceProject project = spy(new WorkspaceProject());
    doReturn("project").when(project).getName();
    doReturn(project).when(projectService).resolveProject(repository1);
    final WorkspaceProjectContextChangeEvent event = service.setupExamples(exOU, exProjects);
    assertNull(event.getOrganizationalUnit());
    assertEquals(project, event.getWorkspaceProject());
    verify(ouService, never()).createOrganizationalUnit(eq("ou"), eq(""), eq(""));
    verify(repositoryCopier, times(2)).copy(eq(ou), anyString(), any(Path.class));
    verify(newProjectEvent, times(2)).fire(any(NewProjectEvent.class));
}
Also used : Path(org.uberfire.backend.vfs.Path) NewProjectEvent(org.guvnor.common.services.project.events.NewProjectEvent) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) Branch(org.guvnor.structure.repositories.Branch) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) ArrayList(java.util.ArrayList) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) WorkspaceProjectContextChangeEvent(org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent) ExampleProject(org.kie.workbench.common.screens.examples.model.ExampleProject) Test(org.junit.Test)

Example 9 with GitRepository

use of org.guvnor.structure.repositories.impl.git.GitRepository in project kie-wb-common by kiegroup.

the class ProjectExplorerContentResolverDefaultSelectionsTest method getGitRepository.

private GitRepository getGitRepository(final String alias) {
    final GitRepository repository = new GitRepository(alias, new Space("scheme"));
    final HashMap<String, Branch> branches = new HashMap<>();
    final Path path = PathFactory.newPath("/", "file://master@module/");
    branches.put("master", new Branch("master", path));
    repository.setBranches(branches);
    return repository;
}
Also used : Space(org.uberfire.spaces.Space) Path(org.uberfire.backend.vfs.Path) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) HashMap(java.util.HashMap) Branch(org.guvnor.structure.repositories.Branch)

Example 10 with GitRepository

use of org.guvnor.structure.repositories.impl.git.GitRepository in project kie-wb-common by kiegroup.

the class ExamplesServiceImplRepositoryNamesTest method setup.

@Before
public void setup() {
    service = spy(new ExamplesServiceImpl(ioService, configurationFactory, repositoryFactory, moduleService, repositoryService, repositoryCopier, ouService, projectService, metadataService, spaces, newProjectEvent, projectScreenService));
    when(ouService.getOrganizationalUnits()).thenReturn(new HashSet<OrganizationalUnit>() {

        {
            add(new OrganizationalUnitImpl("ou1Name", "ou1Owner", "ou1GroupId"));
        }
    });
    when(moduleService.resolveModule(any(Path.class))).thenAnswer(new Answer<KieModule>() {

        @Override
        public KieModule answer(final InvocationOnMock invocationOnMock) throws Throwable {
            final Path path = (Path) invocationOnMock.getArguments()[0];
            final KieModule module = new KieModule(path, path, path, path, path, path, mock(POM.class));
            return module;
        }
    });
    when(sessionInfo.getId()).thenReturn("sessionId");
    when(sessionInfo.getIdentity()).thenReturn(user);
    when(user.getIdentifier()).thenReturn("user");
    when(configurationFactory.newConfigGroup(any(ConfigType.class), anyString(), anyString())).thenReturn(mock(ConfigGroup.class));
    final ExampleProject exProject1 = mock(ExampleProject.class);
    exampleProjects = new ArrayList<ExampleProject>() {

        {
            add(exProject1);
        }
    };
    final OrganizationalUnit ou = mock(OrganizationalUnit.class);
    doReturn("ou").when(ou).getName();
    final GitRepository repository1 = mock(GitRepository.class);
    final Path repositoryRoot = mock(Path.class);
    final Path module1Root = mock(Path.class);
    when(exampleOrganizationalUnit.getName()).thenReturn("ou");
    when(exProject1.getName()).thenReturn("module1");
    when(exProject1.getRoot()).thenReturn(module1Root);
    when(repository1.getBranch("dev_branch")).thenReturn(Optional.of(new Branch("dev_branch", repositoryRoot)));
    final Optional<Branch> master = Optional.of(new Branch("master", PathFactory.newPath("testFile", "file:///")));
    when(repository1.getDefaultBranch()).thenReturn(master);
    when(repositoryRoot.toURI()).thenReturn("default:///");
    when(module1Root.toURI()).thenReturn("default:///module1");
    when(ouService.getOrganizationalUnit(eq("ou"))).thenReturn(ou);
    doReturn("module1").when(repository1).getAlias();
    doReturn(repository1).when(repositoryCopier).copy(eq(ou), anyString(), eq(module1Root));
    final WorkspaceProject project = spy(new WorkspaceProject());
    doReturn(repository1.getAlias()).when(project).getName();
    doReturn(mock(Module.class)).when(project).getMainModule();
    doReturn(mock(OrganizationalUnit.class)).when(project).getOrganizationalUnit();
    doReturn(project).when(projectService).resolveProject(repository1);
    doReturn(project).when(projectService).resolveProject(any(Path.class));
    final ProjectScreenModel model = new ProjectScreenModel();
    model.setPOM(new POM());
    doReturn(model).when(projectScreenService).load(any());
}
Also used : Path(org.uberfire.backend.vfs.Path) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) OrganizationalUnitImpl(org.guvnor.structure.organizationalunit.impl.OrganizationalUnitImpl) ExampleProject(org.kie.workbench.common.screens.examples.model.ExampleProject) POM(org.guvnor.common.services.project.model.POM) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Branch(org.guvnor.structure.repositories.Branch) ConfigGroup(org.guvnor.structure.server.config.ConfigGroup) Module(org.guvnor.common.services.project.model.Module) KieModule(org.kie.workbench.common.services.shared.project.KieModule) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel) ConfigType(org.guvnor.structure.server.config.ConfigType) KieModule(org.kie.workbench.common.services.shared.project.KieModule) Before(org.junit.Before)

Aggregations

GitRepository (org.guvnor.structure.repositories.impl.git.GitRepository)14 Branch (org.guvnor.structure.repositories.Branch)9 Path (org.uberfire.backend.vfs.Path)7 Test (org.junit.Test)6 ExampleProject (org.kie.workbench.common.screens.examples.model.ExampleProject)6 Module (org.guvnor.common.services.project.model.Module)5 OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)5 Repository (org.guvnor.structure.repositories.Repository)5 ConfigGroup (org.guvnor.structure.server.config.ConfigGroup)5 ExampleRepository (org.kie.workbench.common.screens.examples.model.ExampleRepository)5 Space (org.uberfire.spaces.Space)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Before (org.junit.Before)4 KieModule (org.kie.workbench.common.services.shared.project.KieModule)4 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)3 OrganizationalUnitImpl (org.guvnor.structure.organizationalunit.impl.OrganizationalUnitImpl)3 ExampleOrganizationalUnit (org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit)3 WorkspaceProjectContextChangeEvent (org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent)2 NewProjectEvent (org.guvnor.common.services.project.events.NewProjectEvent)2