Example usage for java.time LocalDateTime now

List of usage examples for java.time LocalDateTime now

Introduction

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

Prototype

public static LocalDateTime now() 

Source Link

Document

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

Usage

From source file:alfio.manager.WaitingQueueManagerIntegrationTest.java

@Test
public void testAssignTicketToWaitingQueueUnboundedCategory() {
    LocalDateTime start = LocalDateTime.now().minusMinutes(1);
    LocalDateTime end = LocalDateTime.now().plusMinutes(20);
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null,
            "default", AVAILABLE_SEATS, new DateTimeModification(start.toLocalDate(), start.toLocalTime()),
            new DateTimeModification(end.toLocalDate(), end.toLocalTime()), DESCRIPTION, BigDecimal.TEN, false,
            "", false, null, null, null, null, null));

    configurationManager.saveSystemConfiguration(ConfigurationKeys.ENABLE_WAITING_QUEUE, "true");

    Event event = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository)
            .getKey();/*w ww .ja v  a2  s. c  om*/

    TicketCategory unbounded = ticketCategoryRepository.findByEventId(event.getId()).get(0);

    TicketReservationModification tr = new TicketReservationModification();
    tr.setAmount(AVAILABLE_SEATS - 1);
    tr.setTicketCategoryId(unbounded.getId());

    TicketReservationModification tr2 = new TicketReservationModification();
    tr2.setAmount(1);
    tr2.setTicketCategoryId(unbounded.getId());

    TicketReservationWithOptionalCodeModification multi = new TicketReservationWithOptionalCodeModification(tr,
            Optional.empty());
    TicketReservationWithOptionalCodeModification single = new TicketReservationWithOptionalCodeModification(
            tr2, Optional.empty());

    String reservationId = ticketReservationManager.createTicketReservation(event,
            Collections.singletonList(multi), 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());

    String reservationIdSingle = ticketReservationManager.createTicketReservation(event,
            Collections.singletonList(single), Collections.emptyList(), DateUtils.addDays(new Date(), 1),
            Optional.empty(), Optional.empty(), Locale.ENGLISH, false);
    TotalPrice reservationCostSingle = ticketReservationManager
            .totalReservationCostWithVAT(reservationIdSingle);
    PaymentResult resultSingle = ticketReservationManager.confirm("", null, event, reservationIdSingle,
            "test@test.ch", new CustomerName("Full Name", "Full", "Name", event), Locale.ENGLISH, "",
            reservationCostSingle, Optional.empty(), Optional.of(PaymentProxy.OFFLINE), false, null, null,
            null);
    assertTrue(resultSingle.isSuccessful());

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

    assertTrue(
            waitingQueueManager.subscribe(event, customerJohnDoe(event), "john@doe.com", null, Locale.ENGLISH));

    ticketReservationManager.deleteOfflinePayment(event, reservationIdSingle, false);

    List<Triple<WaitingQueueSubscription, TicketReservationWithOptionalCodeModification, ZonedDateTime>> subscriptions = waitingQueueManager
            .distributeSeats(event).collect(Collectors.toList());
    assertEquals(1, subscriptions.size());
    Triple<WaitingQueueSubscription, TicketReservationWithOptionalCodeModification, ZonedDateTime> subscriptionDetail = subscriptions
            .get(0);
    assertEquals("john@doe.com", subscriptionDetail.getLeft().getEmailAddress());
    TicketReservationWithOptionalCodeModification reservation = subscriptionDetail.getMiddle();
    assertEquals(Integer.valueOf(unbounded.getId()), reservation.getTicketCategoryId());
    assertEquals(Integer.valueOf(1), reservation.getAmount());
    assertTrue(subscriptionDetail.getRight().isAfter(ZonedDateTime.now()));
}

From source file:de.steilerdev.myVerein.server.model.Event.java

/**
 * This function updates the list of invited user of this event
 * @param divisionRepository An active division repository used to expand the division set
 */// w  w w .  jav a  2  s.co  m
public void updateInvitedUser(DivisionRepository divisionRepository) {
    if (invitedDivision == null || (invitedDivision = Division.getExpandedSetOfDivisions(invitedDivision,
            divisionRepository)) == null) {
        logger.error("Unable to update invited user, because invited divisions are null!");
    } else {
        logger.info("Updating invited user for event " + this);
        Set<String> oldInvitedUser = invitedUser == null ? new HashSet<>() : invitedUser.keySet();
        HashSet<String> newInvitedUser = new HashSet<>();
        invitedDivision.stream().forEach(div -> newInvitedUser.addAll(div.getMemberList()));

        if (oldInvitedUser.isEmpty() || newInvitedUser.isEmpty()) {
            logger.debug("Old set of invited user or new set of invited user is empty");
            invitedUser = new HashMap<>();
            if (oldInvitedUser.isEmpty() && !newInvitedUser.isEmpty()) {
                logger.debug("Old set of invited user is empty and new set of invited user is not empty");
                newInvitedUser.stream().forEach(userID -> invitedUser.put(userID, EventStatus.PENDING));
            } else if (newInvitedUser.isEmpty() && !oldInvitedUser.isEmpty()) {
                logger.debug("New set of invited user is empty and old set of invited user is not empty");
                oldInvitedUser.stream().forEach(userID -> invitedUser.put(userID, EventStatus.REMOVED));
                lastChanged = LocalDateTime.now();
            }
        } else {
            logger.debug("Old and new set of invited user is not empty");
            oldInvitedUser.removeAll(newInvitedUser);
            oldInvitedUser.stream().forEach(userID -> invitedUser.put(userID, EventStatus.REMOVED));
            newInvitedUser.stream().forEach(userID -> invitedUser.putIfAbsent(userID, EventStatus.PENDING));
            lastChanged = LocalDateTime.now();
        }
    }
}

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  w  w . 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&amp;ln=default&amp;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&amp;loc=iceland&amp;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&amp;loc=germany&amp;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&amp;ln=default&amp;lv=2_0&amp;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&amp;ln=default&amp;lv=2_0"))
            .doGETandExecuteTest(pageUrlWithPrefixMapping);
}

From source file:org.opencb.opencga.app.cli.CommandExecutor.java

protected void logoutSessionFile() throws IOException {
    Path sessionPath = Paths.get(System.getProperty("user.home"), ".opencga", SESSION_FILENAME);
    if (Files.exists(sessionPath)) {
        ObjectMapper objectMapper = new ObjectMapper();
        SessionFile sessionFile = objectMapper.readValue(sessionPath.toFile(), SessionFile.class);
        sessionFile.setLogout(LocalDateTime.now().toString());
        objectMapper.writerWithDefaultPrettyPrinter().writeValue(sessionPath.toFile(), sessionFile);
    }/*from   www.j av a 2  s . co m*/
}

From source file:org.ops4j.pax.web.itest.jetty.WarJsfResourcehandlerIntegrationTest.java

/**
 * Does multiple assertions in one test since container-startup is slow
 * <p>/*  w  w  w  . ja 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&amp;ln=default&amp;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&amp;loc=iceland&amp;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&amp;loc=germany&amp;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&amp;ln=default&amp;lv=2_0&amp;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&amp;ln=default&amp;lv=2_0"))
            .doGETandExecuteTest(pageUrlWithPrefixMapping);
}

From source file:fr.landel.utils.assertor.OperatorTest.java

/**
 * Test method for {@link Operator#or()}.
 *//*from w w w .ja  va  2s.  c  om*/
@Test
public void testOr() {
    final String text = "text";
    assertTrue(Assertor.that(text).isEmpty().or().isNotBlank().isOK());

    assertTrue(Assertor.that(text).isEmpty().or(true).isTrue().isOK());
    assertFalse(Assertor.that(text).isEmpty().or(true).isFalse().isOK());

    assertTrue(Assertor.that(text).isEmpty().or(text.getClass()).isAssignableFrom(CharSequence.class).isOK());
    assertFalse(Assertor.that(text).isEmpty().or(text.getClass()).isAssignableFrom(StringBuilder.class).isOK());

    assertTrue(Assertor.that(text).isEmpty().or(Calendar.getInstance())
            .isAfter(DateUtils.getCalendar(new Date(0))).isOK());
    assertFalse(Assertor.that(text).isEmpty().or(Calendar.getInstance())
            .isBefore(DateUtils.getCalendar(new Date(0))).isOK());

    assertTrue(Assertor.that(text).isEmpty().or(new Date()).isAfter(new Date(0)).isOK());
    assertFalse(Assertor.that(text).isEmpty().or(new Date()).isBefore(new Date(0)).isOK());

    assertTrue(Assertor.that(text).isEmpty().or(LocalDateTime.now()).isAfter(LocalDateTime.MIN).isOK());
    assertFalse(Assertor.that(text).isEmpty().or(LocalDateTime.now()).isAfter(LocalDateTime.MAX).isOK());

    assertTrue(Assertor.that(text).isEmpty().or(2).isGT(1).isOK());
    assertFalse(Assertor.that(text).isEmpty().or(2).isLT(1).isOK());

    assertTrue(Assertor.that(text).isEmpty().or("tt").isNotEmpty().isOK());
    assertFalse(Assertor.that(text).isEmpty().or("tt").isEmpty().isOK());

    assertTrue(Assertor.that(text).isEmpty().or(new String[] {}).isEmpty().isOK());
    assertFalse(Assertor.that(text).isEmpty().or(new String[] {}).isNotEmpty().isOK());
    assertTrue(Assertor.that(text).isEmpty().or(new String[] {}, EnumAnalysisMode.STREAM).isEmpty().isOK());
    assertFalse(Assertor.that(text).isEmpty().or(new String[] {}, EnumAnalysisMode.STREAM).isNotEmpty().isOK());
    assertTrue(Assertor.that(text).isEmpty().or(new String[] {}, EnumAnalysisMode.PARALLEL).isEmpty().isOK());
    assertFalse(
            Assertor.that(text).isEmpty().or(new String[] {}, EnumAnalysisMode.PARALLEL).isNotEmpty().isOK());

    assertTrue(Assertor.that(text).isEmpty().or(Collections.emptyList()).isEmpty().isOK());
    assertFalse(Assertor.that(text).isEmpty().or(Collections.emptyList()).isNotEmpty().isOK());
    assertTrue(Assertor.that(text).isEmpty().or(Collections.emptyList(), EnumAnalysisMode.STREAM).isEmpty()
            .isOK());
    assertFalse(Assertor.that(text).isEmpty().or(Collections.emptyList(), EnumAnalysisMode.STREAM).isNotEmpty()
            .isOK());
    assertTrue(Assertor.that(text).isEmpty().or(Collections.emptyList(), EnumAnalysisMode.PARALLEL).isEmpty()
            .isOK());
    assertFalse(Assertor.that(text).isEmpty().or(Collections.emptyList(), EnumAnalysisMode.PARALLEL)
            .isNotEmpty().isOK());

    assertTrue(Assertor.that(text).isEmpty().or(Collections.emptyMap()).isEmpty().isOK());
    assertFalse(Assertor.that(text).isEmpty().or(Collections.emptyMap()).isNotEmpty().isOK());
    assertTrue(
            Assertor.that(text).isEmpty().or(Collections.emptyMap(), EnumAnalysisMode.STREAM).isEmpty().isOK());
    assertFalse(Assertor.that(text).isEmpty().or(Collections.emptyMap(), EnumAnalysisMode.STREAM).isNotEmpty()
            .isOK());
    assertTrue(Assertor.that(text).isEmpty().or(Collections.emptyMap(), EnumAnalysisMode.PARALLEL).isEmpty()
            .isOK());
    assertFalse(Assertor.that(text).isEmpty().or(Collections.emptyMap(), EnumAnalysisMode.PARALLEL).isNotEmpty()
            .isOK());

    assertTrue(Assertor.that(text).isEmpty().or((Object) 0).isNotNull().isOK());
    assertFalse(Assertor.that(text).isEmpty().or((Object) 0).isNull().isOK());

    assertTrue(Assertor.that(text).isEmpty().or(new Exception()).isNotNull().isOK());
    assertFalse(Assertor.that(text).isEmpty().or(new Exception()).isNull().isOK());

    assertTrue(Assertor.that(Color.BLACK).isNull().or().isEqual(Color.black).isOK());
    assertTrue(Assertor.that(Color.BLACK).isNull().or((Object) 0).isNotNull().isOK());

    assertTrue(Assertor.that(Color.BLACK).isNotNull().or(Assertor.that(text).isEmpty()).isOK());

    assertTrue(
            Assertor.that(true).isFalse().or(Assertor.that("text").startsWith("t").and().contains("e")).isOK());

    // SUB ASSERTOR

    assertTrue(Assertor.that(text).isNotEmpty().orAssertor(t -> Assertor.that(t.length()).isGT(4)).isOK());
    assertEquals(
            "the char sequence 'text' should be null or empty OR (the number '4' should be greater than '4')",
            Assertor.that(text).isEmpty().orAssertor(t -> Assertor.that(t.length()).isGT(4)).getErrors().get());

    assertException(() -> Assertor.that(text).isNotEmpty()
            .orAssertor((Function<String, StepCharSequence<String>>) null).isOK(), IllegalStateException.class,
            "sub assertor cannot be null");

    // MAPPER

    assertTrue(Assertor.that(true).isTrue().orObject(b -> b.toString()).hasHashCode(Objects.hashCode("true"))
            .isOK());
    assertTrue(Assertor.that(true).isTrue().orCharSequence(b -> b.toString()).contains("ue").isOK());
    assertTrue(Assertor.that("test").isNotEmpty()
            .orArray(s -> ArrayUtils.toObject(s.getBytes(StandardCharsets.UTF_8))).contains((byte) 'e').isOK());
    assertTrue(Assertor.that(true).isTrue().orBoolean(b -> !b).isFalse().isOK());
    assertTrue(Assertor.that(true).isTrue().orClass(b -> b.getClass()).hasSimpleName("Boolean").isOK());
    assertTrue(Assertor.that(true).isTrue().orDate(b -> new Date(1464475553641L))
            .isAfter(new Date(1464475553640L)).isOK());
    assertTrue(Assertor.that(true).isTrue().orCalendar(b -> DateUtils.getCalendar(new Date(1464475553641L)))
            .isBefore(Calendar.getInstance()).isOK());
    assertTrue(
            Assertor.that(true).isTrue().orTemporal(b -> DateUtils.getLocalDateTime(new Date(1464475553641L)))
                    .isBefore(LocalDateTime.now()).isOK());
    assertTrue(Assertor.that(true).isTrue().orEnum(b -> EnumOperator.AND).hasName("AND").isOK());
    assertTrue(Assertor.that(true).isTrue().orIterable(b -> Arrays.asList('t', 'r')).contains('t').isOK());
    assertTrue(Assertor.that(true).isTrue().orMap(b -> MapUtils2.newHashMap("key", b)).contains("key", true)
            .isOK());
    assertTrue(Assertor.that(true).isTrue().orNumber(b -> b.hashCode()).isGT(0).isOK()); // 1231
    assertTrue(Assertor.that(true).isTrue().orThrowable(b -> new IOException(b.toString()))
            .validates(e -> e.getMessage().contains("true")).isOK());
}

From source file:org.ops4j.pax.web.itest.tomcat.WarJsfResourcehandlerIntegrationTest.java

/**
 * Does multiple assertions in one test since container-startup is slow
 * <p>//from  w w w  .  j  a  va  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: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&amp;ln=default&amp;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&amp;loc=iceland&amp;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&amp;loc=germany&amp;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&amp;ln=default&amp;lv=2_0&amp;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&amp;ln=default&amp;lv=2_0"))
            .doGETandExecuteTest(pageUrlWithPrefixMapping);
}

From source file:com.doctor.esper.reference_5_2_0.Chapter6EPLReferenceNamedWindowsAndTables.java

/**
 * 6.9. Explicitly Indexing Named Windows and Tables
 * //w w w.  ja v a2s . c  o  m
 * ?
 * 
 * @see http://www.espertech.com/esper/release-5.2.0/esper-reference/html_single/index.html#named_explicit_index
 * 
 * @see com.espertech.esper.epl.fafquery.FireAndForgetQueryExec
 * 
 * 
 * 
 *      EPRuntimeImpl.executeQuery(EPOnDemandPreparedQueryParameterized) line: 1541
 *      EPRuntimeImpl.executeQueryInternal(String, EPStatementObjectModel, EPOnDemandPreparedQueryParameterized, ContextPartitionSelector[]) line: 1553
 * 
 *      EPPreparedExecuteMethodQuery.execute(ContextPartitionSelector[]) line: 198
 * 
 *      EPPreparedExecuteMethodQuery.getStreamFilterSnapshot(int, ContextPartitionSelector) line: 258
 *      FireAndForgetProcessorNamedWindow.getProcessorInstance(AgentInstanceContext) line: 45
 *      FireAndForgetInstanceNamedWindow.<init>(NamedWindowProcessorInstance) line: 29
 *      EPPreparedExecuteMethodQuery.getStreamSnapshotInstance(int, List<ExprNode>, FireAndForgetInstance) line: 294
 *      NamedWindowTailViewInstance.snapshot(FilterSpecCompiled, Annotation[]) line: 209
 *      NamedWindowTailViewInstance.snapshotNoLock(FilterSpecCompiled, Annotation[]) line: 270
 *      FireAndForgetQueryExec.snapshot(FilterSpecCompiled, Annotation[], VirtualDWView, EventTableIndexRepository, boolean, Log, String, AgentInstanceContext) line: 53
 *      (index?)
 *      NamedWindowTailViewInstance.snapshotNoLock(FilterSpecCompiled, Annotation[]) line: 279
 *      resultnull??
 * @param eventBean
 * @return
 */

@Test
public void test_Explicitly_Indexing_Named_Window() {
    HttpLog httpLog = new HttpLog(1, UUID.randomUUID().toString(), "www.baidu.com/tieba", "www.baidu.com",
            "userAgent", LocalDateTime.now());
    esperTemplateBean.sendEvent(httpLog);
    httpLog = new HttpLog(2, UUID.randomUUID().toString(), "www.baidu.com/tieba", "www.baidu.com", "userAgent",
            LocalDateTime.now());
    esperTemplateBean.sendEvent(httpLog);
    httpLog = new HttpLog(3, UUID.randomUUID().toString(), "www.baidu.com/tieba_son", "www.baidu.com",
            "userAgent", LocalDateTime.now());
    esperTemplateBean.sendEvent(httpLog);
    httpLog = new HttpLog(4, UUID.randomUUID().toString(), "www.baidu.com/tieba", "www.baidu.com", "userAgent",
            LocalDateTime.now());
    esperTemplateBean.sendEvent(httpLog);
    httpLog = new HttpLog(6, UUID.randomUUID().toString(), "www.baidu.com/tieba", "www.baidu.com", "userAgent",
            LocalDateTime.now());
    esperTemplateBean.sendEvent(httpLog);
    httpLog = new HttpLog(8, UUID.randomUUID().toString(), "www.baidu.com/tieba_son", "www.baidu.com",
            "userAgent", LocalDateTime.now());
    esperTemplateBean.sendEvent(httpLog);

    List<HttpLog> list = httpLogWinLength100Query.prepareQueryWithParameters(
            Chapter6EPLReferenceNamedWindowsAndTables::httpLogMapRow, "www.baidu.com/tieba_son", 2, 10);

    System.out.println(list);
}

From source file:com.google.refine.model.medadata.ProjectMetadata.java

public void updateModified() {
    _modified = LocalDateTime.now();
}