use of org.olat.resource.accesscontrol.model.AccessMethod in project OpenOLAT by OpenOLAT.
the class ACFrontendManagerTest method testFreeAccesToBusinessGroupWithWaitingList_enoughPlace.
/**
* Test free access to a group with waiting list enough place
*/
@Test
public void testFreeAccesToBusinessGroupWithWaitingList_enoughPlace() {
// create a group with a free offer
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("agp-" + UUID.randomUUID().toString());
BusinessGroup group = businessGroupService.createBusinessGroup(null, "Free group", "But you must wait", new Integer(0), new Integer(10), true, false, null);
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(id, offerAccess, null);
Assert.assertNotNull(result);
Assert.assertTrue(result.isAccessible());
dbInstance.commitAndCloseSession();
// is id a waiting?
boolean participant = businessGroupRelationDao.hasRole(id, group, GroupRoles.participant.name());
Assert.assertTrue(participant);
boolean waiting = businessGroupRelationDao.hasRole(id, group, GroupRoles.waiting.name());
Assert.assertFalse(waiting);
}
use of org.olat.resource.accesscontrol.model.AccessMethod in project OpenOLAT by OpenOLAT.
the class ACFrontendManagerTest method testFreeAccesToBusinessGroupWithWaitingList_full.
/**
* Test free access to a group with waiting list enough place
*/
@Test
public void testFreeAccesToBusinessGroupWithWaitingList_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), true, 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.assertTrue(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.assertTrue(waiting);
}
use of org.olat.resource.accesscontrol.model.AccessMethod in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class ACFrontendManagerTest method testPaiedAccesToBusinessGroupWithWaitingList_enoughPlaceButAdmin.
/**
* Test paypal scenario where a user begin the process to pay an access
* to a group while an administrator is filling the group,
*/
@Test
public void testPaiedAccesToBusinessGroupWithWaitingList_enoughPlaceButAdmin() {
// 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), true, 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();
// id1 start payment process
boolean reserved = acService.reserveAccessToResource(id1, offerAccess);
Assert.assertTrue(reserved);
dbInstance.commitAndCloseSession();
// admin fill the group
businessGroupRelationDao.addRole(id2, group, GroupRoles.participant.name());
businessGroupRelationDao.addRole(id3, group, GroupRoles.participant.name());
dbInstance.commitAndCloseSession();
// id1 finish the process
AccessResult result = acService.accessResource(id1, offerAccess, null);
Assert.assertNotNull(result);
Assert.assertTrue(result.isAccessible());
dbInstance.commitAndCloseSession();
// is id a waiting?
boolean participant = businessGroupRelationDao.hasRole(id1, group, GroupRoles.participant.name());
Assert.assertTrue(participant);
boolean waiting = businessGroupRelationDao.hasRole(id1, group, GroupRoles.waiting.name());
Assert.assertFalse(waiting);
if (!enabled) {
acModule.setPaypalEnabled(false);
}
}
use of org.olat.resource.accesscontrol.model.AccessMethod in project OpenOLAT by OpenOLAT.
the class AutoAccessManagerImplTest method shouldMakeOfferBeforeGrantingAccessIfNotExists.
@Test
public void shouldMakeOfferBeforeGrantingAccessIfNotExists() {
when(identifierHandlerMock.findRepositoryEntries(any(IdentifierKey.class), anyString())).thenReturn(listWithRespositotyEntryMock);
when(repositoryEntryRelationDaoMock.hasRole(IDENTITY, repositoryEntryMock, GroupRoles.participant.name())).thenReturn(false);
when(acServiceMock.getValidOfferAccess(any(OLATResource.class), any(AccessMethod.class))).thenReturn(new ArrayList<>());
Offer offerMock = mock(Offer.class);
when(acServiceMock.createOffer(any(OLATResource.class), anyString())).thenReturn(offerMock);
List<AccessMethod> methods = Arrays.asList(accessMethodDummy);
when(acServiceMock.getAvailableMethodsByType(METHOD_CLASS)).thenReturn(methods);
Collection<AdvanceOrder> advanceOrders = getPendingAdvanceOrders();
sut.grantAccess(advanceOrders);
verify(acServiceMock, times(2)).createOffer(any(OLATResource.class), anyString());
verify(acServiceMock, times(2)).createOfferAccess(any(Offer.class), isA(AccessMethod.class));
}
Aggregations