Skip to content
Permalink
Browse files
Use the date service to parse dates
  • Loading branch information
nacx committed Jun 28, 2017
1 parent 47c4e72 commit dffc2bba7153a8222b18139298d76dcb2b4bbb6d
Showing 2 changed files with 7 additions and 7 deletions.
@@ -19,9 +19,7 @@
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.Date;

import org.jclouds.azurecompute.arm.domain.Metric;
import org.jclouds.azurecompute.arm.domain.MetricData;
@@ -41,11 +39,10 @@ public class MetricsApiMockTest extends BaseAzureComputeApiMockTest {

public void testList() throws Exception {
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);
assertEquals(metricsApi.list(filter), ImmutableList.of(Metric.create(ImmutableList.of(MetricData
.create(dateFormat.parse("2017-06-01T07:14:00", new ParsePosition(0)), null,
Double.valueOf(0.295), null, null, null)),
Date timestamp = dateService.iso8601DateOrSecondsDateParse("2017-06-01T11:14:00Z");
assertEquals(metricsApi.list(filter), ImmutableList.of(Metric.create(
ImmutableList.of(MetricData.create(timestamp, null, Double.valueOf(0.295), null, null, null)),
"/subscriptions/SUBSCRIPTIONID/resourceGroups/myresourcegroup/providers"
+ "/Microsoft.Compute/virtualMachines/myvm/providers/Microsoft.Insights/metrics/Percentage CPU",
MetricName.create("Percentage CPU", "Percentage CPU"), "Microsoft.Insights/metrics", "Percent")));
@@ -28,6 +28,7 @@
import org.jclouds.azurecompute.arm.AzureComputeApi;
import org.jclouds.azurecompute.arm.AzureComputeProviderMetadata;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.date.DateService;
import org.jclouds.rest.ApiContext;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -52,6 +53,7 @@ public class BaseAzureComputeApiMockTest {
protected MockWebServer server;
protected AzureComputeApi api;
protected ApiContext<AzureComputeApi> context;
protected DateService dateService;

// So that we can ignore formatting.
private final JsonParser parser = new JsonParser();
@@ -68,6 +70,7 @@ public void start() throws IOException {
.overrides(setupProperties())
.build();
api = context.getApi();
dateService = context.utils().injector().getInstance(DateService.class);
}

protected Properties setupProperties() {

0 comments on commit dffc2bb

Please sign in to comment.