Search in sources :

Example 6 with Contributor

use of org.uberfire.security.Contributor in project kie-wb-common by kiegroup.

the class ProjectContributorsListServiceImplTest method getContributorsTest.

@Test
public void getContributorsTest() {
    final List<Contributor> contributors = new ArrayList<>();
    contributors.add(new Contributor("owner", ContributorType.OWNER));
    contributors.add(new Contributor("contributor", ContributorType.CONTRIBUTOR));
    contributors.add(new Contributor("admin", ContributorType.ADMIN));
    final Repository repository = mock(Repository.class);
    doReturn(contributors).when(repository).getContributors();
    doReturn(repository).when(repositoryService).getRepositoryFromSpace(any(), any());
    service.getContributors(repositoryContributors -> {
        assertEquals(3, repositoryContributors.size());
    });
}
Also used : Repository(org.guvnor.structure.repositories.Repository) ArrayList(java.util.ArrayList) Contributor(org.uberfire.security.Contributor) Test(org.junit.Test)

Example 7 with Contributor

use of org.uberfire.security.Contributor in project kie-wb-common by kiegroup.

the class ContributorsListPresenterTest method filterContributorsTest.

@Test
public void filterContributorsTest() {
    final InOrder order = inOrder(contributorsListItemPresenter);
    presenter.contributors = new ArrayList<>();
    presenter.contributors.add(new Contributor("John", ContributorType.OWNER));
    presenter.contributors.add(new Contributor("Mary", ContributorType.ADMIN));
    presenter.contributors.add(new Contributor("Jonathan", ContributorType.CONTRIBUTOR));
    presenter.filterContributors("h");
    verify(view).clearContributors();
    order.verify(contributorsListItemPresenter).setup(presenter.contributors.get(0), presenter, null);
    order.verify(contributorsListItemPresenter).setup(presenter.contributors.get(2), presenter, null);
    verify(view, times(2)).addContributor(any());
}
Also used : InOrder(org.mockito.InOrder) Contributor(org.uberfire.security.Contributor) Test(org.junit.Test)

Example 8 with Contributor

use of org.uberfire.security.Contributor in project kie-wb-common by kiegroup.

the class ContributorsListPresenterTest method setup.

@Before
public void setup() {
    promises = new SyncPromises();
    doReturn(contributorsListItemPresenter).when(contributorsListItemPresenters).get();
    doReturn(mock(ContributorsListItemPresenter.View.class)).when(contributorsListItemPresenter).getView();
    presenter = spy(new ContributorsListPresenter(view, contributorsListItemPresenters, elemental2DomUtil, promises));
    contributors = new ArrayList<>();
    contributors.add(new Contributor("admin", ContributorType.OWNER));
    contributors.add(new Contributor("user", ContributorType.CONTRIBUTOR));
    contributors.add(new Contributor("Director", ContributorType.ADMIN));
    doAnswer(invocationOnMock -> {
        invocationOnMock.getArgument(0, Consumer.class).accept(contributors);
        return null;
    }).when(contributorsListService).getContributors(any());
    final List<String> userNames = Arrays.asList("admin", "user", "Director");
    doAnswer(invocationOnMock -> {
        invocationOnMock.getArgument(0, Consumer.class).accept(userNames);
        return null;
    }).when(contributorsListService).getValidUsernames(any());
}
Also used : Consumer(java.util.function.Consumer) SyncPromises(org.uberfire.promise.SyncPromises) Contributor(org.uberfire.security.Contributor) Before(org.junit.Before)

Example 9 with Contributor

use of org.uberfire.security.Contributor in project kie-wb-common by kiegroup.

the class SpaceContributorsListServiceImplTest method saveContributorsTest.

@Test
public void saveContributorsTest() {
    final OrganizationalUnit organizationalUnit = mock(OrganizationalUnit.class);
    doReturn("ou").when(organizationalUnit).getName();
    doReturn(organizationalUnit).when(organizationalUnitService).getOrganizationalUnit(Mockito.<String>any());
    doReturn(organizationalUnit).when(organizationalUnitService).updateOrganizationalUnit(any(), any(), any());
    final List<Contributor> contributors = new ArrayList<>();
    contributors.add(new Contributor("owner", ContributorType.OWNER));
    contributors.add(new Contributor("contributor", ContributorType.CONTRIBUTOR));
    contributors.add(new Contributor("admin", ContributorType.ADMIN));
    service.saveContributors(contributors, () -> {
    }, null);
    verify(organizationalUnitService).updateOrganizationalUnit("ou", null, contributors);
    verify(afterEditOrganizationalUnitEvent).fire(any());
}
Also used : OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ArrayList(java.util.ArrayList) Contributor(org.uberfire.security.Contributor) Test(org.junit.Test)

Example 10 with Contributor

use of org.uberfire.security.Contributor in project kie-wb-common by kiegroup.

the class SpaceContributorsListServiceImplTest method adminCanEditSomeContributors.

@Test
public void adminCanEditSomeContributors() {
    doReturn(false).when(organizationalUnitController).canUpdateOrgUnit(any());
    final List<Contributor> contributors = new ArrayList<>();
    contributors.add(new Contributor("owner", ContributorType.ADMIN));
    service.canEditContributors(contributors, ContributorType.OWNER).then(canEditContributors -> {
        assertFalse(canEditContributors);
        return promises.resolve();
    });
    service.canEditContributors(contributors, ContributorType.ADMIN).then(canEditContributors -> {
        assertTrue(canEditContributors);
        return promises.resolve();
    });
    service.canEditContributors(contributors, ContributorType.CONTRIBUTOR).then(canEditContributors -> {
        assertTrue(canEditContributors);
        return promises.resolve();
    });
}
Also used : ArrayList(java.util.ArrayList) Contributor(org.uberfire.security.Contributor) Test(org.junit.Test)

Aggregations

Contributor (org.uberfire.security.Contributor)31 ArrayList (java.util.ArrayList)25 Test (org.junit.Test)22 OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)11 Repository (org.guvnor.structure.repositories.Repository)8 POM (org.guvnor.common.services.project.model.POM)6 Consumer (java.util.function.Consumer)4 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)4 List (java.util.List)3 Branch (org.guvnor.structure.repositories.Branch)3 Before (org.junit.Before)3 Collections (java.util.Collections)2 Map (java.util.Map)2 Module (org.guvnor.common.services.project.model.Module)2 BranchPermissions (org.guvnor.structure.organizationalunit.config.BranchPermissions)2 UnauthorizedException (org.jboss.errai.security.shared.exception.UnauthorizedException)2 Archetype (org.kie.workbench.common.screens.archetype.mgmt.shared.model.Archetype)2 ExampleRepository (org.kie.workbench.common.screens.examples.model.ExampleRepository)2 LibraryPreferences (org.kie.workbench.common.screens.library.api.preferences.LibraryPreferences)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2