use of com.google.monitoring.v3.OrganizationName in project java-securitycenter by googleapis.
the class ListNotificationConfigSnippets method listNotificationConfigs.
// [START securitycenter_list_notification_configs]
public static ImmutableList<NotificationConfig> listNotificationConfigs(String organizationId) throws IOException {
// String organizationId = "{your-org-id}";
OrganizationName orgName = OrganizationName.newBuilder().setOrganization(organizationId).build();
try (SecurityCenterClient client = SecurityCenterClient.create()) {
ListNotificationConfigsPagedResponse response = client.listNotificationConfigs(orgName);
ImmutableList<NotificationConfig> notificationConfigs = ImmutableList.copyOf(response.iterateAll());
System.out.println(String.format("List notifications response: %s", response.getPage().getValues()));
return notificationConfigs;
}
}
use of com.google.monitoring.v3.OrganizationName in project java-monitoring by googleapis.
the class NotificationChannelServiceClientTest method listNotificationChannelDescriptorsTest2.
@Test
public void listNotificationChannelDescriptorsTest2() throws Exception {
NotificationChannelDescriptor responsesElement = NotificationChannelDescriptor.newBuilder().build();
ListNotificationChannelDescriptorsResponse expectedResponse = ListNotificationChannelDescriptorsResponse.newBuilder().setNextPageToken("").addAllChannelDescriptors(Arrays.asList(responsesElement)).build();
mockNotificationChannelService.addResponse(expectedResponse);
OrganizationName name = OrganizationName.of("[ORGANIZATION]");
ListNotificationChannelDescriptorsPagedResponse pagedListResponse = client.listNotificationChannelDescriptors(name);
List<NotificationChannelDescriptor> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getChannelDescriptorsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListNotificationChannelDescriptorsRequest actualRequest = ((ListNotificationChannelDescriptorsRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.monitoring.v3.OrganizationName in project java-monitoring by googleapis.
the class NotificationChannelServiceClientTest method listNotificationChannelDescriptorsExceptionTest2.
@Test
public void listNotificationChannelDescriptorsExceptionTest2() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockNotificationChannelService.addException(exception);
try {
OrganizationName name = OrganizationName.of("[ORGANIZATION]");
client.listNotificationChannelDescriptors(name);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.monitoring.v3.OrganizationName in project java-monitoring by googleapis.
the class NotificationChannelServiceClientTest method createNotificationChannelTest2.
@Test
public void createNotificationChannelTest2() throws Exception {
NotificationChannel expectedResponse = NotificationChannel.newBuilder().setType("type3575610").setName(NotificationChannelName.ofProjectNotificationChannelName("[PROJECT]", "[NOTIFICATION_CHANNEL]").toString()).setDisplayName("displayName1714148973").setDescription("description-1724546052").putAllLabels(new HashMap<String, String>()).putAllUserLabels(new HashMap<String, String>()).setEnabled(BoolValue.newBuilder().build()).setCreationRecord(MutationRecord.newBuilder().build()).addAllMutationRecords(new ArrayList<MutationRecord>()).build();
mockNotificationChannelService.addResponse(expectedResponse);
OrganizationName name = OrganizationName.of("[ORGANIZATION]");
NotificationChannel notificationChannel = NotificationChannel.newBuilder().build();
NotificationChannel actualResponse = client.createNotificationChannel(name, notificationChannel);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateNotificationChannelRequest actualRequest = ((CreateNotificationChannelRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertEquals(notificationChannel, actualRequest.getNotificationChannel());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.monitoring.v3.OrganizationName in project java-monitoring by googleapis.
the class MetricServiceClientTest method listMetricDescriptorsExceptionTest2.
@Test
public void listMetricDescriptorsExceptionTest2() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockMetricService.addException(exception);
try {
OrganizationName name = OrganizationName.of("[ORGANIZATION]");
client.listMetricDescriptors(name);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
Aggregations