Search in sources :

Example 31 with ImportProject

use of org.kie.workbench.common.screens.examples.model.ImportProject in project kie-wb-common by kiegroup.

the class ExamplesServiceImplRepositoryNamesTest method setup.

@Before
public void setup() {
    when(ou.getSpace()).thenReturn(space);
    when(space.getName()).thenReturn("ou");
    when(spaceConfigStorageRegistry.get(anyString())).thenReturn(spaceConfigStorage);
    when(spaceConfigStorageRegistry.getBatch(anyString())).thenReturn(new SpaceConfigStorageRegistryImpl.SpaceStorageBatchImpl(spaceConfigStorage));
    when(spaceConfigStorageRegistry.exist(anyString())).thenReturn(true);
    service = spy(new ExamplesServiceImpl(ioService, repositoryFactory, moduleService, ouService, projectService, metadataService, newProjectEvent, projectScreenService, validators, spaceConfigStorageRegistry, systemFS, pathUtil, repositoryService));
    when(validators.getValidators()).thenReturn(new ArrayList<>());
    when(ouService.getOrganizationalUnits()).thenReturn(new HashSet<OrganizationalUnit>() {

        {
            add(new OrganizationalUnitImpl("ou1Name", "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 ImportProject exProject1 = mock(ImportProject.class);
    importProjects = Collections.singletonList(exProject1);
    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> main = Optional.of(new Branch("main", PathFactory.newPath("testFile", "file:///")));
    when(repository1.getDefaultBranch()).thenReturn(main);
    when(repositoryRoot.toURI()).thenReturn("default:///");
    when(module1Root.toURI()).thenReturn("default:///module1");
    when(ouService.getOrganizationalUnit(eq("ou"))).thenReturn(ou);
    final WorkspaceProject project = spy(new WorkspaceProject());
    doReturn("module1").when(repository1).getAlias();
    doReturn(project).when(service).importProject(eq(ou), eq(exProject1));
    doReturn(repository1.getAlias()).when(project).getName();
    doReturn(mock(Module.class)).when(project).getMainModule();
    doReturn(ou).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) SpaceConfigStorageRegistryImpl(org.guvnor.structure.backend.organizationalunit.config.SpaceConfigStorageRegistryImpl) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) ImportProject(org.kie.workbench.common.screens.examples.model.ImportProject) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) OrganizationalUnitImpl(org.guvnor.structure.organizationalunit.impl.OrganizationalUnitImpl) 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)

Example 32 with ImportProject

use of org.kie.workbench.common.screens.examples.model.ImportProject in project kie-wb-common by kiegroup.

the class ExampleImportPresenterTest method filterProjectsTest.

@Test
public void filterProjectsTest() {
    doReturn(false).when(libraryService).isClustered();
    doAnswer(invocationOnMock -> {
        invocationOnMock.getArgument(0, ParameterizedCommand.class).execute(importProjectsPreferences);
        return null;
    }).when(importProjectsPreferences).load(any(ParameterizedCommand.class), any(ParameterizedCommand.class));
    Set<ImportProject> projects = getImportProjects();
    doReturn(projects).when(examplesService).getExampleProjects(any());
    Map<String, String> params = new HashMap<>();
    params.put("repositoryUrl", "repoUrl");
    importPresenter.onStartup(new DefaultPlaceRequest(LibraryPlaces.PROJECT_SCREEN, params));
    final List<ExampleProjectWidget> filteredProjects = importPresenter.filterProjects("a");
    assertEquals(2, filteredProjects.size());
}
Also used : ImportProject(org.kie.workbench.common.screens.examples.model.ImportProject) HashMap(java.util.HashMap) DefaultPlaceRequest(org.uberfire.mvp.impl.DefaultPlaceRequest) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) ExampleProjectWidget(org.kie.workbench.common.screens.library.client.widgets.example.ExampleProjectWidget) Test(org.junit.Test)

Example 33 with ImportProject

use of org.kie.workbench.common.screens.examples.model.ImportProject in project kie-wb-common by kiegroup.

the class ExampleImportPresenterTest method selectProjectWithMultipleProjectSelectionDisabledTest.

@Test
public void selectProjectWithMultipleProjectSelectionDisabledTest() {
    final Set<ImportProject> importProjects = getImportProjects();
    importPresenter.setupProjects(importProjects);
    importPresenter.setMultipleProjectSelectionEnabled(false);
    final List<ImportProject> importProjectsList = new ArrayList<>(importProjects);
    final ImportProject project1 = importProjectsList.get(0);
    final ExampleProjectWidget project1Widget = importPresenter.getProjectWidgetsByProject().get(project1);
    final ImportProject project2 = importProjectsList.get(1);
    final ExampleProjectWidget project2Widget = importPresenter.getProjectWidgetsByProject().get(project2);
    final ImportProject project3 = importProjectsList.get(2);
    final ExampleProjectWidget project3Widget = importPresenter.getProjectWidgetsByProject().get(project3);
    importPresenter.selectProject(project1Widget);
    verify(project1Widget).select();
    verify(project1Widget, never()).unselect();
    verify(project2Widget, never()).select();
    verify(project2Widget).unselect();
    verify(project3Widget, never()).select();
    verify(project3Widget).unselect();
}
Also used : ImportProject(org.kie.workbench.common.screens.examples.model.ImportProject) ArrayList(java.util.ArrayList) ExampleProjectWidget(org.kie.workbench.common.screens.library.client.widgets.example.ExampleProjectWidget) Test(org.junit.Test)

Example 34 with ImportProject

use of org.kie.workbench.common.screens.examples.model.ImportProject in project kie-wb-common by kiegroup.

the class ExampleImportPresenterTest method getImportProjects.

private Set<ImportProject> getImportProjects() {
    Set<ImportProject> projects = new HashSet<>();
    projects.add(new ImportProject(mock(Path.class), "p1a", "p1a description", "git@git.com", null));
    projects.add(new ImportProject(mock(Path.class), "p3b", "p3b description", "git@git.com", null));
    projects.add(new ImportProject(mock(Path.class), "p2a", "p2a description", "git@git.com", null));
    return projects;
}
Also used : ImportProject(org.kie.workbench.common.screens.examples.model.ImportProject) HashSet(java.util.HashSet)

Example 35 with ImportProject

use of org.kie.workbench.common.screens.examples.model.ImportProject in project kie-wb-common by kiegroup.

the class BranchSelectorPopUpPresenterTest method setupWithoutMasterSelectedTest.

@Test
public void setupWithoutMasterSelectedTest() {
    final ImportProject importProject = mock(ImportProject.class);
    final List<String> branches = new ArrayList<>();
    branches.add("branch1");
    doReturn(branches).when(importProject).getSelectedBranches();
    final HTMLElement branchSelectorContainer = mock(HTMLElement.class);
    doReturn(branchSelectorContainer).when(view).getBranchSelectorContainer();
    presenter.setup(importProject, mock(Consumer.class));
    verify(view).init(presenter);
    verify(branchSelector).setup(same(branchSelectorContainer), any(), eq(Arrays.asList("branch1", "master")), any());
    verify(view).show();
    verify(presenter.branchesSelectedCallback, never()).accept(anyList());
}
Also used : HTMLElement(elemental2.dom.HTMLElement) Consumer(java.util.function.Consumer) ImportProject(org.kie.workbench.common.screens.examples.model.ImportProject) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

ImportProject (org.kie.workbench.common.screens.examples.model.ImportProject)37 Test (org.junit.Test)30 ExampleRepository (org.kie.workbench.common.screens.examples.model.ExampleRepository)22 GitRepository (org.guvnor.structure.repositories.impl.git.GitRepository)17 Path (org.uberfire.backend.vfs.Path)17 ImportUtils.makeGitRepository (org.kie.workbench.common.screens.examples.backend.server.ImportUtils.makeGitRepository)14 Module (org.guvnor.common.services.project.model.Module)11 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)11 KieModule (org.kie.workbench.common.services.shared.project.KieModule)10 Mockito.anyString (org.mockito.Mockito.anyString)10 Branch (org.guvnor.structure.repositories.Branch)8 Repository (org.guvnor.structure.repositories.Repository)7 RepositoryEnvironmentConfigurations (org.guvnor.structure.repositories.RepositoryEnvironmentConfigurations)7 JGitFileSystem (org.uberfire.java.nio.fs.jgit.JGitFileSystem)7 OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)5 FileSystem (org.uberfire.java.nio.file.FileSystem)5 ArrayList (java.util.ArrayList)4 WorkspaceProjectContextChangeEvent (org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent)4 POM (org.guvnor.common.services.project.model.POM)4 Credentials (org.kie.workbench.common.screens.examples.model.Credentials)4