List of usage examples for java.time LocalTime now
public static LocalTime now()
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 * *///ww w . ja va 2s .c om @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()); }
From source file:alfio.manager.system.DataMigratorIntegrationTest.java
@Test public void testUpdateDisplayName() { 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, null); Event event = eventUsername.getKey(); try {/*from ww w . ja v a 2 s .co m*/ dataMigrator.migrateEventsToCurrentVersion(); EventMigration eventMigration = eventMigrationRepository.loadEventMigration(event.getId()); assertNotNull(eventMigration); //assertEquals(buildTimestamp, eventMigration.getBuildTimestamp().toString()); assertEquals(currentVersion, eventMigration.getCurrentVersion()); Event withDescription = eventRepository.findById(event.getId()); assertNotNull(withDescription.getDisplayName()); assertEquals(event.getShortName(), withDescription.getShortName()); assertEquals(event.getShortName(), withDescription.getDisplayName()); } finally { eventManager.deleteEvent(event.getId(), eventUsername.getValue()); } }
From source file:alfio.manager.AdminReservationManagerIntegrationTest.java
@Test public void testReserveMixed() 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, "", false, 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"); TicketCategory existingCategory = ticketCategoryRepository.findByEventId(event.getId()).get(0); Category resExistingCategory = new Category(existingCategory.getId(), "", existingCategory.getPrice()); Category resNewCategory = new Category(null, "name", new BigDecimal("100.00")); int attendees = 1; List<TicketsInfo> ticketsInfoList = Arrays.asList( new TicketsInfo(resExistingCategory, generateAttendees(attendees), false, false), new TicketsInfo(resNewCategory, generateAttendees(attendees), false, false), new TicketsInfo(resExistingCategory, generateAttendees(attendees), false, 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 w w.ja v a 2 s. c o m*/ Pair<TicketReservation, List<Ticket>> data = result.getData(); List<Ticket> tickets = data.getRight(); assertTrue(tickets.size() == 3); assertNotNull(data.getLeft()); assertTrue(tickets.stream().allMatch(t -> t.getTicketsReservationId().equals(data.getKey().getId()))); int resExistingCategoryId = tickets.get(0).getCategoryId(); int resNewCategoryId = tickets.get(2).getCategoryId(); Event modified = eventManager.getSingleEvent(event.getShortName(), username); assertEquals(AVAILABLE_SEATS, eventRepository.countExistingTickets(event.getId()).intValue()); assertEquals(3, ticketRepository .findPendingTicketsInCategories(Arrays.asList(resExistingCategoryId, resNewCategoryId)).size()); assertEquals(3, ticketRepository.findTicketsInReservation(data.getLeft().getId()).size()); String reservationId = data.getLeft().getId(); assertEquals(ticketRepository.findTicketsInReservation(reservationId).stream().findFirst().get().getId(), ticketRepository.findFirstTicketInReservation(reservationId).get().getId()); 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:electrical_parameters.TakuNoda.java
public void printAll() { System.out.println("Cas generovania"); System.out.println(LocalTime.now()); System.out.println("R [Ohm/km]"); printRealMatrix(this.R_real); System.out.println("L [mH/km]"); printRealMatrix(this.L_real.scalarMultiply(1000)); System.out.println("X [Ohm/km]"); printRealMatrix(this.X_real); System.out.println("Z [Ohm/km]"); printComplexMatrix(this.Z); System.out.println("Rred [Ohm/km]"); printRealMatrix(this.R_red); System.out.println("Lred [mH/km]"); printRealMatrix(this.L_red.scalarMultiply(1000)); System.out.println("Xred [Ohm/km]"); printRealMatrix(this.X_red); System.out.println("Zred [Ohm/km]"); printComplexMatrix(this.Z_red); System.out.println("Rred_symm [Ohm/km]"); printSymmRealMatrix(this.R_red_symm); System.out.println("Lred_symm [mH/km]"); printSymmRealMatrix(this.L_red_symm.scalarMultiply(1000)); System.out.println("Xred_symm [Ohm/km]"); printSymmRealMatrix(this.X_red_symm); System.out.println("Zred_symm [Ohm/km]"); printSymmComplexMatrix(this.Z_red_symm); }
From source file:alfio.manager.EventManagerIntegrationTest.java
@Test public void testAddUnboundedCategoryShrinkBoundedCategory() { //create the event with a single category which contains all the tickets 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, "", true, null, null, null, null, null)); Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);/* w w w .j a va2s .c o m*/ Event event = pair.getKey(); //shrink the original category to AVAILABLE_SEATS - 2, this would free two seats int categoryId = ticketCategoryRepository.findAllTicketCategories(event.getId()).get(0).getId(); TicketCategoryModification shrink = new TicketCategoryModification(categoryId, "default", AVAILABLE_SEATS - 2, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", true, null, null, null, null, null); eventManager.updateCategory(categoryId, event.getId(), shrink, pair.getRight()); //now insert an unbounded ticket category TicketCategoryModification tcm = 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); eventManager.insertCategory(event.getId(), tcm, pair.getValue()); waitingQueueSubscriptionProcessor.distributeAvailableSeats(event); List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId()); assertNotNull(tickets); assertFalse(tickets.isEmpty()); assertEquals(AVAILABLE_SEATS, tickets.size()); assertEquals(18, tickets.stream().filter(t -> t.getCategoryId() != null && t.getCategoryId() == categoryId).count()); assertEquals(2, tickets.stream().filter(t -> t.getCategoryId() == null).count()); }
From source file:alfio.manager.system.DataMigratorIntegrationTest.java
@Test public void testUpdateTicketReservation() { 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 ww . ja va 2 s .c om*/ TicketReservationModification trm = new TicketReservationModification(); trm.setAmount(1); 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); dataMigrator.fillReservationsLanguage(); TicketReservation ticketReservation = ticketReservationManager.findById(reservationId).get(); assertEquals("en", ticketReservation.getUserLanguage()); } finally { eventManager.deleteEvent(event.getId(), eventUsername.getValue()); } }
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 w w.j av a2 s. c om*/ 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:alfio.manager.WaitingQueueProcessorIntegrationTest.java
private Pair<String, Event> initSoldOutEvent(boolean withUnboundedCategory) throws InterruptedException { int boundedCategorySize = AVAILABLE_SEATS - (withUnboundedCategory ? 1 : 0); List<TicketCategoryModification> categories = new ArrayList<>(); categories.add(new TicketCategoryModification(null, "default", boundedCategorySize, new DateTimeModification(LocalDate.now().minusDays(1), LocalTime.now()), new DateTimeModification(LocalDate.now().plusDays(2), LocalTime.now()), DESCRIPTION, BigDecimal.ZERO, false, "", true, null, null, null, null, null)); if (withUnboundedCategory) { categories.add(new TicketCategoryModification(null, "unbounded", 0, new DateTimeModification(LocalDate.now().minusDays(1), LocalTime.now()), new DateTimeModification(LocalDate.now().plusDays(2), LocalTime.now()), DESCRIPTION, BigDecimal.ZERO, false, "", false, null, null, null, null, null)); }// w w w . ja v a 2 s.co m Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository); Event event = pair.getKey(); List<TicketCategory> ticketCategories = eventManager.loadTicketCategories(event); TicketCategory bounded = ticketCategories.stream().filter(t -> t.getName().equals("default")).findFirst() .orElseThrow(IllegalStateException::new); List<Integer> boundedReserved = ticketRepository.selectFreeTicketsForPreReservation(event.getId(), 20, bounded.getId()); assertEquals(boundedCategorySize, boundedReserved.size()); List<Integer> reserved = new ArrayList<>(boundedReserved); String reservationId = UUID.randomUUID().toString(); ticketReservationRepository.createNewReservation(reservationId, DateUtils.addHours(new Date(), 1), null, Locale.ITALIAN.getLanguage(), event.getId(), event.getVat(), event.isVatIncluded()); List<Integer> reservedForUpdate = withUnboundedCategory ? reserved.subList(0, 19) : reserved; ticketRepository.reserveTickets(reservationId, reservedForUpdate, bounded.getId(), Locale.ITALIAN.getLanguage(), 0); if (withUnboundedCategory) { TicketCategory unbounded = ticketCategories.stream().filter(t -> t.getName().equals("unbounded")) .findFirst().orElseThrow(IllegalStateException::new); List<Integer> unboundedReserved = ticketRepository .selectNotAllocatedFreeTicketsForPreReservation(event.getId(), 20); assertEquals(1, unboundedReserved.size()); reserved.addAll(unboundedReserved); ticketRepository.reserveTickets(reservationId, reserved.subList(19, 20), unbounded.getId(), Locale.ITALIAN.getLanguage(), 0); } ticketRepository.updateTicketsStatusWithReservationId(reservationId, Ticket.TicketStatus.ACQUIRED.name()); //sold-out waitingQueueManager.subscribe(event, new CustomerName("Giuseppe Garibaldi", "Giuseppe", "Garibaldi", event), "peppino@garibaldi.com", null, Locale.ENGLISH); Thread.sleep(100L);//we are testing ordering, not concurrency... waitingQueueManager.subscribe(event, new CustomerName("Nino Bixio", "Nino", "Bixio", event), "bixio@mille.org", null, Locale.ITALIAN); List<WaitingQueueSubscription> subscriptions = waitingQueueRepository.loadAll(event.getId()); assertTrue(waitingQueueRepository.countWaitingPeople(event.getId()) == 2); assertTrue(subscriptions.stream() .allMatch(w -> w.getSubscriptionType().equals(WaitingQueueSubscription.Type.SOLD_OUT))); //the following call shouldn't have any effect waitingQueueSubscriptionProcessor.distributeAvailableSeats(event); assertTrue(waitingQueueRepository.countWaitingPeople(event.getId()) == 2); return Pair.of(reservationId, event); }
From source file:ee.ria.xroad.proxy.ProxyMain.java
private static Map<String, DiagnosticsStatus> checkConnectionToTimestampUrl() { Map<String, DiagnosticsStatus> statuses = new HashMap<>(); for (String tspUrl : ServerConf.getTspUrl()) { try {/*from w w w .j a v a 2 s . c o m*/ URL url = new URL(tspUrl); log.info("Checking timestamp server status for url {}", url); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setConnectTimeout(DIAGNOSTICS_CONNECTION_TIMEOUT_MS); con.setReadTimeout(DIAGNOSTICS_READ_TIMEOUT_MS); con.setDoOutput(true); con.setDoInput(true); con.setRequestMethod("POST"); con.setRequestProperty("Content-type", "application/timestamp-query"); con.connect(); log.info("Checking timestamp server con {}", con); if (con.getResponseCode() != HttpURLConnection.HTTP_OK) { log.warn("Timestamp check received HTTP error: {} - {}. Might still be ok", con.getResponseCode(), con.getResponseMessage()); statuses.put(tspUrl, new DiagnosticsStatus(DiagnosticsErrorCodes.RETURN_SUCCESS, LocalTime.now(), tspUrl)); } else { statuses.put(tspUrl, new DiagnosticsStatus(DiagnosticsErrorCodes.RETURN_SUCCESS, LocalTime.now(), tspUrl)); } } catch (Exception e) { log.warn("Timestamp status check failed {}", e); statuses.put(tspUrl, new DiagnosticsStatus(DiagnosticsUtils.getErrorCode(e), LocalTime.now(), tspUrl)); } } return statuses; }
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 ww w . j a v a 2 s.c om*/ 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()); } }