response = api().list(new ListMetricsOptions());
performDefaultMetricsTests(response);
if (Iterables.size(response) > 0) {
Metric metric = response.iterator().next();
testMetricName = metric.getMetricName();
testNamespace = metric.getNamespace();
if (metric.getDimensions().size() > 0) {
Dimension dimension = metric.getDimensions().iterator().next();
testDimensionName = dimension.getName();
testDimensionValue = dimension.getValue();
}
if (testDimensionName == null) {
for (Metric metric1 : response) {
Set<Dimension> dimensions = metric1.getDimensions();
if (dimensions.size() > 0) {
Dimension dimension = metric.getDimensions().iterator().next();
testDimensionName = dimension.getName();
testDimensionValue = dimension.getValue();
break;
}
}
}
}
// Test with a NextToken, even if it's null
response = api().list(ListMetricsOptions.Builder.afterMarker(response.nextMarker().orNull()));
performDefaultMetricsTests(response);
// Test with a Namespace
response = api().list(ListMetricsOptions.Builder.namespace(testNamespace));
performDefaultMetricsTests(response);
for (Metric metric : response) {
checkArgument(metric.getNamespace().equals(testNamespace),
"All metrics should have the " + testNamespace + " Namespace.");
}
// Test with a MetricName
response = api().list(ListMetricsOptions.Builder.metricName(testMetricName));
performDefaultMetricsTests(response);
for (Metric metric : response) {
checkArgument(metric.getMetricName().equals(testMetricName),
"All metrics should have the " + testMetricName + " MetricName.");
}
// Test with a Dimension
if (testDimensionName != null) {
Dimension testDimension = new Dimension(testDimensionName, testDimensionValue);
response = api().list(ListMetricsOptions.Builder.dimension(testDimension));
performDefaultMetricsTests(response);
for (Metric metric : response) {
Set<Dimension> dimensions = metric.getDimensions();
boolean dimensionFound = false;
for (Dimension dimension : dimensions) {
if (dimension.getName().equals(testDimensionName)) {
dimensionFound = true;