Search in sources :

Example 56 with WorkspaceProject

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

the class LibraryToolbarPresenterTest method activeProjectHasOnlyOneBranch.

@Test
public void activeProjectHasOnlyOneBranch() throws Exception {
    final Repository repository = mock(Repository.class);
    final ArrayList<Branch> branches = new ArrayList<>();
    branches.add(new Branch());
    doReturn(branches).when(repository).getBranches();
    doReturn(Optional.of(new WorkspaceProject(mock(OrganizationalUnit.class), repository, mock(Branch.class), mock(KieModule.class)))).when(projectContext).getActiveWorkspaceProject();
    presenter.setUpBranches();
    verify(view).clearBranches();
    verify(view).setBranchSelectorVisibility(false);
}
Also used : Repository(org.guvnor.structure.repositories.Repository) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) Branch(org.guvnor.structure.repositories.Branch) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) ArrayList(java.util.ArrayList) KieModule(org.kie.workbench.common.services.shared.project.KieModule) Test(org.junit.Test)

Example 57 with WorkspaceProject

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

the class LibraryToolbarPresenterTest method listBranches.

@Test
public void listBranches() throws Exception {
    final Repository repository = mock(Repository.class);
    final ArrayList<Branch> branches = new ArrayList<>();
    branches.add(new Branch("one", mock(Path.class)));
    branches.add(new Branch("two", mock(Path.class)));
    doReturn(branches).when(repository).getBranches();
    // Normally this is in the branch list, but I want to verify it gets set from the branch in the project
    final Branch selectedBranch = new Branch("selectedBranch", mock(Path.class));
    doReturn(Optional.of(new WorkspaceProject(mock(OrganizationalUnit.class), repository, selectedBranch, mock(KieModule.class)))).when(projectContext).getActiveWorkspaceProject();
    presenter.setUpBranches();
    verify(view).addBranch("one");
    verify(view).addBranch("two");
    view.setSelectedBranch("selectedBranch");
}
Also used : Path(org.uberfire.backend.vfs.Path) Repository(org.guvnor.structure.repositories.Repository) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) Branch(org.guvnor.structure.repositories.Branch) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) ArrayList(java.util.ArrayList) KieModule(org.kie.workbench.common.services.shared.project.KieModule) Test(org.junit.Test)

Example 58 with WorkspaceProject

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

the class ProjectScreenServiceImplTest method testSaveClashingGAVForced.

@Test()
public void testSaveClashingGAVForced() {
    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";
    final WorkspaceProject projectToBeReturned = new WorkspaceProject();
    doReturn(projectToBeReturned).when(projectService).resolveProject(pathToPom);
    try {
        final WorkspaceProject project = service.save(pathToPom, model, comment, DeploymentMode.FORCED);
        assertEquals(projectToBeReturned, project);
    } catch (GAVAlreadyExistsException e) {
        fail("Unexpected exception thrown: " + e.getMessage());
    }
    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) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel) Test(org.junit.Test)

Example 59 with WorkspaceProject

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

the class ProjectScreenServiceImplTest method testCopy.

@Test
public void testCopy() throws Exception {
    final WorkspaceProject project = mock(WorkspaceProject.class);
    final OrganizationalUnit ou = mock(OrganizationalUnit.class);
    final Path projectRoot = mock(Path.class);
    doReturn(ou).when(project).getOrganizationalUnit();
    doReturn(projectRoot).when(project).getRootPath();
    final Repository newRepository = mock(Repository.class);
    final Path newRepositoryRoot = PathFactory.newPath("root", "file:///root");
    doReturn(Optional.of(new Branch("master", newRepositoryRoot))).when(newRepository).getDefaultBranch();
    doReturn(newRepository).when(repositoryCopier).copy(ou, "newName", projectRoot);
    final ArgumentCaptor<POM> pomArgumentCaptor = ArgumentCaptor.forClass(POM.class);
    final POM pom = new POM();
    doReturn(pom).when(pomService).load(any(Path.class));
    final Metadata metadata = mock(Metadata.class);
    doReturn(metadata).when(metadataService).getMetadata(any(Path.class));
    service.copy(project, "newName");
    verify(pomService).save(any(Path.class), pomArgumentCaptor.capture(), eq(metadata), eq("Renaming the project."), eq(true));
    final POM updatedPom = pomArgumentCaptor.getValue();
    assertEquals("newName", updatedPom.getName());
    assertEquals("newName", updatedPom.getGav().getArtifactId());
}
Also used : Path(org.uberfire.backend.vfs.Path) Repository(org.guvnor.structure.repositories.Repository) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) Branch(org.guvnor.structure.repositories.Branch) Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) MavenRepositoryMetadata(org.guvnor.common.services.project.model.MavenRepositoryMetadata) POM(org.guvnor.common.services.project.model.POM) Test(org.junit.Test)

Example 60 with WorkspaceProject

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

the class BuildExecutorTest method mockWorkspaceProjectContext.

private void mockWorkspaceProjectContext(final POM pom, final Repository repository, final KieModule module, final Path pomPath) {
    when(context.getActiveWorkspaceProject()).thenReturn(Optional.of(new WorkspaceProject(mock(OrganizationalUnit.class), repository, new Branch("master", mock(Path.class)), module)));
    when(repository.getAlias()).thenReturn("repository");
    when(module.getModuleName()).thenReturn("module");
    when(module.getPomXMLPath()).thenReturn(pomPath);
    when(module.getPom()).thenReturn(pom);
    when(module.getRootPath()).thenReturn(mock(Path.class));
    when(pomPath.getFileName()).thenReturn("pom.xml");
    when(context.getActiveModule()).thenReturn(Optional.of(module));
}
Also used : Path(org.uberfire.backend.vfs.Path) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) Branch(org.guvnor.structure.repositories.Branch)

Aggregations

WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)67 Test (org.junit.Test)42 Branch (org.guvnor.structure.repositories.Branch)29 OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)28 Repository (org.guvnor.structure.repositories.Repository)26 Path (org.uberfire.backend.vfs.Path)26 Module (org.guvnor.common.services.project.model.Module)21 ArrayList (java.util.ArrayList)12 GitRepository (org.guvnor.structure.repositories.impl.git.GitRepository)12 WorkspaceProjectContextChangeEvent (org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent)10 ExampleOrganizationalUnit (org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit)9 Before (org.junit.Before)8 KieModule (org.kie.workbench.common.services.shared.project.KieModule)7 POM (org.guvnor.common.services.project.model.POM)6 ExampleRepository (org.kie.workbench.common.screens.examples.model.ExampleRepository)5 ProjectAssetsQuery (org.kie.workbench.common.screens.library.api.ProjectAssetsQuery)5 ProjectScreenModel (org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel)5 Date (java.util.Date)4 HashSet (java.util.HashSet)4 ExampleProject (org.kie.workbench.common.screens.examples.model.ExampleProject)4