Search in sources :

Example 16 with ProjectName

use of com.google.webrisk.v1.ProjectName in project java-phishingprotection by googleapis.

the class PhishingProtectionServiceV1Beta1ClientTest method reportPhishingTest.

@Test
public void reportPhishingTest() throws Exception {
    ReportPhishingResponse expectedResponse = ReportPhishingResponse.newBuilder().build();
    mockPhishingProtectionServiceV1Beta1.addResponse(expectedResponse);
    ProjectName parent = ProjectName.of("[PROJECT]");
    String uri = "uri116076";
    ReportPhishingResponse actualResponse = client.reportPhishing(parent, uri);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockPhishingProtectionServiceV1Beta1.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ReportPhishingRequest actualRequest = ((ReportPhishingRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(uri, actualRequest.getUri());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ProjectName(com.google.phishingprotection.v1beta1.ProjectName) ReportPhishingResponse(com.google.phishingprotection.v1beta1.ReportPhishingResponse) ReportPhishingRequest(com.google.phishingprotection.v1beta1.ReportPhishingRequest) Test(org.junit.Test)

Example 17 with ProjectName

use of com.google.webrisk.v1.ProjectName in project java-pubsub by googleapis.

the class SchemaServiceClientTest method listSchemasTest.

@Test
public void listSchemasTest() throws Exception {
    Schema responsesElement = Schema.newBuilder().build();
    ListSchemasResponse expectedResponse = ListSchemasResponse.newBuilder().setNextPageToken("").addAllSchemas(Arrays.asList(responsesElement)).build();
    mockSchemaService.addResponse(expectedResponse);
    ProjectName parent = ProjectName.of("[PROJECT]");
    ListSchemasPagedResponse pagedListResponse = client.listSchemas(parent);
    List<Schema> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getSchemasList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockSchemaService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListSchemasRequest actualRequest = ((ListSchemasRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListSchemasRequest(com.google.pubsub.v1.ListSchemasRequest) ListSchemasPagedResponse(com.google.cloud.pubsub.v1.SchemaServiceClient.ListSchemasPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ProjectName(com.google.pubsub.v1.ProjectName) Schema(com.google.pubsub.v1.Schema) ListSchemasResponse(com.google.pubsub.v1.ListSchemasResponse) Test(org.junit.Test)

Example 18 with ProjectName

use of com.google.webrisk.v1.ProjectName in project java-pubsub by googleapis.

the class SubscriptionAdminClientTest method listSnapshotsExceptionTest.

@Test
public void listSnapshotsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockSubscriber.addException(exception);
    try {
        ProjectName project = ProjectName.of("[PROJECT]");
        client.listSnapshots(project);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) ProjectName(com.google.pubsub.v1.ProjectName) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 19 with ProjectName

use of com.google.webrisk.v1.ProjectName in project java-pubsub by googleapis.

the class SchemaServiceClientTest method createSchemaTest.

@Test
public void createSchemaTest() throws Exception {
    Schema expectedResponse = Schema.newBuilder().setName(SchemaName.of("[PROJECT]", "[SCHEMA]").toString()).setDefinition("definition-1014418093").build();
    mockSchemaService.addResponse(expectedResponse);
    ProjectName parent = ProjectName.of("[PROJECT]");
    Schema schema = Schema.newBuilder().build();
    String schemaId = "schemaId-697673060";
    Schema actualResponse = client.createSchema(parent, schema, schemaId);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockSchemaService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateSchemaRequest actualRequest = ((CreateSchemaRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(schema, actualRequest.getSchema());
    Assert.assertEquals(schemaId, actualRequest.getSchemaId());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) CreateSchemaRequest(com.google.pubsub.v1.CreateSchemaRequest) ProjectName(com.google.pubsub.v1.ProjectName) Schema(com.google.pubsub.v1.Schema) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 20 with ProjectName

use of com.google.webrisk.v1.ProjectName in project java-pubsub by googleapis.

the class NativeImagePubSubSample method listTopics.

static void listTopics(String projectId) throws IOException {
    try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
        ProjectName projectName = ProjectName.of(projectId);
        int count = 0;
        for (Topic topic : topicAdminClient.listTopics(projectName).iterateAll()) {
            count += 1;
        }
        System.out.println("Topic count under project: " + count);
    }
}
Also used : TopicAdminClient(com.google.cloud.pubsub.v1.TopicAdminClient) ProjectName(com.google.pubsub.v1.ProjectName) Topic(com.google.pubsub.v1.Topic)

Aggregations

Test (org.junit.Test)178 StatusRuntimeException (io.grpc.StatusRuntimeException)89 AbstractMessage (com.google.protobuf.AbstractMessage)76 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)74 ProjectName (com.google.monitoring.v3.ProjectName)62 ProjectName (com.google.pubsub.v1.ProjectName)44 ProjectName (com.google.logging.v2.ProjectName)31 ArrayList (java.util.ArrayList)31 ProjectName (com.google.privacy.dlp.v2.ProjectName)22 ByteString (com.google.protobuf.ByteString)20 DataTransferServiceClient (com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient)17 ProjectName (com.google.cloud.bigquery.datatransfer.v1.ProjectName)17 IOException (java.io.IOException)17 CreateTransferConfigRequest (com.google.cloud.bigquery.datatransfer.v1.CreateTransferConfigRequest)16 TransferConfig (com.google.cloud.bigquery.datatransfer.v1.TransferConfig)16 ProjectName (com.google.cloud.secretmanager.v1.ProjectName)16 ProjectName (com.google.containeranalysis.v1beta1.ProjectName)16 ApiException (com.google.api.gax.rpc.ApiException)15 MetricServiceClient (com.google.cloud.monitoring.v3.MetricServiceClient)15 TimeSeries (com.google.monitoring.v3.TimeSeries)15