use of com.google.logging.v2.ProjectName in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientTest method listSnapshotsTest.
@Test
@SuppressWarnings("all")
public void listSnapshotsTest() {
String nextPageToken = "";
Snapshot snapshotsElement = Snapshot.newBuilder().build();
List<Snapshot> snapshots = Arrays.asList(snapshotsElement);
ListSnapshotsResponse expectedResponse = ListSnapshotsResponse.newBuilder().setNextPageToken(nextPageToken).addAllSnapshots(snapshots).build();
mockSubscriber.addResponse(expectedResponse);
ProjectName project = ProjectName.create("[PROJECT]");
ListSnapshotsPagedResponse pagedListResponse = client.listSnapshots(project);
List<Snapshot> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getSnapshotsList().get(0), resources.get(0));
List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListSnapshotsRequest actualRequest = (ListSnapshotsRequest) actualRequests.get(0);
Assert.assertEquals(project, actualRequest.getProjectAsProjectName());
}
use of com.google.logging.v2.ProjectName in project google-cloud-java by GoogleCloudPlatform.
the class TopicAdminClientTest method listTopicsTest.
@Test
@SuppressWarnings("all")
public void listTopicsTest() {
String nextPageToken = "";
Topic topicsElement = Topic.newBuilder().build();
List<Topic> topics = Arrays.asList(topicsElement);
ListTopicsResponse expectedResponse = ListTopicsResponse.newBuilder().setNextPageToken(nextPageToken).addAllTopics(topics).build();
mockPublisher.addResponse(expectedResponse);
ProjectName project = ProjectName.create("[PROJECT]");
ListTopicsPagedResponse pagedListResponse = client.listTopics(project);
List<Topic> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getTopicsList().get(0), resources.get(0));
List<GeneratedMessageV3> actualRequests = mockPublisher.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListTopicsRequest actualRequest = (ListTopicsRequest) actualRequests.get(0);
Assert.assertEquals(project, actualRequest.getProjectAsProjectName());
}
use of com.google.logging.v2.ProjectName in project google-cloud-java by GoogleCloudPlatform.
the class TopicAdminClientTest method listTopicsExceptionTest.
@Test
@SuppressWarnings("all")
public void listTopicsExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockPublisher.addException(exception);
try {
ProjectName project = ProjectName.create("[PROJECT]");
client.listTopics(project);
Assert.fail("No exception raised");
} catch (ApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
}
}
use of com.google.logging.v2.ProjectName in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientTest method listSubscriptionsExceptionTest.
@Test
@SuppressWarnings("all")
public void listSubscriptionsExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockSubscriber.addException(exception);
try {
ProjectName project = ProjectName.create("[PROJECT]");
client.listSubscriptions(project);
Assert.fail("No exception raised");
} catch (ApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
}
}
use of com.google.logging.v2.ProjectName in project java-docs-samples by GoogleCloudPlatform.
the class QuickStart method main.
public static void main(String[] args) throws Exception {
// Google Cloud Platform Project ID
String projectId = (args.length > 0) ? args[0] : ServiceOptions.getDefaultProjectId();
ProjectName projectName = ProjectName.of(projectId);
// Instantiate an Error Reporting Client
try (ReportErrorsServiceClient reportErrorsServiceClient = ReportErrorsServiceClient.create()) {
// Custom error events require an error reporting location as well.
ErrorContext errorContext = ErrorContext.newBuilder().setReportLocation(SourceLocation.newBuilder().setFilePath("Test.java").setLineNumber(10).setFunctionName("myMethod").build()).build();
// Report a custom error event
ReportedErrorEvent customErrorEvent = ReportedErrorEvent.getDefaultInstance().toBuilder().setMessage("custom error event").setContext(errorContext).build();
// Report an event synchronously, use .reportErrorEventCallable for asynchronous reporting.
reportErrorsServiceClient.reportErrorEvent(projectName, customErrorEvent);
}
}
Aggregations