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:org.apache.james.transport.mailets.DSNBounceTest.java

@Test
public void serviceShouldUpdateTheMailStateWhenNoSenderAndPassThroughIsFalse() throws Exception {
    FakeMailetConfig mailetConfig = FakeMailetConfig.builder().mailetName(MAILET_NAME)
            .mailetContext(fakeMailContext).setProperty("passThrough", "false").build();
    dsnBounce.init(mailetConfig);//  w ww  .ja  va  2 s.  c  om

    FakeMail mail = FakeMail.builder().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);

    assertThat(mail.getState()).isEqualTo(Mail.GHOST);
}

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

@Test
public void testCreatePersistentDiskAsync() 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.createDiskAsync("foo", new DiskCreateSpec(), new FutureCallback<Task>() {
        @Override/*w ww . java  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.ProjectRestApiTest.java

@Test
public void testCreatePersistentDiskAsync() 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.createDiskAsync("foo", new DiskCreateSpec(), new FutureCallback<Task>() {
        @Override//from   w  w  w. ja  v  a  2 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:org.codice.ddf.registry.transformer.RegistryTransformerTest.java

@Test
public void testFullRegistryPackage() throws Exception {
    MetacardImpl metacard = convert("/csw-full-registry-package.xml");

    Date date = Date.from(ZonedDateTime.parse("2015-11-01T06:15:30-07:00").toInstant());
    assertThat(RegistryUtility.getStringAttribute(metacard, Core.CREATED, null), is(date.toString()));

    date = Date.from(ZonedDateTime.parse("2015-11-01T13:15:30Z").toInstant());
    assertThat(RegistryUtility.getStringAttribute(metacard, DateTime.START, null), is(date.toString()));

    date = Date.from(ZonedDateTime.parse("2015-12-01T23:01:40Z").toInstant());
    assertThat(RegistryUtility.getStringAttribute(metacard, DateTime.END, null), is(date.toString()));

    date = Date.from(ZonedDateTime.parse("2016-01-26T17:16:34.996Z").toInstant());
    assertThat(RegistryUtility.getStringAttribute(metacard, Core.MODIFIED, null), is(date.toString()));

    assertThat(RegistryUtility.getStringAttribute(metacard, RegistryObjectMetacardType.LINKS, null),
            is("https://some/link/to/my/repo"));

    assertThat(RegistryUtility.getStringAttribute(metacard, Core.LOCATION, null),
            is("POINT (112.267472 33.467944)"));
    assertThat(RegistryUtility.getStringAttribute(metacard, RegistryObjectMetacardType.REGION, null),
            is("USA"));

    List<String> attributeValuesList = RegistryUtility.getListOfStringAttribute(metacard,
            RegistryObjectMetacardType.DATA_SOURCES);
    assertThat(attributeValuesList.size(), is(2));
    assertThat(attributeValuesList, hasItem("youtube"));
    assertThat(attributeValuesList, hasItem("myCamera"));

    attributeValuesList = RegistryUtility.getListOfStringAttribute(metacard, Topic.KEYWORD);
    assertThat(attributeValuesList.size(), is(2));
    assertThat(attributeValuesList, hasItem("video"));
    assertThat(attributeValuesList, hasItem("sensor"));

    assertThat(RegistryUtility.getStringAttribute(metacard, RegistryObjectMetacardType.SECURITY_LEVEL, null),
            is("role=guest"));
    assertThat(RegistryUtility.getStringAttribute(metacard, Metacard.TITLE, null), is("Node Name"));
    assertThat(RegistryUtility.getStringAttribute(metacard, Metacard.DESCRIPTION, null),
            is("A little something describing this node in less than 1024 characters"));
    assertThat(RegistryUtility.getStringAttribute(metacard, Metacard.CONTENT_TYPE_VERSION, null), is("2.9.x"));

    attributeValuesList = RegistryUtility.getListOfStringAttribute(metacard,
            RegistryObjectMetacardType.SERVICE_BINDING_TYPES);
    assertThat(attributeValuesList.size(), is(2));
    assertThat(attributeValuesList, hasItem("Csw_Federated_Source"));
    assertThat(attributeValuesList, hasItem("soap13"));

    attributeValuesList = RegistryUtility.getListOfStringAttribute(metacard,
            RegistryObjectMetacardType.SERVICE_BINDINGS);
    assertThat(attributeValuesList.size(), is(2));
    assertThat(attributeValuesList, hasItem("REST"));
    assertThat(attributeValuesList, hasItem("SOAP"));

    assertThat(RegistryUtility.getStringAttribute(metacard, Contact.POINT_OF_CONTACT_NAME, null), is("Codice"));
    assertThat(RegistryUtility.getListOfStringAttribute(metacard, Contact.POINT_OF_CONTACT_ADDRESS),
            hasItem("1234 Some Street, Phoenix, AZ 85037, USA"));
    assertThat(RegistryUtility.getListOfStringAttribute(metacard, Contact.POINT_OF_CONTACT_PHONE),
            hasItem("(555) 555-5555 ext 1234"));
    assertThat(RegistryUtility.getListOfStringAttribute(metacard, Contact.POINT_OF_CONTACT_EMAIL),
            hasItem("emailaddress@something.com"));
    assertThat(RegistryUtility.getStringAttribute(metacard, Metacard.POINT_OF_CONTACT, null),
            is("john doe, (111) 111-1111 ext 1234, emailaddress@something.com"));
}

From source file:fr.lepellerin.ecole.service.internal.CantineServiceImpl.java

@Override
@Transactional(readOnly = true)/*w w w. j  a v a  2s .  co  m*/
public List<DayOfWeek> getJourOuvertCantine(final LocalDate startDate, final Famille famille)
        throws TechnicalException {
    final List<DayOfWeek> jours = new ArrayList<>();
    final Activite activite = getCantineActivite();
    final List<Inscription> icts = this.ictRepository.findByActiviteAndFamille(activite, famille);
    icts.forEach(ict -> {
        final List<Ouverture> ouvertures = this.ouvertureRepository.findByActiviteAndGroupeAndDateDebut(
                activite, ict.getGroupe(),
                Date.from(Instant.from(startDate.atStartOfDay(ZoneId.systemDefault()))));
        ouvertures.forEach(o -> {
            final LocalDate date = LocalDate.from(((java.sql.Date) o.getDate()).toLocalDate());
            if (!jours.contains(date.getDayOfWeek())) {
                jours.add(date.getDayOfWeek());
            }
        });
    });

    return jours;
}

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

@Test
public void testCreateResourceTicketAsync() 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.createResourceTicketAsync("foo", new ResourceTicketCreateSpec(), new FutureCallback<Task>() {
        @Override//ww w  . j a  va 2  s  .  com
        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 testCreateResourceTicketAsync() 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.createResourceTicketAsync("foo", new ResourceTicketCreateSpec(), new FutureCallback<Task>() {
        @Override/* w  ww . ja va 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:org.openhab.binding.chromecast.internal.ChromecastStatusUpdater.java

private Object getValue(String channelId, Map<String, Object> metadata) {
    if (metadata == null) {
        return null;
    }//  w  w  w .  j a  v a 2  s .c o m

    if (channelId.equals(ChromecastBindingConstants.CHANNEL_BROADCAST_DATE)
            || channelId.equals(ChromecastBindingConstants.CHANNEL_RELEASE_DATE)
            || channelId.equals(ChromecastBindingConstants.CHANNEL_CREATION_DATE)) {
        String dateString = (String) metadata.get(channelId);
        if (dateString == null) {
            return null;
        }

        Instant instant = Instant.parse(dateString);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(Date.from(instant));

        return calendar;
    }

    return metadata.get(channelId);
}

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

@Test
public void serviceShouldNotUpdateTheMailStateWhenNoSenderPassThroughHasDefaultValue() throws Exception {
    FakeMailetConfig mailetConfig = FakeMailetConfig.builder().mailetName(MAILET_NAME)
            .mailetContext(fakeMailContext).build();
    dsnBounce.init(mailetConfig);/*from  w w  w.j a  v a2 s  .com*/

    FakeMail mail = FakeMail.builder().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);

    assertThat(mail.getState()).isNull();
}

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

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

    VmApi vmApi = new VmApi(restClient);

    Task task = vmApi.performStartOperation("foo");
    assertEquals(task, responseTask);/*from   ww w  .  ja  va  2 s .com*/
}