Search in sources :

Example 1 with PluginSetContext

use of com.google.gerrit.server.plugincontext.PluginSetContext in project gerrit by GerritCodeReview.

the class UniversalGroupBackendTest method setup.

@Before
public void setup() {
    user = mock(IdentifiedUser.class);
    backends = new DynamicSet<>();
    backends.add("gerrit", new SystemGroupBackend(new Config()));
    backend = new UniversalGroupBackend(new PluginSetContext<>(backends, PluginMetrics.DISABLED_INSTANCE));
}
Also used : PluginSetContext(com.google.gerrit.server.plugincontext.PluginSetContext) Config(org.eclipse.jgit.lib.Config) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) SystemGroupBackend(com.google.gerrit.server.group.SystemGroupBackend) Before(org.junit.Before)

Example 2 with PluginSetContext

use of com.google.gerrit.server.plugincontext.PluginSetContext in project gerrit by GerritCodeReview.

the class UniversalGroupBackendTest method otherMemberships.

@Test
public void otherMemberships() {
    final AccountGroup.UUID handled = AccountGroup.uuid("handled");
    final AccountGroup.UUID notHandled = AccountGroup.uuid("not handled");
    final IdentifiedUser member = mock(IdentifiedUser.class);
    final IdentifiedUser notMember = mock(IdentifiedUser.class);
    GroupBackend backend = mock(GroupBackend.class);
    when(backend.handles(eq(handled))).thenReturn(true);
    when(backend.handles(not(eq(handled)))).thenReturn(false);
    when(backend.membershipsOf(any(IdentifiedUser.class))).thenAnswer(new Answer<GroupMembership>() {

        @Override
        public GroupMembership answer(InvocationOnMock invocation) {
            GroupMembership membership = mock(GroupMembership.class);
            when(membership.contains(eq(handled))).thenReturn(invocation.getArguments()[0] == member);
            when(membership.contains(eq(notHandled))).thenReturn(false);
            return membership;
        }
    });
    backends = new DynamicSet<>();
    backends.add("gerrit", backend);
    backend = new UniversalGroupBackend(new PluginSetContext<>(backends, PluginMetrics.DISABLED_INSTANCE));
    GroupMembership checker = backend.membershipsOf(member);
    assertFalse(checker.contains(REGISTERED_USERS));
    assertFalse(checker.contains(OTHER_UUID));
    assertTrue(checker.contains(handled));
    assertFalse(checker.contains(notHandled));
    checker = backend.membershipsOf(notMember);
    assertFalse(checker.contains(handled));
    assertFalse(checker.contains(notHandled));
}
Also used : SystemGroupBackend(com.google.gerrit.server.group.SystemGroupBackend) AccountGroup(com.google.gerrit.entities.AccountGroup) PluginSetContext(com.google.gerrit.server.plugincontext.PluginSetContext) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) UUID(com.google.gerrit.entities.AccountGroup.UUID) Test(org.junit.Test)

Aggregations

IdentifiedUser (com.google.gerrit.server.IdentifiedUser)2 SystemGroupBackend (com.google.gerrit.server.group.SystemGroupBackend)2 PluginSetContext (com.google.gerrit.server.plugincontext.PluginSetContext)2 AccountGroup (com.google.gerrit.entities.AccountGroup)1 UUID (com.google.gerrit.entities.AccountGroup.UUID)1 Config (org.eclipse.jgit.lib.Config)1 Before (org.junit.Before)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1