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.TicketReservationManagerIntegrationTest.java

@Test
public void testTicketWithDiscount() {
    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 ww.j  a va 2 s  .  c  o m

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

    //promo code at event level
    eventManager.addPromoCode("MYPROMOCODE", event.getId(), null, event.getBegin(), event.getEnd(), 10,
            PromoCodeDiscount.DiscountType.PERCENTAGE, null);

    //promo code at organization level
    eventManager.addPromoCode("MYFIXEDPROMO", null, event.getOrganizationId(), event.getBegin(), event.getEnd(),
            5, PromoCodeDiscount.DiscountType.FIXED_AMOUNT, null);

    TicketReservationModification tr = new TicketReservationModification();
    tr.setAmount(3);
    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.of("MYPROMOCODE"), Locale.ENGLISH, false);

    TotalPrice totalPrice = ticketReservationManager.totalReservationCostWithVAT(reservationId);

    // 3 * 10 chf is the normal price, 10% discount -> 300 discount
    Assert.assertEquals(2700, totalPrice.getPriceWithVAT());
    Assert.assertEquals(27, totalPrice.getVAT());
    Assert.assertEquals(-300, totalPrice.getDiscount());
    Assert.assertEquals(1, totalPrice.getDiscountAppliedCount());

    OrderSummary orderSummary = ticketReservationManager.orderSummaryForReservationId(reservationId, event,
            Locale.ENGLISH);
    Assert.assertEquals("27.00", orderSummary.getTotalPrice());
    Assert.assertEquals("0.27", orderSummary.getTotalVAT());
    Assert.assertEquals(3, orderSummary.getTicketAmount());

    TicketReservationModification trFixed = new TicketReservationModification();
    trFixed.setAmount(3);
    trFixed.setTicketCategoryId(unbounded.getId());
    TicketReservationWithOptionalCodeModification modFixed = new TicketReservationWithOptionalCodeModification(
            trFixed, Optional.empty());

    String reservationIdFixed = ticketReservationManager.createTicketReservation(event,
            Collections.singletonList(modFixed), Collections.emptyList(), DateUtils.addDays(new Date(), 1),
            Optional.empty(), Optional.of("MYFIXEDPROMO"), Locale.ENGLISH, false);

    TotalPrice totalPriceFixed = ticketReservationManager.totalReservationCostWithVAT(reservationIdFixed);

    // 3 * 10 chf is the normal price, 3 * 5 is the discount
    Assert.assertEquals(2985, totalPriceFixed.getPriceWithVAT());
    Assert.assertEquals(30, totalPriceFixed.getVAT());
    Assert.assertEquals(-15, totalPriceFixed.getDiscount());
    Assert.assertEquals(3, totalPriceFixed.getDiscountAppliedCount());

    OrderSummary orderSummaryFixed = ticketReservationManager.orderSummaryForReservationId(reservationIdFixed,
            event, Locale.ENGLISH);
    Assert.assertEquals("29.85", orderSummaryFixed.getTotalPrice());
    Assert.assertEquals("0.30", orderSummaryFixed.getTotalVAT());
    Assert.assertEquals(3, orderSummaryFixed.getTicketAmount());

}

From source file:de.iteratec.iteraplan.businesslogic.exchange.nettoExport.NettoCSVTransformerTest.java

private void prepareTestData() {

    /*/*ww w  . ja  v a2s  .  c  o  m*/
     * Create a Numeric Attribute
     */
    AttributeTypeGroup atg = testDataHelper.createAttributeTypeGroup("test", "test description");
    numberAT = testDataHelper.createNumberAttributeType("Complexity", "description", atg);
    testDataHelper.getBuildingBlockType(TypeOfBuildingBlock.INFORMATIONSYSTEMRELEASE)
            .addAttributeTypeTwoWay(numberAT);

    NumberAV numberAV1;
    NumberAV numberAV2;

    numberAV1 = testDataHelper.createNumberAV(BigDecimal.ONE, numberAT);
    numberAV2 = testDataHelper.createNumberAV(BigDecimal.TEN, numberAT);

    sourceList = new ArrayList<BuildingBlock>();

    InformationSystem is = testDataHelper.createInformationSystem("Unit-Test Information-System");
    isArray = new InformationSystemRelease[4];

    isArray[0] = testDataHelper.createInformationSystemRelease(is, "1.0", "Description", "10.10.2015",
            "10.10.2020", TypeOfStatus.PLANNED);
    isArray[1] = testDataHelper.createInformationSystemRelease(is, "2.0", "Description", "11.09.2016",
            "10.10.2020", TypeOfStatus.CURRENT);
    isArray[2] = testDataHelper.createInformationSystemRelease(is, "3.0", "Description", "12.08.2017",
            "10.10.2020", TypeOfStatus.PLANNED);
    isArray[3] = testDataHelper.createInformationSystemRelease(is, "4.0", "Description", "13.07.2018",
            "10.10.2020", TypeOfStatus.CURRENT);

    testDataHelper.createAVA(isArray[0], numberAV1);
    testDataHelper.createAVA(isArray[1], numberAV2);
    testDataHelper.createAVA(isArray[2], numberAV1);
    testDataHelper.createAVA(isArray[3], numberAV2);

    sourceList.add(isArray[0]);
    sourceList.add(isArray[1]);
    sourceList.add(isArray[2]);
    sourceList.add(isArray[3]);

}

From source file:org.apache.olingo.fit.proxy.APIBasicDesignTestITCase.java

@Test
public void createDelete() {
    // Create order ....
    final Order order = getContainer().newEntityInstance(Order.class);
    order.setOrderID(1105);/*from w ww. jav  a  2s  . co m*/

    final Calendar orderDate = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    orderDate.clear();
    orderDate.set(2011, 3, 4, 16, 3, 57);
    order.setOrderDate(new Timestamp(orderDate.getTimeInMillis()));

    order.setShelfLife(BigDecimal.ZERO);

    final PrimitiveCollection<BigDecimal> osl = getContainer().newPrimitiveCollection(BigDecimal.class);
    osl.add(BigDecimal.TEN.negate());
    osl.add(BigDecimal.TEN);

    order.setOrderShelfLifes(osl);

    getContainer().getOrders().add(order);
    getContainer().flush();

    Order actual = getContainer().getOrders().getByKey(1105);
    assertNull(actual.getOrderID());

    actual.load();
    assertEquals(1105, actual.getOrderID(), 0);
    assertEquals(orderDate.getTimeInMillis(), actual.getOrderDate().getTime());
    assertEquals(BigDecimal.ZERO, actual.getShelfLife());
    assertEquals(2, actual.getOrderShelfLifes().size());

    service.getContext().detachAll();

    // (1) Delete by key (see EntityCreateTestITCase)
    getContainer().getOrders().delete(1105);
    assertNull(getContainer().getOrders().getByKey(1105));

    service.getContext().detachAll(); // detach to show the second delete case

    // (2) Delete by object (see EntityCreateTestITCase)
    getContainer().getOrders().delete(getContainer().getOrders().getByKey(1105));
    assertNull(getContainer().getOrders().getByKey(1105));

    // (3) Delete by invoking delete method on the object itself
    service.getContext().detachAll(); // detach to show the third delete case
    getContainer().getOrders().getByKey(1105).delete();
    assertNull(getContainer().getOrders().getByKey(1105));

    getContainer().flush();

    service.getContext().detachAll();
    try {
        getContainer().getOrders().getByKey(1105).load();
        fail();
    } catch (IllegalArgumentException e) {
        // Test
    }
    service.getContext().detachAll(); // avoid influences
}

From source file:org.openestate.io.is24_xml.Is24XmlUtils.java

public static String printPreisAufAnfrage(BigDecimal value) {
    if (value == null || value.compareTo(BigDecimal.ZERO) == -1
            || value.compareTo(BigDecimal.TEN.pow(13)) != -1)
        throw new IllegalArgumentException("Can't print decimal value '" + value + "'!");
    else if (value.compareTo(BigDecimal.ZERO) == 0)
        return "0";
    else//  w  w w  . j  av  a2 s.  c o  m
        return DatatypeConverter.printDecimal(value.setScale(2, BigDecimal.ROUND_HALF_UP));
}

From source file:org.marketcetera.saclient.SAClientWSTest.java

@Test
public void setProperties() throws Exception {
    final ModuleURN input1 = new ModuleURN("test:prov:me:A");
    final Map<String, Object> i2 = new HashMap<String, Object>();
    i2.put("first", BigDecimal.ONE);
    i2.put("second", "mnext");
    i2.put("third", 999);
    //Test a non-empty and an empty map.
    List<Map<String, Object>> inputs = Arrays.asList(i2, new HashMap<String, Object>());
    final Map<String, Object> out = new HashMap<String, Object>();
    out.put("first", BigDecimal.TEN);
    out.put("second", "next");
    out.put("third", 909);
    //Test a non-empty and an empty map.
    List<Map<String, Object>> outputs = Arrays.asList(out, new HashMap<String, Object>());
    for (int i = 0; i < inputs.size(); i++) {
        final Map<String, Object> input2 = inputs.get(i);
        final Map<String, Object> output = outputs.get(i);
        testAPI(new WSTester<Map<String, Object>>() {
            @Override/*from   w ww .j  ava2 s  . c o m*/
            protected Map<String, Object> invokeApi(boolean isNullParams) throws Exception {
                return getClient().setProperties(isNullParams ? null : input1, isNullParams ? null : input2);
            }

            @Override
            protected Map<String, Object> setReturnValue(boolean isNullParams) {
                getMockSAService()
                        .setPropertiesOut(isNullParams ? null : new MapWrapper<String, Object>(output));
                return isNullParams ? null : output;
            }

            @Override
            protected void verifyInputParams(boolean isNullParams) throws Exception {
                assertEquals(isNullParams ? null : input1, getMockSAService().getURN());
                MapWrapper<String, Object> mapWrapper = getMockSAService().getPropertiesIn();
                verifyEquals(isNullParams ? null : input2, mapWrapper == null ? null : mapWrapper.getMap());
            }
        });
        resetServiceParameters();
    }
}

From source file:org.openhab.binding.denon.internal.DenonConnector.java

private String toDenonValue(BigDecimal percent) {
    // Round to nearest number divisible by 0.5 
    percent = percent.divide(POINTFIVE).setScale(0, RoundingMode.UP).multiply(POINTFIVE)
            .min(connection.getMainVolumeMax()).max(BigDecimal.ZERO);

    String dbString = String.valueOf(percent.intValue());

    if (percent.compareTo(BigDecimal.TEN) == -1) {
        dbString = "0" + dbString;
    }//  ww  w .  j a v  a  2 s.  c om
    if (percent.remainder(BigDecimal.ONE).equals(POINTFIVE)) {
        dbString = dbString + "5";
    }

    return dbString;
}

From source file:org.openhab.binding.denon.internal.DenonConnector.java

private BigDecimal fromDenonValue(String string) {
    /*//from  ww  w .  j ava  2 s  .  c o m
     * 455 = 45,5
     * 45 = 45
     * 045 = 4,5
     * 04 = 4 
     */
    BigDecimal value = new BigDecimal(string);
    if (value.compareTo(NINETYNINE) == 1 || (string.startsWith("0") && string.length() > 2)) {
        value = value.divide(BigDecimal.TEN);
    }

    return value;
}

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

@Test
public void testUpdateGender() {
    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();
    try {//from w w  w. ja  v  a  2s  . c  o m
        TicketReservationModification trm = new TicketReservationModification();
        trm.setAmount(2);
        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);
        ticketReservationManager.confirm("TOKEN", null, event, reservationId, "email@email.ch",
                new CustomerName("Full Name", "Full", "Name", event), Locale.ENGLISH, null,
                new TotalPrice(1000, 10, 0, 0), Optional.empty(), Optional.of(PaymentProxy.ON_SITE), false,
                null, null, null);
        List<Ticket> tickets = ticketRepository.findTicketsInReservation(reservationId);
        UpdateTicketOwnerForm first = new UpdateTicketOwnerForm();
        first.setEmail("email@email.ch");
        //first.setTShirtSize("SMALL");
        //first.setGender("F");
        first.setFirstName("Full");
        first.setLastName("Name");
        UpdateTicketOwnerForm second = new UpdateTicketOwnerForm();
        //second.setTShirtSize("SMALL-F");
        second.setEmail("email@email.ch");
        second.setFirstName("Full");
        second.setLastName("Name");
        PartialTicketPDFGenerator generator = TemplateProcessor.buildPartialPDFTicket(Locale.ITALIAN, event,
                ticketReservationManager.findById(reservationId).get(),
                ticketCategoryRepository.getByIdAndActive(tickets.get(0).getCategoryId(), event.getId()),
                organizationRepository.getById(event.getOrganizationId()), templateManager, fileUploadManager,
                "");
        ticketReservationManager.updateTicketOwner(tickets.get(0), Locale.ITALIAN, event, first, (t) -> "",
                (t) -> "", Optional.empty());
        ticketReservationManager.updateTicketOwner(tickets.get(1), Locale.ITALIAN, event, second, (t) -> "",
                (t) -> "", Optional.empty());
        //FIXME
        //dataMigrator.fillTicketsGender();
        //ticketRepository.findTicketsInReservation(reservationId).forEach(t -> assertEquals("F", t.getGender()));
    } finally {
        eventManager.deleteEvent(event.getId(), eventUsername.getValue());
    }
}

From source file:alfio.manager.EventManagerIntegrationTest.java

@Test
public void testIncreaseEventSeatsWithAnUnboundedCategory() {
    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  ava  2 s . co 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());
    waitingQueueSubscriptionProcessor.distributeAvailableSeats(event);
    tickets = ticketRepository.findFreeByEventId(event.getId());
    assertEquals(40, tickets.size());
    assertEquals(40, tickets.stream().filter(t -> t.getCategoryId() == null).count());
}

From source file:alfio.manager.AdminReservationManagerIntegrationTest.java

@Test
public void testConfirmReservation() throws Exception {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null,
            "default", 1, new DateTimeModification(LocalDate.now(), LocalTime.now()),
            new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "",
            true, null, null, null, null, null));
    Triple<Event, String, TicketReservation> testResult = performExistingCategoryTest(categories, true,
            Collections.singletonList(2), false, true, 0, AVAILABLE_SEATS);
    assertNotNull(testResult);/*from  ww  w. java 2 s  .  co m*/
    Result<Triple<TicketReservation, List<Ticket>, Event>> result = adminReservationManager.confirmReservation(
            testResult.getLeft().getShortName(), testResult.getRight().getId(), testResult.getMiddle());
    assertTrue(result.isSuccess());
    Triple<TicketReservation, List<Ticket>, Event> triple = result.getData();
    assertEquals(TicketReservation.TicketReservationStatus.COMPLETE, triple.getLeft().getStatus());
    triple.getMiddle().forEach(t -> assertEquals(Ticket.TicketStatus.ACQUIRED, t.getStatus()));
    assertTrue(emailMessageRepository.findByEventId(triple.getRight().getId(), 0, 50, null).isEmpty());
    ticketCategoryRepository.findByEventId(triple.getRight().getId())
            .forEach(tc -> assertTrue(specialPriceRepository.findAllByCategoryId(tc.getId()).stream()
                    .allMatch(sp -> sp.getStatus() == SpecialPrice.Status.TAKEN)));
    assertFalse(ticketRepository.findAllReservationsConfirmedButNotAssigned(triple.getRight().getId())
            .contains(triple.getLeft().getId()));
}