Search in sources :

Example 81 with AccessMethod

use of org.olat.resource.accesscontrol.model.AccessMethod in project openolat by klemens.

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);
    }
}
Also used : OLATResource(org.olat.resource.OLATResource) SortKey(org.olat.core.commons.persistence.SortKey) RawOrderItem(org.olat.resource.accesscontrol.model.RawOrderItem) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) OrderCol(org.olat.resource.accesscontrol.ui.OrdersDataModel.OrderCol) Test(org.junit.Test)

Example 82 with AccessMethod

use of org.olat.resource.accesscontrol.model.AccessMethod in project openolat by klemens.

the class ACOrderManagerTest method testSaveOneClickOrderWithPrice.

@Test
public void testSaveOneClickOrderWithPrice() {
    // make extensiv test on one order
    // create some offers to buy
    OLATResource randomOres1 = createResource();
    Offer offer1 = acService.createOffer(randomOres1, "TestSaveOneClickOrder 1");
    Price price1 = new PriceImpl(new BigDecimal("20.00"), "CHF");
    offer1.setPrice(price1);
    offer1 = acService.save(offer1);
    dbInstance.commitAndCloseSession();
    // create a link offer to method
    List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(FreeAccessMethod.class);
    assertNotNull(methods);
    assertEquals(1, methods.size());
    AccessMethod method = methods.get(0);
    OfferAccess access1 = acMethodManager.createOfferAccess(offer1, method);
    acMethodManager.save(access1);
    dbInstance.commitAndCloseSession();
    // one clicks
    Order order = acOrderManager.saveOneClick(ident7, access1);
    dbInstance.commitAndCloseSession();
    // load order
    Order retrivedOrder = acOrderManager.loadOrderByKey(order.getKey());
    // check order
    assertNotNull(retrivedOrder);
    assertNotNull(retrivedOrder.getCreationDate());
    assertNotNull(retrivedOrder.getDelivery());
    assertNotNull(retrivedOrder.getOrderNr());
    assertNotNull(retrivedOrder.getParts());
    assertNotNull(retrivedOrder.getTotal());
    assertNotNull(retrivedOrder.getTotalOrderLines());
    assertEquals(ident7, retrivedOrder.getDelivery());
    assertEquals(1, retrivedOrder.getParts().size());
    assertEquals(price1.getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN), retrivedOrder.getTotalOrderLines().getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(price1.getCurrencyCode(), retrivedOrder.getTotalOrderLines().getCurrencyCode());
    assertEquals(price1.getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN), retrivedOrder.getTotal().getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(price1.getCurrencyCode(), retrivedOrder.getTotal().getCurrencyCode());
    // check order part
    OrderPart orderPart = retrivedOrder.getParts().get(0);
    assertNotNull(orderPart);
    assertNotNull(orderPart.getTotal());
    assertNotNull(orderPart.getTotalOrderLines());
    assertEquals(1, orderPart.getOrderLines().size());
    assertEquals(price1.getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN), orderPart.getTotalOrderLines().getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(price1.getCurrencyCode(), orderPart.getTotalOrderLines().getCurrencyCode());
    assertEquals(price1.getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN), orderPart.getTotal().getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(price1.getCurrencyCode(), orderPart.getTotal().getCurrencyCode());
    // check order line
    OrderLine line = orderPart.getOrderLines().get(0);
    Assert.assertNotNull(line);
    Assert.assertNotNull(line.getOffer());
    Assert.assertNotNull(line.getUnitPrice());
    Assert.assertNotNull(line.getTotal());
    Assert.assertEquals(offer1, line.getOffer());
    Assert.assertEquals(price1.getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN), line.getUnitPrice().getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN));
    Assert.assertEquals(price1.getCurrencyCode(), line.getUnitPrice().getCurrencyCode());
    Assert.assertEquals(price1.getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN), line.getTotal().getAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN));
    Assert.assertEquals(price1.getCurrencyCode(), line.getTotal().getCurrencyCode());
}
Also used : PriceImpl(org.olat.resource.accesscontrol.model.PriceImpl) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) OLATResource(org.olat.resource.OLATResource) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 83 with AccessMethod

use of org.olat.resource.accesscontrol.model.AccessMethod in project openolat by klemens.

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

Example 84 with AccessMethod

use of org.olat.resource.accesscontrol.model.AccessMethod in project openolat by klemens.

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

Example 85 with AccessMethod

use of org.olat.resource.accesscontrol.model.AccessMethod in project openolat by klemens.

the class ACOrderManagerTest method testSaveOneClickOrder.

@Test
public void testSaveOneClickOrder() {
    // make extensiv test on one order
    // create some offers to buy
    OLATResource randomOres1 = createResource();
    Offer offer = acService.createOffer(randomOres1, "TestSaveOneClickOrder 1");
    offer = acService.save(offer);
    dbInstance.commitAndCloseSession();
    // create a link offer to method
    List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(FreeAccessMethod.class);
    Assert.assertNotNull(methods);
    Assert.assertEquals(1, methods.size());
    AccessMethod method = methods.get(0);
    OfferAccess access1 = acMethodManager.createOfferAccess(offer, method);
    acMethodManager.save(access1);
    dbInstance.commitAndCloseSession();
    // one clicks
    Order order = acOrderManager.saveOneClick(ident7, access1);
    dbInstance.commitAndCloseSession();
    // load order
    Order retrivedOrder = acOrderManager.loadOrderByKey(order.getKey());
    Assert.assertNotNull(retrivedOrder);
    Assert.assertNotNull(retrivedOrder.getCreationDate());
    Assert.assertNotNull(retrivedOrder.getDelivery());
    Assert.assertNotNull(retrivedOrder.getOrderNr());
    Assert.assertNotNull(retrivedOrder.getParts());
    Assert.assertEquals(ident7, retrivedOrder.getDelivery());
    Assert.assertEquals(1, retrivedOrder.getParts().size());
    OrderPart orderPart = retrivedOrder.getParts().get(0);
    Assert.assertNotNull(orderPart);
    Assert.assertEquals(1, orderPart.getOrderLines().size());
    OrderLine line = orderPart.getOrderLines().get(0);
    Assert.assertNotNull(line);
    Assert.assertNotNull(line.getOffer());
    Assert.assertEquals(offer, line.getOffer());
}
Also used : AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) 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