List of usage examples for java.time Instant parse
public static Instant parse(final CharSequence text)
From source file:jp.classmethod.aws.brian.BrianClient.java
@Override public UpdateTriggerResult updateTrigger(BrianTrigger trigger) throws BrianClientException, BrianServerException { logger.debug("update trigger: {}/{}", trigger.getGroup(), trigger.getName()); HttpResponse httpResponse = null;/*from w w w . j a va 2 s . c o m*/ try { BrianTriggerRequest request = trigger.toBrianTriggerRequest(); String requestBody = mapper.writeValueAsString(request); logger.trace("update: requestBody = {}", requestBody); HttpEntity entity = new StringEntity(requestBody); String path = String.format("/triggers/%s/%s", trigger.getGroup(), trigger.getName()); URI uri = new URI(scheme, null, hostname, port, path, null, null); HttpUriRequest httpRequest = RequestBuilder.put().setUri(uri).setEntity(entity).build(); httpResponse = httpClientExecute(httpRequest); int statusCode = httpResponse.getStatusLine().getStatusCode(); logger.debug("statusCode: {}", statusCode); JsonNode tree = mapper.readTree(httpResponse.getEntity().getContent()); if (statusCode == HttpStatus.SC_OK) { String nextFireTime = tree.path("content").path("nextFireTime").asText(); logger.info("trigger updated: nextFireTime = {}", nextFireTime); return new UpdateTriggerResult(Instant.parse(nextFireTime)); } else if (statusCode >= 500) { throw new BrianServerException(String.format("status = %d; message = %s", new Object[] { statusCode, tree.get("message").textValue() })); } else if (statusCode == HttpStatus.SC_NOT_FOUND) { throw new BrianClientException(String.format("triggerKey (%s/%s) is not found", new Object[] { trigger.getGroup(), trigger.getName() })); } else if (statusCode >= 400) { throw new BrianClientException(String.format("status = %d; message = %s", new Object[] { statusCode, tree.get("message").textValue() })); } else { throw new Error(String.format("status = %d; message = %s", new Object[] { statusCode, tree.get("message").textValue() })); } } catch (JsonProcessingException e) { throw new BrianServerException(e); } catch (URISyntaxException e) { throw new IllegalStateException(e); } catch (IOException e) { throw new BrianServerException(e); } catch (IllegalStateException e) { throw new Error(e); } finally { if (httpResponse != null) { EntityUtils.consumeQuietly(httpResponse.getEntity()); } } }
From source file:org.apache.james.transport.mailets.DSNBounceTest.java
@Test public void serviceShouldNotAttachTheOriginalMailWhenAttachmentIsEqualToNone() throws Exception { FakeMailetConfig mailetConfig = FakeMailetConfig.builder().mailetName(MAILET_NAME) .mailetContext(fakeMailContext).setProperty("attachment", "none").build(); dsnBounce.init(mailetConfig);/*from www .j a v a 2s . c om*/ MailAddress senderMailAddress = new MailAddress("sender@domain.com"); FakeMail mail = FakeMail.builder().sender(senderMailAddress) .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); List<SentMail> sentMails = fakeMailContext.getSentMails(); assertThat(sentMails).hasSize(1); SentMail sentMail = sentMails.get(0); assertThat(sentMail.getSender()).isNull(); assertThat(sentMail.getRecipients()).containsOnly(senderMailAddress); MimeMessage sentMessage = sentMail.getMsg(); MimeMultipart content = (MimeMultipart) sentMessage.getContent(); assertThat(content.getCount()).isEqualTo(2); }
From source file:com.orange.ngsi2.utility.Utils.java
static public Subscription retrieveSubscriptionReference() throws MalformedURLException { Subscription subscription = createSubscriptionReference(); subscription.setId("abcdef"); subscription.getNotification().setTimesSent(12); subscription.getNotification().setLastNotification(Instant.parse("2015-10-05T16:00:00.10Z")); subscription.setStatus(Subscription.Status.active); return subscription; }
From source file:com.orange.ngsi2.utility.Utils.java
static public Subscription updateSubscriptionReference() { Subscription subscription = new Subscription(); subscription.setExpires(Instant.parse("2016-04-05T14:00:00.20Z")); return subscription; }
From source file:org.apache.james.transport.mailets.DSNBounceTest.java
@Test public void serviceShouldAttachTheOriginalMailWhenAttachmentIsEqualToAll() throws Exception { FakeMailetConfig mailetConfig = FakeMailetConfig.builder().mailetName(MAILET_NAME) .mailetContext(fakeMailContext).setProperty("attachment", "all").build(); dsnBounce.init(mailetConfig);//from w w w . ja v a2 s . c o m MailAddress senderMailAddress = new MailAddress("sender@domain.com"); MimeMessage mimeMessage = MimeMessageBuilder.mimeMessageBuilder().setText("My content").build(); FakeMail mail = FakeMail.builder().sender(senderMailAddress).name(MAILET_NAME) .recipient("recipient@domain.com").lastUpdated(Date.from(Instant.parse("2016-09-08T14:25:52.000Z"))) .mimeMessage(mimeMessage).build(); MimeMessage mimeMessageCopy = new MimeMessage(mimeMessage); dsnBounce.service(mail); List<SentMail> sentMails = fakeMailContext.getSentMails(); assertThat(sentMails).hasSize(1); SentMail sentMail = sentMails.get(0); assertThat(sentMail.getSender()).isNull(); assertThat(sentMail.getRecipients()).containsOnly(senderMailAddress); MimeMessage sentMessage = sentMail.getMsg(); MimeMultipart content = (MimeMultipart) sentMessage.getContent(); assertThat(sentMail.getMsg().getContentType()).startsWith("multipart/report;"); assertThat(MimeMessageUtil.asString((MimeMessage) content.getBodyPart(2).getContent())) .isEqualTo(MimeMessageUtil.asString(mimeMessageCopy)); }
From source file:org.apache.james.transport.mailets.DSNBounceTest.java
@Test public void serviceShouldAttachTheOriginalMailHeadersOnlyWhenAttachmentIsEqualToHeads() throws Exception { FakeMailetConfig mailetConfig = FakeMailetConfig.builder().mailetName(MAILET_NAME) .mailetContext(fakeMailContext).setProperty("attachment", "heads").build(); dsnBounce.init(mailetConfig);//from w ww . j ava 2s. c om MailAddress senderMailAddress = new MailAddress("sender@domain.com"); FakeMail mail = FakeMail.builder().sender(senderMailAddress) .mimeMessage(MimeMessageBuilder.mimeMessageBuilder().setText("My content") .addHeader("myHeader", "myValue").setSubject("mySubject")) .name(MAILET_NAME).recipient("recipient@domain.com") .lastUpdated(Date.from(Instant.parse("2016-09-08T14:25:52.000Z"))).build(); dsnBounce.service(mail); List<SentMail> sentMails = fakeMailContext.getSentMails(); assertThat(sentMails).hasSize(1); SentMail sentMail = sentMails.get(0); assertThat(sentMail.getSender()).isNull(); assertThat(sentMail.getRecipients()).containsOnly(senderMailAddress); MimeMessage sentMessage = sentMail.getMsg(); MimeMultipart content = (MimeMultipart) sentMessage.getContent(); BodyPart bodyPart = content.getBodyPart(2); SharedByteArrayInputStream actualContent = (SharedByteArrayInputStream) bodyPart.getContent(); assertThat(IOUtils.toString(actualContent, StandardCharsets.UTF_8)).contains("Subject: mySubject") .contains("myHeader: myValue"); assertThat(bodyPart.getContentType()).isEqualTo("text/rfc822-headers; name=mySubject"); }
From source file:org.apache.tinkerpop.gremlin.structure.io.Model.java
private Model() { final Configuration conf = new BaseConfiguration(); conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_DEFAULT_VERTEX_PROPERTY_CARDINALITY, VertexProperty.Cardinality.list.name()); final TinkerGraph graph = TinkerGraph.open(conf); TinkerFactory.generateTheCrew(graph); final GraphTraversalSource g = graph.traversal(); final Compatibility[] noTypeGraphSONPlusGryo3_2_3 = Compatibilities.with(GryoCompatibility.class) .beforeRelease("3.2.4").join(Compatibilities.UNTYPED_GRAPHSON).matchToArray(); final Compatibility[] noTypeGraphSONPlusGryo3_3_0 = Compatibilities.with(GryoCompatibility.class) .beforeRelease("3.3.0").join(Compatibilities.UNTYPED_GRAPHSON).matchToArray(); final Compatibility[] noGraphSONBeforeV3 = Compatibilities.with(GraphSONCompatibility.class) .configuredAs(".*v2d0-partial|v1d0|v2d0-no-types").join(Compatibilities.GRYO_ONLY).matchToArray(); // IMPORTANT - the "title" or name of the Entry needs to be unique // Serialization of Class in Gryo 1.0 had a bug that prevented proper operation in versions prior to 3.2.4. addCoreEntry(File.class, "Class", "", noTypeGraphSONPlusGryo3_2_3); addCoreEntry(new Date(1481750076295L), "Date"); addCoreEntry(100.00d, "Double"); addCoreEntry(100.00f, "Float", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addCoreEntry(100, "Integer"); addCoreEntry(Arrays.asList(1, "person", true), "List", "List is used to distinguish between different collection types as JSON is not explicit enough for all of Gremlin's requirements.", noGraphSONBeforeV3);//from ww w. ja va 2 s . co m addCoreEntry(100L, "Long", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); final Map<Object, Object> map = new HashMap<>(); map.put("test", 123); map.put(new Date(1481750076295L), "red"); map.put(Arrays.asList(1, 2, 3), new Date(1481750076295L)); addCoreEntry(map, "Map", "Map is redefined so that to provide the ability to allow for non-String keys, which is not possible in JSON.", noGraphSONBeforeV3); addCoreEntry(new HashSet<>(Arrays.asList(1, "person", true)), "Set", "Allows a JSON collection to behave as a Set.", noGraphSONBeforeV3); // Timestamp was added to Gryo 1.0 as of 3.2.4. It was not supported in 3.2.3. addCoreEntry(new java.sql.Timestamp(1481750076295L), "Timestamp", "", noTypeGraphSONPlusGryo3_2_3); addCoreEntry(UUID.fromString("41d2e28a-20a4-4ab0-b379-d810dede3786"), "UUID"); addGraphStructureEntry(graph.edges().next(), "Edge", ""); addGraphStructureEntry(g.V().out().out().path().next(), "Path", ""); addGraphStructureEntry(graph.edges().next().properties().next(), "Property", ""); // TODO: missing a stargraph deserializer in graphson v1/v2 addEntry("Graph Structure", StarGraph.of(graph.vertices().next()), "StarGraph", "", Compatibilities.GRYO_ONLY.match()); addGraphStructureEntry(graph, "TinkerGraph", "`TinkerGraph` has a custom serializer that is registered as part of the `TinkerIoRegistry`."); // TODO: tree has bugs for graphson addEntry("Graph Structure", g.V(1).out().out().tree().next(), "Tree", "", Compatibilities.GRYO_ONLY.match()); addGraphStructureEntry(graph.vertices().next(), "Vertex", ""); addGraphStructureEntry(graph.vertices().next().properties().next(), "VertexProperty", ""); addGraphProcessEntry(SackFunctions.Barrier.normSack, "Barrier", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addGraphProcessEntry(new Bytecode.Binding("x", 1), "Binding", "A \"Binding\" refers to a `Bytecode.Binding`.", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addGraphProcessEntry(g.V().hasLabel("person").out().in().tree().asAdmin().getBytecode(), "Bytecode", "The following `Bytecode` example represents the traversal of `g.V().hasLabel('person').out().in().tree()`. Obviously the serialized `Bytecode` woudl be quite different for the endless variations of commands that could be used together in the Gremlin language.", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addGraphProcessEntry(VertexProperty.Cardinality.list, "Cardinality", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addGraphProcessEntry(Column.keys, "Column", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addGraphProcessEntry(Direction.OUT, "Direction", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addGraphProcessEntry(Operator.sum, "Operator", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addGraphProcessEntry(Order.incr, "Order", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addGraphProcessEntry(TraversalOptionParent.Pick.any, "Pick", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addGraphProcessEntry(Pop.all, "Pop", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addGraphProcessEntry(org.apache.tinkerpop.gremlin.util.function.Lambda.function("{ it.get() }"), "Lambda", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); final TraversalMetrics tm = createStaticTraversalMetrics(); final MutableMetrics metrics = new MutableMetrics(tm.getMetrics("7.0.0()")); metrics.addNested(new MutableMetrics(tm.getMetrics("3.0.0()"))); addGraphProcessEntry(metrics, "Metrics", "", noTypeGraphSONPlusGryo3_3_0); addGraphProcessEntry(P.gt(0), "P", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addGraphProcessEntry(P.within(1), "P within", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addGraphProcessEntry(P.without(1, 2), "P without", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); // A bug in the the Gryo serialization of ConjunctiveP prevented its proper serialization in versions prior to 3.3.0 and 3.2.4. addGraphProcessEntry(P.gt(0).and(P.lt(10)), "P and", "", noTypeGraphSONPlusGryo3_2_3); // A bug in the the Gryo serialization of ConjunctiveP prevented its proper serialization in versions prior to 3.3.0 and 3.2.4. addGraphProcessEntry(P.gt(0).or(P.within(-1, -10, -100)), "P or", "", noTypeGraphSONPlusGryo3_2_3); addGraphProcessEntry(Scope.local, "Scope", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addGraphProcessEntry(T.label, "T", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addGraphProcessEntry(createStaticTraversalMetrics(), "TraversalMetrics", "", noTypeGraphSONPlusGryo3_3_0); addGraphProcessEntry(g.V().hasLabel("person").asAdmin().nextTraverser(), "Traverser", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); final Map<String, Object> requestBindings = new HashMap<>(); requestBindings.put("x", 1); final Map<String, Object> requestAliases = new HashMap<>(); requestAliases.put("g", "social"); // RequestMessage is not testable prior to Gryo 3.0 as serialization was handled by an intermediate component // (MessageSerializer) that doesn't fit the test model. RequestMessage requestMessage; requestMessage = RequestMessage.build("authentication") .overrideRequestId(UUID.fromString("cb682578-9d92-4499-9ebc-5c6aa73c5397")) .add("saslMechanism", "PLAIN", "sasl", "AHN0ZXBocGhlbgBwYXNzd29yZA==").create(); addRequestMessageEntry(requestMessage, "Authentication Response", "The following `RequestMessage` is an example of the response that should be made to a SASL-based authentication challenge."); requestMessage = RequestMessage.build("eval").processor("session") .overrideRequestId(UUID.fromString("cb682578-9d92-4499-9ebc-5c6aa73c5397")) .add("gremlin", "g.V(x)", "bindings", requestBindings, "language", "gremlin-groovy", "session", UUID.fromString("41d2e28a-20a4-4ab0-b379-d810dede3786")) .create(); addRequestMessageEntry(requestMessage, "Session Eval", "The following `RequestMessage` is an example of a simple session request for a script evaluation with parameters."); requestMessage = RequestMessage.build("eval").processor("session") .overrideRequestId(UUID.fromString("cb682578-9d92-4499-9ebc-5c6aa73c5397")) .add("gremlin", "social.V(x)", "bindings", requestBindings, "language", "gremlin-groovy", "aliases", requestAliases, "session", UUID.fromString("41d2e28a-20a4-4ab0-b379-d810dede3786")) .create(); addRequestMessageEntry(requestMessage, "Session Eval Aliased", "The following `RequestMessage` is an example of a session request for a script evaluation with an alias that binds the `TraversalSource` of \"g\" to \"social\"."); requestMessage = RequestMessage.build("close").processor("session") .overrideRequestId(UUID.fromString("cb682578-9d92-4499-9ebc-5c6aa73c5397")) .add("session", UUID.fromString("41d2e28a-20a4-4ab0-b379-d810dede3786")).create(); addRequestMessageEntry(requestMessage, "Session Close", "The following `RequestMessage` is an example of a request to close a session."); requestMessage = RequestMessage.build("eval") .overrideRequestId(UUID.fromString("cb682578-9d92-4499-9ebc-5c6aa73c5397")) .add("gremlin", "g.V(x)", "bindings", requestBindings, "language", "gremlin-groovy").create(); addRequestMessageEntry(requestMessage, "Sessionless Eval", "The following `RequestMessage` is an example of a simple sessionless request for a script evaluation with parameters."); requestMessage = RequestMessage.build("eval") .overrideRequestId(UUID.fromString("cb682578-9d92-4499-9ebc-5c6aa73c5397")) .add("gremlin", "social.V(x)", "bindings", requestBindings, "language", "gremlin-groovy", "aliases", requestAliases) .create(); addRequestMessageEntry(requestMessage, "Sessionless Eval Aliased", "The following `RequestMessage` is an example of a sessionless request for a script evaluation with an alias that binds the `TraversalSource` of \"g\" to \"social\"."); // ResponseMessage is not testable prior to Gryo 3.0 as serialization was handled by an intermediate component // (MessageSerializer) that doesn't fit the test model ResponseMessage responseMessage = ResponseMessage .build(UUID.fromString("41d2e28a-20a4-4ab0-b379-d810dede3786")) .code(org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode.AUTHENTICATE).create(); addResponseMessageEntry(responseMessage, "Authentication Challenge", "When authentication is enabled, an initial request to the server will result in an authentication challenge. The typical response message will appear as follows, but handling it could be different depending on the SASL implementation (e.g. multiple challenges maybe requested in some cases, but not in the default provided by Gremlin Server)."); responseMessage = ResponseMessage.build(UUID.fromString("41d2e28a-20a4-4ab0-b379-d810dede3786")) .code(org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode.SUCCESS) .result(Collections.singletonList(graph.vertices().next())).create(); addResponseMessageEntry(responseMessage, "Standard Result", "The following `ResponseMessage` is a typical example of the typical successful response Gremlin Server will return when returning results from a script."); addExtendedEntry(new BigDecimal(new java.math.BigInteger("123456789987654321123456789987654321")), "BigDecimal", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addExtendedEntry(new BigInteger("123456789987654321123456789987654321"), "BigInteger", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addExtendedEntry(new Byte("1"), "Byte", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); // ByteBuffer was added to Gryo 1.0 as of 3.2.4. It was not supported in earlier versions. addEntry("Extended", () -> java.nio.ByteBuffer.wrap("some bytes for you".getBytes()), "ByteBuffer", "", noTypeGraphSONPlusGryo3_2_3); addExtendedEntry("x".charAt(0), "Char", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addExtendedEntry(Duration.ofDays(5), "Duration", "The following example is a `Duration` of five days.", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); try { // InetAddress was added to Gryo 1.0 as of 3.2.4. It was not supported in earlier versions. addEntry("Extended", InetAddress.getByName("localhost"), "InetAddress", "", noTypeGraphSONPlusGryo3_2_3); } catch (Exception ex) { throw new RuntimeException(ex); } addExtendedEntry(Instant.parse("2016-12-14T16:39:19.349Z"), "Instant", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addExtendedEntry(LocalDate.of(2016, 1, 1), "LocalDate", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addExtendedEntry(LocalDateTime.of(2016, 1, 1, 12, 30), "LocalDateTime", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addExtendedEntry(LocalTime.of(12, 30, 45), "LocalTime", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addExtendedEntry(MonthDay.of(1, 1), "MonthDay", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addExtendedEntry(OffsetDateTime.parse("2007-12-03T10:15:30+01:00"), "OffsetDateTime", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addExtendedEntry(OffsetTime.parse("10:15:30+01:00"), "OffsetTime", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addExtendedEntry(Period.of(1, 6, 15), "Period", "The following example is a `Period` of one year, six months and fifteen days.", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addExtendedEntry(new Short("100"), "Short", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addExtendedEntry(Year.of(2016), "Year", "The following example is of the `Year` \"2016\".", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addExtendedEntry(YearMonth.of(2016, 6), "YearMonth", "The following example is a `YearMonth` of \"June 2016\"", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addExtendedEntry(ZonedDateTime.of(2016, 12, 23, 12, 12, 24, 36, ZoneId.of("GMT+2")), "ZonedDateTime", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addExtendedEntry(ZoneOffset.ofHoursMinutesSeconds(3, 6, 9), "ZoneOffset", "The following example is a `ZoneOffset` of three hours, six minutes, and nine seconds.", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); }
From source file:org.apache.james.transport.mailets.DSNBounceTest.java
@Test public void serviceShouldSetTheDateHeaderWhenNone() throws Exception { FakeMailetConfig mailetConfig = FakeMailetConfig.builder().mailetName(MAILET_NAME) .mailetContext(fakeMailContext).build(); dsnBounce.init(mailetConfig);// ww w. j a va 2 s .c om MailAddress senderMailAddress = new MailAddress("sender@domain.com"); FakeMail mail = FakeMail.builder().sender(senderMailAddress) .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); List<SentMail> sentMails = fakeMailContext.getSentMails(); assertThat(sentMails).hasSize(1); SentMail sentMail = sentMails.get(0); assertThat(sentMail.getSender()).isNull(); assertThat(sentMail.getRecipients()).containsOnly(senderMailAddress); MimeMessage sentMessage = sentMail.getMsg(); assertThat(sentMessage.getHeader(RFC2822Headers.DATE)).isNotNull(); }
From source file:com.sillelien.dollar.api.types.DollarFactory.java
@NotNull private static var fromJson(@NotNull JsonObject jsonObject) { final Type type; if (!jsonObject.containsField(TYPE_KEY)) { type = Type.MAP;//www.java 2 s.c o m } else { type = Type.valueOf(jsonObject.getString(TYPE_KEY)); } if (type.equals(Type.VOID)) { return $void(); } else if (type.equals(Type.INTEGER)) { return fromValue(jsonObject.getLong(VALUE_KEY)); } else if (type.equals(Type.BOOLEAN)) { return fromValue(jsonObject.getBoolean(VALUE_KEY)); } else if (type.equals(Type.DATE)) { return wrap(new DollarDate(ImmutableList.of(), Instant.parse(jsonObject.getString(TEXT_KEY)))); } else if (type.equals(Type.DECIMAL)) { return fromValue(jsonObject.getNumber(VALUE_KEY)); } else if (type.equals(Type.LIST)) { final JsonArray array = jsonObject.getArray(VALUE_KEY); ArrayList<Object> arrayList = new ArrayList<>(); for (Object o : array) { arrayList.add(fromJson(o)); } return wrap(new DollarList(ImmutableList.of(), ImmutableList.copyOf(arrayList))); } else if (type.equals(Type.MAP)) { final JsonObject json; json = jsonObject; LinkedHashMap<String, Object> map = new LinkedHashMap<>(); final Set<String> fieldNames = json.getFieldNames(); for (String fieldName : fieldNames) { if (!fieldName.equals(TYPE_KEY)) { map.put(fieldName, fromJson(json.get(fieldName))); } } return wrap(new DollarMap(ImmutableList.of(), map)); } else if (type.equals(Type.ERROR)) { final String errorType = jsonObject.getString("errorType"); final String errorMessage = jsonObject.getString("errorMessage"); return wrap(new DollarError(ImmutableList.<Throwable>of(), ErrorType.valueOf(errorType), errorMessage)); } else if (type.equals(Type.RANGE)) { final var lower = fromJson(jsonObject.get(LOWERBOUND_KEY)); final var upper = fromJson(jsonObject.get(UPPERBOUND_KEY)); return wrap(new DollarRange(ImmutableList.of(), lower, upper)); } else if (type.equals(Type.URI)) { return wrap(new DollarURI(ImmutableList.of(), URI.parse(jsonObject.getString(VALUE_KEY)))); } else if (type.equals(Type.INFINITY)) { return wrap(new DollarInfinity(ImmutableList.of(), jsonObject.getBoolean(POSITIVE_KEY))); } else if (type.equals(Type.STRING)) { if (!(jsonObject.get(VALUE_KEY) instanceof String)) { System.out.println(jsonObject.get(VALUE_KEY)); } return wrap(new DollarString(ImmutableList.of(), jsonObject.getString(VALUE_KEY))); } else { throw new DollarException("Unrecognized type " + type); } }
From source file:org.apache.james.transport.mailets.DSNBounceTest.java
@Test public void serviceShouldNotModifyTheDateHeaderWhenAlreadyPresent() throws Exception { FakeMailetConfig mailetConfig = FakeMailetConfig.builder().mailetName(MAILET_NAME) .mailetContext(fakeMailContext).build(); dsnBounce.init(mailetConfig);//from w ww. j a v a 2 s. c om MailAddress senderMailAddress = new MailAddress("sender@domain.com"); String expectedDate = "Wed, 28 Sep 2016 14:25:52 +0000 (UTC)"; FakeMail mail = FakeMail.builder().sender(senderMailAddress) .mimeMessage(MimeMessageBuilder.mimeMessageBuilder().setText("My content") .addHeader(RFC2822Headers.DATE, expectedDate)) .name(MAILET_NAME).recipient("recipient@domain.com") .lastUpdated(Date.from(Instant.parse("2016-09-08T14:25:52.000Z"))).build(); dsnBounce.service(mail); List<SentMail> sentMails = fakeMailContext.getSentMails(); assertThat(sentMails).hasSize(1); SentMail sentMail = sentMails.get(0); assertThat(sentMail.getSender()).isNull(); assertThat(sentMail.getRecipients()).containsOnly(senderMailAddress); MimeMessage sentMessage = sentMail.getMsg(); assertThat(sentMessage.getHeader(RFC2822Headers.DATE)[0]).isEqualTo(expectedDate); }