Search in sources :

Example 1 with ControlEntryType

use of io.joynr.accesscontrol.global.jee.persistence.ControlEntryType in project joynr by bmwcarit.

the class GlobalDomainAccessControlListEditorBeanTest method testFindEditableMasterAndMediatorRegistrationControlEntryByUserId.

@Test
public void testFindEditableMasterAndMediatorRegistrationControlEntryByUserId() {
    Map<ControlEntryType, Function<String, MasterRegistrationControlEntry[]>> getters = new HashMap<>();
    getters.put(ControlEntryType.MASTER, (String userId) -> {
        return globalDomainAccessControlListEditorSubject.getEditableMasterRegistrationControlEntries(userId);
    });
    getters.put(ControlEntryType.MEDIATOR, (String userId) -> {
        return globalDomainAccessControlListEditorSubject.getEditableMediatorRegistrationControlEntries(userId);
    });
    for (ControlEntryType type : new ControlEntryType[] { ControlEntryType.MASTER, ControlEntryType.MEDIATOR }) {
        when(masterRegistrationControlEntryManagerMock.findByUserIdAndThatAreEditable(USER_ID, type)).thenReturn(new MasterRegistrationControlEntry[0]);
        MasterRegistrationControlEntry[] result = getters.get(type).apply(USER_ID);
        assertNotNull(result);
        assertEquals(0, result.length);
        verify(masterRegistrationControlEntryManagerMock).findByUserIdAndThatAreEditable(eq(USER_ID), eq(type));
    }
}
Also used : Function(java.util.function.Function) ControlEntryType(io.joynr.accesscontrol.global.jee.persistence.ControlEntryType) HashMap(java.util.HashMap) MasterRegistrationControlEntry(joynr.infrastructure.DacTypes.MasterRegistrationControlEntry) Test(org.junit.Test)

Example 2 with ControlEntryType

use of io.joynr.accesscontrol.global.jee.persistence.ControlEntryType in project joynr by bmwcarit.

the class GlobalDomainAccessControllerBeanTest method testFindMasterAndMediatorRegistrationControlEntryByUserId.

@Test
public void testFindMasterAndMediatorRegistrationControlEntryByUserId() {
    Map<ControlEntryType, Function<String, MasterRegistrationControlEntry[]>> getters = new HashMap<>();
    getters.put(ControlEntryType.MASTER, (String userId) -> {
        return globalDomainAccessControllerSubject.getMasterRegistrationControlEntries(userId);
    });
    getters.put(ControlEntryType.MEDIATOR, (String userId) -> {
        return globalDomainAccessControllerSubject.getMediatorRegistrationControlEntries(userId);
    });
    for (ControlEntryType type : new ControlEntryType[] { ControlEntryType.MASTER, ControlEntryType.MEDIATOR }) {
        when(masterRegistrationControlEntryManagerMock.findByUserIdAndType(USER_ID, type)).thenReturn(new MasterRegistrationControlEntry[0]);
        MasterRegistrationControlEntry[] result = getters.get(type).apply(USER_ID);
        assertNotNull(result);
        assertEquals(0, result.length);
        verify(masterRegistrationControlEntryManagerMock).findByUserIdAndType(eq(USER_ID), eq(type));
    }
}
Also used : Function(java.util.function.Function) ControlEntryType(io.joynr.accesscontrol.global.jee.persistence.ControlEntryType) HashMap(java.util.HashMap) MasterRegistrationControlEntry(joynr.infrastructure.DacTypes.MasterRegistrationControlEntry) Test(org.junit.Test)

Example 3 with ControlEntryType

use of io.joynr.accesscontrol.global.jee.persistence.ControlEntryType in project joynr by bmwcarit.

the class GlobalDomainAccessControlListEditorBeanTest method testRemoveMasterAndMediatorRegistrationControlEntry.

@Test
public void testRemoveMasterAndMediatorRegistrationControlEntry() {
    Map<ControlEntryType, Supplier<Boolean>> globalDomainAccessControllerSubjectCalls = new HashMap<>();
    globalDomainAccessControllerSubjectCalls.put(ControlEntryType.MASTER, () -> {
        return globalDomainAccessControlListEditorSubject.removeMasterRegistrationControlEntry(USER_ID, DOMAIN, INTERFACE_NAME);
    });
    globalDomainAccessControllerSubjectCalls.put(ControlEntryType.MEDIATOR, () -> {
        return globalDomainAccessControlListEditorSubject.removeMediatorRegistrationControlEntry(USER_ID, DOMAIN, INTERFACE_NAME);
    });
    Map<ControlEntryType, Consumer<MasterRegistrationControlEntry>> multicastVerifiers = new HashMap<>();
    multicastVerifiers.put(ControlEntryType.MASTER, (mrce) -> {
        verify(globalDomainAccessControllerBeanMock).doFireMasterRegistrationControlEntryChanged(eq(ChangeType.REMOVE), eq(mrce));
    });
    multicastVerifiers.put(ControlEntryType.MEDIATOR, (mrce) -> {
        verify(globalDomainAccessControllerBeanMock).doFireMediatorRegistrationControlEntryChanged(eq(ChangeType.REMOVE), eq(mrce));
    });
    for (ControlEntryType type : new ControlEntryType[] { ControlEntryType.MASTER, ControlEntryType.MEDIATOR }) {
        MasterRegistrationControlEntry mrce = new MasterRegistrationControlEntry(USER_ID, DOMAIN, INTERFACE_NAME, TrustLevel.LOW, new TrustLevel[0], TrustLevel.HIGH, new TrustLevel[0], Permission.ASK, new Permission[0]);
        when(masterRegistrationControlEntryManagerMock.removeByUserIdDomainInterfaceNameAndType(USER_ID, DOMAIN, INTERFACE_NAME, type)).thenReturn(mrce);
        assertTrue(globalDomainAccessControllerSubjectCalls.get(type).get());
        verify(masterRegistrationControlEntryManagerMock).removeByUserIdDomainInterfaceNameAndType(eq(USER_ID), eq(DOMAIN), eq(INTERFACE_NAME), eq(type));
        multicastVerifiers.get(type).accept(mrce);
    }
}
Also used : ControlEntryType(io.joynr.accesscontrol.global.jee.persistence.ControlEntryType) Consumer(java.util.function.Consumer) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) MasterRegistrationControlEntry(joynr.infrastructure.DacTypes.MasterRegistrationControlEntry) Test(org.junit.Test)

Example 4 with ControlEntryType

use of io.joynr.accesscontrol.global.jee.persistence.ControlEntryType in project joynr by bmwcarit.

the class GlobalDomainAccessControlListEditorBeanTest method testCreateAndUpdateMasterAndMediatorRegistrationControlEntry.

@Test
public void testCreateAndUpdateMasterAndMediatorRegistrationControlEntry() {
    for (ChangeType changeType : new ChangeType[] { ChangeType.ADD, ChangeType.UPDATE }) {
        Map<ControlEntryType, Function<MasterRegistrationControlEntry, Boolean>> globalDomainAccessControllerSubjectCalls = new HashMap<>();
        globalDomainAccessControllerSubjectCalls.put(ControlEntryType.MASTER, (updatedEntry) -> {
            return globalDomainAccessControlListEditorSubject.updateMasterRegistrationControlEntry(updatedEntry);
        });
        globalDomainAccessControllerSubjectCalls.put(ControlEntryType.MEDIATOR, (updatedEntry) -> {
            return globalDomainAccessControlListEditorSubject.updateMediatorRegistrationControlEntry(updatedEntry);
        });
        Map<ControlEntryType, Consumer<MasterRegistrationControlEntry>> multicastVerifiers = new HashMap<>();
        multicastVerifiers.put(ControlEntryType.MASTER, (mrce) -> {
            verify(globalDomainAccessControllerBeanMock).doFireMasterRegistrationControlEntryChanged(eq(changeType), eq(mrce));
        });
        multicastVerifiers.put(ControlEntryType.MEDIATOR, (mrce) -> {
            verify(globalDomainAccessControllerBeanMock).doFireMediatorRegistrationControlEntryChanged(eq(changeType), eq(mrce));
        });
        for (ControlEntryType type : new ControlEntryType[] { ControlEntryType.MASTER, ControlEntryType.MEDIATOR }) {
            reset(masterRegistrationControlEntryManagerMock);
            // reset(globalDomainAccessControllerSubscriptionPublisherMock);
            MasterRegistrationControlEntry mrce = new MasterRegistrationControlEntry(USER_ID, DOMAIN, INTERFACE_NAME, TrustLevel.LOW, new TrustLevel[0], TrustLevel.HIGH, new TrustLevel[0], Permission.ASK, new Permission[0]);
            when(masterRegistrationControlEntryManagerMock.createOrUpdate(mrce, type)).thenReturn(new CreateOrUpdateResult<MasterRegistrationControlEntry>(mrce, changeType));
            assertTrue(globalDomainAccessControllerSubjectCalls.get(type).apply(mrce));
            verify(masterRegistrationControlEntryManagerMock).createOrUpdate(mrce, type);
            multicastVerifiers.get(type).accept(mrce);
        }
    }
}
Also used : Function(java.util.function.Function) ControlEntryType(io.joynr.accesscontrol.global.jee.persistence.ControlEntryType) Consumer(java.util.function.Consumer) ChangeType(joynr.infrastructure.DacTypes.ChangeType) HashMap(java.util.HashMap) MasterRegistrationControlEntry(joynr.infrastructure.DacTypes.MasterRegistrationControlEntry) Test(org.junit.Test)

Example 5 with ControlEntryType

use of io.joynr.accesscontrol.global.jee.persistence.ControlEntryType in project joynr by bmwcarit.

the class MasterAccessControlEntryManagerTest method testCorrectTypeFound.

@Test
public void testCorrectTypeFound() {
    create("user", "domain", "interfaceName", TrustLevel.HIGH, new TrustLevel[0], TrustLevel.LOW, new TrustLevel[0], "operation", Permission.YES, new Permission[0], MASTER);
    create("user", "domain", "interfaceName", TrustLevel.HIGH, new TrustLevel[0], TrustLevel.LOW, new TrustLevel[0], "operation", Permission.YES, new Permission[0], MEDIATOR);
    flushAndClear();
    for (ControlEntryType type : new ControlEntryType[] { MASTER, MEDIATOR }) {
        MasterAccessControlEntry[] persisted = subject.findByUserId("user", type);
        assertNotNull("Not found for user and " + type, persisted);
        assertEquals("Not found for user and " + type, 1, persisted.length);
    }
}
Also used : ControlEntryType(io.joynr.accesscontrol.global.jee.persistence.ControlEntryType) MasterAccessControlEntry(joynr.infrastructure.DacTypes.MasterAccessControlEntry) Test(org.junit.Test)

Aggregations

ControlEntryType (io.joynr.accesscontrol.global.jee.persistence.ControlEntryType)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)4 MasterRegistrationControlEntry (joynr.infrastructure.DacTypes.MasterRegistrationControlEntry)4 Function (java.util.function.Function)3 Consumer (java.util.function.Consumer)2 Supplier (java.util.function.Supplier)1 ChangeType (joynr.infrastructure.DacTypes.ChangeType)1 MasterAccessControlEntry (joynr.infrastructure.DacTypes.MasterAccessControlEntry)1