use of io.joynr.accesscontrol.global.jee.persistence.OwnerRegistrationControlEntryEntity in project joynr by bmwcarit.
the class OwnerRegistrationControlEntryManagerTest method testRemove.
@Test
public void testRemove() {
String userId = "user";
String domain = "domain";
String interfaceName = "interfaceName";
OwnerRegistrationControlEntryEntity entity = create(userId, domain, interfaceName, TrustLevel.MID, TrustLevel.HIGH, Permission.ASK);
flushAndClear();
OwnerRegistrationControlEntry removedEntry = subject.removeByUserIdDomainAndInterfaceName(userId, domain, interfaceName);
assertNotNull(removedEntry);
assertEquals(userId, removedEntry.getUid());
flushAndClear();
OwnerRegistrationControlEntryEntity persisted = entityManager.find(OwnerRegistrationControlEntryEntity.class, entity.getId());
assertNull(persisted);
}
use of io.joynr.accesscontrol.global.jee.persistence.OwnerRegistrationControlEntryEntity in project joynr by bmwcarit.
the class OwnerRegistrationControlEntryManagerTest method create.
private OwnerRegistrationControlEntryEntity create(String userId, String domain, String interfaceName, TrustLevel requiredTrustLevel, TrustLevel requiredAceChangeTrustLevel, Permission providerPermission) {
OwnerRegistrationControlEntryEntity entity = new OwnerRegistrationControlEntryEntity();
entity.setUserId(userId);
entity.setDomain(domain);
entity.setInterfaceName(interfaceName);
entity.setRequiredTrustLevel(requiredTrustLevel);
entity.setRequiredAceChangeTrustLevel(requiredAceChangeTrustLevel);
entity.setProviderPermission(providerPermission);
entityManager.persist(entity);
return entity;
}
use of io.joynr.accesscontrol.global.jee.persistence.OwnerRegistrationControlEntryEntity in project joynr by bmwcarit.
the class OwnerRegistrationControlEntryManagerTest method testUpdate.
@Test
public void testUpdate() {
String userId = "user";
String domain = "domain";
String interfaceName = "interfaceName";
OwnerRegistrationControlEntryEntity entity = create(userId, domain, interfaceName, TrustLevel.MID, TrustLevel.HIGH, Permission.ASK);
flushAndClear();
OwnerRegistrationControlEntry updatedData = new OwnerRegistrationControlEntry(userId, domain, interfaceName, TrustLevel.HIGH, TrustLevel.LOW, Permission.NO);
CreateOrUpdateResult<OwnerRegistrationControlEntry> result = subject.createOrUpdate(updatedData);
assertNotNull(result);
assertEquals(ChangeType.UPDATE, result.getChangeType());
assertNotNull(result.getEntry());
assertEquals(userId, result.getEntry().getUid());
flushAndClear();
OwnerRegistrationControlEntryEntity persisted = entityManager.find(OwnerRegistrationControlEntryEntity.class, entity.getId());
assertNotNull(persisted);
assertEquals(TrustLevel.HIGH, persisted.getRequiredTrustLevel());
assertEquals(TrustLevel.LOW, persisted.getRequiredAceChangeTrustLevel());
assertEquals(Permission.NO, persisted.getProviderPermission());
}
use of io.joynr.accesscontrol.global.jee.persistence.OwnerRegistrationControlEntryEntity in project joynr by bmwcarit.
the class OwnerRegistrationControlEntryManager method findByUserIdDomainAndInterfaceName.
private OwnerRegistrationControlEntryEntity findByUserIdDomainAndInterfaceName(String userId, String domain, String interfaceName) {
Query query = entityManager.createQuery("select orce from OwnerRegistrationControlEntryEntity orce " + "where orce.userId = :userId and orce.domain = :domain and orce.interfaceName = :interfaceName", OwnerRegistrationControlEntryEntity.class);
query.setParameter("userId", userId);
query.setParameter("domain", domain);
query.setParameter("interfaceName", interfaceName);
List<OwnerRegistrationControlEntryEntity> resultList = query.getResultList();
OwnerRegistrationControlEntryEntity entity = null;
if (resultList.size() == 1) {
entity = resultList.get(0);
} else if (resultList.size() > 1) {
throw new JoynrIllegalStateException(format("Too many results found for %s for userId / domain / interfaceName / operation: %s / %s / %s", OwnerRegistrationControlEntryEntity.class.getSimpleName(), userId, domain, interfaceName));
}
return entity;
}
use of io.joynr.accesscontrol.global.jee.persistence.OwnerRegistrationControlEntryEntity in project joynr by bmwcarit.
the class OwnerRegistrationControlEntryManagerTest method testRemoveNotAllowedWithoutOwnerRole.
@Test
public void testRemoveNotAllowedWithoutOwnerRole() {
String userId = "user";
String domain = "domain";
String interfaceName = "interfaceName";
OwnerRegistrationControlEntryEntity entity = create(userId, domain, interfaceName, TrustLevel.MID, TrustLevel.HIGH, Permission.ASK);
flushAndClear();
JoynrJeeMessageContext.getInstance().activate();
try {
joynrCallingPrincipal.setUsername(userId);
assertNull(subject.removeByUserIdDomainAndInterfaceName(userId, domain, interfaceName));
} finally {
JoynrJeeMessageContext.getInstance().deactivate();
}
flushAndClear();
OwnerRegistrationControlEntryEntity persisted = entityManager.find(OwnerRegistrationControlEntryEntity.class, entity.getId());
assertNotNull(persisted);
}
Aggregations