List of usage examples for java.util Date from
public static Date from(Instant instant)
From source file:ddf.catalog.registry.converter.RegistryPackageConverter.java
private static List<Date> getSlotDateAttributes(SlotType1 slot) { List<Date> dates = new ArrayList<>(); if (slot.isSetValueList()) { ValueListType valueList = slot.getValueList().getValue(); if (valueList.isSetValue()) { List<String> values = valueList.getValue(); for (String dateString : values) { Date date = Date.from(ZonedDateTime.parse(dateString).toInstant()); if (date != null) { dates.add(date);//from w w w . j av a 2 s .co m } } } } return dates; }
From source file:com.vmware.photon.controller.api.client.resource.VmApiTest.java
@Test public void testDetachDiskFromVmAsync() 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.detachDiskAsync("foo", new VmDiskOperation(), new FutureCallback<Task>() { @Override/*from w w w .ja va 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:io.gravitee.gateway.services.sync.SyncManagerTest.java
@Test public void test_shouldUpdateIfLastEventIsStartAPI() throws Exception { io.gravitee.repository.management.model.Api api = new RepositoryApiBuilder().id("api-test") .updatedAt(new Date()).definition("test").lifecycleState(LifecycleState.STOPPED).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.STARTED) .build();/*from w w w.ja v a 2 s . co m*/ final Api mockApi = mockApi(api); mockApi(api2); final Event mockEvent = mockEvent(api, EventType.PUBLISH_API); final Event mockEvent2 = mockEvent(api2, EventType.START_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)); 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:com.vmware.photon.controller.api.client.resource.VmRestApiTest.java
@Test public void testDetachDiskFromVmAsync() 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.detachDiskAsync("foo", new VmDiskOperation(), new FutureCallback<Task>() { @Override// w w w. j av 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:com.streamsets.pipeline.lib.jdbc.JdbcUtil.java
public Field resultToField(ResultSetMetaData md, ResultSet rs, int columnIndex, int maxClobSize, int maxBlobSize, DataType userSpecifiedType, UnknownTypeAction unknownTypeAction, boolean timestampToString) throws SQLException, IOException, StageException { Field field;//from w ww. java 2 s . c o m if (userSpecifiedType != DataType.USE_COLUMN_TYPE) { // If user specifies the data type, overwrite the column type returned by database. field = Field.create(Field.Type.valueOf(userSpecifiedType.getLabel()), rs.getObject(columnIndex)); } else { // All types as of JDBC 2.0 are here: // https://docs.oracle.com/javase/8/docs/api/constant-values.html#java.sql.Types.ARRAY // Good source of recommended mappings is here: // http://www.cs.mun.ca/java-api-1.5/guide/jdbc/getstart/mapping.html switch (md.getColumnType(columnIndex)) { case Types.BIGINT: field = Field.create(Field.Type.LONG, rs.getObject(columnIndex)); break; case Types.BINARY: case Types.LONGVARBINARY: case Types.VARBINARY: field = Field.create(Field.Type.BYTE_ARRAY, rs.getBytes(columnIndex)); break; case Types.BIT: case Types.BOOLEAN: field = Field.create(Field.Type.BOOLEAN, rs.getObject(columnIndex)); break; case Types.CHAR: case Types.LONGNVARCHAR: case Types.LONGVARCHAR: case Types.NCHAR: case Types.NVARCHAR: case Types.VARCHAR: field = Field.create(Field.Type.STRING, rs.getObject(columnIndex)); break; case Types.CLOB: case Types.NCLOB: field = Field.create(Field.Type.STRING, getClobString(rs.getClob(columnIndex), maxClobSize)); break; case Types.BLOB: field = Field.create(Field.Type.BYTE_ARRAY, getBlobBytes(rs.getBlob(columnIndex), maxBlobSize)); break; case Types.DATE: field = Field.create(Field.Type.DATE, rs.getDate(columnIndex)); break; case Types.DECIMAL: case Types.NUMERIC: field = Field.create(Field.Type.DECIMAL, rs.getBigDecimal(columnIndex)); field.setAttribute(HeaderAttributeConstants.ATTR_SCALE, String.valueOf(rs.getMetaData().getScale(columnIndex))); field.setAttribute(HeaderAttributeConstants.ATTR_PRECISION, String.valueOf(rs.getMetaData().getPrecision(columnIndex))); break; case Types.DOUBLE: field = Field.create(Field.Type.DOUBLE, rs.getObject(columnIndex)); break; case Types.FLOAT: case Types.REAL: field = Field.create(Field.Type.FLOAT, rs.getObject(columnIndex)); break; case Types.INTEGER: field = Field.create(Field.Type.INTEGER, rs.getObject(columnIndex)); break; case Types.ROWID: field = Field.create(Field.Type.STRING, rs.getRowId(columnIndex).toString()); break; case Types.SMALLINT: case Types.TINYINT: field = Field.create(Field.Type.SHORT, rs.getObject(columnIndex)); break; case Types.TIME: field = Field.create(Field.Type.TIME, rs.getObject(columnIndex)); break; case Types.TIMESTAMP: final Timestamp timestamp = rs.getTimestamp(columnIndex); if (timestampToString) { field = Field.create(Field.Type.STRING, timestamp == null ? null : timestamp.toString()); } else { field = Field.create(Field.Type.DATETIME, timestamp); if (timestamp != null) { final long actualNanos = timestamp.getNanos() % NANOS_TO_MILLIS_ADJUSTMENT; if (actualNanos > 0) { field.setAttribute(FIELD_ATTRIBUTE_NANOSECONDS, String.valueOf(actualNanos)); } } } break; // Ugly hack until we can support LocalTime, LocalDate, LocalDateTime, etc. case Types.TIME_WITH_TIMEZONE: OffsetTime offsetTime = rs.getObject(columnIndex, OffsetTime.class); field = Field.create(Field.Type.TIME, Date.from(offsetTime.atDate(LocalDate.MIN).toInstant())); break; case Types.TIMESTAMP_WITH_TIMEZONE: OffsetDateTime offsetDateTime = rs.getObject(columnIndex, OffsetDateTime.class); field = Field.create(Field.Type.ZONED_DATETIME, offsetDateTime.toZonedDateTime()); break; //case Types.REF_CURSOR: // JDK8 only case Types.SQLXML: case Types.STRUCT: case Types.ARRAY: case Types.DATALINK: case Types.DISTINCT: case Types.JAVA_OBJECT: case Types.NULL: case Types.OTHER: case Types.REF: default: if (unknownTypeAction == null) { return null; } switch (unknownTypeAction) { case STOP_PIPELINE: throw new StageException(JdbcErrors.JDBC_37, md.getColumnType(columnIndex), md.getColumnLabel(columnIndex)); case CONVERT_TO_STRING: Object value = rs.getObject(columnIndex); if (value != null) { field = Field.create(Field.Type.STRING, rs.getObject(columnIndex).toString()); } else { field = Field.create(Field.Type.STRING, null); } break; default: throw new IllegalStateException("Unknown action: " + unknownTypeAction); } } } return field; }
From source file:com.vmware.photon.controller.api.client.resource.VmApiTest.java
@Test public void testUploadAndAttachIso() 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.uploadAndAttachIso("foo", "file"); assertEquals(task, responseTask);//w w w . j av a2 s.c om }
From source file:com.vmware.photon.controller.api.client.resource.VmRestApiTest.java
@Test public void testUploadAndAttachIso() 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.uploadAndAttachIso("foo", "file"); assertEquals(task, responseTask);/*w ww . j av a 2 s . com*/ }
From source file:com.vmware.photon.controller.api.client.resource.VmApiTest.java
@Test public void testDetachIso() 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.detachIso("foo"); assertEquals(task, responseTask);/*from w w w . j ava 2 s. c o m*/ }
From source file:ddf.catalog.definition.impl.DefinitionParser.java
private Serializable parseDefaultValue(AttributeDescriptor descriptor, String defaultValue) { switch (descriptor.getType().getAttributeFormat()) { case BOOLEAN: return Boolean.parseBoolean(defaultValue); case DATE:/*from ww w . j a v a 2 s . c o m*/ return Date.from(Instant.from(DATE_FORMATTER.parse(defaultValue))); case DOUBLE: return Double.parseDouble(defaultValue); case FLOAT: return Float.parseFloat(defaultValue); case SHORT: return Short.parseShort(defaultValue); case INTEGER: return Integer.parseInt(defaultValue); case LONG: return Long.parseLong(defaultValue); case BINARY: return defaultValue.getBytes(StandardCharsets.UTF_8); default: return defaultValue; } }
From source file:com.vmware.photon.controller.api.client.resource.VmRestApiTest.java
@Test public void testDetachIso() 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.detachIso("foo"); assertEquals(task, responseTask);/*from w w w . ja v a 2 s . co m*/ }