Search in sources :

Example 56 with AccessMethod

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);
}
Also used : PaypalAccessMethod(org.olat.resource.accesscontrol.provider.paypal.model.PaypalAccessMethod) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 57 with AccessMethod

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);
}
Also used : PaypalAccessMethod(org.olat.resource.accesscontrol.provider.paypal.model.PaypalAccessMethod) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 58 with AccessMethod

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);
}
Also used : PaypalAccessMethod(org.olat.resource.accesscontrol.provider.paypal.model.PaypalAccessMethod) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 59 with AccessMethod

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);
    }
}
Also used : PaypalAccessMethod(org.olat.resource.accesscontrol.provider.paypal.model.PaypalAccessMethod) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 60 with AccessMethod

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));
}
Also used : IdentifierKey(org.olat.resource.accesscontrol.provider.auto.IdentifierKey) AutoAccessMethod(org.olat.resource.accesscontrol.provider.auto.model.AutoAccessMethod) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) Offer(org.olat.resource.accesscontrol.Offer) AdvanceOrder(org.olat.resource.accesscontrol.provider.auto.AdvanceOrder) OLATResource(org.olat.resource.OLATResource) Test(org.junit.Test)

Aggregations

AccessMethod (org.olat.resource.accesscontrol.model.AccessMethod)92 TokenAccessMethod (org.olat.resource.accesscontrol.model.TokenAccessMethod)62 Test (org.junit.Test)56 FreeAccessMethod (org.olat.resource.accesscontrol.model.FreeAccessMethod)54 OLATResource (org.olat.resource.OLATResource)40 Identity (org.olat.core.id.Identity)22 ShibbolethAutoAccessMethod (org.olat.shibboleth.manager.ShibbolethAutoAccessMethod)22 BusinessGroup (org.olat.group.BusinessGroup)18 PaypalAccessMethod (org.olat.resource.accesscontrol.provider.paypal.model.PaypalAccessMethod)18 ArrayList (java.util.ArrayList)16 Date (java.util.Date)12 Offer (org.olat.resource.accesscontrol.Offer)12 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)10 OfferAccess (org.olat.resource.accesscontrol.OfferAccess)10 AccessMethodHandler (org.olat.resource.accesscontrol.method.AccessMethodHandler)10 AbstractAccessMethod (org.olat.resource.accesscontrol.model.AbstractAccessMethod)10 HashSet (java.util.HashSet)8 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)8 RepositoryEntry (org.olat.repository.RepositoryEntry)8 OLATResourceable (org.olat.core.id.OLATResourceable)6