Search in sources :

Example 66 with ProjectName

use of com.google.bigtable.repackaged.com.google.monitoring.v3.ProjectName in project java-containeranalysis by googleapis.

the class GrafeasV1Beta1ClientTest method listNotesTest.

@Test
@SuppressWarnings("all")
public void listNotesTest() {
    String nextPageToken = "";
    Note notesElement = Note.newBuilder().build();
    List<Note> notes = Arrays.asList(notesElement);
    ListNotesResponse expectedResponse = ListNotesResponse.newBuilder().setNextPageToken(nextPageToken).addAllNotes(notes).build();
    mockGrafeasV1Beta1.addResponse(expectedResponse);
    ProjectName parent = ProjectName.of("[PROJECT]");
    String filter = "filter-1274492040";
    ListNotesPagedResponse pagedListResponse = client.listNotes(parent, filter);
    List<Note> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getNotesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockGrafeasV1Beta1.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListNotesRequest actualRequest = (ListNotesRequest) actualRequests.get(0);
    Assert.assertEquals(parent, ProjectName.parse(actualRequest.getParent()));
    Assert.assertEquals(filter, actualRequest.getFilter());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListNotesRequest(io.grafeas.v1beta1.ListNotesRequest) AbstractMessage(com.google.protobuf.AbstractMessage) ProjectName(com.google.containeranalysis.v1beta1.ProjectName) Note(io.grafeas.v1beta1.Note) ListNotesResponse(io.grafeas.v1beta1.ListNotesResponse) ListNotesPagedResponse(com.google.cloud.devtools.containeranalysis.v1beta1.GrafeasV1Beta1Client.ListNotesPagedResponse) Test(org.junit.Test)

Example 67 with ProjectName

use of com.google.bigtable.repackaged.com.google.monitoring.v3.ProjectName in project native-image-support-java by GoogleCloudPlatform.

the class PubSubSampleApplication method listTopics.

private 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)

Example 68 with ProjectName

use of com.google.bigtable.repackaged.com.google.monitoring.v3.ProjectName in project native-image-support-java by GoogleCloudPlatform.

the class PubSubSampleApplication method listSubscriptionInProject.

private static void listSubscriptionInProject(String projectId) throws IOException {
    try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
        ProjectName projectName = ProjectName.of(projectId);
        int count = 0;
        for (Subscription subscription : subscriptionAdminClient.listSubscriptions(projectName).iterateAll()) {
            count += 1;
        }
        System.out.println("Subscriptions in project count: " + count);
    }
}
Also used : ProjectName(com.google.pubsub.v1.ProjectName) SubscriptionAdminClient(com.google.cloud.pubsub.v1.SubscriptionAdminClient) Subscription(com.google.pubsub.v1.Subscription)

Example 69 with ProjectName

use of com.google.bigtable.repackaged.com.google.monitoring.v3.ProjectName in project native-image-support-java by GoogleCloudPlatform.

the class SecretManagerSampleApplication method createSecret.

static void createSecret(SecretManagerServiceClient client, String projectId, String secretId) {
    ProjectName projectName = ProjectName.of(projectId);
    Secret secret = Secret.newBuilder().setReplication(Replication.newBuilder().setAutomatic(Replication.Automatic.newBuilder().build()).build()).build();
    Secret createdSecret = client.createSecret(projectName, secretId, secret);
    System.out.println("Created secret: " + createdSecret.getName());
}
Also used : Secret(com.google.cloud.secretmanager.v1.Secret) ProjectName(com.google.cloud.secretmanager.v1.ProjectName)

Example 70 with ProjectName

use of com.google.bigtable.repackaged.com.google.monitoring.v3.ProjectName in project native-image-support-java by GoogleCloudPlatform.

the class SecretManagerSampleApplication method hasSecret.

static boolean hasSecret(SecretManagerServiceClient client, String projectId, String secretId) {
    ProjectName projectName = ProjectName.of(projectId);
    ListSecretsPagedResponse pagedResponse = client.listSecrets(projectName);
    for (Secret secret : pagedResponse.iterateAll()) {
        String otherSecretId = extractSecretId(secret);
        if (secretId.equals(otherSecretId)) {
            return true;
        }
    }
    return false;
}
Also used : Secret(com.google.cloud.secretmanager.v1.Secret) ProjectName(com.google.cloud.secretmanager.v1.ProjectName) ListSecretsPagedResponse(com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretsPagedResponse) ByteString(com.google.protobuf.ByteString)

Aggregations

Test (org.junit.Test)146 StatusRuntimeException (io.grpc.StatusRuntimeException)73 ProjectName (com.google.monitoring.v3.ProjectName)62 AbstractMessage (com.google.protobuf.AbstractMessage)60 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)58 ProjectName (com.google.pubsub.v1.ProjectName)30 ArrayList (java.util.ArrayList)29 ProjectName (com.google.privacy.dlp.v2.ProjectName)22 ByteString (com.google.protobuf.ByteString)18 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 ProjectName (com.google.logging.v2.ProjectName)14