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

@Test
public void testReserveFromNewCategory() 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));
    Pair<Event, String> eventWithUsername = initEvent(categories, organizationRepository, userManager,
            eventManager, eventRepository);
    Event event = eventWithUsername.getKey();
    String username = eventWithUsername.getValue();
    DateTimeModification expiration = DateTimeModification.fromZonedDateTime(ZonedDateTime.now().plusDays(1));
    CustomerData customerData = new CustomerData("Integration", "Test", "integration-test@test.ch",
            "Billing Address", "en");
    Category category = new Category(null, "name", new BigDecimal("100.00"));
    int attendees = AVAILABLE_SEATS;
    List<TicketsInfo> ticketsInfoList = Collections
            .singletonList(new TicketsInfo(category, generateAttendees(attendees), true, false));
    AdminReservationModification modification = new AdminReservationModification(expiration, customerData,
            ticketsInfoList, "en", false, null);
    Result<Pair<TicketReservation, List<Ticket>>> result = adminReservationManager
            .createReservation(modification, event.getShortName(), username);
    assertTrue(result.isSuccess());//from w  ww .j  a v a 2 s  . co  m
    Pair<TicketReservation, List<Ticket>> data = result.getData();
    List<Ticket> tickets = data.getRight();
    assertTrue(tickets.size() == attendees);
    assertNotNull(data.getLeft());
    int categoryId = tickets.get(0).getCategoryId();
    Event modified = eventManager.getSingleEvent(event.getShortName(), username);
    assertEquals(attendees + 1, eventRepository.countExistingTickets(event.getId()).intValue());
    assertEquals(attendees,
            ticketRepository.findPendingTicketsInCategories(Collections.singletonList(categoryId)).size());
    TicketCategory categoryModified = ticketCategoryRepository.getByIdAndActive(categoryId, event.getId());
    assertEquals(categoryModified.getMaxTickets(), attendees);
    ticketCategoryRepository.findByEventId(event.getId())
            .forEach(tc -> assertTrue(specialPriceRepository.findAllByCategoryId(tc.getId()).stream()
                    .allMatch(sp -> sp.getStatus() == SpecialPrice.Status.PENDING)));
    adminReservationManager.confirmReservation(event.getShortName(), data.getLeft().getId(), username);
    ticketCategoryRepository.findByEventId(event.getId())
            .forEach(tc -> assertTrue(specialPriceRepository.findAllByCategoryId(tc.getId()).stream()
                    .allMatch(sp -> sp.getStatus() == SpecialPrice.Status.TAKEN)));
    assertFalse(ticketRepository.findAllReservationsConfirmedButNotAssigned(event.getId())
            .contains(data.getLeft().getId()));
}

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

@Test
public void createWithBackNavigation() {
    final Integer id = 102;

    // -------------------------------
    // Create a new order
    // -------------------------------
    Order order = getContainer().newEntityInstance(Order.class);
    order.setOrderID(id);//  w ww  .  j  a  v a2 s . c  o 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.TEN);

    PrimitiveCollection<BigDecimal> osl = getContainer().newPrimitiveCollection(BigDecimal.class);
    osl.add(BigDecimal.TEN.negate());
    osl.add(BigDecimal.TEN);
    order.setOrderShelfLifes(osl);
    // -------------------------------

    // -------------------------------
    // Create a new customer
    // -------------------------------
    final Customer customer = getContainer().newEntityInstance(Customer.class);
    customer.setPersonID(id);
    customer.setPersonID(id);
    customer.setFirstName("Fabio");
    customer.setLastName("Martelli");
    customer.setCity("Pescara");

    PrimitiveCollection<String> value = getContainer().newPrimitiveCollection(String.class);
    value.add("fabio.martelli@tirasa.net");
    customer.setEmails(value);

    final Address homeAddress = getContainer().newComplexInstance(HomeAddress.class);
    homeAddress.setCity("Pescara");
    homeAddress.setPostalCode("65100");
    homeAddress.setStreet("viale Gabriele D'Annunzio 256");
    customer.setHomeAddress(homeAddress);

    value = getContainer().newPrimitiveCollection(String.class);
    value.add("3204725072");
    value.add("08569930");
    customer.setNumbers(value);

    final OrderCollection orders = getContainer().newEntityCollection(OrderCollection.class);
    orders.add(order);
    customer.setOrders(orders);
    // -------------------------------

    // -------------------------------
    // Link customer to order
    // -------------------------------
    order.setCustomerForOrder(customer);
    // -------------------------------

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

    assertEquals(id, order.getOrderID());
    assertEquals(id, customer.getPersonID());

    Customer actual = readCustomer(getContainer(), id);
    Assert.assertEquals(homeAddress.getCity(), actual.getHomeAddress().getCity());
    Assert.assertEquals(1, actual.getOrders().execute().size());
    Assert.assertEquals(id, actual.getOrders().iterator().next().getOrderID());

    order = getContainer().getOrders().getByKey(id);
    assertNotNull(order);
    Assert.assertEquals(id, order.getCustomerForOrder().load().getPersonID());

    getContainer().getOrders().delete(actual.getOrders());
    getContainer().flush();

    try {
        getContainer().getOrders().getByKey(id).load();
        fail();
    } catch (IllegalArgumentException e) {
        // Expected
    }

    actual = readCustomer(getContainer(), id);
    assertTrue(actual.getOrders().isEmpty());

    getContainer().getCustomers().delete(actual.getPersonID());
    getContainer().flush();

    try {
        getContainer().getCustomers().getByKey(id).load();
        fail();
    } catch (IllegalArgumentException e) {
        // Expected
    }
}

From source file:alfio.manager.EventManagerIntegrationTest.java

@Test(expected = IllegalArgumentException.class)
public void testEventGenerationWithOverflow() {
    List<TicketCategoryModification> categories = Arrays.asList(
            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),
            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),
            new TicketCategoryModification(null, "default", 0,
                    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   ww  w  . ja  v a2 s. c  o m
    List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
    assertNotNull(tickets);
    assertFalse(tickets.isEmpty());
    assertEquals(AVAILABLE_SEATS, tickets.size());
    assertTrue(tickets.stream().noneMatch(t -> t.getCategoryId() == null));
}

From source file:org.apache.olingo.server.core.serializer.json.EdmAssistedJsonSerializerTest.java

@Test
public void entityCollectionWithComplexProperty() throws Exception {
    Entity entity = new Entity();
    entity.setId(null);/*from w ww.  j a v  a2s .  c  om*/
    entity.addProperty(new Property(null, "Property1", ValueType.PRIMITIVE, 1L));
    ComplexValue complexValue = new ComplexValue();
    complexValue.getValue()
            .add(new Property(null, "Inner1", ValueType.PRIMITIVE, BigDecimal.TEN.scaleByPowerOfTen(-5)));
    Calendar time = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    time.clear();
    time.set(Calendar.HOUR_OF_DAY, 13);
    time.set(Calendar.SECOND, 59);
    time.set(Calendar.MILLISECOND, 999);
    complexValue.getValue().add(new Property("Edm.TimeOfDay", "Inner2", ValueType.PRIMITIVE, time));
    entity.addProperty(new Property("Namespace.ComplexType", "Property2", ValueType.COMPLEX, complexValue));
    EntityCollection entityCollection = new EntityCollection();
    entityCollection.getEntities().add(entity);
    Assert.assertEquals(
            "{\"@odata.context\":\"$metadata#EntitySet(Property1,Property2)\","
                    + "\"value\":[{\"@odata.id\":null," + "\"Property1@odata.type\":\"#Int64\",\"Property1\":1,"
                    + "\"Property2\":{\"@odata.type\":\"#Namespace.ComplexType\","
                    + "\"Inner1@odata.type\":\"#Decimal\",\"Inner1\":0.00010,"
                    + "\"Inner2@odata.type\":\"#TimeOfDay\",\"Inner2\":\"13:00:59.999\"}}]}",
            serialize(serializer, metadata, null, entityCollection, null));
}

From source file:org.openvpms.archetype.rules.patient.PatientMergerTestCase.java

/**
 * Helper to create and save a new discount type entity.
 *
 * @return a new discount//from   w  ww  .  j  a  v  a2 s.co m
 */
private Entity createDiscount() {
    return DiscountTestHelper.createDiscount(BigDecimal.TEN, true, DiscountRules.PERCENTAGE);
}

From source file:uk.dsxt.voting.client.web.MockVotingApiResource.java

License:asdf

@POST
@Path("/votingResults")
@Produces("application/json")
public RequestResult votingResults(@FormParam("cookie") String cookie, @FormParam("votingId") String votingId) {
    log.debug("votingResults method called. votingId={}", votingId);
    final AnswerWeb[] answers1 = new AnswerWeb[4];
    answers1[0] = new AnswerWeb("1", "answer_1", BigDecimal.TEN);
    answers1[1] = new AnswerWeb("2", "answer_2", BigDecimal.ONE);
    answers1[2] = new AnswerWeb("3", "answer_3", BigDecimal.TEN);
    answers1[3] = new AnswerWeb("4", "answer_4", BigDecimal.ONE);

    final AnswerWeb[] answers2 = new AnswerWeb[1];
    answers2[0] = new AnswerWeb("1", "yes", BigDecimal.TEN);

    final QuestionWeb[] questions = new QuestionWeb[3];
    questions[0] = new QuestionWeb("1", "question_1_multi", answers1, true, 1);
    questions[1] = new QuestionWeb("2", "question_2_yes_no", answers2, false, 1);
    questions[2] = new QuestionWeb("3", "question_3_no_vote", new AnswerWeb[0], false, 1);
    return new RequestResult<>(new VotingInfoWeb(questions, new BigDecimal(22), null,
            "asdkfhbwerjhwbejhsdhfsjjsjdf3k345k", VoteResultStatus.OK, System.currentTimeMillis(), "nodeSign"),
            null);/* w ww.  jav  a 2s  .  co m*/
}

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

@Test
public void testAlreadyMigratedEvent() {
    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 .  j ava  2 s.  c o m
        ZonedDateTime migrationTs = ZonedDateTime.now(ZoneId.of("UTC"));
        eventMigrationRepository.insertMigrationData(event.getId(), currentVersion, migrationTs,
                EventMigration.Status.COMPLETE.toString());
        eventRepository.updatePrices("CHF", 40, false, BigDecimal.ONE, "STRIPE", event.getId(),
                PriceContainer.VatStatus.NOT_INCLUDED, 1000);
        dataMigrator.migrateEventsToCurrentVersion();
        EventMigration eventMigration = eventMigrationRepository.loadEventMigration(event.getId());
        assertNotNull(eventMigration);
        //assertEquals(migrationTs.toString(), eventMigration.getBuildTimestamp().toString());
        assertEquals(currentVersion, eventMigration.getCurrentVersion());

        List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
        assertNotNull(tickets);
        assertFalse(tickets.isEmpty());
        assertEquals(AVAILABLE_SEATS, tickets.size());//<-- the migration has not been done
        assertTrue(tickets.stream().allMatch(t -> t.getCategoryId() == null));
    } finally {
        eventManager.deleteEvent(event.getId(), eventUsername.getValue());
    }
}

From source file:org.fineract.module.stellar.TestPaymentInSimpleNetwork.java

@Test
public void paymentSumApproachesCreditLimit() throws Exception {
    logger.info("paymentSumApproachesCreditLimit test begin");

    final BigDecimal transferIncrement = BigDecimal.valueOf(99.99);
    final BigDecimal lastBit = BigDecimal.valueOf(0.1);

    final AccountListener accountListener = new AccountListener(serverAddress, firstTenantId, secondTenantId);

    //Approach the creditMatcher limit, then go back down to zero.
    Collections.nCopies(10, transferIncrement).parallelStream()
            .forEach((transferAmount) -> makePayment(firstTenantId, firstTenantApiKey, secondTenantId,
                    ASSET_CODE, transferAmount));

    {//from w  ww . j a  v a 2  s.  c  o  m
        final List<AccountListener.CreditMatcher> transfers = new ArrayList<>();
        transfers.addAll(Collections.nCopies(10,
                creditMatcher(secondTenantId, transferIncrement, ASSET_CODE, firstTenantId)));

        accountListener.waitForCredits(PAY_WAIT * 3, transfers);
    }

    checkBalance(secondTenantId, secondTenantApiKey, ASSET_CODE, tenantVaultStellarAddress(secondTenantId),
            VAULT_BALANCE);

    checkBalance(secondTenantId, secondTenantApiKey, ASSET_CODE, tenantVaultStellarAddress(firstTenantId),
            transferIncrement.multiply(BigDecimal.TEN));

    logger.info("paymentSumApproachesCreditLimit transfers back");
    Collections.nCopies(10, transferIncrement).parallelStream()
            .forEach((transferAmount) -> makePayment(secondTenantId, secondTenantApiKey, firstTenantId,
                    ASSET_CODE, transferAmount));

    {
        final List<AccountListener.CreditMatcher> transfers = new ArrayList<>();
        transfers.addAll(Collections.nCopies(10, creditMatcher(firstTenantId, transferIncrement, ASSET_CODE,
                vaultMatcher(firstTenantId, secondTenantId))));

        accountListener.waitForCredits(PAY_WAIT * 3, transfers);

        accountListener.waitForCreditsToAccumulate(PAY_WAIT * 3,
                creditMatcher(secondTenantId, transferIncrement.multiply(BigDecimal.TEN), ASSET_CODE,
                        vaultMatcher(firstTenantId, secondTenantId)));

        accountListener.waitForCreditsToAccumulate(PAY_WAIT * 3,
                creditMatcher(firstTenantId, transferIncrement.multiply(BigDecimal.TEN), ASSET_CODE,
                        vaultMatcher(firstTenantId, secondTenantId)));
    }

    checkBalance(firstTenantId, firstTenantApiKey, ASSET_CODE, tenantVaultStellarAddress(secondTenantId),
            BigDecimal.ZERO);
    checkBalance(secondTenantId, secondTenantApiKey, ASSET_CODE, tenantVaultStellarAddress(firstTenantId),
            BigDecimal.ZERO);

    //Approach the creditMatcher limit again, then go to exactly the creditMatcher limit
    Collections.nCopies(10, transferIncrement).parallelStream()
            .forEach((transferAmount) -> makePayment(firstTenantId, firstTenantApiKey, secondTenantId,
                    ASSET_CODE, transferAmount));
    makePayment(firstTenantId, firstTenantApiKey, secondTenantId, ASSET_CODE, lastBit);

    {
        final List<AccountListener.CreditMatcher> transfers = new ArrayList<>();
        transfers.addAll(Collections.nCopies(10,
                creditMatcher(secondTenantId, transferIncrement, ASSET_CODE, firstTenantId)));
        transfers.add(creditMatcher(secondTenantId, lastBit, ASSET_CODE, firstTenantId));

        accountListener.waitForCredits(PAY_WAIT * 3, transfers);
    }

    checkBalance(secondTenantId, secondTenantApiKey, ASSET_CODE, tenantVaultStellarAddress(firstTenantId),
            TRUST_LIMIT);

    //Now try to go over the creditMatcher limit.
    makePayment(firstTenantId, firstTenantApiKey, secondTenantId, ASSET_CODE, lastBit);

    accountListener.waitForCredits(PAY_WAIT,
            creditMatcher(secondTenantId, lastBit, ASSET_CODE, vaultMatcher(firstTenantId, secondTenantId)));

    checkBalance(secondTenantId, secondTenantApiKey, ASSET_CODE, tenantVaultStellarAddress(firstTenantId),
            TRUST_LIMIT);

    //Zero out balance for next test.
    makePayment(secondTenantId, secondTenantApiKey, firstTenantId, ASSET_CODE, TRUST_LIMIT);
    accountListener.waitForCredits(PAY_WAIT,
            creditMatcher(firstTenantId, TRUST_LIMIT, ASSET_CODE, vaultMatcher(firstTenantId, secondTenantId)));
}

From source file:alfio.manager.WaitingQueueManagerIntegrationTest.java

@Test
public void testWaitingQueueForUnboundedCategory() {
    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 ww  .  j  a v  a  2 s .  c  o  m*/
    TicketCategory unbounded = ticketCategoryRepository.findByEventId(event.getId()).get(0);

    TicketReservationModification tr = new TicketReservationModification();
    tr.setAmount(AVAILABLE_SEATS);
    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.<String>empty(), Optional.<String>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());

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

From source file:alfio.manager.EventManagerIntegrationTest.java

/**
 * When adding an unbounded category, we won't update the tickets status, because:
 * 1) if the unbounded category is using existing seats, the event cannot be already sold-out
 * 2) if the unbounded category has been added after an event edit (add seats), then the tickets are already "RELEASED"
 * 3) if there is another unbounded category, then it is safe not to update the tickets' status, in order to not
 *    interfere with the existing category
 *
 *//*w w  w.j  a  v a  2s. c  o  m*/
@Test
public void testAddUnboundedCategory() {
    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);
    Event event = pair.getKey();
    TicketCategoryModification tcm = 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);
    eventManager.insertCategory(event.getId(), tcm, pair.getValue());
    List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
    assertNotNull(tickets);
    assertFalse(tickets.isEmpty());
    assertEquals(AVAILABLE_SEATS, tickets.size());
    assertEquals(10, tickets.stream().filter(t -> t.getCategoryId() == null).count());
}