Example usage for java.math BigDecimal TEN

List of usage examples for java.math BigDecimal TEN

Introduction

In this page you can find the example usage for java.math BigDecimal TEN.

Prototype

BigDecimal TEN

To view the source code for java.math BigDecimal TEN.

Click Source Link

Document

The value 10, with a scale of 0.

Usage

From source file:alfio.manager.EventManagerIntegrationTest.java

@Test
public void testIncreaseEventSeatsWithABoundedCategory() {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null,
            "default", 10, new DateTimeModification(LocalDate.now(), LocalTime.now()),
            new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "",
            true, null, null, null, null, null));
    Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager,
            eventRepository);/*w w w  .ja va  2  s.c  o  m*/
    Event event = pair.getKey();
    EventModification update = new EventModification(event.getId(), Event.EventType.INTERNAL, null, null, null,
            null, null, null, null, event.getOrganizationId(), null, "0.0", "0.0",
            ZoneId.systemDefault().getId(), null, DateTimeModification.fromZonedDateTime(event.getBegin()),
            DateTimeModification.fromZonedDateTime(event.getEnd()), event.getRegularPrice(),
            event.getCurrency(), 40, event.getVat(), event.isVatIncluded(), event.getAllowedPaymentProxies(),
            null, event.isFreeOfCharge(), null, 7, null, null);
    eventManager.updateEventPrices(event, update, pair.getValue());
    List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
    assertNotNull(tickets);
    assertFalse(tickets.isEmpty());
    assertEquals(20, tickets.size());
    assertEquals(20, ticketRepository.countReleasedUnboundedTickets(event.getId()).intValue());
    assertEquals(10, tickets.stream().filter(t -> t.getCategoryId() != null).count());
}

From source file:alfio.manager.WaitingQueueManagerIntegrationTest.java

@Test
public void testAssignTicketToWaitingQueueBoundedCategory() {
    LocalDateTime start = LocalDateTime.now().minusMinutes(2);
    LocalDateTime end = LocalDateTime.now().plusMinutes(20);
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null,
            "default", AVAILABLE_SEATS, new DateTimeModification(start.toLocalDate(), start.toLocalTime()),
            new DateTimeModification(end.toLocalDate(), end.toLocalTime()), DESCRIPTION, BigDecimal.TEN, false,
            "", true, null, null, null, null, null));

    configurationManager.saveSystemConfiguration(ConfigurationKeys.ENABLE_WAITING_QUEUE, "true");

    Event event = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository)
            .getKey();/*from  w w  w  .  j  a va2s  .co m*/

    TicketCategory bounded = ticketCategoryRepository.findByEventId(event.getId()).get(0);

    TicketReservationModification tr = new TicketReservationModification();
    tr.setAmount(AVAILABLE_SEATS - 1);
    tr.setTicketCategoryId(bounded.getId());

    TicketReservationModification tr2 = new TicketReservationModification();
    tr2.setAmount(1);
    tr2.setTicketCategoryId(bounded.getId());

    TicketReservationWithOptionalCodeModification multi = new TicketReservationWithOptionalCodeModification(tr,
            Optional.empty());
    TicketReservationWithOptionalCodeModification single = new TicketReservationWithOptionalCodeModification(
            tr2, Optional.empty());

    String reservationId = ticketReservationManager.createTicketReservation(event,
            Collections.singletonList(multi), Collections.emptyList(), DateUtils.addDays(new Date(), 1),
            Optional.empty(), Optional.empty(), Locale.ENGLISH, false);
    TotalPrice reservationCost = ticketReservationManager.totalReservationCostWithVAT(reservationId);
    PaymentResult result = ticketReservationManager.confirm("", null, event, reservationId, "test@test.ch",
            new CustomerName("Full Name", "Full", "Name", event), Locale.ENGLISH, "", reservationCost,
            Optional.empty(), Optional.of(PaymentProxy.OFFLINE), false, null, null, null);
    assertTrue(result.isSuccessful());

    String reservationIdSingle = ticketReservationManager.createTicketReservation(event,
            Collections.singletonList(single), Collections.emptyList(), DateUtils.addDays(new Date(), 1),
            Optional.empty(), Optional.empty(), Locale.ENGLISH, false);
    TotalPrice reservationCostSingle = ticketReservationManager
            .totalReservationCostWithVAT(reservationIdSingle);
    PaymentResult resultSingle = ticketReservationManager.confirm("", null, event, reservationIdSingle,
            "test@test.ch", new CustomerName("Full Name", "Full", "Name", event), Locale.ENGLISH, "",
            reservationCostSingle, Optional.empty(), Optional.of(PaymentProxy.OFFLINE), false, null, null,
            null);
    assertTrue(resultSingle.isSuccessful());

    assertEquals(0, eventRepository.findStatisticsFor(event.getId()).getDynamicAllocation());

    assertTrue(
            waitingQueueManager.subscribe(event, customerJohnDoe(event), "john@doe.com", null, Locale.ENGLISH));

    ticketReservationManager.deleteOfflinePayment(event, reservationIdSingle, false);

    List<Triple<WaitingQueueSubscription, TicketReservationWithOptionalCodeModification, ZonedDateTime>> subscriptions = waitingQueueManager
            .distributeSeats(event).collect(Collectors.toList());
    assertEquals(1, subscriptions.size());
    Triple<WaitingQueueSubscription, TicketReservationWithOptionalCodeModification, ZonedDateTime> subscriptionDetail = subscriptions
            .get(0);
    assertEquals("john@doe.com", subscriptionDetail.getLeft().getEmailAddress());
    TicketReservationWithOptionalCodeModification reservation = subscriptionDetail.getMiddle();
    assertEquals(Integer.valueOf(bounded.getId()), reservation.getTicketCategoryId());
    assertEquals(Integer.valueOf(1), reservation.getAmount());
    assertTrue(subscriptionDetail.getRight().isAfter(ZonedDateTime.now()));
}

From source file:org.openvpms.web.workspace.workflow.checkin.CheckInWorkflowTestCase.java

/**
 * Performs a check in, one day after a patient was invoiced but using the same invoice.
 * <p/>//from  ww w .j a va 2 s  . com
 * This verifies the fix for OVPMS-1302.
 */
@Test
public void testCheckInWithInProgressInvoice() {
    // Two visits should be created, one on date1, the other on date2
    Date date1 = getDatetime("2012-01-01 10:00:00");
    Date date2 = getDatetime("2012-01-02 12:00:00");

    // Invoice the customer for a medication1 for the patient on 1/1/2012.
    // Leave the invoice IN_PROGRESS
    Product medication1 = TestHelper.createProduct();
    FinancialAct charge = (FinancialAct) create(CustomerAccountArchetypes.INVOICE);
    charge.setActivityStartTime(date1);

    context.setCustomer(customer);
    context.setPatient(patient);
    context.setPractice(getPractice());
    context.setClinician(clinician);
    LayoutContext layoutContext = new DefaultLayoutContext(context, new HelpContext("foo", null));

    TestChargeEditor editor = new TestChargeEditor(charge, layoutContext, false);
    editor.getComponent();
    CustomerChargeActItemEditor itemEditor1 = editor.addItem();
    itemEditor1.setStartTime(date1); // otherwise will default to now
    setItem(editor, itemEditor1, patient, medication1, BigDecimal.TEN, editor.getQueue());

    assertTrue(SaveHelper.save(editor));

    // Verify that an event has been created, linked to the charge
    Act item1 = (Act) itemEditor1.getObject();
    ActBean bean = new ActBean(item1);
    Act event1 = bean.getSourceAct(PatientArchetypes.CLINICAL_EVENT_CHARGE_ITEM);
    assertNotNull(event1);
    assertEquals(date1, event1.getActivityStartTime());
    assertEquals(ActStatus.IN_PROGRESS, event1.getStatus());

    // complete the event. This will force a new event to be created on subsequent check-in
    event1.setActivityEndTime(getDatetime("2012-01-01 11:30:00"));
    event1.setStatus(ActStatus.COMPLETED);
    save(event1);

    Act appointment = createAppointment(date2, customer, patient, clinician);
    CheckInWorkflowRunner workflow = new CheckInWorkflowRunner(appointment, getPractice(), context);
    workflow.setArrivalTime(date2);

    runCheckInToVisit(workflow);

    // Add another invoice item.
    Product medication2 = TestHelper.createProduct();
    VisitChargeItemEditor itemEditor2 = workflow.addVisitInvoiceItem(patient, clinician, medication2);

    // close the dialog
    PopupDialog eventDialog = workflow.editVisit();
    fireDialogButton(eventDialog, PopupDialog.OK_ID);
    Act event2 = workflow.checkEvent(patient, clinician, ActStatus.IN_PROGRESS);
    workflow.checkComplete(true, customer, patient, context);

    // verify the second item is linked to event2
    Act item2 = (Act) itemEditor2.getObject();
    ActBean bean2 = new ActBean(item2);
    assertEquals(event2, bean2.getSourceAct(PatientArchetypes.CLINICAL_EVENT_CHARGE_ITEM));

    // verify the second event is not the same as the first, and that none of the acts in the second event
    // are the same as those in the first
    assertNotEquals(event1, event2);
    ActBean event1Bean = new ActBean(event1);
    ActBean event2Bean = new ActBean(event2);
    List<Act> event1Items = event1Bean.getActs();
    List<Act> event2Items = event2Bean.getActs();
    Collection inBoth = CollectionUtils.intersection(event1Items, event2Items);
    assertTrue(inBoth.isEmpty());
}

From source file:alfio.manager.TicketReservationManagerIntegrationTest.java

@Test(expected = TicketReservationManager.NotEnoughTicketsException.class)
public void testTicketSelectionNotEnoughTicketsAvailable() {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null,
            "default", AVAILABLE_SEATS, new DateTimeModification(LocalDate.now(), LocalTime.now()),
            new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "",
            false, null, null, null, null, null));
    Event event = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository)
            .getKey();/*  w w  w. ja v a2  s.  com*/

    TicketCategory unbounded = ticketCategoryRepository.findByEventId(event.getId()).stream()
            .filter(t -> !t.isBounded()).findFirst().orElseThrow(IllegalStateException::new);

    TicketReservationModification tr = new TicketReservationModification();
    tr.setAmount(AVAILABLE_SEATS + 1);
    tr.setTicketCategoryId(unbounded.getId());
    TicketReservationWithOptionalCodeModification mod = new TicketReservationWithOptionalCodeModification(tr,
            Optional.empty());

    ticketReservationManager.createTicketReservation(event, Collections.singletonList(mod),
            Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.empty(), Optional.empty(),
            Locale.ENGLISH, false);
}

From source file:jp.furplag.util.commons.NumberUtilsTest.java

/**
 * {@link jp.furplag.util.commons.NumberUtils#ceil(java.lang.Object, java.lang.Class)}.
 *///from   www  .j av a2 s. co  m
@SuppressWarnings("unchecked")
@Test
public void testCeilObjectClassOfT() {
    assertEquals("null", null, ceil(null, null));
    assertEquals("null", null, ceil("", null));
    assertEquals("null", null, ceil("not a number.", null));
    for (Class<?> type : NUMBERS) {
        try {
            Object expected = null;
            Class<? extends Number> typeOfN = (Class<? extends Number>) type;
            Class<? extends Number> wrapper = (Class<? extends Number>) ClassUtils.primitiveToWrapper(type);
            if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, "4");
            } else {
                Constructor<?> c = type.getDeclaredConstructor(String.class);
                expected = c.newInstance("4");
            }
            assertEquals("PI: String: " + type.getSimpleName(), expected, ceil("3.14", typeOfN));
            assertEquals("PI: Float: " + type.getSimpleName(), expected, ceil(3.141592653589793f, typeOfN));
            assertEquals("PI: Double: " + type.getSimpleName(), expected, ceil(Math.PI, typeOfN));
            assertEquals("PI: BigDecimal: " + type.getSimpleName(), expected,
                    ceil(BigDecimal.valueOf(Math.PI), typeOfN));
            assertEquals("(Double) (10 / 3): " + type.getSimpleName(), expected, ceil(
                    (Object) (BigDecimal.TEN.divide(new BigDecimal("3"), MathContext.DECIMAL128)), typeOfN));
            if (ObjectUtils.isAny(wrapper, Double.class, Float.class)) {
                expected = wrapper.getField("POSITIVE_INFINITY").get(null);
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getField("MAX_VALUE").get(null);
                assertEquals("Huge: " + type.getSimpleName(), expected,
                        ceil((Object) INFINITY_DOUBLE.pow(10, MathContext.DECIMAL128), typeOfN));
            } else if (BigDecimal.class.equals(type)) {
                expected = INFINITY_DOUBLE.pow(10, MathContext.DECIMAL128).toPlainString();
                Object actual = ceil((Object) INFINITY_DOUBLE.pow(10, MathContext.DECIMAL128), BigDecimal.class)
                        .toPlainString();
                assertEquals("Huge: " + type.getSimpleName(), expected, actual);
            } else {
                expected = INFINITY_DOUBLE.pow(10, MathContext.DECIMAL128).toBigInteger();
                Object actual = ceil((Object) INFINITY_DOUBLE.pow(10, MathContext.DECIMAL128),
                        BigInteger.class);
                assertEquals("Huge: " + type.getSimpleName(), expected, actual);
            }
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage() + "\n" + Arrays.toString(e.getStackTrace()));
        }
    }
}

From source file:alfio.manager.system.DataMigratorIntegrationTest.java

@Test
public void testFixCategoriesSize() {
    List<TicketCategoryModification> categories = Arrays.asList(
            new TicketCategoryModification(null, "default", AVAILABLE_SEATS - 1,
                    new DateTimeModification(LocalDate.now(), LocalTime.now()),
                    new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN,
                    false, "", true, null, null, null, null, null),
            new TicketCategoryModification(null, "default", 1,
                    new DateTimeModification(LocalDate.now(), LocalTime.now()),
                    new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN,
                    false, "", false, null, null, null, null, null));
    Pair<Event, String> eventUsername = initEvent(categories);
    Event event = eventUsername.getKey();
    TicketCategory firstCategory = ticketCategoryRepository.findByEventId(event.getId()).stream()
            .filter(TicketCategory::isBounded).findFirst().orElseThrow(IllegalStateException::new);
    int firstCategoryID = firstCategory.getId();
    ticketCategoryRepository.updateSeatsAvailability(firstCategoryID, AVAILABLE_SEATS + 1);
    dataMigrator.fixCategoriesSize(event);
    assertEquals(AVAILABLE_SEATS - 1, ticketRepository.countAllocatedTicketsForEvent(event.getId()).intValue());
    assertEquals(1, ticketRepository.countFreeTicketsForUnbounded(event.getId()).intValue());
    assertEquals(AVAILABLE_SEATS - 1,//from   ww w. j  a  va 2 s .  c o m
            ticketRepository.countFreeTickets(event.getId(), firstCategoryID).intValue());
    assertEquals(AVAILABLE_SEATS - 1, firstCategory.getMaxTickets());
}

From source file:alfio.manager.EventManagerIntegrationTest.java

@Test
public void testDecreaseEventSeatsWithAnUnboundedCategory() {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null,
            "default", 10, new DateTimeModification(LocalDate.now(), LocalTime.now()),
            new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "",
            false, null, null, null, null, null));
    Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager,
            eventRepository);// w  w  w.  j  av a 2 s  .c  o  m
    Event event = pair.getKey();
    EventModification update = new EventModification(event.getId(), Event.EventType.INTERNAL, null, null, null,
            null, null, null, null, event.getOrganizationId(), null, "0.0", "0.0",
            ZoneId.systemDefault().getId(), null, DateTimeModification.fromZonedDateTime(event.getBegin()),
            DateTimeModification.fromZonedDateTime(event.getEnd()), event.getRegularPrice(),
            event.getCurrency(), 10, event.getVat(), event.isVatIncluded(), event.getAllowedPaymentProxies(),
            null, event.isFreeOfCharge(), null, 7, null, null);
    eventManager.updateEventPrices(event, update, pair.getValue());
    List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
    assertNotNull(tickets);
    assertFalse(tickets.isEmpty());
    assertEquals(10, tickets.size());
    assertEquals(10, tickets.stream().filter(t -> t.getCategoryId() == null).count());
}

From source file:alfio.manager.TicketReservationManagerIntegrationTest.java

@Test
public void testDeletePendingPaymentUnboundedCategory() {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null,
            "default", AVAILABLE_SEATS, new DateTimeModification(LocalDate.now(), LocalTime.now()),
            new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "",
            false, null, null, null, null, null));
    Event event = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository)
            .getKey();/*from w  w w.  j a v  a  2 s.  c  om*/

    TicketCategory unbounded = ticketCategoryRepository.findByEventId(event.getId()).get(0);

    TicketReservationModification tr = new TicketReservationModification();
    tr.setAmount(AVAILABLE_SEATS / 2 + 1);
    tr.setTicketCategoryId(unbounded.getId());

    TicketReservationWithOptionalCodeModification mod = new TicketReservationWithOptionalCodeModification(tr,
            Optional.empty());
    String reservationId = ticketReservationManager.createTicketReservation(event,
            Collections.singletonList(mod), Collections.emptyList(), DateUtils.addDays(new Date(), 1),
            Optional.empty(), Optional.empty(), Locale.ENGLISH, false);
    TotalPrice reservationCost = ticketReservationManager.totalReservationCostWithVAT(reservationId);
    PaymentResult result = ticketReservationManager.confirm("", null, event, reservationId, "test@test.ch",
            new CustomerName("full name", "full", "name", event), Locale.ENGLISH, "", reservationCost,
            Optional.empty(), Optional.of(PaymentProxy.OFFLINE), false, null, null, null);
    assertTrue(result.isSuccessful());
    ticketReservationManager.deleteOfflinePayment(event, reservationId, false);
    waitingQueueManager.distributeSeats(event);

    mod = new TicketReservationWithOptionalCodeModification(tr, Optional.empty());
    reservationId = ticketReservationManager.createTicketReservation(event, Collections.singletonList(mod),
            Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.empty(), Optional.empty(),
            Locale.ENGLISH, false);
    reservationCost = ticketReservationManager.totalReservationCostWithVAT(reservationId);
    result = ticketReservationManager.confirm("", null, event, reservationId, "test@test.ch",
            new CustomerName("full name", "full", "name", event), Locale.ENGLISH, "", reservationCost,
            Optional.empty(), Optional.of(PaymentProxy.OFFLINE), false, null, null, null);
    assertTrue(result.isSuccessful());
}

From source file:alfio.manager.system.DataMigratorIntegrationTest.java

@Test
public void testFixStuckTickets() {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null,
            "default", AVAILABLE_SEATS, new DateTimeModification(LocalDate.now(), LocalTime.now()),
            new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "",
            false, null, null, null, null, null));
    Pair<Event, String> eventUsername = initEvent(categories);
    Event event = eventUsername.getKey();
    TicketReservationModification trm = new TicketReservationModification();
    trm.setAmount(1);/* w  w  w. j  a  v a  2  s .c  o m*/
    trm.setTicketCategoryId(eventManager.loadTicketCategories(event).get(0).getId());
    TicketReservationWithOptionalCodeModification r = new TicketReservationWithOptionalCodeModification(trm,
            Optional.empty());
    Date expiration = DateUtils.addDays(new Date(), 1);
    String reservationId = ticketReservationManager.createTicketReservation(event, Collections.singletonList(r),
            Collections.emptyList(), expiration, Optional.empty(), Optional.empty(), Locale.ENGLISH, false);
    //simulate the effect of a reservation cancellation after #392, as described in #391
    ticketReservationRepository.updateReservationStatus(reservationId,
            TicketReservation.TicketReservationStatus.CANCELLED.name());
    List<Ticket> ticketsInReservation = ticketRepository.findTicketsInReservation(reservationId);
    assertEquals(1, ticketsInReservation.size());
    String uuid = ticketsInReservation.get(0).getUuid();
    assertTrue(ticketsInReservation.stream().allMatch(t -> t.getStatus() == Ticket.TicketStatus.PENDING));
    dataMigrator.fixStuckTickets(event.getId());
    assertTrue(ticketRepository.findByUUID(uuid).getStatus() == Ticket.TicketStatus.RELEASED);
}

From source file:alfio.manager.EventManagerIntegrationTest.java

@Test
public void testDecreaseEventSeatsWithABoundedCategory() {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null,
            "default", 10, new DateTimeModification(LocalDate.now(), LocalTime.now()),
            new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "",
            true, null, null, null, null, null));
    Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager,
            eventRepository);//w  w  w .  j av  a 2s. c  om
    Event event = pair.getKey();
    EventModification update = new EventModification(event.getId(), Event.EventType.INTERNAL, null, null, null,
            null, null, null, null, event.getOrganizationId(), null, "0.0", "0.0",
            ZoneId.systemDefault().getId(), null, DateTimeModification.fromZonedDateTime(event.getBegin()),
            DateTimeModification.fromZonedDateTime(event.getEnd()), event.getRegularPrice(),
            event.getCurrency(), 10, event.getVat(), event.isVatIncluded(), event.getAllowedPaymentProxies(),
            null, event.isFreeOfCharge(), null, 7, null, null);
    eventManager.updateEventPrices(event, update, pair.getValue());
    List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
    assertNotNull(tickets);
    assertFalse(tickets.isEmpty());
    assertEquals(10, tickets.size());
    assertTrue(tickets.stream().allMatch(t -> t.getCategoryId() != null));
}