use of com.google.containeranalysis.v1beta1.ProjectName in project java-pubsub by googleapis.
the class TopicAdminClientTest method listTopicsTest.
@Test
public void listTopicsTest() throws Exception {
Topic responsesElement = Topic.newBuilder().build();
ListTopicsResponse expectedResponse = ListTopicsResponse.newBuilder().setNextPageToken("").addAllTopics(Arrays.asList(responsesElement)).build();
mockPublisher.addResponse(expectedResponse);
ProjectName project = ProjectName.of("[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<AbstractMessage> actualRequests = mockPublisher.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListTopicsRequest actualRequest = ((ListTopicsRequest) actualRequests.get(0));
Assert.assertEquals(project.toString(), actualRequest.getProject());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.containeranalysis.v1beta1.ProjectName in project java-pubsub by googleapis.
the class CreateAvroSchemaExample method createAvroSchemaExample.
public static void createAvroSchemaExample(String projectId, String schemaId, String avscFile) throws IOException {
ProjectName projectName = ProjectName.of(projectId);
SchemaName schemaName = SchemaName.of(projectId, schemaId);
// Read an Avro schema file formatted in JSON as a string.
String avscSource = new String(Files.readAllBytes(Paths.get(avscFile)));
try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
Schema schema = schemaServiceClient.createSchema(projectName, Schema.newBuilder().setName(schemaName.toString()).setType(Schema.Type.AVRO).setDefinition(avscSource).build(), schemaId);
System.out.println("Created a schema using an Avro schema:\n" + schema);
} catch (AlreadyExistsException e) {
System.out.println(schemaName + "already exists.");
}
}
use of com.google.containeranalysis.v1beta1.ProjectName in project java-pubsub by googleapis.
the class CreateProtoSchemaExample method createProtoSchemaExample.
public static void createProtoSchemaExample(String projectId, String schemaId, String protoFile) throws IOException {
ProjectName projectName = ProjectName.of(projectId);
SchemaName schemaName = SchemaName.of(projectId, schemaId);
// Read a proto file as a string.
String protoSource = new String(Files.readAllBytes(Paths.get(protoFile)));
try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
Schema schema = schemaServiceClient.createSchema(projectName, Schema.newBuilder().setName(schemaName.toString()).setType(Schema.Type.PROTOCOL_BUFFER).setDefinition(protoSource).build(), schemaId);
System.out.println("Created a schema using a protobuf schema:\n" + schema);
} catch (AlreadyExistsException e) {
System.out.println(schemaName + "already exists.");
}
}
use of com.google.containeranalysis.v1beta1.ProjectName in project java-pubsub by googleapis.
the class TopicAdminClientTest method listTopicsExceptionTest.
@Test
public void listTopicsExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockPublisher.addException(exception);
try {
ProjectName project = ProjectName.of("[PROJECT]");
client.listTopics(project);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.containeranalysis.v1beta1.ProjectName in project java-pubsub by googleapis.
the class ListSubscriptionsInProjectExample method listSubscriptionInProjectExample.
public static void listSubscriptionInProjectExample(String projectId) throws IOException {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectName projectName = ProjectName.of(projectId);
for (Subscription subscription : subscriptionAdminClient.listSubscriptions(projectName).iterateAll()) {
System.out.println(subscription.getName());
}
System.out.println("Listed all the subscriptions in the project.");
}
}
Aggregations