Search in sources :

Example 1 with LibraryService

use of org.kie.workbench.common.screens.library.api.LibraryService in project kie-wb-common by kiegroup.

the class PopulatedLibraryScreenTest method setup.

@Before
public void setup() {
    libraryServiceCaller = new CallerMock<>(libraryService);
    libraryScreen = spy(new PopulatedLibraryScreen(view, libraryPlaces, libraryServiceCaller, projectController, projectContext, tileWidgets, addProjectButtonPresenter, projectCountUpdateEvent));
    doReturn(true).when(projectController).canCreateProjects(any());
    project1 = mockProject(PROJECT_1);
    project2 = mockProject(PROJECT_2);
    project3 = mockProject(PROJECT_3);
    final List<WorkspaceProject> projects = new ArrayList<>();
    projects.add(project1);
    projects.add(project2);
    projects.add(project3);
    when(projectContext.getActiveOrganizationalUnit()).thenReturn(Optional.of(organizationalUnit));
    when(projectContext.getActiveWorkspaceProject()).thenReturn(Optional.empty());
    when(projectContext.getActiveModule()).thenReturn(Optional.empty());
    when(projectContext.getActiveRepositoryRoot()).thenReturn(Optional.empty());
    when(projectContext.getActivePackage()).thenReturn(Optional.empty());
    final LibraryInfo libraryInfo = new LibraryInfo(projects);
    doReturn(libraryInfo).when(libraryService).getLibraryInfo(organizationalUnit);
    doReturn(mock(TileWidget.View.class)).when(tileWidget).getView();
    when(tileWidgets.get()).thenAnswer((Answer<TileWidget<WorkspaceProject>>) invocationOnMock -> {
        TileWidget tile = mock(TileWidget.class);
        doReturn(mock(TileWidget.View.class)).when(tile).getView();
        doAnswer((Answer<Void>) invocationOnMock1 -> {
            when(tile.getContent()).thenReturn(invocationOnMock1.getArgument(0, WorkspaceProject.class));
            return null;
        }).when(tile).setContent(any());
        return tile;
    });
    doReturn(mock(AddProjectButtonPresenter.View.class)).when(addProjectButtonPresenter).getView();
    libraryScreen.setup();
}
Also used : TileWidget(org.kie.workbench.common.screens.library.client.widgets.common.TileWidget) CallerMock(org.uberfire.mocks.CallerMock) Space(org.uberfire.spaces.Space) Mock(org.mockito.Mock) ManagedInstance(org.jboss.errai.ioc.client.api.ManagedInstance) RunWith(org.junit.runner.RunWith) ProjectAssetListUpdated(org.kie.workbench.common.screens.library.api.ProjectAssetListUpdated) Mockito.spy(org.mockito.Mockito.spy) ArrayList(java.util.ArrayList) LibraryPlaces(org.kie.workbench.common.screens.library.client.util.LibraryPlaces) Answer(org.mockito.stubbing.Answer) ArgumentCaptor(org.mockito.ArgumentCaptor) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Module(org.guvnor.common.services.project.model.Module) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) Mockito.doReturn(org.mockito.Mockito.doReturn) Before(org.junit.Before) Event(javax.enterprise.event.Event) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) NewProjectEvent(org.guvnor.common.services.project.events.NewProjectEvent) Repository(org.guvnor.structure.repositories.Repository) Answers(org.mockito.Answers) LibraryInfo(org.kie.workbench.common.screens.library.api.LibraryInfo) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) LibraryService(org.kie.workbench.common.screens.library.api.LibraryService) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.when(org.mockito.Mockito.when) WorkspaceProjectContext(org.guvnor.common.services.project.client.context.WorkspaceProjectContext) Mockito.verify(org.mockito.Mockito.verify) RepositoryRemovedEvent(org.guvnor.structure.repositories.RepositoryRemovedEvent) List(java.util.List) Mockito.never(org.mockito.Mockito.never) Caller(org.jboss.errai.common.client.api.Caller) ProjectController(org.guvnor.common.services.project.client.security.ProjectController) AddProjectButtonPresenter(org.kie.workbench.common.screens.library.client.widgets.library.AddProjectButtonPresenter) Optional(java.util.Optional) Mockito.anyInt(org.mockito.Mockito.anyInt) Assert(org.junit.Assert) Mockito.any(org.mockito.Mockito.any) ProjectCountUpdate(org.kie.workbench.common.screens.library.api.ProjectCountUpdate) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.eq(org.mockito.Mockito.eq) Mockito.mock(org.mockito.Mockito.mock) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) LibraryInfo(org.kie.workbench.common.screens.library.api.LibraryInfo) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) ArrayList(java.util.ArrayList) TileWidget(org.kie.workbench.common.screens.library.client.widgets.common.TileWidget) Before(org.junit.Before)

Example 2 with LibraryService

use of org.kie.workbench.common.screens.library.api.LibraryService in project kie-wb-common by kiegroup.

the class BranchManagementPresenterTest method setupWithUpdatableBranchesTest.

@Test
public void setupWithUpdatableBranchesTest() {
    final Map<String, RolePermissions> permissionsByRole = new HashMap<>();
    permissionsByRole.put("CONTRIBUTOR", new RolePermissions("CONTRIBUTOR", true, false, true, true));
    doReturn(new BranchPermissions("myBranch", permissionsByRole)).when(libraryService).loadBranchPermissions("mySpace", "myProject", "myBranch");
    doReturn(promises.resolve(Arrays.asList(new Branch("main", mock(Path.class)), new Branch("myBranch", mock(Path.class))))).when(projectController).getUpdatableBranches(any());
    presenter.setup(mock(ProjectScreenModel.class)).then(v -> {
        assertEquals("myBranch", presenter.selectedBranch);
        verify(view).init(presenter);
        verify(view, never()).showEmptyState();
        verify(view).setupBranchSelect(any(), any(), any());
        verify(libraryService).loadBranchPermissions("mySpace", "myProject", "myBranch");
        return promises.resolve();
    }).catch_(error -> {
        fail();
        return promises.resolve();
    });
}
Also used : RolePermissions(org.guvnor.structure.organizationalunit.config.RolePermissions) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) CallerMock(org.uberfire.mocks.CallerMock) Space(org.uberfire.spaces.Space) Mock(org.mockito.Mock) Promises(org.uberfire.client.promise.Promises) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) SettingsSectionChange(org.kie.workbench.common.screens.library.client.settings.SettingsSectionChange) ArrayList(java.util.ArrayList) LibraryPlaces(org.kie.workbench.common.screens.library.client.util.LibraryPlaces) BranchPermissions(org.guvnor.structure.organizationalunit.config.BranchPermissions) Map(java.util.Map) Module(org.guvnor.common.services.project.model.Module) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) Assert.fail(org.junit.Assert.fail) SyncPromises(org.uberfire.promise.SyncPromises) Mockito.anyString(org.mockito.Mockito.anyString) Mockito.doReturn(org.mockito.Mockito.doReturn) Path(org.uberfire.backend.vfs.Path) Before(org.junit.Before) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) Repository(org.guvnor.structure.repositories.Repository) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel) Test(org.junit.Test) LibraryService(org.kie.workbench.common.screens.library.api.LibraryService) MenuItem(org.kie.workbench.common.screens.library.client.settings.util.sections.MenuItem) Contributor(org.uberfire.security.Contributor) Mockito.verify(org.mockito.Mockito.verify) List(java.util.List) Mockito.never(org.mockito.Mockito.never) Caller(org.jboss.errai.common.client.api.Caller) ProjectController(org.guvnor.common.services.project.client.security.ProjectController) EventSourceMock(org.uberfire.mocks.EventSourceMock) Collections(java.util.Collections) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) Branch(org.guvnor.structure.repositories.Branch) Mockito.mock(org.mockito.Mockito.mock) BranchPermissions(org.guvnor.structure.organizationalunit.config.BranchPermissions) RolePermissions(org.guvnor.structure.organizationalunit.config.RolePermissions) HashMap(java.util.HashMap) Branch(org.guvnor.structure.repositories.Branch) Mockito.anyString(org.mockito.Mockito.anyString) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 List (java.util.List)2 ProjectController (org.guvnor.common.services.project.client.security.ProjectController)2 Module (org.guvnor.common.services.project.model.Module)2 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)2 OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)2 Repository (org.guvnor.structure.repositories.Repository)2 Caller (org.jboss.errai.common.client.api.Caller)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Before (org.junit.Before)2 Test (org.junit.Test)2 RunWith (org.junit.runner.RunWith)2 LibraryService (org.kie.workbench.common.screens.library.api.LibraryService)2 LibraryPlaces (org.kie.workbench.common.screens.library.client.util.LibraryPlaces)2 Mock (org.mockito.Mock)2 Mockito.doReturn (org.mockito.Mockito.doReturn)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.never (org.mockito.Mockito.never)2 Mockito.spy (org.mockito.Mockito.spy)2 Mockito.verify (org.mockito.Mockito.verify)2