Search in sources :

Example 61 with Schema

use of com.reprezen.kaizen.oasparser.model3.Schema in project java-pubsub by googleapis.

the class SchemaServiceClientTest method getSchemaTest.

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

Example 62 with Schema

use of com.reprezen.kaizen.oasparser.model3.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()));
}
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 63 with Schema

use of com.reprezen.kaizen.oasparser.model3.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()));
}
Also used : ValidateSchemaResponse(com.google.pubsub.v1.ValidateSchemaResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Schema(com.google.pubsub.v1.Schema) ByteString(com.google.protobuf.ByteString) ValidateSchemaRequest(com.google.pubsub.v1.ValidateSchemaRequest) Test(org.junit.Test)

Example 64 with Schema

use of com.reprezen.kaizen.oasparser.model3.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.");
    }
}
Also used : AlreadyExistsException(com.google.api.gax.rpc.AlreadyExistsException) ProjectName(com.google.pubsub.v1.ProjectName) Schema(com.google.pubsub.v1.Schema) SchemaServiceClient(com.google.cloud.pubsub.v1.SchemaServiceClient) SchemaName(com.google.pubsub.v1.SchemaName)

Example 65 with Schema

use of com.reprezen.kaizen.oasparser.model3.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.");
    }
}
Also used : AlreadyExistsException(com.google.api.gax.rpc.AlreadyExistsException) ProjectName(com.google.pubsub.v1.ProjectName) Schema(com.google.pubsub.v1.Schema) SchemaServiceClient(com.google.cloud.pubsub.v1.SchemaServiceClient) SchemaName(com.google.pubsub.v1.SchemaName)

Aggregations

Test (org.junit.Test)57 Schema (com.google.pubsub.v1.Schema)38 Schema (org.molgenis.emx2.Schema)38 AbstractMessage (com.google.protobuf.AbstractMessage)16 ByteString (com.google.protobuf.ByteString)16 QName (javax.xml.namespace.QName)16 File (java.io.File)15 URL (java.net.URL)15 Schema (org.geosdi.geoplatform.xml.xsd.v2001.Schema)15 SchemaServiceClient (com.google.cloud.pubsub.v1.SchemaServiceClient)14 ProjectName (com.google.pubsub.v1.ProjectName)14 LayerSchemaDTO (org.geosdi.geoplatform.connector.wfs.response.LayerSchemaDTO)14 IOException (java.io.IOException)13 StringWriter (java.io.StringWriter)13 Schema (org.oasisopen.odata.csdl.v4.Schema)13 Schema (com.reprezen.kaizen.oasparser.model3.Schema)11 JAXBElement (javax.xml.bind.JAXBElement)10 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 List (java.util.List)8