Example usage for java.util Date from

List of usage examples for java.util Date from

Introduction

In this page you can find the example usage for java.util Date from.

Prototype

public static Date from(Instant instant) 

Source Link

Document

Obtains an instance of Date from an Instant object.

Usage

From source file:com.vmware.photon.controller.api.client.resource.TenantsRestApiTest.java

@Test
public void testDelete() 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.delete("foo");
    assertEquals(task, responseTask);//  w  ww.j a va2 s . c o m
}

From source file:com.vmware.photon.controller.api.client.resource.ImagesApiTest.java

@Test
public void testDeleteImageAsync() 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);

    ImagesApi imagesApi = new ImagesApi(this.restClient);
    final CountDownLatch latch = new CountDownLatch(1);

    imagesApi.deleteAsync("foo", new FutureCallback<Task>() {
        @Override/* w  ww .j  a  v a 2s. 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.ImagesRestApiTest.java

@Test
public void testDeleteImageAsync() 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);

    ImagesApi imagesApi = new ImagesRestApi(this.restClient);
    final CountDownLatch latch = new CountDownLatch(1);

    imagesApi.deleteAsync("foo", new FutureCallback<Task>() {
        @Override// www.  j a v a  2s. 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: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);//  w w w  .j  a va 2 s.  c  o  m

    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//from  www .ja  v a2  s. co m
    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:com.vmware.photon.controller.client.resource.VmApiTest.java

@Test
public void testPerformOperationAsync() 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);

    VmOperation vmOperation = new VmOperation();
    vmOperation.setOperation(Operation.START_VM.name());

    final CountDownLatch latch = new CountDownLatch(1);

    vmApi.performOperationAsync("foo", vmOperation, new FutureCallback<Task>() {
        @Override/*from   w  w w. j  a  va  2s.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.ProjectApiTest.java

@Test
public void testDeleteAsync() 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.deleteAsync("foo", new FutureCallback<Task>() {
        @Override//from w  w w.  jav  a2  s .  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:net.ceos.project.poi.annotated.core.CellFormulaHandler.java

/**
 * Apply a Date value to the cell./*from   w w w.ja  v a  2 s  .c  o m*/
 * 
 * @param configCriteria
 *            the {@link XConfigCriteria}
 * @param object
 *            the object
 * @param cell
 *            the {@link Cell} to use
 * @throws IllegalAccessException
 * @throws ConverterException
 */
protected static void localDateTimeHandler(final XConfigCriteria configCriteria, final Object object,
        final Cell cell) throws IllegalAccessException, ConverterException {
    LocalDateTime date = (LocalDateTime) configCriteria.getField().get(object);
    if (StringUtils.isNotBlank(configCriteria.getElement().transformMask())) {
        // apply transformation mask
        String decorator = configCriteria.getElement().transformMask();
        convertDate(cell, Date.from(date.atZone(ZoneId.systemDefault()).toInstant()), decorator);
    } else if (StringUtils.isNotBlank(configCriteria.getElement().formatMask())) {
        // apply format mask
        CellValueHandler.consumeValue(cell, Date.from(date.atZone(ZoneId.systemDefault()).toInstant()));
    } else {
        // apply default date mask
        CellValueHandler.consumeValue(cell, Date.from(date.atZone(ZoneId.systemDefault()).toInstant()));
    }
}

From source file:com.vmware.photon.controller.api.client.resource.ProjectRestApiTest.java

@Test
public void testDeleteAsync() 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.deleteAsync("foo", new FutureCallback<Task>() {
        @Override/*from  www  . ja  va 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.TenantsApiTest.java

@Test
public void testDeleteAsync() 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.deleteAsync("foo", new FutureCallback<Task>() {
        @Override/*from   w  ww .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));
}