use of org.olat.resource.accesscontrol.model.AccessMethod in project OpenOLAT by OpenOLAT.
the class ACFrontendManagerTest method testRepoWorkflow.
@Test
public void testRepoWorkflow() {
// create a repository entry
RepositoryEntry re = createRepositoryEntry();
assertNotNull(re);
// create and save an offer
Offer offer = acService.createOffer(re.getOlatResource(), "TestRepoWorkflow");
assertNotNull(offer);
offer = acService.save(offer);
dbInstance.commitAndCloseSession();
// create a link offer to method
List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(TokenAccessMethod.class);
AccessMethod method = methods.get(0);
OfferAccess access = acMethodManager.createOfferAccess(offer, method);
acMethodManager.save(access);
dbInstance.commitAndCloseSession();
// retrieve the offer
List<Offer> offers = acService.findOfferByResource(re.getOlatResource(), true, null);
assertEquals(1, offers.size());
Offer savedOffer = offers.get(0);
assertNotNull(savedOffer);
assertNotNull(savedOffer.getResource());
assertTrue(re.getOlatResource().equalsByPersistableKey(savedOffer.getResource()));
}
use of org.olat.resource.accesscontrol.model.AccessMethod in project OpenOLAT by OpenOLAT.
the class ACFrontendManagerTest method testStandardMethods.
@Test
public void testStandardMethods() {
Identity ident = JunitTestHelper.createAndPersistIdentityAsRndUser("ac-method-mgr");
Roles roles = new Roles(false, false, false, true, false, false, false);
List<AccessMethod> methods = acService.getAvailableMethods(ident, roles);
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);
}
use of org.olat.resource.accesscontrol.model.AccessMethod in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
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 OpenOLAT.
the class ACFrontendManagerTest method makeAccessible.
@Test
public void makeAccessible() {
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("acc-" + UUID.randomUUID());
List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(FreeAccessMethod.class);
AccessMethod method = methods.get(0);
RepositoryEntry re = createRepositoryEntry();
Assert.assertNotNull(re);
// create an offer to buy
OLATResource randomOres = re.getOlatResource();
Offer offer = acService.createOffer(randomOres, "Test auto access");
offer.setAutoBooking(true);
OfferAccess link = acService.createOfferAccess(offer, method);
offer = acService.save(offer);
acService.saveOfferAccess(link);
dbInstance.commit();
long start = System.nanoTime();
AccessResult acResult = acService.isAccessible(re, id, false, true);
Assert.assertNotNull(acResult);
Assert.assertTrue(acResult.isAccessible());
dbInstance.commit();
CodeHelper.printNanoTime(start, "One click");
}
Aggregations