Search in sources :

Example 1 with DomainRoleEntry

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));
}
Also used : DomainRoleEntry(joynr.infrastructure.DacTypes.DomainRoleEntry) Test(org.junit.Test)

Example 2 with DomainRoleEntry

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));
}
Also used : DomainRoleEntry(joynr.infrastructure.DacTypes.DomainRoleEntry) Test(org.junit.Test)

Example 3 with DomainRoleEntry

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());
        }
    }
}
Also used : DomainRoleEntry(joynr.infrastructure.DacTypes.DomainRoleEntry) Test(org.junit.Test)

Example 4 with DomainRoleEntry

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);
}
Also used : DomainRoleEntry(joynr.infrastructure.DacTypes.DomainRoleEntry) Test(org.junit.Test)

Example 5 with DomainRoleEntry

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;
}
Also used : Role(joynr.infrastructure.DacTypes.Role) Query(net.sf.ehcache.search.Query) Results(net.sf.ehcache.search.Results) DomainRoleEntry(joynr.infrastructure.DacTypes.DomainRoleEntry) Cache(net.sf.ehcache.Cache)

Aggregations

DomainRoleEntry (joynr.infrastructure.DacTypes.DomainRoleEntry)21 Test (org.junit.Test)8 MasterAccessControlEntry (joynr.infrastructure.DacTypes.MasterAccessControlEntry)7 OwnerAccessControlEntry (joynr.infrastructure.DacTypes.OwnerAccessControlEntry)6 Permission (joynr.infrastructure.DacTypes.Permission)4 TrustLevel (joynr.infrastructure.DacTypes.TrustLevel)4 Cache (net.sf.ehcache.Cache)4 Before (org.junit.Before)4 ArrayList (java.util.ArrayList)3 Query (net.sf.ehcache.search.Query)3 Results (net.sf.ehcache.search.Results)3 DomainRoleEntryEntity (io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity)2 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)2 MessagingQos (io.joynr.messaging.MessagingQos)2 Result (net.sf.ehcache.search.Result)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DomainAccessControlStoreEhCache (io.joynr.accesscontrol.DomainAccessControlStoreEhCache)1 UserRoleKey (io.joynr.accesscontrol.primarykey.UserRoleKey)1 Promise (io.joynr.provider.Promise)1 ProxyBuilderFactoryImpl (io.joynr.proxy.ProxyBuilderFactoryImpl)1