use of org.olat.resource.accesscontrol.model.AccessMethod in project openolat by klemens.
the class ACFrontendManagerTest method testFreeAccesToBusinessGroup_full.
/**
* Test free access to a group without waiting list and which is full
*/
@Test
public void testFreeAccesToBusinessGroup_full() {
// create a group with a free offer, fill 2 places on 2
Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("agp-" + UUID.randomUUID().toString());
Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("agp-" + UUID.randomUUID().toString());
Identity id3 = JunitTestHelper.createAndPersistIdentityAsUser("agp-" + UUID.randomUUID().toString());
BusinessGroup group = businessGroupService.createBusinessGroup(null, "Free group", "But you must wait", new Integer(0), new Integer(2), false, false, null);
businessGroupRelationDao.addRole(id1, group, GroupRoles.participant.name());
businessGroupRelationDao.addRole(id2, group, GroupRoles.participant.name());
Offer offer = acService.createOffer(group.getResource(), "Free group (waiting)");
offer = acService.save(offer);
List<AccessMethod> freeMethods = acMethodManager.getAvailableMethodsByType(FreeAccessMethod.class);
OfferAccess offerAccess = acService.createOfferAccess(offer, freeMethods.get(0));
Assert.assertNotNull(offerAccess);
dbInstance.commitAndCloseSession();
// access it
AccessResult result = acService.accessResource(id3, offerAccess, null);
Assert.assertNotNull(result);
Assert.assertFalse(result.isAccessible());
dbInstance.commitAndCloseSession();
// is id a waiting?
boolean participant = businessGroupRelationDao.hasRole(id3, group, GroupRoles.participant.name());
Assert.assertFalse(participant);
boolean waiting = businessGroupRelationDao.hasRole(id3, group, GroupRoles.waiting.name());
Assert.assertFalse(waiting);
}
use of org.olat.resource.accesscontrol.model.AccessMethod in project openolat by klemens.
the class ACFrontendManagerTest method testPaiedAccesToBusinessGroup_full.
@Test
public void testPaiedAccesToBusinessGroup_full() {
// enable paypal
boolean enabled = acModule.isPaypalEnabled();
if (!enabled) {
acModule.setPaypalEnabled(true);
}
// create a group with a free offer
Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("pay-1-" + UUID.randomUUID().toString());
Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("agp-" + UUID.randomUUID().toString());
Identity id3 = JunitTestHelper.createAndPersistIdentityAsUser("agp-" + UUID.randomUUID().toString());
BusinessGroup group = businessGroupService.createBusinessGroup(null, "Free group", "But you must wait", new Integer(0), new Integer(2), false, false, null);
Offer offer = acService.createOffer(group.getResource(), "Free group (waiting)");
offer = acService.save(offer);
List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(PaypalAccessMethod.class);
Assert.assertFalse(methods.isEmpty());
OfferAccess offerAccess = acService.createOfferAccess(offer, methods.get(0));
Assert.assertNotNull(offerAccess);
dbInstance.commitAndCloseSession();
// admin fill the group
businessGroupRelationDao.addRole(id2, group, GroupRoles.participant.name());
businessGroupRelationDao.addRole(id3, group, GroupRoles.participant.name());
dbInstance.commitAndCloseSession();
// id1 try to reserve a place before the payment process
boolean reserved = acService.reserveAccessToResource(id1, offerAccess);
Assert.assertFalse(reserved);
if (!enabled) {
acModule.setPaypalEnabled(false);
}
}
use of org.olat.resource.accesscontrol.model.AccessMethod in project openolat by klemens.
the class ACFrontendManagerTest method testFreeAccesToBusinessGroup.
/**
* Test free access to a group without waiting list
*/
@Test
public void testFreeAccesToBusinessGroup() {
// create a group with a free offer
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("agp-" + UUID.randomUUID().toString());
BusinessGroup group = businessGroupService.createBusinessGroup(null, "Free group", "Really free", null, null, false, false, null);
Offer offer = acService.createOffer(group.getResource(), "FreeGroup");
offer = acService.save(offer);
List<AccessMethod> freeMethods = acMethodManager.getAvailableMethodsByType(FreeAccessMethod.class);
OfferAccess offerAccess = acService.createOfferAccess(offer, freeMethods.get(0));
Assert.assertNotNull(offerAccess);
dbInstance.commitAndCloseSession();
// access it
AccessResult result = acService.accessResource(id, offerAccess, null);
Assert.assertNotNull(result);
Assert.assertTrue(result.isAccessible());
dbInstance.commitAndCloseSession();
// is id a participant?
boolean participant = businessGroupRelationDao.hasRole(id, group, GroupRoles.participant.name());
Assert.assertTrue(participant);
}
use of org.olat.resource.accesscontrol.model.AccessMethod in project openolat by klemens.
the class ACMethodManagerTest method testDeleteOfferAccess.
@Test
public void testDeleteOfferAccess() {
// create some resources and offers
OLATResource randomOres1 = createResource();
Offer offer = acService.createOffer(randomOres1, "TestDeleteOfferAccess");
offer = acService.save(offer);
dbInstance.commitAndCloseSession();
// create two link offer to method
List<AccessMethod> tokenMethods = acMethodManager.getAvailableMethodsByType(TokenAccessMethod.class);
assertNotNull(tokenMethods);
assertEquals(1, tokenMethods.size());
AccessMethod tokenMethod = tokenMethods.get(0);
List<AccessMethod> freeMethods = acMethodManager.getAvailableMethodsByType(FreeAccessMethod.class);
assertNotNull(freeMethods);
assertEquals(1, freeMethods.size());
AccessMethod freeMethod = freeMethods.get(0);
OfferAccess access3_1 = acMethodManager.createOfferAccess(offer, tokenMethod);
acMethodManager.save(access3_1);
OfferAccess access3_2 = acMethodManager.createOfferAccess(offer, freeMethod);
acMethodManager.save(access3_2);
dbInstance.commitAndCloseSession();
// delete one of them
acMethodManager.delete(access3_2);
dbInstance.commitAndCloseSession();
// retrieve
List<OfferAccess> retrievedOfferAccess = acMethodManager.getOfferAccess(offer, true);
assertNotNull(retrievedOfferAccess);
assertEquals(1, retrievedOfferAccess.size());
assertEquals(access3_1, retrievedOfferAccess.get(0));
}
use of org.olat.resource.accesscontrol.model.AccessMethod in project openolat by klemens.
the class ACMethodManagerTest method testStandardMethods.
@Test
public void testStandardMethods() {
List<AccessMethod> methods = acMethodManager.getAvailableMethods();
assertNotNull(methods);
assertTrue(methods.size() >= 2);
Set<String> duplicateTypes = new HashSet<>();
boolean foundFree = false;
boolean foundToken = false;
for (AccessMethod method : methods) {
Assert.assertFalse(duplicateTypes.contains(method.getType()));
if (method instanceof FreeAccessMethod) {
foundFree = true;
} else if (method instanceof TokenAccessMethod) {
foundToken = true;
}
assertTrue(method.isEnabled());
assertTrue(method.isValid());
duplicateTypes.add(method.getType());
}
assertTrue(foundFree);
assertTrue(foundToken);
}
Aggregations