List of usage examples for java.util Date from
public static Date from(Instant instant)
From source file:com.vmware.photon.controller.api.client.resource.TenantsRestApiTest.java
@Test public void testCreateProject() throws IOException { Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); TenantsApi tenantsApi = new TenantsRestApi(restClient); Task task = tenantsApi.createProject("foo", new ProjectCreateSpec()); assertEquals(task, responseTask);/* w w w. j a v a 2s. com*/ }
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 w w . j a va2s .c o m 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); }
From source file:com.vmware.photon.controller.api.client.resource.ProjectApiTest.java
@Test public void testCreateVmAsync() throws IOException, InterruptedException { final Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); ProjectApi projectApi = new ProjectApi(restClient); final CountDownLatch latch = new CountDownLatch(1); projectApi.createVmAsync("foo", new VmCreateSpec(), new FutureCallback<Task>() { @Override/*from ww w . jav a2s. co m*/ public void onSuccess(@Nullable Task result) { assertEquals(result, responseTask); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.vmware.photon.controller.api.client.resource.VmApiTest.java
@Test public void testPerformSuspendOperationAsync() throws IOException, InterruptedException { final Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); VmApi vmApi = new VmApi(restClient); final CountDownLatch latch = new CountDownLatch(1); vmApi.performSuspendOperationAsync("foo", new FutureCallback<Task>() { @Override/* w ww . j a v a 2 s . c o m*/ public void onSuccess(@Nullable Task result) { assertEquals(result, responseTask); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.vmware.photon.controller.api.client.resource.ProjectRestApiTest.java
@Test public void testCreateVmAsync() throws IOException, InterruptedException { final Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); ProjectApi projectApi = new ProjectRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); projectApi.createVmAsync("foo", new VmCreateSpec(), new FutureCallback<Task>() { @Override// w w w. j a va2s. c o m public void onSuccess(@Nullable Task result) { assertEquals(result, responseTask); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.vmware.photon.controller.api.client.resource.VmRestApiTest.java
@Test public void testPerformSuspendOperationAsync() throws IOException, InterruptedException { final Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); VmApi vmApi = new VmRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); vmApi.performSuspendOperationAsync("foo", new FutureCallback<Task>() { @Override/*from w w w .j a va2 s . c o m*/ public void onSuccess(@Nullable Task result) { assertEquals(result, responseTask); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:org.apache.drill.exec.store.solr.SolrRecordReader.java
private void processRecord(ValueVector vv, Object fieldValue, int recordCounter) { String fieldValueStr = null;/*from w ww. j a v a2 s . c o m*/ byte[] record = null; try { fieldValueStr = fieldValue.toString(); record = fieldValueStr.getBytes(Charsets.UTF_8); if (vv.getClass().equals(NullableVarCharVector.class)) { NullableVarCharVector v = (NullableVarCharVector) vv; v.getMutator().setSafe(recordCounter, record, 0, record.length); v.getMutator().setValueLengthSafe(recordCounter, record.length); } else if (vv.getClass().equals(NullableBigIntVector.class)) { NullableBigIntVector v = (NullableBigIntVector) vv; BigDecimal bd = new BigDecimal(fieldValueStr); v.getMutator().setSafe(recordCounter, bd.longValue()); } else if (vv.getClass().equals(NullableIntVector.class)) { NullableIntVector v = (NullableIntVector) vv; v.getMutator().setSafe(recordCounter, Integer.parseInt(fieldValueStr)); } else if (vv.getClass().equals(NullableFloat8Vector.class)) { NullableFloat8Vector v = (NullableFloat8Vector) vv; Double d = Double.parseDouble(fieldValueStr); v.getMutator().setSafe(recordCounter, d); } else if (vv.getClass().equals(DateVector.class)) { DateVector v = (DateVector) vv; long dtime = 0L; try { TemporalAccessor accessor = SolrRecordReader.timeFormatter.parse(fieldValueStr); Date date = Date.from(Instant.from(accessor)); dtime = date.getTime(); } catch (Exception e) { SimpleDateFormat dateParser = new SimpleDateFormat(SolrRecordReader.defaultDateFormat); dtime = dateParser.parse(fieldValueStr).getTime(); } v.getMutator().setSafe(recordCounter, dtime); } else if (vv.getClass().equals(NullableTimeStampVector.class)) { NullableTimeStampVector v = (NullableTimeStampVector) vv; DateTimeFormatter timeFormatter = DateTimeFormatter.ISO_DATE_TIME; long dtime = 0L; try { TemporalAccessor accessor = timeFormatter.parse(fieldValueStr); Date date = Date.from(Instant.from(accessor)); dtime = date.getTime(); } catch (Exception e) { SimpleDateFormat dateParser = new SimpleDateFormat(SolrRecordReader.defaultDateFormat); dtime = dateParser.parse(fieldValueStr).getTime(); } v.getMutator().setSafe(recordCounter, dtime); } } catch (Exception e) { SolrRecordReader.logger.error("Error processing record: " + e.getMessage() + vv.getField().getPath() + " Field type " + vv.getField().getType() + " " + vv.getClass()); } }
From source file:com.vmware.photon.controller.api.client.resource.TenantsApiTest.java
@Test public void testCreateProjectAsync() throws IOException, InterruptedException { final Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); TenantsApi tenantsApi = new TenantsApi(restClient); final CountDownLatch latch = new CountDownLatch(1); tenantsApi.createProjectAsync("foo", new ProjectCreateSpec(), new FutureCallback<Task>() { @Override//from w w w. j av a 2 s. c om public void onSuccess(@Nullable Task result) { assertEquals(result, responseTask); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.vmware.photon.controller.api.client.resource.TenantsRestApiTest.java
@Test public void testCreateProjectAsync() throws IOException, InterruptedException { final Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); TenantsApi tenantsApi = new TenantsRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); tenantsApi.createProjectAsync("foo", new ProjectCreateSpec(), new FutureCallback<Task>() { @Override/*w ww . j a v a 2 s. c o m*/ public void onSuccess(@Nullable Task result) { assertEquals(result, responseTask); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.esri.geoportal.commons.csw.client.impl.Client.java
/** * Parses ISO date/*from ww w. j a v a 2 s. c o m*/ * * @param strDate ISO date as string * @return date object or <code>null</code> if unable to parse date */ private static Date parseIsoDate(String strDate) { try { return Date.from(ZonedDateTime.from(DateTimeFormatter.ISO_DATE_TIME.parse(strDate)).toInstant()); } catch (Exception ex) { return null; } }