List of usage examples for java.util Date from
public static Date from(Instant instant)
From source file:edu.usu.sdl.openstorefront.service.UserServiceImpl.java
@Override public void cleanupOldUserMessages() { int maxDays = Convert.toInteger(PropertiesManager.getValue(PropertiesManager.KEY_MESSAGE_KEEP_DAYS, "30")); LocalDateTime archiveTime = LocalDateTime.now(); archiveTime = archiveTime.minusDays(maxDays); archiveTime = archiveTime.truncatedTo(ChronoUnit.DAYS); String deleteQuery = "updateDts < :maxUpdateDts AND activeStatus = :activeStatusParam"; ZonedDateTime zdt = archiveTime.atZone(ZoneId.systemDefault()); Date archiveDts = Date.from(zdt.toInstant()); Map<String, Object> queryParams = new HashMap<>(); queryParams.put("maxUpdateDts", archiveDts); queryParams.put("activeStatusParam", UserMessage.INACTIVE_STATUS); persistenceService.deleteByQuery(UserMessage.class, deleteQuery, queryParams); }
From source file:io.gravitee.gateway.services.sync.SyncManagerTest.java
@Test public void test_shouldUpdateIfLastEventIsStopAPI() throws Exception { io.gravitee.repository.management.model.Api api = new RepositoryApiBuilder().id("api-test") .updatedAt(new Date()).definition("test").lifecycleState(LifecycleState.STARTED).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("test").lifecycleState(LifecycleState.STOPPED) .build();//from ww w .ja v a2 s .co m final Api mockApi = mockApi(api); mockApi(api2); final Event mockEvent = mockEvent(api, EventType.PUBLISH_API); final Event mockEvent2 = mockEvent(api2, EventType.STOP_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(Collections.singletonList(mockEvent)); when(apiRepository.findAll()).thenReturn(Collections.singleton(api)); when(apiManager.apis()).thenReturn(Collections.singleton(mockApi)); syncManager.refresh(); 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(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:org.codice.ddf.catalog.ui.util.EndpointUtil.java
@SuppressWarnings("squid:S2293") // results in class cast error public Map.Entry<String, Object> convertDateEntries(Map.Entry<String, Object> entry) { if (entry == null || entry.getKey() == null || entry.getValue() == null) { return entry; }//from ww w.j a v a2 s.co m return attributeRegistry.lookup(entry.getKey()) .filter(ad -> AttributeType.AttributeFormat.DATE.equals(ad.getType().getAttributeFormat())) .map(attributeDescriptor -> { Serializable date = parseDate((Serializable) entry.getValue()); if (date instanceof Instant) { // must be Date object for solr to parse correctly date = Date.from((Instant) date); } return (Map.Entry<String, Object>) new AbstractMap.SimpleEntry<String, Object>(entry.getKey(), date); }).orElse(entry); }
From source file:com.vmware.photon.controller.client.resource.VmApiTest.java
@Test public void testGetNetworks() 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_OK); VmApi vmApi = new VmApi(restClient); Task task = vmApi.getNetworks("foo"); assertEquals(task, responseTask);// w w w . j a v a 2 s .com }
From source file:com.vmware.photon.controller.api.client.resource.VmApiTest.java
@Test public void testDetachIsoAsync() 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.detachIsoAsync("foo", new FutureCallback<Task>() { @Override//from ww w .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 testDetachIsoAsync() 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.detachIsoAsync("foo", new FutureCallback<Task>() { @Override//from w w w.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.VmApiTest.java
@Test public void testGetNetworks() 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.getNetworks("foo"); assertEquals(task, responseTask);/*from ww w.ja v a 2 s . c om*/ }
From source file:com.vmware.photon.controller.api.client.resource.VmRestApiTest.java
@Test public void testGetNetworks() 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 VmRestApi(restClient); Task task = vmApi.getNetworks("foo"); assertEquals(task, responseTask);//from w w w.j a v a2 s . c o m }
From source file:com.vmware.photon.controller.api.client.resource.VmApiTest.java
@Test public void testGetNetworksAsync() 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.getNetworksAsync("foo", new FutureCallback<Task>() { @Override// w w w . j ava 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.VmRestApiTest.java
@Test public void testGetNetworksAsync() 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.getNetworksAsync("foo", new FutureCallback<Task>() { @Override/*from w w w.j av 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)); }