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();
}
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()));
}
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());
}
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);
}
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));
}
Aggregations