Example usage for java.time Instant parse

List of usage examples for java.time Instant parse

Introduction

In this page you can find the example usage for java.time Instant parse.

Prototype

public static Instant parse(final CharSequence text) 

Source Link

Document

Obtains an instance of Instant from a text string such as 2007-12-03T10:15:30.00Z .

Usage

From source file:org.apache.james.transport.mailets.DSNBounceTest.java

@Test
public void serviceShouldSendMultipartMailContainingTextPartWhenCustomMessageIsConfigured() throws Exception {
    FakeMailetConfig mailetConfig = FakeMailetConfig.builder().mailetName(MAILET_NAME)
            .mailetContext(fakeMailContext).setProperty("messageString", "My custom message\n").build();
    dsnBounce.init(mailetConfig);// w  w  w.j  a v  a 2  s.  com

    MailAddress senderMailAddress = new MailAddress("sender@domain.com");
    FakeMail mail = FakeMail.builder().sender(senderMailAddress).attribute("delivery-error", "Delivery error")
            .mimeMessage(MimeMessageBuilder.mimeMessageBuilder().setText("My content")).name(MAILET_NAME)
            .recipient("recipient@domain.com").lastUpdated(Date.from(Instant.parse("2016-09-08T14:25:52.000Z")))
            .build();

    dsnBounce.service(mail);

    String expectedContent = "My custom message\n\n" + "Failed recipient(s):\n" + "recipient@domain.com\n"
            + "\n" + "Error message:\n" + "Delivery error\n" + "\n";

    List<SentMail> sentMails = fakeMailContext.getSentMails();
    assertThat(sentMails).hasSize(1);
    SentMail sentMail = sentMails.get(0);
    MimeMessage sentMessage = sentMail.getMsg();
    MimeMultipart content = (MimeMultipart) sentMessage.getContent();
    BodyPart bodyPart = content.getBodyPart(0);
    assertThat(bodyPart.getContentType()).isEqualTo("text/plain; charset=us-ascii");
    assertThat(bodyPart.getContent()).isEqualTo(expectedContent);
}

From source file:com.linecorp.bot.model.event.CallbackRequestTest.java

@Test
public void testJoin() throws IOException {
    parse("callback/join.json", callbackRequest -> {
        assertThat(callbackRequest.getEvents()).hasSize(1);
        Event event = callbackRequest.getEvents().get(0);
        assertThat(event).isInstanceOf(JoinEvent.class);
        assertThat(event.getSource()).isInstanceOf(GroupSource.class);
        assertThat(((GroupSource) event.getSource()).getGroupId())
                .isEqualTo("cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
        assertThat(event.getTimestamp()).isEqualTo(Instant.parse("2016-05-07T13:57:59.859Z"));
    });/*from w ww  .jav a2 s .  c om*/
}

From source file:password.pwm.util.java.JavaHelper.java

public static Instant parseIsoToInstant(final String input) {
    return Instant.parse(input);
}

From source file:com.linecorp.bot.model.event.CallbackRequestTest.java

@Test
public void testLeave() throws IOException {
    parse("callback/leave.json", callbackRequest -> {
        assertThat(callbackRequest.getEvents()).hasSize(1);
        Event event = callbackRequest.getEvents().get(0);
        assertThat(event).isInstanceOf(LeaveEvent.class);
        assertThat(event.getSource()).isInstanceOf(GroupSource.class);
        assertThat(((GroupSource) event.getSource()).getGroupId())
                .isEqualTo("cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
        assertThat(event.getTimestamp()).isEqualTo(Instant.parse("2016-05-07T13:57:59.859Z"));
    });/*from  www .  j  ava2 s  .  c om*/
}

From source file:org.apache.james.transport.mailets.DSNBounceTest.java

@Test
public void serviceShouldSendMultipartMailContainingDSNPart() throws Exception {
    FakeMailetConfig mailetConfig = FakeMailetConfig.builder().mailetName(MAILET_NAME)
            .mailetContext(fakeMailContext).build();
    dsnBounce.init(mailetConfig);/*from  w ww.jav a  2s. c  om*/

    MailAddress senderMailAddress = new MailAddress("sender@domain.com");
    FakeMail mail = FakeMail.builder().sender(senderMailAddress).attribute("delivery-error", "Delivery error")
            .mimeMessage(MimeMessageBuilder.mimeMessageBuilder().setText("My content")).name(MAILET_NAME)
            .recipient("recipient@domain.com").lastUpdated(Date.from(Instant.parse("2016-09-08T14:25:52.000Z")))
            .remoteAddr("remoteHost").build();

    dsnBounce.service(mail);

    String expectedContent = "Reporting-MTA: dns; myhost\n" + "Received-From-MTA: dns; 111.222.333.444\n" + "\n"
            + "Final-Recipient: rfc822; recipient@domain.com\n" + "Action: failed\n"
            + "Status: Delivery error\n" + "Diagnostic-Code: X-James; Delivery error\n"
            + "Last-Attempt-Date: Thu, 8 Sep 2016 14:25:52 XXXXX (UTC)\n";

    List<SentMail> sentMails = fakeMailContext.getSentMails();
    assertThat(sentMails).hasSize(1);
    SentMail sentMail = sentMails.get(0);
    MimeMessage sentMessage = sentMail.getMsg();
    MimeMultipart content = (MimeMultipart) sentMessage.getContent();
    SharedByteArrayInputStream actualContent = (SharedByteArrayInputStream) content.getBodyPart(1).getContent();
    assertThat(IOUtils.toString(actualContent, StandardCharsets.UTF_8)).isEqualTo(expectedContent);
}

From source file:org.codice.ddf.catalog.ui.forms.SearchFormsSymbolsIT.java

@Test
public void testXmlToJson() throws UnsupportedQueryException, SourceUnavailableException, FederationException {
    // Prepare/* www  .j ava 2 s  . com*/
    QueryTemplateMetacard queryTemplateMetacard = new QueryTemplateMetacard(CANNED_TITLE, CANNED_DESCRIPTION,
            CANNED_ID);
    queryTemplateMetacard.setFormsFilter(formFilterXml);
    queryTemplateMetacard.setCreatedDate(Date.from(Instant.parse(CANNED_ISO_DATE)));
    queryTemplateMetacard.setModifiedDate(Date.from(Instant.parse(CANNED_ISO_DATE)));

    QueryResponseImpl response = new QueryResponseImpl(new QueryRequestImpl(new QueryImpl(Filter.INCLUDE)));
    response.addResult(new ResultImpl(queryTemplateMetacard), true);

    doReturn(response).when(MOCK_FRAMEWORK).query(any());

    // Execute
    String json = RestAssured.given().header(CONTENT_IS_JSON).get(localhostFormsUrl).body().asString();
    assertThat(json, is(formResponseJson));
}

From source file:ws.salient.aws.dynamodb.DynamoDBStore.java

public Session get(Command command, KnowledgeRepository repository, Properties properties,
        Injector parentInjector, Sessions sessions, QuerySpec sessionQuery) {
    String sessionId = command.getSessionId();
    String accountId = command.getAccountId();

    SecretKeySpec secretKey;//from w  ww. j av a 2  s.c  om
    ByteBuffer encryptedKey;
    Session session = new Session(sessionId);
    Page<Item, QueryOutcome> page = dynamodb.getTable("SalientSession").query(sessionQuery).firstPage();
    if (page != null && page.size() > 0) {

        try {
            Item result = page.iterator().next();

            encryptedKey = ByteBuffer.wrap((byte[]) result.getMap("secretKey").get("encrypted"));
            if (encryptedKey != null) {
                DecryptResult decrypt = kms.decrypt(new DecryptRequest()
                        .addEncryptionContextEntry("accountId", accountId)
                        .addEncryptionContextEntry("sessionId", sessionId).withCiphertextBlob(encryptedKey));
                byte[] key = decrypt.getPlaintext().array();
                secretKey = new SecretKeySpec(key, (String) result.getMap("secretKey").get("algorithm"));
            } else {
                secretKey = null;
            }

            result = decrypt(result, secretKey, "properties", "session");

            properties = json.readValue(result.getBinary("properties"), Properties.class);
            String knowledgeBaseId = result.getString("knowledgeBaseId");
            KnowledgeBase knowledgeBase = repository.getKnowledgeBase(knowledgeBaseId);
            String timestamp = result.getString("timestamp");

            session.init(knowledgeBase, properties, parentInjector, Instant.parse(timestamp),
                    result.getBinary("session"), sessions);

            int processCount = session.getProcessCount();

            List<Item> eventItems = new LinkedList();
            ItemCollection<QueryOutcome> query = dynamodb.getTable("SalientSessionEvent")
                    .query(new QuerySpec().withConsistentRead(true).withHashKey("sessionId", sessionId)
                            .withRangeKeyCondition(new RangeKeyCondition("timestamp").gt(timestamp)));
            query.pages().forEach((eventPage) -> {
                eventPage.forEach((eventItem) -> {
                    eventItems.add(eventItem);
                });
            });

            List<Command> commands = new LinkedList();

            eventItems.forEach((eventItem) -> {
                try {
                    eventItem = decrypt(eventItem, secretKey, "command");
                    byte[] value = eventItem.getBinary("command");
                    ObjectInputStream objectIn = new ObjectInputStream(new ByteArrayInputStream(value)) {
                        protected Class<?> resolveClass(ObjectStreamClass desc)
                                throws IOException, ClassNotFoundException {
                            return session.getKnowledgeBase().getContainer().getClassLoader()
                                    .loadClass(desc.getName());
                        }
                    };
                    Command event = (Command) objectIn.readObject();
                    if (event instanceof WorkItem) {
                        session.getWorkItemHandlers().forEach((handler) -> {
                            handler.getCompletedWorkItemIds().add(((WorkItem) event).getWorkItemId());
                        });
                    }
                    commands.add(event);
                } catch (ClassNotFoundException | IOException ex) {
                    throw new RuntimeException(ex);
                }
            });
            commands.forEach((event) -> {
                session.accept(event);
            });
            session.getWorkItemHandlers().forEach((handler) -> {
                handler.getCompletedWorkItemIds().clear();
            });

        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    } else {
        GenerateDataKeyResult dataKey = generateEncryptionKey(accountId, sessionId);
        byte[] key = dataKey.getPlaintext().array();
        secretKey = new SecretKeySpec(key, "AES");
        encryptedKey = dataKey.getCiphertextBlob();
        KnowledgeBase knowledgeBase = repository.getKnowledgeBase(command.getKnowledgeBaseId());
        session.init(knowledgeBase, properties, parentInjector, command.getTimestamp(), sessions);
    }
    session.setEncryptedKey(encryptedKey);
    session.setSecretKey(secretKey);
    return session;
}

From source file:com.linecorp.bot.model.event.CallbackRequestTest.java

@Test
public void testPostback() throws IOException {
    parse("callback/postback.json", callbackRequest -> {
        assertThat(callbackRequest.getEvents()).hasSize(1);
        Event event = callbackRequest.getEvents().get(0);
        assertThat(event).isInstanceOf(PostbackEvent.class);
        assertThat(event.getSource()).isInstanceOf(UserSource.class);
        assertThat(event.getSource().getUserId()).isEqualTo("u206d25c2ea6bd87c17655609a1c37cb8");
        assertThat(event.getTimestamp()).isEqualTo(Instant.parse("2016-05-07T13:57:59.859Z"));

        PostbackEvent postbackEvent = (PostbackEvent) event;
        assertThat(postbackEvent.getPostbackContent().getData())
                .isEqualTo("action=buyItem&itemId=123123&color=red");
    });/*www.  ja  v  a2 s.  c  om*/
}

From source file:com.linecorp.bot.model.event.CallbackRequestTest.java

@Test
public void testBeacon() throws IOException {
    parse("callback/beacon.json", callbackRequest -> {
        assertThat(callbackRequest.getEvents()).hasSize(1);
        Event event = callbackRequest.getEvents().get(0);
        assertThat(event).isInstanceOf(BeaconEvent.class);
        assertThat(event.getSource()).isInstanceOf(UserSource.class);
        assertThat(event.getSource().getUserId()).isEqualTo("U012345678901234567890123456789ab");
        assertThat(event.getTimestamp()).isEqualTo(Instant.parse("2016-05-07T13:57:59.859Z"));

        BeaconEvent beaconEvent = (BeaconEvent) event;
        assertThat(beaconEvent.getBeacon().getHwid()).isEqualTo("374591320");
        assertThat(beaconEvent.getBeacon().getType()).isEqualTo("enter");
    });//from w  w  w . j  a v  a 2s.  c om
}

From source file:com.spotify.styx.cli.Main.java

private void backfillCreate() throws ExecutionException, InterruptedException, IOException {
    final String component = namespace.getString(parser.backfillCreateComponent.getDest());
    final String workflow = namespace.getString(parser.backfillCreateWorkflow.getDest());
    final String start = namespace.getString(parser.backfillCreateStart.getDest());
    final String end = namespace.getString(parser.backfillCreateEnd.getDest());
    final int concurrency = namespace.getInt(parser.backfillCreateConcurrency.getDest());

    final BackfillInput backfillInput = BackfillInput.create(Instant.parse(start), Instant.parse(end),
            component, workflow, concurrency);

    final ByteString payload = serialize(backfillInput);
    final ByteString response = send(Request.forUri(apiUrl("backfills"), "POST").withPayload(payload));
    final Backfill backfill = deserialize(response, Backfill.class);
    cliOutput.printBackfill(backfill);/*from ww  w .j av a 2  s.co m*/
}