List of usage examples for java.time ZoneId of
public static ZoneId of(String zoneId)
From source file:org.ops4j.pax.web.itest.tomcat.WarJsfResourcehandlerIntegrationTest.java
/** * Does multiple assertions in one test since container-startup is slow * <p>// w ww. j a v a 2 s .co m * <pre> * <ul> * <li>Check if pax-web-resources-jsf is started</li> * <li>Check if application under test (jsf-application-myfaces) is started * <li>Test actual resource-handler * <ul> * <li>Test for occurence of 'Hello JSF' (jsf-application-myfaces)</li> * <li>Test for occurence of 'Standard Header' (jsf-resourcebundle)</li> * <li>Test for occurence of 'iceland.jpg' from library 'default' in version '2_0' (jsf-resourcebundle)</li> * <li>Test for occurence of 'Customized Footer' (jsf-resourcebundle)</li> * <li>Access a resource (image) via HTTP which gets loaded from a other bundle (jsf-resourcebundle)</li> * </ul> * </li> * <li>Test localized resource * <ul> * <li>Test for occurence of 'flag.png' from library 'layout' with default locale 'en' which resolves to 'iceland' (default in faces-config)</li> * <li>Test for occurence of 'flag.png' from library 'layout' with default locale 'de' which resolves to 'germany'</li> * </ul> * </li> * <li>Test resource-overide * <ul> * <li>Install another bundle (jsf-resourcebundle-override) which also serves template/footer.xhtml</li> * <li>Test for occurence of 'Overriden Footer' (jsf-resourcebundle-override)</li> * <li>Test for occurence of 'iceland.jpg' from library 'default' in version '3_0' (jsf-resourcebundle-override)</li> * <li>Uninstall the previously installed bundle</li> * <li>Test again, this time for occurence of 'Customized Footer' (jsf-resourcebundle)</li> * </ul> * </li> * <li> * Test {@link OsgiResource#userAgentNeedsUpdate(FacesContext)} * with an If-Modified-Since header * </li> * <li>Test servletmapping with prefix (faces/*) rather than extension for both, page and image serving</li> * </ul> * </pre> */ @Test public void testJsfResourceHandler() throws Exception { final String pageUrl = "http://127.0.0.1:8282/osgi-resourcehandler-myfaces/index.xhtml"; final String imageUrl = "http://127.0.0.1:8282/osgi-resourcehandler-myfaces/javax.faces.resource/images/iceland.jpg.xhtml?type=osgi&ln=default&lv=2_0"; // prepare Bundle initWebListener(); installAndStartBundle(mavenBundle().groupId("org.ops4j.pax.web.samples") .artifactId("jsf-resourcehandler-myfaces").versionAsInProject().getURL()); waitForWebListener(); new WaitCondition2("pax-web-resources-extender done scanning for webresources-bundles", () -> { try { HttpTestClientFactory.createDefaultTestClient().doGETandExecuteTest(imageUrl); return true; } catch (AssertionError | Exception e) { return false; } }).waitForCondition(20000, 1000, () -> fail("Image not served in time. pax-web-resources-extender not finished")); // start testing BundleMatchers.isBundleActive("org.ops4j.pax.web.pax-web-resources-extender", bundleContext); BundleMatchers.isBundleActive("org.ops4j.pax.web.pax-web-resources-jsf", bundleContext); BundleMatchers.isBundleActive("jsf-resourcehandler-resourcebundle", bundleContext); BundleMatchers.isBundleActive("jsf-resourcehandler-myfaces", bundleContext); HttpTestClientFactory.createDefaultTestClient().withResponseAssertion( "Some Content shall be included from the jsf-application-bundle to test internal view-resources", resp -> StringUtils.contains(resp, "Hello Included Content")) .withResponseAssertion( "Standard header shall be loaded from resourcebundle to test external view-resources", resp -> StringUtils.contains(resp, "Standard Header")) .withResponseAssertion("Images shall be loaded from resourcebundle to test external resources", resp -> StringUtils.contains(resp, "iceland.jpg")) .withResponseAssertion( "Customized footer shall be loaded from resourcebundle to test external view-resources", resp -> StringUtils.contains(resp, "Customized Footer")) .withResponseAssertion("Image-URL must be created from OsgiResource", resp -> StringUtils.contains( resp, "/osgi-resourcehandler-myfaces/javax.faces.resource/images/iceland.jpg.xhtml?type=osgi&ln=default&lv=2_0")) .withResponseAssertion("Flag-URL must be served from iceland-folder", resp -> StringUtils.contains( resp, "/osgi-resourcehandler-myfaces/javax.faces.resource/flag.png.xhtml?type=osgi&loc=iceland&ln=layout")) .doGETandExecuteTest(pageUrl); // Test German image HttpTestClientFactory.createDefaultTestClient() // set header for german-locale in JSF .addRequestHeader("Accept-Language", "de").withReturnCode(200) .withResponseAssertion("Flag-URL must be served from germany-folder", resp -> StringUtils.contains( resp, "/osgi-resourcehandler-myfaces/javax.faces.resource/flag.png.xhtml?type=osgi&loc=germany&ln=layout")) .doGETandExecuteTest(pageUrl); // test resource serving for image HttpTestClientFactory.createDefaultTestClient().doGETandExecuteTest(imageUrl); // Install override bundle String bundlePath = mavenBundle().groupId("org.ops4j.pax.web.samples") .artifactId("jsf-resourcehandler-resourcebundle-override").versionAsInProject().getURL(); Bundle installedResourceBundle = installAndStartBundle(bundlePath); BundleMatchers.isBundleActive(installedResourceBundle.getSymbolicName(), bundleContext); HttpTestClientFactory.createDefaultTestClient().withResponseAssertion( "Overriden footer shall be loaded from resourcebundle-override to test external view-resources which are overriden", resp -> StringUtils.contains(resp, "Overriden Footer")) .withResponseAssertion("Iceland-Picture shall be found in version 3.0 from resourcebunde-override", resp -> StringUtils.contains(resp, "javax.faces.resource/images/iceland.jpg.xhtml?type=osgi&ln=default&lv=2_0&rv=3_0.jpg")) .doGETandExecuteTest(pageUrl); // uninstall overriding bundle installedResourceBundle.stop(); new WaitCondition2("Customized footer shall be loaded from resourcebundle", () -> { try { HttpTestClientFactory.createDefaultTestClient() .withResponseAssertion("Customized footer shall be loaded from resourcebundle", resp -> StringUtils.contains(resp, "Customized Footer")) .doGETandExecuteTest(pageUrl); return true; } catch (AssertionError | Exception e) { return false; } }).waitForCondition(5000, 1000, () -> fail("After uninstalling 'jsf-resourcehandler-resourcebundle-override' " + "the customized foot must be loaded again.")); // Test If-Modified-Since ZonedDateTime now = ZonedDateTime.of(LocalDateTime.now(), ZoneId.of(ZoneId.SHORT_IDS.get("ECT"))); // "Modified-Since should mark response with 304" HttpTestClientFactory.createDefaultTestClient().withReturnCode(304) .addRequestHeader("If-Modified-Since", now.format(DateTimeFormatter.RFC_1123_DATE_TIME)) .doGETandExecuteTest(imageUrl); // Test second faces-mapping which uses a prefix (faces/*) final String pageUrlWithPrefixMapping = "http://127.0.0.1:8282/osgi-resourcehandler-myfaces/faces/index.xhtml"; final String imageUrlWithPrefixMapping = "http://127.0.0.1:8282/osgi-resourcehandler-myfaces/faces/javax.faces.resource/images/iceland.jpg?type=osgi&ln=default&lv=2_0"; HttpTestClientFactory.createDefaultTestClient().doGETandExecuteTest(imageUrlWithPrefixMapping); HttpTestClientFactory.createDefaultTestClient().withResponseAssertion( "Image-URL must be created from OsgiResource. This time the second servlet-mapping (faces/*) must be used.", resp -> StringUtils.contains(resp, "/osgi-resourcehandler-myfaces/faces/javax.faces.resource/images/iceland.jpg?type=osgi&ln=default&lv=2_0")) .doGETandExecuteTest(pageUrlWithPrefixMapping); }
From source file:org.apache.james.mailbox.elasticsearch.json.MailboxMessageToElasticSearchJsonTest.java
@Test(expected = NullPointerException.class) public void getUpdatedJsonMessagePartShouldThrowIfFlagsIsNull() throws Exception { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris")); messageToElasticSearchJson.getUpdatedJsonMessagePart(null, MOD_SEQ); }
From source file:alfio.manager.EventManager.java
private Integer findAdditionalService(Event event, EventModification.AdditionalService as) { ZoneId utc = ZoneId.of("UTC"); int eventId = event.getId(); String checksum = new AdditionalService(0, eventId, as.isFixPrice(), as.getOrdinal(), as.getAvailableQuantity(), as.getMaxQtyPerOrder(), as.getInception().toZonedDateTime(event.getZoneId()).withZoneSameInstant(utc), as.getExpiration().toZonedDateTime(event.getZoneId()).withZoneSameInstant(utc), as.getVat(), as.getVatType(), Optional.ofNullable(as.getPrice()).map(MonetaryUtil::unitToCents).orElse(0), as.getType(), as.getSupplementPolicy()).getChecksum(); return additionalServiceRepository.loadAllForEvent(eventId).stream() .filter(as1 -> as1.getChecksum().equals(checksum)).findFirst().map(AdditionalService::getId) .orElse(null);//from w w w .j a va 2 s .c o m }
From source file:org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJsonTest.java
@Test public void emailWithAttachmentsShouldNotConvertAttachmentsWhenIndexAttachmentsIsFalse() throws IOException { // Given/*from ww w . j a va 2 s . c o m*/ MailboxMessage mailWithNoInternalDate = new SimpleMailboxMessage(MESSAGE_ID, null, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/recursiveMail.eml"))), new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("debian", "security").build(), propertyBuilder, MAILBOX_ID); mailWithNoInternalDate.setModSeq(MOD_SEQ); mailWithNoInternalDate.setUid(UID); // When MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.NO); String convertToJson = messageToElasticSearchJson.convertToJson(mailWithNoInternalDate, ImmutableList.of(new MockMailboxSession("username").getUser())); // Then assertThatJson(convertToJson).when(IGNORING_ARRAY_ORDER).when(IGNORING_VALUES).isEqualTo( IOUtils.toString(ClassLoader.getSystemResource("eml/recursiveMailWithoutAttachments.json"))); }
From source file:org.onosproject.drivers.ciena.waveserver.rest.CienaRestDevice.java
private long parseAlarmTime(String time) { /*//from w ww . ja va2 s.c o m * expecting WaveServer time to be set to UTC. */ try { DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_TIME_FORMAT); LocalDateTime localDateTime = LocalDateTime.parse(time, formatter); return localDateTime.atZone(ZoneId.of(UTC)).toInstant().toEpochMilli(); } catch (DateTimeParseException e2) { log.error("unable to parse time {}, using system time", time); return System.currentTimeMillis(); } }
From source file:org.silverpeas.core.calendar.notification.CalendarContributionReminderUserNotificationTest.java
@Test public void durationReminderWithAnotherBeforeCalendarZoneIdOnSeveralDaysEventOnAllDayShouldWork() throws Exception { final CalendarEvent calendarEvent = setupSeveralDaysEventOnAllDay(); when(calendarEvent.getCalendar().getZoneId()).thenReturn(ZoneId.of("America/Cancun")); final DurationReminder durationReminder = initReminderBuilder(calendarEvent).triggerBefore(0, TimeUnit.MINUTE, ""); triggerDateTime(durationReminder);/*from w w w . ja va 2 s. co m*/ final Map<String, String> titles = computeNotificationTitles(durationReminder); assertThat(titles.get(DE), is("Reminder about the event super test - 21.02.2018 - 22.02.2018 (America/Cancun)")); assertThat(titles.get(EN), is("Reminder about the event super test - 02/21/2018 - 02/22/2018 (America/Cancun)")); assertThat(titles.get(FR), is("Rappel sur l'vnement super test - 21/02/2018 - 22/02/2018 (America/Cancun)")); final Map<String, String> contents = computeNotificationContents(durationReminder); assertThat(contents.get(DE), is( "REMINDER: The event <b>super test</b> will be from 21.02.2018 to 22.02.2018 (America/Cancun).")); assertThat(contents.get(EN), is( "REMINDER: The event <b>super test</b> will be from 02/21/2018 to 02/22/2018 (America/Cancun).")); assertThat(contents.get(FR), is( "RAPPEL : L'vnement <b>super test</b> aura lieu du 21/02/2018 au 22/02/2018 (America/Cancun).")); }
From source file:org.apache.james.mailbox.elasticsearch.json.MailboxMessageToElasticSearchJsonTest.java
@Test public void spamEmailShouldBeWellConvertedToJsonWithApacheTika() throws IOException { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new TikaTextExtractor(), ZoneId.of("Europe/Paris")); MailboxMessage spamMail = new SimpleMailboxMessage(date, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/nonTextual.eml"))), new Flags(), propertyBuilder, MAILBOX_ID); spamMail.setModSeq(MOD_SEQ);// w w w . j a v a2s . c om assertThatJson(messageToElasticSearchJson.convertToJson(spamMail, ImmutableList.of(new MockMailboxSession("username").getUser()))).when(IGNORING_ARRAY_ORDER) .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/nonTextual.json"), CHARSET)); }
From source file:org.jboss.as.test.integration.logging.formatters.XmlFormatterTestCase.java
@Test public void testDateFormat() throws Exception { configure(Collections.emptyMap(), Collections.emptyMap(), false); final String dateFormat = "yyyy-MM-dd'T'HH:mm:ssSSSZ"; final String timezone = "GMT"; // Change the date format and time zone final CompositeOperationBuilder builder = CompositeOperationBuilder.create(); builder.addStep(Operations.createWriteAttributeOperation(FORMATTER_ADDRESS, "date-format", dateFormat)); builder.addStep(Operations.createWriteAttributeOperation(FORMATTER_ADDRESS, "zone-id", timezone)); executeOperation(builder.build());/*from w ww .j ava 2 s . c o m*/ final String msg = "Logging test: XmlFormatterTestCase.testNoExceptions"; int statusCode = getResponse(msg, Collections.singletonMap(LoggingServiceActivator.LOG_EXCEPTION_KEY, "false")); Assert.assertEquals("Invalid response statusCode: " + statusCode, statusCode, HttpStatus.SC_OK); final List<String> expectedKeys = createDefaultKeys(); final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); final DocumentBuilder documentBuilder = factory.newDocumentBuilder(); for (String s : Files.readAllLines(logFile, StandardCharsets.UTF_8)) { if (s.trim().isEmpty()) continue; final Document doc = documentBuilder.parse(new InputSource(new StringReader(s))); validateDefault(doc, expectedKeys, msg); validateStackTrace(doc, false, false); // Validate the date format is correct. We don't want to validate the specific date, only that it's // parsable. final NodeList timestampNode = doc.getElementsByTagName("timestamp"); Assert.assertEquals(1, timestampNode.getLength()); final String xmlDate = timestampNode.item(0).getTextContent(); // If the date is not parsable an exception should be thrown try { DateTimeFormatter.ofPattern(dateFormat, Locale.ROOT).withZone(ZoneId.of(timezone)).parse(xmlDate); } catch (Exception e) { Assert.fail(String.format("Failed to parse %s with pattern %s and zone %s: %s", xmlDate, dateFormat, timezone, e.getMessage())); } } }
From source file:org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJsonTest.java
@Test(expected = NullPointerException.class) public void emailWithNoMailboxIdShouldThrow() throws IOException { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.YES); MailboxMessage mailWithNoMailboxId;//from w ww . j a va2 s . c o m try { mailWithNoMailboxId = new SimpleMailboxMessage(MESSAGE_ID, date, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/recursiveMail.eml"))), new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("debian", "security").build(), propertyBuilder, null); mailWithNoMailboxId.setModSeq(MOD_SEQ); mailWithNoMailboxId.setUid(UID); } catch (Exception exception) { throw Throwables.propagate(exception); } messageToElasticSearchJson.convertToJson(mailWithNoMailboxId, ImmutableList.of(new MockMailboxSession("username").getUser())); }
From source file:alfio.manager.EventManager.java
public void updateEventHeader(Event original, EventModification em, String username) { checkOwnership(original, username, em.getOrganizationId()); int eventId = original.getId(); final ZoneId zoneId = ZoneId.of(em.getZoneId()); final ZonedDateTime begin = em.getBegin().toZonedDateTime(zoneId); final ZonedDateTime end = em.getEnd().toZonedDateTime(zoneId); eventRepository.updateHeader(eventId, em.getDisplayName(), em.getWebsiteUrl(), em.getExternalUrl(), em.getTermsAndConditionsUrl(), em.getImageUrl(), em.getFileBlobId(), em.getLocation(), em.getLatitude(), em.getLongitude(), begin, end, em.getZoneId(), em.getOrganizationId(), em.getLocales());//from ww w. j a v a 2 s . c om createOrUpdateEventDescription(eventId, em); if (!original.getBegin().equals(begin) || !original.getEnd().equals(end)) { fixOutOfRangeCategories(em, username, zoneId, end); } }