Search in sources :

Example 76 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class ACOfferManagerTest method testDeleteOffer.

@Test
public void testDeleteOffer() {
    OLATResourceable testOreable = new TypedResourceable(UUID.randomUUID().toString().replace("-", ""));
    OLATResource testOres = OLATResourceManager.getInstance().findOrPersistResourceable(testOreable);
    assertNotNull(testOres);
    dbInstance.commitAndCloseSession();
    // create an offer
    Offer offer = acOfferManager.createOffer(testOres, "TestDeleteOffer");
    assertNotNull(offer);
    assertEquals(OfferImpl.class, offer.getClass());
    // and save the offer
    acOfferManager.saveOffer(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 = acOfferManager.findOfferByResource(testOres, true, null);
    assertNotNull(offers);
    assertEquals(1, offers.size());
    assertEquals(offer, offers.get(0));
    dbInstance.commitAndCloseSession();
    // delete the offer
    acOfferManager.deleteOffer(offer);
    dbInstance.commitAndCloseSession();
    // try to retrieve the offer
    List<Offer> noOffers = acOfferManager.findOfferByResource(testOres, true, null);
    assertNotNull(noOffers);
    assertEquals(0, noOffers.size());
    dbInstance.commitAndCloseSession();
    // retrieve all offers, deleted too
    List<Offer> delOffers = acOfferManager.findOfferByResource(testOres, false, null);
    assertNotNull(delOffers);
    assertEquals(1, delOffers.size());
    assertEquals(offer, delOffers.get(0));
    assertEquals(false, delOffers.get(0).isValid());
    dbInstance.commitAndCloseSession();
}
Also used : AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) OLATResourceable(org.olat.core.id.OLATResourceable) OLATResource(org.olat.resource.OLATResource) Test(org.junit.Test)

Example 77 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class ACOfferManagerTest method testFilterWithDelete.

@Test
public void testFilterWithDelete() {
    // create resources
    OLATResourceable testOreable1 = new TypedResourceable(UUID.randomUUID().toString().replace("-", ""));
    OLATResource testOres1 = OLATResourceManager.getInstance().findOrPersistResourceable(testOreable1);
    assertNotNull(testOres1);
    OLATResourceable testOreable2 = new TypedResourceable(UUID.randomUUID().toString().replace("-", ""));
    OLATResource testOres2 = OLATResourceManager.getInstance().findOrPersistResourceable(testOreable2);
    assertNotNull(testOres2);
    OLATResourceable testOreable3 = new TypedResourceable(UUID.randomUUID().toString().replace("-", ""));
    OLATResource testOres3 = OLATResourceManager.getInstance().findOrPersistResourceable(testOreable3);
    assertNotNull(testOres3);
    dbInstance.commitAndCloseSession();
    // create  offers
    Offer offer1 = acOfferManager.createOffer(testOres1, "TestFilterWithDelete 1");
    Offer offer2 = acOfferManager.createOffer(testOres2, "TestFilterWithDelete 2");
    acOfferManager.saveOffer(offer1);
    acOfferManager.saveOffer(offer2);
    dbInstance.commitAndCloseSession();
    // delete resource of offer 2
    testOres2 = dbInstance.getCurrentEntityManager().find(OLATResourceImpl.class, testOres2.getKey());
    dbInstance.deleteObject(testOres2);
    // filter by resources
    List<Long> resourceKeys = new ArrayList<Long>();
    resourceKeys.add(testOres1.getKey());
    resourceKeys.add(testOres2.getKey());
    resourceKeys.add(testOres3.getKey());
    Set<Long> filteredKeys = acOfferManager.filterResourceWithOffer(resourceKeys);
    assertNotNull(filteredKeys);
    assertEquals(1, filteredKeys.size());
    assertTrue(filteredKeys.contains(testOres1.getKey()));
    assertFalse(filteredKeys.contains(testOres2.getKey()));
    assertFalse(filteredKeys.contains(testOres3.getKey()));
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource) OLATResourceImpl(org.olat.resource.OLATResourceImpl) Test(org.junit.Test)

Example 78 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class ACOfferManagerTest method testSaveOffer.

@Test
public void testSaveOffer() {
    // create a resource
    OLATResourceable testOreable = new TypedResourceable(UUID.randomUUID().toString().replace("-", ""));
    OLATResource testOres = OLATResourceManager.getInstance().findOrPersistResourceable(testOreable);
    assertNotNull(testOres);
    dbInstance.commitAndCloseSession();
    // create an offer
    Offer offer = acOfferManager.createOffer(testOres, "TestSaveOffer");
    assertNotNull(offer);
    assertEquals(OfferImpl.class, offer.getClass());
    if (offer instanceof OfferImpl) {
        OfferImpl offerImpl = (OfferImpl) offer;
        offerImpl.setToken("token1");
    }
    offer.setValidFrom(new Date());
    offer.setValidTo(new Date());
    // and save the offer
    acOfferManager.saveOffer(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();
    // check if the offer is saved
    List<Offer> offers = acOfferManager.findOfferByResource(testOres, true, null);
    assertNotNull(offers);
    assertEquals(1, offers.size());
    Offer savedOffer = offers.get(0);
    assertNotNull(savedOffer);
    assertEquals(OfferImpl.class, savedOffer.getClass());
    if (savedOffer instanceof OfferImpl) {
        OfferImpl offerImpl = (OfferImpl) savedOffer;
        assertEquals("token1", offerImpl.getToken());
    }
    assertNotNull(offer.getValidFrom());
    assertNotNull(offer.getValidTo());
    assertEquals(testOres.getResourceableId(), savedOffer.getResourceId());
    assertEquals(testOres.getResourceableTypeName(), savedOffer.getResourceTypeName());
    assertEquals("TestSaveOffer", savedOffer.getResourceDisplayName());
}
Also used : AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) OLATResourceable(org.olat.core.id.OLATResourceable) OfferImpl(org.olat.resource.accesscontrol.model.OfferImpl) OLATResource(org.olat.resource.OLATResource) Date(java.util.Date) Test(org.junit.Test)

Example 79 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class ACReservationDAOTest method testDeleteReservations.

@Test
public void testDeleteReservations() {
    // create 3 identities and 3 reservations
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("reserv-7-" + UUID.randomUUID().toString());
    OLATResource resource1 = JunitTestHelper.createRandomResource();
    OLATResource resource2 = JunitTestHelper.createRandomResource();
    ResourceReservation reservation1_1 = acReservationDao.createReservation(id, "test delete 1", null, resource1);
    ResourceReservation reservation1_2 = acReservationDao.createReservation(id, "test delete 2", null, resource1);
    ResourceReservation reservation2_1 = acReservationDao.createReservation(id, "test delete 3", null, resource2);
    dbInstance.commitAndCloseSession();
    acReservationDao.deleteReservations(resource1);
    dbInstance.commitAndCloseSession();
    // check the 2 reservations are deleted
    ResourceReservation deletedReservation1_1 = acReservationDao.loadReservation(reservation1_1.getKey());
    Assert.assertNull(deletedReservation1_1);
    ResourceReservation deletedReservation1_2 = acReservationDao.loadReservation(reservation1_2.getKey());
    Assert.assertNull(deletedReservation1_2);
    // check the third reservation on resource 2 survive
    ResourceReservation deletedReservation2_1 = acReservationDao.loadReservation(reservation2_1.getKey());
    Assert.assertNotNull(deletedReservation2_1);
    Assert.assertEquals(reservation2_1, deletedReservation2_1);
}
Also used : OLATResource(org.olat.resource.OLATResource) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 80 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class ACReservationDAOTest method testLoadOldReservation.

@Test
public void testLoadOldReservation() throws Exception {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("reserv-1-" + UUID.randomUUID().toString());
    OLATResource resource = JunitTestHelper.createRandomResource();
    dbInstance.commitAndCloseSession();
    ResourceReservation reservation = acReservationDao.createReservation(id, "test", null, resource);
    dbInstance.commitAndCloseSession();
    Thread.sleep(5000);
    // check by load
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.SECOND, -2);
    Date date = cal.getTime();
    List<ResourceReservation> oldReservations = acReservationDao.loadReservationOlderThan(date);
    Assert.assertNotNull(oldReservations);
    Assert.assertFalse(oldReservations.isEmpty());
    Assert.assertTrue(oldReservations.contains(reservation));
}
Also used : Calendar(java.util.Calendar) OLATResource(org.olat.resource.OLATResource) Identity(org.olat.core.id.Identity) Date(java.util.Date) Test(org.junit.Test)

Aggregations

OLATResource (org.olat.resource.OLATResource)706 Test (org.junit.Test)304 RepositoryEntry (org.olat.repository.RepositoryEntry)198 Identity (org.olat.core.id.Identity)170 File (java.io.File)80 Date (java.util.Date)72 Feed (org.olat.modules.webFeed.Feed)72 ArrayList (java.util.ArrayList)64 ICourse (org.olat.course.ICourse)64 RepositoryService (org.olat.repository.RepositoryService)62 OLATResourceable (org.olat.core.id.OLATResourceable)60 BusinessGroup (org.olat.group.BusinessGroup)58 Item (org.olat.modules.webFeed.Item)44 AccessMethod (org.olat.resource.accesscontrol.model.AccessMethod)38 OLATResourceManager (org.olat.resource.OLATResourceManager)34 TokenAccessMethod (org.olat.resource.accesscontrol.model.TokenAccessMethod)34 PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)30 PortfolioStructureMap (org.olat.portfolio.model.structel.PortfolioStructureMap)30 FreeAccessMethod (org.olat.resource.accesscontrol.model.FreeAccessMethod)28 Group (org.olat.basesecurity.Group)26