use of joynr.infrastructure.DacTypes.MasterRegistrationControlEntry 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);
}
}
}
use of joynr.infrastructure.DacTypes.MasterRegistrationControlEntry in project joynr by bmwcarit.
the class MasterRegistrationControlEntryManagerTest method testFindByUserIdAndThatAreEditable.
@Test
public void testFindByUserIdAndThatAreEditable() {
String userId = "user";
String domain = "domain1";
create(userId, domain, "interfaceName1", TrustLevel.HIGH, new TrustLevel[0], TrustLevel.LOW, new TrustLevel[0], Permission.YES, new Permission[0], ControlEntryType.MASTER);
create(userId, domain, "interfaceName1", TrustLevel.HIGH, new TrustLevel[0], TrustLevel.LOW, new TrustLevel[0], Permission.YES, new Permission[0], ControlEntryType.MEDIATOR);
create(userId, "domain2", "interfaceName2", TrustLevel.HIGH, new TrustLevel[0], TrustLevel.LOW, new TrustLevel[0], Permission.YES, new Permission[0], ControlEntryType.MASTER);
DomainRoleEntryEntity domainRoleEntryEntity = new DomainRoleEntryEntity();
domainRoleEntryEntity.setUserId(userId);
domainRoleEntryEntity.setRole(Role.MASTER);
domainRoleEntryEntity.setDomains(Sets.newHashSet(domain));
entityManager.persist(domainRoleEntryEntity);
flushAndClear();
MasterRegistrationControlEntry[] result = subject.findByUserIdAndThatAreEditable(userId, ControlEntryType.MASTER);
assertNotNull(result);
assertEquals(1, result.length);
assertEquals(domain, result[0].getDomain());
}
use of joynr.infrastructure.DacTypes.MasterRegistrationControlEntry in project joynr by bmwcarit.
the class MasterRegistrationControlEntryManagerTest method testCreate.
@Test
public void testCreate() {
String userId = "userId";
String domain = "domain";
String interfaceName = "interfaceName";
MasterRegistrationControlEntry data = new MasterRegistrationControlEntry(userId, domain, interfaceName, TrustLevel.LOW, new TrustLevel[0], TrustLevel.LOW, new TrustLevel[0], Permission.ASK, new Permission[0]);
CreateOrUpdateResult<MasterRegistrationControlEntry> result = subject.createOrUpdate(data, ControlEntryType.MASTER);
assertNotNull(result);
assertEquals(ChangeType.ADD, result.getChangeType());
assertNotNull(result.getEntry());
assertEquals(userId, result.getEntry().getUid());
flushAndClear();
MasterRegistrationControlEntry[] persisted = subject.findByUserIdAndType(userId, ControlEntryType.MASTER);
assertNotNull(persisted);
assertEquals(1, persisted.length);
assertEquals(domain, persisted[0].getDomain());
assertEquals(interfaceName, persisted[0].getInterfaceName());
assertEquals(TrustLevel.LOW, persisted[0].getDefaultRequiredTrustLevel());
}
use of joynr.infrastructure.DacTypes.MasterRegistrationControlEntry in project joynr by bmwcarit.
the class MasterRegistrationControlEntryManagerTest method testCreateNotAllowedWithoutMasterRole.
@Test
public void testCreateNotAllowedWithoutMasterRole() {
String userId = "userId";
String domain = "domain";
String interfaceName = "interfaceName";
MasterRegistrationControlEntry data = new MasterRegistrationControlEntry(userId, domain, interfaceName, TrustLevel.LOW, new TrustLevel[0], TrustLevel.LOW, new TrustLevel[0], Permission.ASK, new Permission[0]);
DomainRoleEntryEntity domainRoleEntryEntity = new DomainRoleEntryEntity();
domainRoleEntryEntity.setUserId(userId);
domainRoleEntryEntity.setRole(Role.OWNER);
domainRoleEntryEntity.setDomains(Sets.newHashSet(domain));
entityManager.persist(domainRoleEntryEntity);
flushAndClear();
JoynrJeeMessageContext.getInstance().activate();
CreateOrUpdateResult<MasterRegistrationControlEntry> result = null;
try {
joynrCallingPrincipal.setUsername(userId);
result = subject.createOrUpdate(data, ControlEntryType.MASTER);
} finally {
JoynrJeeMessageContext.getInstance().deactivate();
}
assertNull(result);
flushAndClear();
MasterRegistrationControlEntry[] persisted = subject.findByUserIdAndType(userId, ControlEntryType.MASTER);
assertNotNull(persisted);
assertEquals(0, persisted.length);
}
use of joynr.infrastructure.DacTypes.MasterRegistrationControlEntry in project joynr by bmwcarit.
the class MasterRegistrationControlEntryManager method mapEntityToJoynrType.
private MasterRegistrationControlEntry mapEntityToJoynrType(MasterRegistrationControlEntryEntity entity) {
Set<TrustLevel> possibleRequiredTrustLevels = Sets.newHashSet(entity.getPossibleRequiredTrustLevels());
Set<TrustLevel> possibleRequiredControlEntryChangeTrustLevels = Sets.newHashSet(entity.getPossibleRequiredControlEntryChangeTrustLevels());
Set<Permission> possibleProviderPermissions = Sets.newHashSet(entity.getDefaultProviderPermission());
MasterRegistrationControlEntry entry = new MasterRegistrationControlEntry(entity.getUserId(), entity.getDomain(), entity.getInterfaceName(), entity.getDefaultRequiredTrustLevel(), possibleRequiredTrustLevels.toArray(new TrustLevel[possibleRequiredTrustLevels.size()]), entity.getDefaultRequiredControlEntryChangeTrustLevel(), possibleRequiredControlEntryChangeTrustLevels.toArray(new TrustLevel[possibleRequiredControlEntryChangeTrustLevels.size()]), entity.getDefaultProviderPermission(), possibleProviderPermissions.toArray(new Permission[possibleProviderPermissions.size()]));
return entry;
}
Aggregations