mirror of https://github.com/apache/jclouds.git
Use the date service to parse dates
This commit is contained in:
parent
b2cc647ff2
commit
f086c050f9
|
@ -19,9 +19,7 @@ package org.jclouds.azurecompute.arm.features;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
import static org.testng.Assert.assertTrue;
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
import java.text.ParsePosition;
|
import java.util.Date;
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import org.jclouds.azurecompute.arm.domain.Metric;
|
import org.jclouds.azurecompute.arm.domain.Metric;
|
||||||
import org.jclouds.azurecompute.arm.domain.MetricData;
|
import org.jclouds.azurecompute.arm.domain.MetricData;
|
||||||
|
@ -41,11 +39,10 @@ public class MetricsApiMockTest extends BaseAzureComputeApiMockTest {
|
||||||
|
|
||||||
public void testList() throws Exception {
|
public void testList() throws Exception {
|
||||||
server.enqueue(jsonResponse("/metrics.json"));
|
server.enqueue(jsonResponse("/metrics.json"));
|
||||||
final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US);
|
|
||||||
final MetricsApi metricsApi = api.getMetricsApi(resourceId);
|
final MetricsApi metricsApi = api.getMetricsApi(resourceId);
|
||||||
assertEquals(metricsApi.list(filter), ImmutableList.of(Metric.create(ImmutableList.of(MetricData
|
Date timestamp = dateService.iso8601DateOrSecondsDateParse("2017-06-01T11:14:00Z");
|
||||||
.create(dateFormat.parse("2017-06-01T07:14:00", new ParsePosition(0)), null,
|
assertEquals(metricsApi.list(filter), ImmutableList.of(Metric.create(
|
||||||
Double.valueOf(0.295), null, null, null)),
|
ImmutableList.of(MetricData.create(timestamp, null, Double.valueOf(0.295), null, null, null)),
|
||||||
"/subscriptions/SUBSCRIPTIONID/resourceGroups/myresourcegroup/providers"
|
"/subscriptions/SUBSCRIPTIONID/resourceGroups/myresourcegroup/providers"
|
||||||
+ "/Microsoft.Compute/virtualMachines/myvm/providers/Microsoft.Insights/metrics/Percentage CPU",
|
+ "/Microsoft.Compute/virtualMachines/myvm/providers/Microsoft.Insights/metrics/Percentage CPU",
|
||||||
MetricName.create("Percentage CPU", "Percentage CPU"), "Microsoft.Insights/metrics", "Percent")));
|
MetricName.create("Percentage CPU", "Percentage CPU"), "Microsoft.Insights/metrics", "Percent")));
|
||||||
|
|
|
@ -28,6 +28,7 @@ import org.jclouds.ContextBuilder;
|
||||||
import org.jclouds.azurecompute.arm.AzureComputeApi;
|
import org.jclouds.azurecompute.arm.AzureComputeApi;
|
||||||
import org.jclouds.azurecompute.arm.AzureComputeProviderMetadata;
|
import org.jclouds.azurecompute.arm.AzureComputeProviderMetadata;
|
||||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
||||||
|
import org.jclouds.date.DateService;
|
||||||
import org.jclouds.rest.ApiContext;
|
import org.jclouds.rest.ApiContext;
|
||||||
import org.testng.annotations.AfterMethod;
|
import org.testng.annotations.AfterMethod;
|
||||||
import org.testng.annotations.BeforeMethod;
|
import org.testng.annotations.BeforeMethod;
|
||||||
|
@ -52,6 +53,7 @@ public class BaseAzureComputeApiMockTest {
|
||||||
protected MockWebServer server;
|
protected MockWebServer server;
|
||||||
protected AzureComputeApi api;
|
protected AzureComputeApi api;
|
||||||
protected ApiContext<AzureComputeApi> context;
|
protected ApiContext<AzureComputeApi> context;
|
||||||
|
protected DateService dateService;
|
||||||
|
|
||||||
// So that we can ignore formatting.
|
// So that we can ignore formatting.
|
||||||
private final JsonParser parser = new JsonParser();
|
private final JsonParser parser = new JsonParser();
|
||||||
|
@ -68,6 +70,7 @@ public class BaseAzureComputeApiMockTest {
|
||||||
.overrides(setupProperties())
|
.overrides(setupProperties())
|
||||||
.build();
|
.build();
|
||||||
api = context.getApi();
|
api = context.getApi();
|
||||||
|
dateService = context.utils().injector().getInstance(DateService.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Properties setupProperties() {
|
protected Properties setupProperties() {
|
||||||
|
|
Loading…
Reference in New Issue