Example usage for java.time LocalTime now

List of usage examples for java.time LocalTime now

Introduction

In this page you can find the example usage for java.time LocalTime now.

Prototype

public static LocalTime now() 

Source Link

Document

Obtains the current time from the system clock in the default time-zone.

Usage

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);/*from w w  w. j  av  a2s  .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());
    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);// w w w .  j a va  2  s . c o  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()));
}

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);/*ww  w. j ava  2s  .  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.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 ww  . j  a va 2 s  . co  m*/

    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: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 w  w w .  j a va 2s.  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 ww.  ja v a 2s  .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   ww w. jav  a 2s.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:net.jmhertlein.alphonseirc.AlphonseBot.java

private void handleDadCommand(final String target, String sender, String[] args) {
    if (args.length == 1) {
        sendMessage(target, "Usage: !dad [left|list|say]");
        return;/*from ww  w  .j  a va 2 s  .com*/
    }

    switch (args[1]) {
    case "left":
        ZonedDateTime now = ZonedDateTime.now();
        this.dadLeaveTimes.put(LocalDate.now(), LocalTime.now());
        sendMessage(target,
                "Marked dad's leave time as now (" + now.format(DateTimeFormatter.ISO_LOCAL_TIME) + ").");
        break;
    case "list":
        int num = 3;
        if (args.length == 3) {
            try {
                num = Integer.parseInt(args[2]);
                if (num > 10)
                    num = 10;
            } catch (NumberFormatException nfe) {
                sendMessage(target, "Error parsing " + args[2] + " into int: " + nfe.getMessage());
                sendMessage(target, "Usage: !dad list (optional: number, default 3, max 10)");
                return;
            }
        }

        final int prevDays = num;
        dadLeaveTimes.keySet().stream().sorted()
                .filter(date -> date.isAfter(LocalDate.now().minusDays(prevDays)))
                .map(date -> date.format(DateTimeFormatter.ISO_LOCAL_DATE) + " || "
                        + dadLeaveTimes.get(date).format(DateTimeFormatter.ISO_LOCAL_TIME))
                .forEach(leaveTime -> sendMessage(target, leaveTime));

        break;
    case "say":
        String msg;
        switch (gen.nextInt(9)) {
        case 0:
            msg = "TYPES LOUDLY";
            break;
        case 1:
            msg = "BREATHES DEEPLY";
            break;
        case 2:
            msg = "ANGRILY TYPES AN EMAIL";
            break;
        case 3:
            msg = "BACKSPACES WITH AUTHORITY";
            break;
        case 4:
            msg = "STRETCHES WHILE EXHALING";
            break;
        case 5:
            msg = "thinks about Happy Hour";
            break;
        case 6:
            msg = "browses Yahoo! news";
            break;
        case 7:
            msg = "tells everyone to GET BACK TO WORK";
            break;
        case 8:
            msg = "ignores Lantzer standing in front of his desk";
            break;
        default:
            msg = "Someone made nextInt() go too high";
            break;
        }

        this.sendAction(target, msg);
        break;
    default:
        System.out.println("Bad switch on " + args[1]);
    }

}

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);// ww  w  . ja  v  a2 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);/*from  w ww  . j a v a2  s . com*/
    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));
}