use of com.google.monitoring.v3.MonitoredResourceDescriptorName in project google-cloud-java by GoogleCloudPlatform.
the class MetricServiceClientTest method getMonitoredResourceDescriptorExceptionTest.
@Test
@SuppressWarnings("all")
public void getMonitoredResourceDescriptorExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockMetricService.addException(exception);
try {
MonitoredResourceDescriptorName name = MonitoredResourceDescriptorName.create("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]");
client.getMonitoredResourceDescriptor(name);
Assert.fail("No exception raised");
} catch (ApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
}
}
use of com.google.monitoring.v3.MonitoredResourceDescriptorName in project java-docs-samples by GoogleCloudPlatform.
the class Snippets method describeMonitoredResources.
/**
* Gets full information for a monitored resource.
*
* @param type The resource type
*/
void describeMonitoredResources(String type) throws IOException {
// [START monitoring_get_descriptor]
// Your Google Cloud Platform project ID
String projectId = System.getProperty("projectId");
final MetricServiceClient client = MetricServiceClient.create();
MonitoredResourceDescriptorName name = MonitoredResourceDescriptorName.of(projectId, type);
MonitoredResourceDescriptor response = client.getMonitoredResourceDescriptor(name);
System.out.println("Printing monitored resource descriptor: ");
System.out.println(response);
// [END monitoring_get_descriptor]
}
use of com.google.monitoring.v3.MonitoredResourceDescriptorName in project google-cloud-java by GoogleCloudPlatform.
the class MetricServiceClientTest method getMonitoredResourceDescriptorTest.
@Test
@SuppressWarnings("all")
public void getMonitoredResourceDescriptorTest() {
String name2 = "name2-1052831874";
String type = "type3575610";
String displayName = "displayName1615086568";
String description = "description-1724546052";
MonitoredResourceDescriptor expectedResponse = MonitoredResourceDescriptor.newBuilder().setName(name2).setType(type).setDisplayName(displayName).setDescription(description).build();
mockMetricService.addResponse(expectedResponse);
MonitoredResourceDescriptorName name = MonitoredResourceDescriptorName.create("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]");
MonitoredResourceDescriptor actualResponse = client.getMonitoredResourceDescriptor(name);
Assert.assertEquals(expectedResponse, actualResponse);
List<GeneratedMessageV3> actualRequests = mockMetricService.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetMonitoredResourceDescriptorRequest actualRequest = (GetMonitoredResourceDescriptorRequest) actualRequests.get(0);
Assert.assertEquals(name, actualRequest.getNameAsMonitoredResourceDescriptorName());
}
Aggregations