Search in sources :

Example 21 with WorkspaceProject

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

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

the class AddProjectPopUpPresenter method createProject.

private void createProject(final DeploymentMode mode) {
    view.showBusyIndicator(view.getSavingMessage());
    final String name = view.getName();
    final String description = view.getDescription();
    final String groupId = view.getGroupId();
    final String artifactId = view.getArtifactId();
    final String version = view.getVersion();
    validateFields(name, groupId, artifactId, version, () -> {
        final RemoteCallback<WorkspaceProject> successCallback = getSuccessCallback();
        final ErrorCallback<?> errorCallback = getErrorCallback();
        if (view.isAdvancedOptionsSelected()) {
            final POM pom = new POM(new GAV(groupId, artifactId, version));
            pom.setName(name);
            pom.setDescription(description);
            libraryService.call(successCallback, errorCallback).createProject(projectContext.getActiveOrganizationalUnit().orElseThrow(() -> new IllegalStateException("Cannot create new project without an active organizational unit.")), pom, mode);
        } else {
            libraryService.call(successCallback, errorCallback).createProject(name, projectContext.getActiveOrganizationalUnit().orElseThrow(() -> new IllegalStateException("Cannot create new project without an active organizational unit.")), description, mode);
        }
    });
}
Also used : WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) GAV(org.guvnor.common.services.project.model.GAV) POM(org.guvnor.common.services.project.model.POM)

Example 23 with WorkspaceProject

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

the class AssetsScreenTest method setUp.

@Before
public void setUp() {
    WorkspaceProject projectInfo = mock(WorkspaceProject.class);
    when(libraryPlaces.getActiveWorkspaceContext()).thenReturn(projectInfo);
    EmptyAssetsView emptyView = mock(EmptyAssetsView.class);
    PopulatedAssetsView populatedView = mock(PopulatedAssetsView.class);
    HTMLElement emptyElement = mock(HTMLElement.class);
    HTMLElement populatedElement = mock(HTMLElement.class);
    when(emptyAssetsScreen.getView()).thenReturn(emptyView);
    when(emptyView.getElement()).thenReturn(emptyElement);
    when(populatedAssetsScreen.getView()).thenReturn(populatedView);
    when(populatedView.getElement()).thenReturn(populatedElement);
    this.assetsScreen = new AssetsScreen(view, libraryPlaces, emptyAssetsScreen, populatedAssetsScreen, ts, busyIndicatorView, new CallerMock<>(libraryService));
}
Also used : HTMLElement(elemental2.dom.HTMLElement) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) CallerMock(org.uberfire.mocks.CallerMock) Before(org.junit.Before)

Example 24 with WorkspaceProject

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

the class LibraryServiceImplTest method importDefaultProjectTest.

@Test
public void importDefaultProjectTest() {
    final Repository repository = mock(Repository.class);
    when(repository.getAlias()).thenReturn("example");
    final OrganizationalUnit organizationalUnit = mock(OrganizationalUnit.class);
    when(organizationalUnit.getName()).thenReturn("ou");
    when(organizationalUnit.getIdentifier()).thenReturn("ou");
    when(organizationalUnit.getRepositories()).thenReturn(singletonList(repository));
    when(ouService.getOrganizationalUnits()).thenReturn(singletonList(organizationalUnit));
    final ExampleProject exampleProject = mock(ExampleProject.class);
    doReturn("example").when(exampleProject).getName();
    final WorkspaceProject project = mock(WorkspaceProject.class);
    final Module module = mock(Module.class);
    doReturn(module).when(project).getMainModule();
    final WorkspaceProjectContextChangeEvent projectContextChangeEvent = mock(WorkspaceProjectContextChangeEvent.class);
    doReturn(project).when(projectContextChangeEvent).getWorkspaceProject();
    doReturn(projectContextChangeEvent).when(examplesService).setupExamples(any(ExampleOrganizationalUnit.class), anyList());
    final WorkspaceProject importedProject = libraryService.importProject(organizationalUnit, exampleProject);
    assertEquals(module, importedProject.getMainModule());
    verify(examplesService).setupExamples(new ExampleOrganizationalUnit(organizationalUnit.getName()), singletonList(exampleProject));
}
Also used : ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) Repository(org.guvnor.structure.repositories.Repository) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) WorkspaceProjectContextChangeEvent(org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent) Module(org.guvnor.common.services.project.model.Module) ExampleProject(org.kie.workbench.common.screens.examples.model.ExampleProject) Test(org.junit.Test)

Example 25 with WorkspaceProject

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

the class LibraryServiceImplTest method queryingUnindexedProjectGivesUnindexedResult.

@Test
public void queryingUnindexedProjectGivesUnindexedResult() throws Exception {
    Branch branch = new Branch("fake-branch", mockPath("default:///a/b/c"));
    final WorkspaceProject project = new WorkspaceProject(ou1, repo1, branch, mock(Module.class));
    when(indexOracle.isIndexed(project)).thenReturn(false);
    when(ioService.exists(any())).thenReturn(true);
    final ProjectAssetsQuery query = new ProjectAssetsQuery(project, "", 0, 10, Collections.emptyList());
    AssetQueryResult result = libraryService.getProjectAssets(query);
    assertEquals(ResultType.Unindexed, result.getResultType());
    assertFalse(result.getAssetInfos().isPresent());
}
Also used : ProjectAssetsQuery(org.kie.workbench.common.screens.library.api.ProjectAssetsQuery) Branch(org.guvnor.structure.repositories.Branch) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) AssetQueryResult(org.kie.workbench.common.screens.library.api.AssetQueryResult) Module(org.guvnor.common.services.project.model.Module) Test(org.junit.Test)

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