use of joynr.infrastructure.DacTypes.DomainRoleEntry in project joynr by bmwcarit.
the class GlobalDomainRoleControllerBeanTest method testUpdate.
@Test
public void testUpdate() {
DomainRoleEntry domainRoleEntry = new DomainRoleEntry(USER_ID, DOMAINS, ROLE);
CreateOrUpdateResult<DomainRoleEntry> createOrUpdateResult = new CreateOrUpdateResult<>(domainRoleEntry, ChangeType.UPDATE);
when(domainRoleEntryManagerMock.createOrUpdate(domainRoleEntry)).thenReturn(createOrUpdateResult);
assertTrue(globalDomainRoleControllerSubject.updateDomainRole(domainRoleEntry));
verify(domainRoleEntryManagerMock).createOrUpdate(eq(domainRoleEntry));
verify(globalDomainRoleControllerSubscriptionPublisherMock).fireDomainRoleEntryChanged(eq(ChangeType.UPDATE), eq(domainRoleEntry), eq(USER_PARTITION));
}
use of joynr.infrastructure.DacTypes.DomainRoleEntry in project joynr by bmwcarit.
the class GlobalDomainRoleControllerBeanTest method testCreate.
@Test
public void testCreate() {
DomainRoleEntry domainRoleEntry = new DomainRoleEntry(USER_ID, DOMAINS, ROLE);
CreateOrUpdateResult<DomainRoleEntry> createOrUpdateResult = new CreateOrUpdateResult<>(domainRoleEntry, ChangeType.ADD);
when(domainRoleEntryManagerMock.createOrUpdate(domainRoleEntry)).thenReturn(createOrUpdateResult);
assertTrue(globalDomainRoleControllerSubject.updateDomainRole(domainRoleEntry));
verify(domainRoleEntryManagerMock).createOrUpdate(eq(domainRoleEntry));
verify(globalDomainRoleControllerSubscriptionPublisherMock).fireDomainRoleEntryChanged(eq(ChangeType.ADD), eq(domainRoleEntry), eq(USER_PARTITION));
}
use of joynr.infrastructure.DacTypes.DomainRoleEntry in project joynr by bmwcarit.
the class DomainRoleEntryManagerTest method testFindByUserId.
@Test
public void testFindByUserId() {
String userId = "user";
Set<String> domains1 = Sets.newHashSet("domain.1", "domain.2");
Set<String> domains2 = Sets.newHashSet("domain.3", "domain.4", "domain.5");
create(userId, domains1, Role.MASTER);
create(userId, domains2, Role.OWNER);
entityManager.flush();
entityManager.clear();
DomainRoleEntry[] result = subject.findByUserId(userId);
assertNotNull(result);
assertEquals(2, result.length);
for (DomainRoleEntry entry : result) {
assertEquals(userId, entry.getUid());
if (Role.MASTER.equals(entry.getRole())) {
assertEquals(domains1, Sets.newHashSet(entry.getDomains()));
} else if (Role.OWNER.equals(entry.getRole())) {
assertEquals(domains2, Sets.newHashSet(entry.getDomains()));
} else {
fail("Should only have master and owner roles. Got: " + entry.getRole());
}
}
}
use of joynr.infrastructure.DacTypes.DomainRoleEntry in project joynr by bmwcarit.
the class DomainRoleEntryManagerTest method testCreate.
@Test
public void testCreate() {
String userId = "user";
DomainRoleEntry newEntry = new DomainRoleEntry(userId, new String[] { "domain" }, Role.OWNER);
CreateOrUpdateResult<DomainRoleEntry> result = subject.createOrUpdate(newEntry);
flushAndClear();
assertNotNull(result);
assertEquals(ChangeType.ADD, result.getChangeType());
assertEquals(userId, result.getEntry().getUid());
assertEquals(Role.OWNER, result.getEntry().getRole());
assertEquals(1, result.getEntry().getDomains().length);
assertEquals("domain", result.getEntry().getDomains()[0]);
DomainRoleEntry[] persisted = subject.findByUserId(userId);
assertNotNull(persisted);
assertEquals(1, persisted.length);
}
use of joynr.infrastructure.DacTypes.DomainRoleEntry in project joynr by bmwcarit.
the class DomainAccessControlStoreEhCache method getDomainRole.
@Override
public DomainRoleEntry getDomainRole(String uid, Role role) {
Cache cache = getCache(CacheId.DOMAIN_ROLES);
Attribute<String> uidAttribute = cache.getSearchAttribute(UserRoleKey.USER_ID);
Attribute<Role> roleAttribute = cache.getSearchAttribute(UserRoleKey.ROLE);
// query is the fastest if you search for keys and if you need value then call Cache.get(key)
Query queryRequestedUid = cache.createQuery().addCriteria(uidAttribute.eq(uid)).addCriteria(roleAttribute.eq(role)).includeKeys().end();
Results results = queryRequestedUid.execute();
DomainRoleEntry domainRole = null;
if (!results.all().isEmpty()) {
// results is either empty or contains exactly one entry
assert (results.all().size() == 1);
domainRole = (DomainAccessControlStoreEhCache.<DomainRoleEntry>getElementValue(cache.get(results.all().get(0).getKey())));
}
return domainRole;
}
Aggregations