use of com.google.pubsub.v1.Schema 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()));
}
use of com.google.pubsub.v1.Schema in project java-pubsub by googleapis.
the class SchemaServiceClientTest method validateSchemaTest2.
@Test
public void validateSchemaTest2() throws Exception {
ValidateSchemaResponse expectedResponse = ValidateSchemaResponse.newBuilder().build();
mockSchemaService.addResponse(expectedResponse);
String parent = "parent-995424086";
Schema schema = Schema.newBuilder().build();
ValidateSchemaResponse actualResponse = client.validateSchema(parent, schema);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockSchemaService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ValidateSchemaRequest actualRequest = ((ValidateSchemaRequest) actualRequests.get(0));
Assert.assertEquals(parent, actualRequest.getParent());
Assert.assertEquals(schema, actualRequest.getSchema());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.pubsub.v1.Schema 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.pubsub.v1.Schema 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.pubsub.v1.Schema in project java-pubsub by googleapis.
the class SchemaServiceClient method deleteSchema.
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Deletes a schema.
*
* <p>Sample code:
*
* <pre>{@code
* // This snippet has been automatically generated for illustrative purposes only.
* // It may require modifications to work in your environment.
* try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
* SchemaName name = SchemaName.of("[PROJECT]", "[SCHEMA]");
* schemaServiceClient.deleteSchema(name);
* }
* }</pre>
*
* @param name Required. Name of the schema to delete. Format is
* `projects/{project}/schemas/{schema}`.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final void deleteSchema(SchemaName name) {
DeleteSchemaRequest request = DeleteSchemaRequest.newBuilder().setName(name == null ? null : name.toString()).build();
deleteSchema(request);
}
Aggregations