List of usage examples for java.util Date from
public static Date from(Instant instant)
From source file:org.silverpeas.core.web.http.FileResponse.java
/** * Gets last modified date./*from www.java 2 s . c o m*/ * @param path the path of the file to send. * @return the last modified date. * @throws IOException if the file is not readable. */ Date getLastModifiedDate(final Path path) throws IOException { return Date.from(Files.getLastModifiedTime(path).toInstant()); }
From source file:org.noorganization.instalist.server.api.CategoriesResourceTest.java
@Test public void testPutCategory() throws Exception { final String url = "/groups/%d/categories/%s"; Response wrongTokenResponse = target(String.format(url, mGroup.getId(), mCategory.getId())).request() .header(HttpHeaders.AUTHORIZATION, "X-Token wrongToken") .put(Entity.json(new CategoryInfo().withName("dev111"))); assertEquals(401, wrongTokenResponse.getStatus()); Response wrongGroupResponse = target( String.format(url, mNotAccessibleGroup.getId(), mCategory.getUUID().toString())).request() .header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken) .put(Entity.json(new CategoryInfo().withName("dev111"))); assertEquals(401, wrongGroupResponse.getStatus()); Response wrongCatResponse = target( String.format(url, mGroup.getId(), mNotAccessibleCategory.getUUID().toString())).request() .header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken) .put(Entity.json(new CategoryInfo().withName("dev111"))); assertEquals(404, wrongCatResponse.getStatus()); Response invalidCatResponse = target(String.format(url, mGroup.getId(), mCategory.getUUID().toString())) .request().header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).put(Entity.json(new CategoryInfo() .withUUID(mNotAccessibleCategory.getUUID().toString()).withName("dev111"))); assertEquals(400, invalidCatResponse.getStatus()); mManager.refresh(mNotAccessibleCategory); mManager.refresh(mCategory);//from w w w . j a v a 2s . co m assertEquals("cat1", mCategory.getName()); assertEquals("cat2", mNotAccessibleCategory.getName()); Instant beforeChange = Instant.now(); Thread.sleep(200); Response validCatResponse = target(String.format(url, mGroup.getId(), mCategory.getUUID().toString())) .request().header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken) .put(Entity.json(new CategoryInfo().withName("dev111"))); assertEquals(200, validCatResponse.getStatus()); mManager.refresh(mCategory); assertEquals("dev111", mCategory.getName()); assertTrue(beforeChange.isBefore(mCategory.getUpdated())); Response conflictCatResponse = target(String.format(url, mGroup.getId(), mCategory.getUUID().toString())) .request().header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken) .put(Entity.json(new CategoryInfo().withName("cat1").withLastChanged(Date.from(beforeChange)))); assertEquals(409, conflictCatResponse.getStatus()); mManager.refresh(mCategory); assertEquals("dev111", mCategory.getName()); assertTrue(beforeChange.isBefore(mCategory.getUpdated())); }
From source file:com.vmware.photon.controller.api.client.resource.ProjectApiTest.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); ProjectApi projectApi = new ProjectApi(restClient); Task task = projectApi.delete("foo"); assertEquals(task, responseTask);/*www. j a v a 2 s . c o m*/ }
From source file:com.vmware.photon.controller.api.client.resource.ProjectRestApiTest.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); ProjectApi projectApi = new ProjectRestApi(restClient); Task task = projectApi.delete("foo"); assertEquals(task, responseTask);//from w ww. ja v a 2 s. co m }
From source file:ddf.catalog.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(metacard.getAttribute(RegistryObjectMetacardType.LIVE_DATE).getValue(), is(date)); date = Date.from(ZonedDateTime.parse("2015-11-01T13:15:30Z").toInstant()); assertThat(metacard.getAttribute(RegistryObjectMetacardType.DATA_START_DATE).getValue(), is(date)); date = Date.from(ZonedDateTime.parse("2015-12-01T23:01:40Z").toInstant()); assertThat(metacard.getAttribute(RegistryObjectMetacardType.DATA_END_DATE).getValue(), is(date)); date = Date.from(ZonedDateTime.parse("2016-01-26T17:16:34.996Z").toInstant()); assertThat(metacard.getAttribute(Metacard.MODIFIED).getValue(), is(date)); assertThat(metacard.getAttribute(RegistryObjectMetacardType.LINKS).getValue(), is("https://some/link/to/my/repo")); assertThat(metacard.getAttribute(Metacard.GEOGRAPHY).getValue(), is("POINT (112.267472 33.467944)")); assertThat(metacard.getAttribute(RegistryObjectMetacardType.REGION).getValue(), is("USA")); List<Serializable> serializableList = metacard.getAttribute(RegistryObjectMetacardType.DATA_SOURCES) .getValues();/*from w w w . ja va2 s . c o m*/ assertThat(serializableList.size(), is(2)); assertThat(serializableList, hasItem("youtube")); assertThat(serializableList, hasItem("myCamera")); serializableList = metacard.getAttribute(RegistryObjectMetacardType.DATA_TYPES).getValues(); assertThat(serializableList.size(), is(2)); assertThat(serializableList, hasItem("video")); assertThat(serializableList, hasItem("sensor")); assertThat(metacard.getAttribute(RegistryObjectMetacardType.SECURITY_LEVEL).getValue(), is("role=guest")); assertThat(metacard.getAttribute(Metacard.TITLE).getValue(), is("Node Name")); assertThat(metacard.getAttribute(Metacard.DESCRIPTION).getValue(), is("A little something describing this node in less than 1024 characters")); assertThat(metacard.getAttribute(Metacard.CONTENT_TYPE_VERSION).getValue(), is("2.9.x")); serializableList = metacard.getAttribute(RegistryObjectMetacardType.SERVICE_BINDING_TYPES).getValues(); assertThat(serializableList.size(), is(2)); assertThat(serializableList, hasItem("Csw_Federated_Source")); assertThat(serializableList, hasItem("soap13")); serializableList = metacard.getAttribute(RegistryObjectMetacardType.SERVICE_BINDINGS).getValues(); assertThat(serializableList.size(), is(2)); assertThat(serializableList, hasItem("REST")); assertThat(serializableList, hasItem("SOAP")); assertThat(metacard.getAttribute(RegistryObjectMetacardType.ORGANIZATION_NAME).getValue(), is("Codice")); assertThat(metacard.getAttribute(RegistryObjectMetacardType.ORGANIZATION_EMAIL).getValue(), is("emailaddress@something.com")); assertThat(metacard.getAttribute(RegistryObjectMetacardType.ORGANIZATION_PHONE_NUMBER).getValue(), is("(555) 555-5555 extension 1234")); assertThat(metacard.getAttribute(RegistryObjectMetacardType.ORGANIZATION_ADDRESS).getValue(), is("1234 Some Street, Phoenix, AZ 85037, USA")); assertThat(metacard.getAttribute(Metacard.POINT_OF_CONTACT).getValue(), is("john doe, (111) 111-1111 extension 1234, emailaddress@something.com")); }
From source file:io.gravitee.gateway.services.sync.SyncManagerTest.java
@Test public void test_twiceWithTwoApis_apiToUpdate() throws Exception { io.gravitee.repository.management.model.Api api = new RepositoryApiBuilder().id("api-test") .updatedAt(new Date()).definition("test").build(); Instant updateDateInst = api.getUpdatedAt().toInstant().plus(Duration.ofHours(1)); io.gravitee.repository.management.model.Api api2 = new RepositoryApiBuilder().id("api-test") .updatedAt(Date.from(updateDateInst)).definition("test2").build(); final Api mockApi = mockApi(api); mockApi(api2);//from w w w .j ava2 s . co m final Event mockEvent = mockEvent(api, EventType.PUBLISH_API); final Event mockEvent2 = mockEvent(api2, EventType.PUBLISH_API); List<Event> events = new ArrayList<Event>(); events.add(mockEvent); events.add(mockEvent2); when(eventRepository.search(new EventCriteria.Builder() .types(EventType.PUBLISH_API, EventType.UNPUBLISH_API, EventType.START_API, EventType.STOP_API) .build())).thenReturn(events); when(apiRepository.findAll()).thenReturn(Collections.singleton(api)); syncManager.refresh(); when(apiRepository.findAll()).thenReturn(Collections.singleton(api2)); when(apiManager.get(api.getId())).thenReturn(mockApi); syncManager.refresh(); verify(apiManager).deploy(mockApi); verify(apiManager).update(mockApi); verify(apiManager, never()).undeploy(any(String.class)); }
From source file:com.vmware.photon.controller.api.client.resource.VmApiTest.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); VmApi vmApi = new VmApi(restClient); final CountDownLatch latch = new CountDownLatch(1); vmApi.deleteAsync("foo", new FutureCallback<Task>() { @Override// www . ja 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.VmRestApiTest.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); VmApi vmApi = new VmRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); vmApi.deleteAsync("foo", new FutureCallback<Task>() { @Override/*from ww w . j a v a 2s .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.orange.clara.cloud.servicedbdumper.task.job.JobFactoryTest.java
@Test public void when_purge_finished_jobs_and_jobs_in_error_exist_it_should_delete_job_which_pass_expiration_and_have_null_database_target_and_source_and_service_instance() { Job jobNotExpired = new Job(); jobNotExpired.setUpdatedAt(new Date()); jobNotExpired.setDatabaseRefSrc(new DatabaseRef()); Date date = new Date(); LocalDateTime localDateTime = LocalDateTime.from(date.toInstant().atZone(ZoneId.systemDefault())) .minusMinutes(jobFinishedDeleteExpirationMinutes + 1); Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant(); Job jobExpired = new Job(); jobExpired.setUpdatedAt(Date.from(instant)); when(jobRepo.findByJobEventOrderByUpdatedAtDesc(anyObject())) .thenReturn(Arrays.asList(jobNotExpired, jobExpired)); jobFactory.purgeFinishedJob();//from w ww . j a v a 2s. co m verify(jobRepo, times(1)).delete((Job) notNull()); }
From source file:com.vmware.photon.controller.api.client.resource.TenantsApiTest.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 TenantsApi(restClient); Task task = tenantsApi.delete("foo"); assertEquals(task, responseTask);/*w w w.ja va2 s . c om*/ }