Search in sources :

Example 71 with ProjectName

use of com.google.webrisk.v1.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());
}
Also used : Snapshot(com.google.pubsub.v1.Snapshot) ListSnapshotsRequest(com.google.pubsub.v1.ListSnapshotsRequest) ListSnapshotsResponse(com.google.pubsub.v1.ListSnapshotsResponse) ListSnapshotsPagedResponse(com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListSnapshotsPagedResponse) ProjectName(com.google.pubsub.v1.ProjectName) ByteString(com.google.protobuf.ByteString) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 72 with ProjectName

use of com.google.webrisk.v1.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());
}
Also used : ListTopicsPagedResponse(com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListTopicsPagedResponse) ProjectName(com.google.pubsub.v1.ProjectName) ListTopicsRequest(com.google.pubsub.v1.ListTopicsRequest) ByteString(com.google.protobuf.ByteString) Topic(com.google.pubsub.v1.Topic) ListTopicsResponse(com.google.pubsub.v1.ListTopicsResponse) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 73 with ProjectName

use of com.google.webrisk.v1.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());
    }
}
Also used : ProjectName(com.google.pubsub.v1.ProjectName) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 74 with ProjectName

use of com.google.webrisk.v1.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());
    }
}
Also used : ProjectName(com.google.pubsub.v1.ProjectName) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 75 with ProjectName

use of com.google.webrisk.v1.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);
    }
}
Also used : ProjectName(com.google.devtools.clouderrorreporting.v1beta1.ProjectName) ErrorContext(com.google.devtools.clouderrorreporting.v1beta1.ErrorContext) ReportedErrorEvent(com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent) ReportErrorsServiceClient(com.google.cloud.errorreporting.v1beta1.ReportErrorsServiceClient)

Aggregations

Test (org.junit.Test)70 StatusRuntimeException (io.grpc.StatusRuntimeException)34 ProjectName (com.google.privacy.dlp.v2.ProjectName)22 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)21 ProjectName (com.google.monitoring.v3.ProjectName)21 AbstractMessage (com.google.protobuf.AbstractMessage)21 DataTransferServiceClient (com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient)17 ProjectName (com.google.cloud.bigquery.datatransfer.v1.ProjectName)17 CreateTransferConfigRequest (com.google.cloud.bigquery.datatransfer.v1.CreateTransferConfigRequest)16 TransferConfig (com.google.cloud.bigquery.datatransfer.v1.TransferConfig)16 ApiException (com.google.api.gax.rpc.ApiException)15 ProjectName (com.google.cloud.secretmanager.v1.ProjectName)14 ProjectName (com.google.logging.v2.ProjectName)14 ApiException (com.google.api.gax.grpc.ApiException)13 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)13 ProjectName (com.google.devtools.clouderrorreporting.v1beta1.ProjectName)11 ArrayList (java.util.ArrayList)11 SecretManagerServiceClient (com.google.cloud.secretmanager.v1.SecretManagerServiceClient)10 MetricServiceClient (com.google.cloud.monitoring.v3.MetricServiceClient)9 TimeSeries (com.google.monitoring.v3.TimeSeries)9