use of org.olat.resource.accesscontrol.model.AccessMethod in project OpenOLAT by OpenOLAT.
the class ACOrderManagerTest method testDeleteResource.
@Test
public void testDeleteResource() {
// create some offers to buy
OLATResource randomOres1 = createResource();
Offer offer1 = acService.createOffer(randomOres1, "TestDeleteResource 1");
offer1 = acService.save(offer1);
dbInstance.commitAndCloseSession();
// create a link offer to method
List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(TokenAccessMethod.class);
assertNotNull(methods);
assertEquals(1, methods.size());
AccessMethod method = methods.get(0);
OfferAccess access = acMethodManager.createOfferAccess(offer1, method);
acMethodManager.save(access);
dbInstance.commitAndCloseSession();
// save an order
Order order1 = acOrderManager.saveOneClick(ident8, access);
dbInstance.commitAndCloseSession();
// delete the resource
randomOres1 = dbInstance.getCurrentEntityManager().find(OLATResourceImpl.class, randomOres1.getKey());
dbInstance.deleteObject(randomOres1);
dbInstance.commitAndCloseSession();
// load order
Order retrievedOrder1 = acOrderManager.loadOrderByKey(order1.getKey());
assertNotNull(retrievedOrder1);
}
use of org.olat.resource.accesscontrol.model.AccessMethod in project OpenOLAT by OpenOLAT.
the class ACOrderManagerTest method testSaveOneClickOrders.
@Test
public void testSaveOneClickOrders() {
// create some offers to buy
OLATResource randomOres1 = createResource();
Offer offer1 = acService.createOffer(randomOres1, "TestSaveOneClickOrders 1");
offer1 = acService.save(offer1);
OLATResource randomOres2 = createResource();
Offer offer2 = acService.createOffer(randomOres2, "TestSaveOneClickOrders 2");
offer2 = acService.save(offer2);
dbInstance.commitAndCloseSession();
// create a link offer to method
List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(TokenAccessMethod.class);
assertNotNull(methods);
assertEquals(1, methods.size());
AccessMethod method = methods.get(0);
OfferAccess access1 = acMethodManager.createOfferAccess(offer1, method);
acMethodManager.save(access1);
OfferAccess access2 = acMethodManager.createOfferAccess(offer2, method);
acMethodManager.save(access2);
dbInstance.commitAndCloseSession();
// one clicks
acOrderManager.saveOneClick(ident1, access1);
acOrderManager.saveOneClick(ident2, access2);
acOrderManager.saveOneClick(ident3, access1);
acOrderManager.saveOneClick(ident3, access2);
dbInstance.commitAndCloseSession();
// retrieves by identity
List<Order> ordersIdent3 = acOrderManager.findOrdersByDelivery(ident3);
assertEquals(2, ordersIdent3.size());
assertEquals(ident3, ordersIdent3.get(0).getDelivery());
assertEquals(ident3, ordersIdent3.get(1).getDelivery());
// retrieves by resource
List<Order> ordersResource2 = acOrderManager.findOrdersByResource(randomOres2);
assertEquals(2, ordersResource2.size());
}
use of org.olat.resource.accesscontrol.model.AccessMethod in project OpenOLAT by OpenOLAT.
the class ACOrderManagerTest method findOrderItems_1.
@Test
public void findOrderItems_1() {
// create an offer to buy
List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(TokenAccessMethod.class);
assertNotNull(methods);
assertEquals(1, methods.size());
AccessMethod tokenMethod = methods.get(0);
OLATResource randomOres = createResource();
Offer offer = acService.createOffer(randomOres, "TestSaveOrder");
offer = acService.save(offer);
dbInstance.commitAndCloseSession();
// create and save an order
Order order = acOrderManager.createOrder(ident1);
OrderPart part = acOrderManager.addOrderPart(order);
OrderLine line = acOrderManager.addOrderLine(part, offer);
order = acOrderManager.save(order);
Assert.assertNotNull(order);
Assert.assertNotNull(order.getDelivery());
Assert.assertNotNull(line);
Assert.assertEquals(ident1, order.getDelivery());
dbInstance.commitAndCloseSession();
AccessTransaction accessTransaction = acTransactionManager.createTransaction(order, part, tokenMethod);
assertNotNull(accessTransaction);
acTransactionManager.save(accessTransaction);
AccessTransaction accessTransaction2 = acTransactionManager.createTransaction(order, part, tokenMethod);
assertNotNull(accessTransaction2);
acTransactionManager.save(accessTransaction2);
dbInstance.commitAndCloseSession();
acTransactionManager.update(accessTransaction, AccessTransactionStatus.NEW);
acTransactionManager.update(accessTransaction2, AccessTransactionStatus.CANCELED);
long start = System.nanoTime();
List<RawOrderItem> items = acOrderManager.findNativeOrderItems(randomOres, null, null, null, null, null, 0, -1, null);
CodeHelper.printNanoTime(start, "Order itemized");
Assert.assertNotNull(items);
// check the order by
for (OrderCol col : OrderCol.values()) {
List<RawOrderItem> rawItems = acOrderManager.findNativeOrderItems(randomOres, null, null, null, null, null, 0, -1, null, new SortKey(col.sortKey(), false));
Assert.assertNotNull(rawItems);
}
}
use of org.olat.resource.accesscontrol.model.AccessMethod in project OpenOLAT by OpenOLAT.
the class ACTransactionManagerTest method testSaveTransaction.
@Test
public void testSaveTransaction() {
// pick up a method
List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(TokenAccessMethod.class);
assertNotNull(methods);
assertEquals(1, methods.size());
AccessMethod tokenMethod = methods.get(0);
// create an offer to buy
OLATResource randomOres = createResource();
Offer offer = acService.createOffer(randomOres, "TestSaveTransaction");
offer = acService.save(offer);
dbInstance.commitAndCloseSession();
// create and save an order
Order order = acOrderManager.createOrder(ident1);
OrderPart orderPart = acOrderManager.addOrderPart(order);
OrderLine item = acOrderManager.addOrderLine(orderPart, offer);
assertNotNull(order);
assertNotNull(item);
assertNotNull(order.getDelivery());
assertEquals(ident1, order.getDelivery());
acOrderManager.save(order);
AccessTransaction accessTransaction = acTransactionManager.createTransaction(order, orderPart, tokenMethod);
assertNotNull(accessTransaction);
acTransactionManager.save(accessTransaction);
dbInstance.commitAndCloseSession();
{
// test load by key
AccessTransaction retrievedTransaction = acTransactionManager.loadTransactionByKey(accessTransaction.getKey());
assertNotNull(retrievedTransaction);
assertNotNull(retrievedTransaction.getOrder());
assertEquals(order, retrievedTransaction.getOrder());
assertNotNull(retrievedTransaction.getOrderPart());
assertEquals(orderPart, retrievedTransaction.getOrderPart());
assertNotNull(retrievedTransaction.getMethod());
assertEquals(tokenMethod, retrievedTransaction.getMethod());
}
{
// test load by order
List<AccessTransaction> retrievedTransactions = acTransactionManager.loadTransactionsForOrder(order);
assertNotNull(retrievedTransactions);
assertEquals(1, retrievedTransactions.size());
AccessTransaction retrievedTransaction = retrievedTransactions.get(0);
assertNotNull(retrievedTransaction);
assertNotNull(retrievedTransaction.getOrder());
assertEquals(order, retrievedTransaction.getOrder());
assertNotNull(retrievedTransaction.getOrderPart());
assertEquals(orderPart, retrievedTransaction.getOrderPart());
assertNotNull(retrievedTransaction.getMethod());
assertEquals(tokenMethod, retrievedTransaction.getMethod());
}
}
use of org.olat.resource.accesscontrol.model.AccessMethod in project OpenOLAT by OpenOLAT.
the class ACMethodManagerTest method testOfferAccess.
@Test
public void testOfferAccess() {
// create a resource and an offer
OLATResource randomOres = createResource();
Offer offer = acService.createOffer(randomOres, "TestOfferAccess");
offer = acService.save(offer);
dbInstance.commitAndCloseSession();
// create a link offer to method
List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(TokenAccessMethod.class);
assertNotNull(methods);
assertEquals(1, methods.size());
AccessMethod method = methods.get(0);
OfferAccess access = acMethodManager.createOfferAccess(offer, method);
acMethodManager.save(access);
dbInstance.commitAndCloseSession();
// retrieve the link
List<OfferAccess> retrievedOfferAccess = acMethodManager.getOfferAccess(offer, true);
assertNotNull(retrievedOfferAccess);
assertEquals(1, retrievedOfferAccess.size());
OfferAccess retrievedAccess = retrievedOfferAccess.get(0);
assertNotNull(retrievedAccess);
assertNotNull(retrievedAccess.getMethod());
assertEquals(method, retrievedAccess.getMethod());
assertNotNull(retrievedAccess.getOffer());
Assert.assertEquals(offer, retrievedAccess.getOffer());
}
Aggregations