Search in sources :

Example 76 with AccessMethod

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);
}
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 77 with AccessMethod

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);
    }
}
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 78 with AccessMethod

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);
}
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 79 with AccessMethod

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));
}
Also used : AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) ShibbolethAutoAccessMethod(org.olat.shibboleth.manager.ShibbolethAutoAccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) OLATResource(org.olat.resource.OLATResource) Test(org.junit.Test)

Example 80 with AccessMethod

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);
}
Also used : TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) ShibbolethAutoAccessMethod(org.olat.shibboleth.manager.ShibbolethAutoAccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) HashSet(java.util.HashSet) 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