List of usage examples for java.time ZoneId of
public static ZoneId of(String zoneId)
From source file:io.manasobi.utils.DateUtils.java
public static long convertToTimeMillis(LocalDateTime dateTime) { ZonedDateTime zdt = dateTime.atZone(ZoneId.of("Asia/Seoul")); return zdt.toInstant().toEpochMilli(); }
From source file:ox.softeng.burst.service.BurstService.java
private void generateStartupMessage() { Message message = new Message("burst-service", "Burst Service starting\n" + version(), SeverityEnum.INFORMATIONAL, OffsetDateTime.now(ZoneId.of("UTC")), "Burst Service Startup"); message.addTopic("service"); message.addTopic("startup"); message.addTopic("burst"); message.addMetadata("gmc", "gel"); message.addMetadata("burst_service_version", version()); try {/*from w ww .ja v a 2s.com*/ message.save(entityManagerFactory); } catch (HibernateException he) { logger.error("Could not save startup message to database: " + he.getMessage(), he); } catch (Exception e) { logger.error("Unhandled exception trying to process startup message", e); } }
From source file:org.apache.james.mailbox.elasticsearch.json.MailboxMessageToElasticSearchJsonTest.java
@Test public void getUpdatedJsonMessagePartShouldBehaveWellOnEmptyFlags() throws Exception { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris")); assertThatJson(messageToElasticSearchJson.getUpdatedJsonMessagePart(new Flags(), MOD_SEQ)).isEqualTo( "{\"modSeq\":42,\"isAnswered\":false,\"isDeleted\":false,\"isDraft\":false,\"isFlagged\":false,\"isRecent\":false,\"userFlags\":[],\"isUnread\":true}"); }
From source file:org.silverpeas.core.calendar.notification.CalendarContributionReminderUserNotificationTest.java
@Test public void durationReminderWithAnotherUserZoneIdOnSeveralDaysEventOnAllDayShouldWork() throws Exception { receiver.getUserPreferences().setZoneId(ZoneId.of("Asia/Muscat")); final DurationReminder durationReminder = initReminderBuilder(setupSeveralDaysEventOnAllDay()) .triggerBefore(0, TimeUnit.MINUTE, ""); triggerDateTime(durationReminder);//from ww w . j a v a2 s . c om final Map<String, String> titles = computeNotificationTitles(durationReminder); assertThat(titles.get(DE), is("Reminder about the event super test - 21.02.2018 - 22.02.2018 (UTC)")); assertThat(titles.get(EN), is("Reminder about the event super test - 02/21/2018 - 02/22/2018 (UTC)")); assertThat(titles.get(FR), is("Rappel sur l'vnement super test - 21/02/2018 - 22/02/2018 (UTC)")); 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 (UTC).")); assertThat(contents.get(EN), is("REMINDER: The event <b>super test</b> will be from 02/21/2018 to 02/22/2018 (UTC).")); assertThat(contents.get(FR), is("RAPPEL : L'vnement <b>super test</b> aura lieu du 21/02/2018 au 22/02/2018 (UTC).")); }
From source file:org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJsonTest.java
@Test public void emailWithAttachmentsShouldConvertAttachmentsWhenIndexAttachmentsIsTrue() throws IOException { // Given/*ww w . ja v a2 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.YES); 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/recursiveMail.json"))); }
From source file:org.apache.james.mailbox.elasticsearch.json.MailboxMessageToElasticSearchJsonTest.java
@Test public void getUpdatedJsonMessagePartShouldBehaveWellOnNonEmptyFlags() throws Exception { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris")); assertThatJson(messageToElasticSearchJson.getUpdatedJsonMessagePart(new FlagsBuilder() .add(Flags.Flag.DELETED, Flags.Flag.FLAGGED).add("user").build(), MOD_SEQ)).isEqualTo( "{\"modSeq\":42,\"isAnswered\":false,\"isDeleted\":true,\"isDraft\":false,\"isFlagged\":true,\"isRecent\":false,\"userFlags\":[\"user\"],\"isUnread\":true}"); }
From source file:org.jboss.as.test.integration.logging.formatters.JsonFormatterTestCase.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 w w .j a v a 2 s . c o m final String msg = "Logging test: JsonFormatterTestCase.testNoExceptions"; int statusCode = getResponse(msg, Collections.singletonMap(LoggingServiceActivator.LOG_EXCEPTION_KEY, "false")); Assert.assertTrue("Invalid response statusCode: " + statusCode, statusCode == HttpStatus.SC_OK); final List<String> expectedKeys = createDefaultKeys(); for (String s : Files.readAllLines(logFile, StandardCharsets.UTF_8)) { if (s.trim().isEmpty()) continue; try (JsonReader reader = Json.createReader(new StringReader(s))) { final JsonObject json = reader.readObject(); validateDefault(json, expectedKeys, msg); validateStackTrace(json, false, false); // Validate the date format is correct. We don't want to validate the specific date, only that it's // parsable. final String jsonDate = json.getString("timestamp"); // If the date is not parsable an exception should be thrown try { DateTimeFormatter.ofPattern(dateFormat, Locale.ROOT).withZone(ZoneId.of(timezone)) .parse(jsonDate); } catch (Exception e) { Assert.fail(String.format("Failed to parse %s with pattern %s and zone %s: %s", jsonDate, dateFormat, timezone, e.getMessage())); } } } }
From source file:org.ops4j.pax.web.itest.undertow.WarJsfResourcehandlerIntegrationTest.java
/** * Does multiple assertions in one test since container-startup is slow * <p>//from w ww . j a v a 2 s. c o 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:8181/osgi-resourcehandler-myfaces/index.xhtml"; final String imageUrl = "http://127.0.0.1:8181/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:8181/osgi-resourcehandler-myfaces/faces/index.xhtml"; final String imageUrlWithPrefixMapping = "http://127.0.0.1:8181/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.ops4j.pax.web.itest.jetty.WarJsfResourcehandlerIntegrationTest.java
/** * Does multiple assertions in one test since container-startup is slow * <p>/*from ww w . j ava 2s.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:8181/osgi-resourcehandler-myfaces/index.xhtml"; final String imageUrl = "http://127.0.0.1:8181/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:8181/osgi-resourcehandler-myfaces/faces/index.xhtml"; final String imageUrlWithPrefixMapping = "http://127.0.0.1:8181/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); }