Replace use of Date with OffsetDateTime and Instant in Actuator
Closes gh-10976
This commit is contained in:
parent
a99adb1047
commit
2b99962a85
|
@ -321,6 +321,12 @@
|
|||
<artifactId>spring-session-core</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<!-- Runtime -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<!-- Annotation processing -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,11 +16,10 @@
|
|||
|
||||
package org.springframework.boot.actuate.autoconfigure.endpoint.web.documentation;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -74,10 +73,9 @@ public class AuditEventsEndpointDocumentationTests
|
|||
|
||||
@Test
|
||||
public void filteredAuditEvents() throws Exception {
|
||||
ZonedDateTime now = ZonedDateTime.now();
|
||||
OffsetDateTime now = OffsetDateTime.now();
|
||||
String queryTimestamp = DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(now);
|
||||
Date date = new Date(now.toEpochSecond() * 1000);
|
||||
given(this.repository.find("alice", date, "logout")).willReturn(
|
||||
given(this.repository.find("alice", now.toInstant(), "logout")).willReturn(
|
||||
Arrays.asList(new AuditEvent("alice", "logout", Collections.emptyMap())));
|
||||
this.mockMvc
|
||||
.perform(get("/actuator/auditevents").param("principal", "alice")
|
||||
|
@ -94,7 +92,7 @@ public class AuditEventsEndpointDocumentationTests
|
|||
parameterWithName("type").description(
|
||||
"Restricts the events to those with the given "
|
||||
+ "type. Optional."))));
|
||||
verify(this.repository).find("alice", date, "logout");
|
||||
verify(this.repository).find("alice", now.toInstant(), "logout");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -17,12 +17,11 @@
|
|||
package org.springframework.boot.actuate.audit;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.Instant;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
|
||||
|
@ -46,7 +45,7 @@ import org.springframework.util.Assert;
|
|||
@JsonInclude(Include.NON_EMPTY)
|
||||
public class AuditEvent implements Serializable {
|
||||
|
||||
private final Date timestamp;
|
||||
private final Instant timestamp;
|
||||
|
||||
private final String principal;
|
||||
|
||||
|
@ -61,7 +60,7 @@ public class AuditEvent implements Serializable {
|
|||
* @param data The event data
|
||||
*/
|
||||
public AuditEvent(String principal, String type, Map<String, Object> data) {
|
||||
this(new Date(), principal, type, data);
|
||||
this(Instant.now(), principal, type, data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,7 +71,7 @@ public class AuditEvent implements Serializable {
|
|||
* @param data The event data in the form 'key=value' or simply 'key'
|
||||
*/
|
||||
public AuditEvent(String principal, String type, String... data) {
|
||||
this(new Date(), principal, type, convert(data));
|
||||
this(Instant.now(), principal, type, convert(data));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,7 +81,7 @@ public class AuditEvent implements Serializable {
|
|||
* @param type the event type
|
||||
* @param data The event data
|
||||
*/
|
||||
public AuditEvent(Date timestamp, String principal, String type,
|
||||
public AuditEvent(Instant timestamp, String principal, String type,
|
||||
Map<String, Object> data) {
|
||||
Assert.notNull(timestamp, "Timestamp must not be null");
|
||||
Assert.notNull(type, "Type must not be null");
|
||||
|
@ -107,11 +106,10 @@ public class AuditEvent implements Serializable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the date/time that the even was logged.
|
||||
* Returns the date/time that the event was logged.
|
||||
* @return the timestamp
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ssZ")
|
||||
public Date getTimestamp() {
|
||||
public Instant getTimestamp() {
|
||||
return this.timestamp;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package org.springframework.boot.actuate.audit;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -43,6 +43,6 @@ public interface AuditEventRepository {
|
|||
* @return audit events of specified type relating to the principal
|
||||
* @since 1.4.0
|
||||
*/
|
||||
List<AuditEvent> find(String principal, Date after, String type);
|
||||
List<AuditEvent> find(String principal, Instant after, String type);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,7 +16,7 @@
|
|||
|
||||
package org.springframework.boot.actuate.audit;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
|
@ -40,10 +40,10 @@ public class AuditEventsEndpoint {
|
|||
}
|
||||
|
||||
@ReadOperation
|
||||
public AuditEventsDescriptor eventsWithPrincipalDateAfterAndType(String principal,
|
||||
Date after, String type) {
|
||||
return new AuditEventsDescriptor(
|
||||
this.auditEventRepository.find(principal, after, type));
|
||||
public AuditEventsDescriptor events(String principal, OffsetDateTime after,
|
||||
String type) {
|
||||
return new AuditEventsDescriptor(this.auditEventRepository.find(principal,
|
||||
after == null ? null : after.toInstant(), type));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,7 +16,7 @@
|
|||
|
||||
package org.springframework.boot.actuate.audit;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
import org.springframework.boot.actuate.audit.AuditEventsEndpoint.AuditEventsDescriptor;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
|
||||
|
@ -40,10 +40,9 @@ public class AuditEventsEndpointWebExtension {
|
|||
}
|
||||
|
||||
@ReadOperation
|
||||
public WebEndpointResponse<AuditEventsDescriptor> eventsWithPrincipalDateAfterAndType(
|
||||
@Nullable String principal, Date after, @Nullable String type) {
|
||||
AuditEventsDescriptor auditEvents = this.delegate
|
||||
.eventsWithPrincipalDateAfterAndType(principal, after, type);
|
||||
public WebEndpointResponse<AuditEventsDescriptor> events(@Nullable String principal,
|
||||
OffsetDateTime after, @Nullable String type) {
|
||||
AuditEventsDescriptor auditEvents = this.delegate.events(principal, after, type);
|
||||
return new WebEndpointResponse<>(auditEvents);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,7 +16,7 @@
|
|||
|
||||
package org.springframework.boot.actuate.audit;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
import org.springframework.boot.actuate.audit.AuditEventsEndpoint.AuditEventsDescriptor;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
|
||||
|
@ -39,15 +39,14 @@ public class AuditEventsJmxEndpointExtension {
|
|||
}
|
||||
|
||||
@ReadOperation
|
||||
public AuditEventsDescriptor eventsWithDateAfter(Date dateAfter) {
|
||||
return this.delegate.eventsWithPrincipalDateAfterAndType(null, dateAfter, null);
|
||||
public AuditEventsDescriptor eventsAfter(OffsetDateTime after) {
|
||||
return this.delegate.events(null, after, null);
|
||||
}
|
||||
|
||||
@ReadOperation
|
||||
public AuditEventsDescriptor eventsWithPrincipalAndDateAfter(String principal,
|
||||
Date dateAfter) {
|
||||
return this.delegate.eventsWithPrincipalDateAfterAndType(principal, dateAfter,
|
||||
null);
|
||||
public AuditEventsDescriptor eventsWithPrincipalAndAfter(String principal,
|
||||
OffsetDateTime after) {
|
||||
return this.delegate.events(principal, after, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package org.springframework.boot.actuate.audit;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.Instant;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -70,7 +70,7 @@ public class InMemoryAuditEventRepository implements AuditEventRepository {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<AuditEvent> find(String principal, Date after, String type) {
|
||||
public List<AuditEvent> find(String principal, Instant after, String type) {
|
||||
LinkedList<AuditEvent> events = new LinkedList<>();
|
||||
synchronized (this.monitor) {
|
||||
for (int i = 0; i < this.events.length; i++) {
|
||||
|
@ -83,10 +83,11 @@ public class InMemoryAuditEventRepository implements AuditEventRepository {
|
|||
return events;
|
||||
}
|
||||
|
||||
private boolean isMatch(String principal, Date after, String type, AuditEvent event) {
|
||||
private boolean isMatch(String principal, Instant after, String type,
|
||||
AuditEvent event) {
|
||||
boolean match = true;
|
||||
match = match && (principal == null || event.getPrincipal().equals(principal));
|
||||
match = match && (after == null || event.getTimestamp().compareTo(after) >= 0);
|
||||
match = match && (after == null || event.getTimestamp().isAfter(after));
|
||||
match = match && (type == null || event.getType().equals(type));
|
||||
return match;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,7 +16,7 @@
|
|||
|
||||
package org.springframework.boot.actuate.audit.listener;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.Instant;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.boot.actuate.audit.AuditEvent;
|
||||
|
@ -64,9 +64,9 @@ public class AuditApplicationEvent extends ApplicationEvent {
|
|||
* @param principal the principal
|
||||
* @param type the event type
|
||||
* @param data the event data
|
||||
* @see AuditEvent#AuditEvent(Date, String, String, Map)
|
||||
* @see AuditEvent#AuditEvent(Instant, String, String, Map)
|
||||
*/
|
||||
public AuditApplicationEvent(Date timestamp, String principal, String type,
|
||||
public AuditApplicationEvent(Instant timestamp, String principal, String type,
|
||||
Map<String, Object> data) {
|
||||
this(new AuditEvent(timestamp, principal, type, data));
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -18,29 +18,25 @@ package org.springframework.boot.actuate.endpoint.convert;
|
|||
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.convert.converter.ConverterRegistry;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* A {@link String} to {@link Date} {@link Converter} that uses
|
||||
* A {@link String} to {@link OffsetDateTime} {@link Converter} that uses
|
||||
* {@link DateTimeFormatter#ISO_OFFSET_DATE_TIME ISO offset} parsing.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Stephane Nicoll
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public class IsoOffsetDateTimeConverter implements Converter<String, Date> {
|
||||
public class IsoOffsetDateTimeConverter implements Converter<String, OffsetDateTime> {
|
||||
|
||||
@Override
|
||||
public Date convert(String source) {
|
||||
public OffsetDateTime convert(String source) {
|
||||
if (StringUtils.hasLength(source)) {
|
||||
OffsetDateTime offsetDateTime = OffsetDateTime.parse(source,
|
||||
DateTimeFormatter.ISO_OFFSET_DATE_TIME);
|
||||
return new Date(TimeUnit.SECONDS.toMillis(offsetDateTime.toEpochSecond()));
|
||||
return OffsetDateTime.parse(source, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -18,9 +18,9 @@ package org.springframework.boot.actuate.endpoint.jmx.annotation;
|
|||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
@ -113,7 +113,7 @@ class JmxEndpointOperationFactory implements OperationFactory<JmxOperation> {
|
|||
if (type.isEnum()) {
|
||||
return String.class;
|
||||
}
|
||||
if (Date.class.isAssignableFrom(type)) {
|
||||
if (Instant.class.isAssignableFrom(type)) {
|
||||
return String.class;
|
||||
}
|
||||
if (type.getName().startsWith("java.")) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,7 +16,7 @@
|
|||
|
||||
package org.springframework.boot.actuate.flyway;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -99,7 +99,7 @@ public class FlywayEndpoint {
|
|||
|
||||
private final String installedBy;
|
||||
|
||||
private final Date installedOn;
|
||||
private final Instant installedOn;
|
||||
|
||||
private final Integer installedRank;
|
||||
|
||||
|
@ -113,7 +113,7 @@ public class FlywayEndpoint {
|
|||
this.script = info.getScript();
|
||||
this.state = info.getState();
|
||||
this.installedBy = info.getInstalledBy();
|
||||
this.installedOn = info.getInstalledOn();
|
||||
this.installedOn = Instant.ofEpochMilli(info.getInstalledOn().getTime());
|
||||
this.installedRank = info.getInstalledRank();
|
||||
this.executionTime = info.getExecutionTime();
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ public class FlywayEndpoint {
|
|||
return this.installedBy;
|
||||
}
|
||||
|
||||
public Date getInstalledOn() {
|
||||
public Instant getInstalledOn() {
|
||||
return this.installedOn;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,7 +16,7 @@
|
|||
|
||||
package org.springframework.boot.actuate.info;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.Instant;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
|
@ -59,7 +59,7 @@ public class GitInfoContributor extends InfoPropertiesInfoContributor<GitPropert
|
|||
|
||||
/**
|
||||
* Post-process the content to expose. By default, well known keys representing dates
|
||||
* are converted to {@link Date} instances.
|
||||
* are converted to {@link Instant} instances.
|
||||
* @param content the content to expose
|
||||
*/
|
||||
@Override
|
||||
|
@ -67,7 +67,7 @@ public class GitInfoContributor extends InfoPropertiesInfoContributor<GitPropert
|
|||
replaceValue(getNestedMap(content, "commit"), "time",
|
||||
getProperties().getCommitTime());
|
||||
replaceValue(getNestedMap(content, "build"), "time",
|
||||
getProperties().getDate("build.time"));
|
||||
getProperties().getInstant("build.time"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,7 +16,7 @@
|
|||
|
||||
package org.springframework.boot.actuate.liquibase;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -119,7 +119,7 @@ public class LiquibaseEndpoint {
|
|||
|
||||
private final Set<String> contexts;
|
||||
|
||||
private final Date dateExecuted;
|
||||
private final Instant dateExecuted;
|
||||
|
||||
private final String deploymentId;
|
||||
|
||||
|
@ -142,7 +142,8 @@ public class LiquibaseEndpoint {
|
|||
this.changeLog = ranChangeSet.getChangeLog();
|
||||
this.comments = ranChangeSet.getComments();
|
||||
this.contexts = ranChangeSet.getContextExpression().getContexts();
|
||||
this.dateExecuted = ranChangeSet.getDateExecuted();
|
||||
this.dateExecuted = Instant
|
||||
.ofEpochMilli(ranChangeSet.getDateExecuted().getTime());
|
||||
this.deploymentId = ranChangeSet.getDeploymentId();
|
||||
this.description = ranChangeSet.getDescription();
|
||||
this.execType = ranChangeSet.getExecType();
|
||||
|
@ -170,7 +171,7 @@ public class LiquibaseEndpoint {
|
|||
return this.contexts;
|
||||
}
|
||||
|
||||
public Date getDateExecuted() {
|
||||
public Instant getDateExecuted() {
|
||||
return this.dateExecuted;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,9 +16,9 @@
|
|||
|
||||
package org.springframework.boot.actuate.trace;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -66,7 +66,7 @@ public class InMemoryTraceRepository implements TraceRepository {
|
|||
|
||||
@Override
|
||||
public void add(Map<String, Object> map) {
|
||||
Trace trace = new Trace(new Date(), map);
|
||||
Trace trace = new Trace(Instant.now(), map);
|
||||
synchronized (this.traces) {
|
||||
while (this.traces.size() >= this.capacity) {
|
||||
this.traces.remove(this.reverse ? this.capacity - 1 : 0);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,7 +16,7 @@
|
|||
|
||||
package org.springframework.boot.actuate.trace;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.Instant;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
@ -29,18 +29,18 @@ import org.springframework.util.Assert;
|
|||
*/
|
||||
public final class Trace {
|
||||
|
||||
private final Date timestamp;
|
||||
private final Instant timestamp;
|
||||
|
||||
private final Map<String, Object> info;
|
||||
|
||||
public Trace(Date timestamp, Map<String, Object> info) {
|
||||
public Trace(Instant timestamp, Map<String, Object> info) {
|
||||
Assert.notNull(timestamp, "Timestamp must not be null");
|
||||
Assert.notNull(info, "Info must not be null");
|
||||
this.timestamp = timestamp;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public Date getTimestamp() {
|
||||
public Instant getTimestamp() {
|
||||
return this.timestamp;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,8 +16,8 @@
|
|||
|
||||
package org.springframework.boot.actuate.audit;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
@ -44,18 +44,16 @@ public class AuditEventsEndpointTests {
|
|||
public void eventsWithType() {
|
||||
given(this.repository.find(null, null, "type"))
|
||||
.willReturn(Collections.singletonList(this.event));
|
||||
List<AuditEvent> result = this.endpoint
|
||||
.eventsWithPrincipalDateAfterAndType(null, null, "type").getEvents();
|
||||
List<AuditEvent> result = this.endpoint.events(null, null, "type").getEvents();
|
||||
assertThat(result).isEqualTo(Collections.singletonList(this.event));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eventsWithDateAfter() {
|
||||
Date date = new Date();
|
||||
given(this.repository.find(null, date, null))
|
||||
public void eventsCreatedAfter() {
|
||||
OffsetDateTime now = OffsetDateTime.now();
|
||||
given(this.repository.find(null, now.toInstant(), null))
|
||||
.willReturn(Collections.singletonList(this.event));
|
||||
List<AuditEvent> result = this.endpoint
|
||||
.eventsWithPrincipalDateAfterAndType(null, date, null).getEvents();
|
||||
List<AuditEvent> result = this.endpoint.events(null, now, null).getEvents();
|
||||
assertThat(result).isEqualTo(Collections.singletonList(this.event));
|
||||
}
|
||||
|
||||
|
@ -63,8 +61,7 @@ public class AuditEventsEndpointTests {
|
|||
public void eventsWithPrincipal() {
|
||||
given(this.repository.find("Joan", null, null))
|
||||
.willReturn(Collections.singletonList(this.event));
|
||||
List<AuditEvent> result = this.endpoint
|
||||
.eventsWithPrincipalDateAfterAndType("Joan", null, null).getEvents();
|
||||
List<AuditEvent> result = this.endpoint.events("Joan", null, null).getEvents();
|
||||
assertThat(result).isEqualTo(Collections.singletonList(this.event));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -18,7 +18,6 @@ package org.springframework.boot.actuate.audit;
|
|||
|
||||
import java.time.Instant;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
|
||||
import net.minidev.json.JSONArray;
|
||||
import org.junit.Test;
|
||||
|
@ -105,7 +104,7 @@ public class AuditEventsEndpointWebIntegrationTests {
|
|||
}
|
||||
|
||||
private AuditEvent createEvent(String instant, String principal, String type) {
|
||||
return new AuditEvent(Date.from(Instant.parse(instant)), principal, type,
|
||||
return new AuditEvent(Instant.parse(instant), principal, type,
|
||||
Collections.emptyMap());
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,8 +16,8 @@
|
|||
|
||||
package org.springframework.boot.actuate.audit;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
@ -42,21 +42,21 @@ public class AuditEventsJmxEndpointExtensionTests {
|
|||
Collections.singletonMap("a", "alpha"));
|
||||
|
||||
@Test
|
||||
public void eventsWithDateAfter() {
|
||||
Date date = new Date();
|
||||
given(this.repository.find(null, date, null))
|
||||
public void eventsCreatedAfter() {
|
||||
OffsetDateTime now = OffsetDateTime.now();
|
||||
given(this.repository.find(null, now.toInstant(), null))
|
||||
.willReturn(Collections.singletonList(this.event));
|
||||
List<AuditEvent> result = this.extension.eventsWithDateAfter(date).getEvents();
|
||||
List<AuditEvent> result = this.extension.eventsAfter(now).getEvents();
|
||||
assertThat(result).isEqualTo(Collections.singletonList(this.event));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eventsWithPrincipalAndDateAfter() {
|
||||
Date date = new Date();
|
||||
given(this.repository.find("Joan", date, null))
|
||||
OffsetDateTime now = OffsetDateTime.now();
|
||||
given(this.repository.find("Joan", now.toInstant(), null))
|
||||
.willReturn(Collections.singletonList(this.event));
|
||||
List<AuditEvent> result = this.extension
|
||||
.eventsWithPrincipalAndDateAfter("Joan", date).getEvents();
|
||||
List<AuditEvent> result = this.extension.eventsWithPrincipalAndAfter("Joan", now)
|
||||
.getEvents();
|
||||
assertThat(result).isEqualTo(Collections.singletonList(this.event));
|
||||
}
|
||||
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
|
||||
package org.springframework.boot.actuate.audit;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -99,20 +99,17 @@ public class InMemoryAuditEventRepositoryTests {
|
|||
|
||||
@Test
|
||||
public void findByDate() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(2000, 1, 1, 0, 0, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
Instant instant = Instant.now();
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
InMemoryAuditEventRepository repository = new InMemoryAuditEventRepository();
|
||||
repository.add(new AuditEvent(calendar.getTime(), "dave", "a", data));
|
||||
calendar.add(Calendar.DAY_OF_YEAR, 1);
|
||||
repository.add(new AuditEvent(calendar.getTime(), "phil", "b", data));
|
||||
calendar.add(Calendar.DAY_OF_YEAR, 1);
|
||||
Date after = calendar.getTime();
|
||||
repository.add(new AuditEvent(calendar.getTime(), "dave", "c", data));
|
||||
calendar.add(Calendar.DAY_OF_YEAR, 1);
|
||||
repository.add(new AuditEvent(calendar.getTime(), "phil", "d", data));
|
||||
calendar.add(Calendar.DAY_OF_YEAR, 1);
|
||||
repository.add(new AuditEvent(instant, "dave", "a", data));
|
||||
repository
|
||||
.add(new AuditEvent(instant.plus(1, ChronoUnit.DAYS), "phil", "b", data));
|
||||
repository
|
||||
.add(new AuditEvent(instant.plus(2, ChronoUnit.DAYS), "dave", "c", data));
|
||||
repository
|
||||
.add(new AuditEvent(instant.plus(3, ChronoUnit.DAYS), "phil", "d", data));
|
||||
Instant after = instant.plus(1, ChronoUnit.DAYS);
|
||||
List<AuditEvent> events = repository.find(null, after, null);
|
||||
assertThat(events.size()).isEqualTo(2);
|
||||
assertThat(events.get(0).getType()).isEqualTo("c");
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,7 +16,7 @@
|
|||
|
||||
package org.springframework.boot.actuate.endpoint.convert;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
@ -77,7 +77,8 @@ public class ConversionServiceParameterMapperTests {
|
|||
@Test
|
||||
public void createShouldRegisterIsoOffsetDateTimeConverter() {
|
||||
ConversionServiceParameterMapper mapper = new ConversionServiceParameterMapper();
|
||||
Date mapped = mapper.mapParameter("2011-12-03T10:15:30+01:00", Date.class);
|
||||
OffsetDateTime mapped = mapper.mapParameter("2011-12-03T10:15:30+01:00",
|
||||
OffsetDateTime.class);
|
||||
assertThat(mapped).isNotNull();
|
||||
}
|
||||
|
||||
|
@ -87,7 +88,7 @@ public class ConversionServiceParameterMapperTests {
|
|||
ConversionServiceParameterMapper mapper = new ConversionServiceParameterMapper(
|
||||
conversionService);
|
||||
this.thrown.expect(ParameterMappingException.class);
|
||||
mapper.mapParameter("2011-12-03T10:15:30+01:00", Date.class);
|
||||
mapper.mapParameter("2011-12-03T10:15:30+01:00", OffsetDateTime.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,7 +16,7 @@
|
|||
|
||||
package org.springframework.boot.actuate.endpoint.convert;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -34,16 +34,17 @@ public class IsoOffsetDateTimeConverterTests {
|
|||
@Test
|
||||
public void convertShouldConvertIsoDate() {
|
||||
IsoOffsetDateTimeConverter converter = new IsoOffsetDateTimeConverter();
|
||||
Date date = converter.convert("2011-12-03T10:15:30+01:00");
|
||||
assertThat(date).isNotNull();
|
||||
OffsetDateTime time = converter.convert("2011-12-03T10:15:30+01:00");
|
||||
assertThat(time).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void registerConverterShouldRegister() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
IsoOffsetDateTimeConverter.registerConverter(service);
|
||||
Date date = service.convert("2011-12-03T10:15:30+01:00", Date.class);
|
||||
assertThat(date).isNotNull();
|
||||
OffsetDateTime time = service.convert("2011-12-03T10:15:30+01:00",
|
||||
OffsetDateTime.class);
|
||||
assertThat(time).isNotNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,7 +16,7 @@
|
|||
|
||||
package org.springframework.boot.actuate.info;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.Instant;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
|
@ -45,8 +45,8 @@ public class GitInfoContributorTests {
|
|||
assertThat(content.get("commit")).isInstanceOf(Map.class);
|
||||
Map<String, Object> commit = (Map<String, Object>) content.get("commit");
|
||||
Object commitTime = commit.get("time");
|
||||
assertThat(commitTime).isInstanceOf(Date.class);
|
||||
assertThat(((Date) commitTime).getTime()).isEqualTo(1457098593000L);
|
||||
assertThat(commitTime).isInstanceOf(Instant.class);
|
||||
assertThat(((Instant) commitTime).toEpochMilli()).isEqualTo(1457098593000L);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -79,7 +79,7 @@ public class ProjectInfoAutoConfigurationTests {
|
|||
assertThat(buildProperties.getArtifact()).isEqualTo("demo");
|
||||
assertThat(buildProperties.getName()).isEqualTo("Demo Project");
|
||||
assertThat(buildProperties.getVersion()).isEqualTo("0.0.1-SNAPSHOT");
|
||||
assertThat(buildProperties.getTime().getTime()).isEqualTo(1457100965000L);
|
||||
assertThat(buildProperties.getTime().toEpochMilli()).isEqualTo(1457100965000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -90,7 +90,7 @@ public class ProjectInfoAutoConfigurationTests {
|
|||
assertThat(buildProperties.getArtifact()).isEqualTo("acme");
|
||||
assertThat(buildProperties.getName()).isEqualTo("acme");
|
||||
assertThat(buildProperties.getVersion()).isEqualTo("1.0.1-SNAPSHOT");
|
||||
assertThat(buildProperties.getTime().getTime()).isEqualTo(1457088120000L);
|
||||
assertThat(buildProperties.getTime().toEpochMilli()).isEqualTo(1457088120000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -18,7 +18,7 @@ package org.springframework.boot.info;
|
|||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.time.Instant;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
|
@ -77,8 +77,8 @@ public class BuildProperties extends InfoProperties {
|
|||
* @return the build time
|
||||
* @see #get(String)
|
||||
*/
|
||||
public Date getTime() {
|
||||
return getDate("time");
|
||||
public Instant getTime() {
|
||||
return getInstant("time");
|
||||
}
|
||||
|
||||
private static Properties processEntries(Properties properties) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -18,7 +18,7 @@ package org.springframework.boot.info;
|
|||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.time.Instant;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
|
@ -73,8 +73,8 @@ public class GitProperties extends InfoProperties {
|
|||
* @return the commit time
|
||||
* @see #get(String)
|
||||
*/
|
||||
public Date getCommitTime() {
|
||||
return getDate("commit.time");
|
||||
public Instant getCommitTime() {
|
||||
return getInstant("commit.time");
|
||||
}
|
||||
|
||||
private static Properties processEntries(Properties properties) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,7 +16,7 @@
|
|||
|
||||
package org.springframework.boot.info;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.Instant;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
@ -55,16 +55,16 @@ public class InfoProperties implements Iterable<InfoProperties.Entry> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return the value of the specified property as a {@link Date} or {@code null} if the
|
||||
* value is not a valid {@link Long} representation of an epoch time.
|
||||
* Return the value of the specified property as an {@link Instant} or {@code null} if
|
||||
* the value is not a valid {@link Long} representation of an epoch time.
|
||||
* @param key the key of the property
|
||||
* @return the property value
|
||||
*/
|
||||
public Date getDate(String key) {
|
||||
public Instant getInstant(String key) {
|
||||
String s = get(key);
|
||||
if (s != null) {
|
||||
try {
|
||||
return new Date(Long.parseLong(s));
|
||||
return Instant.ofEpochMilli(Long.parseLong(s));
|
||||
}
|
||||
catch (NumberFormatException ex) {
|
||||
// Not valid epoch time
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -38,7 +38,7 @@ public class BuildPropertiesTests {
|
|||
assertThat(properties.getVersion()).isEqualTo("0.0.1");
|
||||
assertThat(properties.getTime()).isNotNull();
|
||||
assertThat(properties.get("time")).isEqualTo("1457098593000");
|
||||
assertThat(properties.getTime().getTime()).isEqualTo(1457098593000L);
|
||||
assertThat(properties.getTime().toEpochMilli()).isEqualTo(1457098593000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -53,7 +53,7 @@ public class GitPropertiesTests {
|
|||
createProperties("master", "abcdefg", null, "1457527123"));
|
||||
assertThat(properties.getCommitTime()).isNotNull();
|
||||
assertThat(properties.get("commit.time")).isEqualTo("1457527123000");
|
||||
assertThat(properties.getCommitTime().getTime()).isEqualTo(1457527123000L);
|
||||
assertThat(properties.getCommitTime().toEpochMilli()).isEqualTo(1457527123000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -62,7 +62,7 @@ public class GitPropertiesTests {
|
|||
createProperties("master", "abcdefg", null, "2016-03-04T14:36:33+0100"));
|
||||
assertThat(properties.getCommitTime()).isNotNull();
|
||||
assertThat(properties.get("commit.time")).isEqualTo("1457098593000");
|
||||
assertThat(properties.getCommitTime().getTime()).isEqualTo(1457098593000L);
|
||||
assertThat(properties.getCommitTime().toEpochMilli()).isEqualTo(1457098593000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue