Search in sources :

Example 16 with Schema

use of com.google.pubsub.v1.Schema in project gapic-generator-java 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 17 with Schema

use of com.google.pubsub.v1.Schema in project gapic-generator-java 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 18 with Schema

use of com.google.pubsub.v1.Schema in project gapic-generator-java by googleapis.

the class SchemaServiceClientTest method getSchemaExceptionTest.

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

Example 19 with Schema

use of com.google.pubsub.v1.Schema in project cobigen by devonfw.

the class OpenAPIInputReader method extractParameters.

/**
 * @param operationOverlay overlay of the operation to get all parameters from
 * @return a list of {@link ParameterDef} from a collection of parameters of an operation
 */
private List<ParameterDef> extractParameters(Overlay<Operation> operationOverlay) {
    Collection<? extends Parameter> parameters = operationOverlay.get().getParameters();
    Collection<String> tags = operationOverlay.get().getTags();
    RequestBody requestBody = operationOverlay.get().getRequestBody();
    List<ParameterDef> parametersList = new LinkedList<>();
    ParameterDef parameter;
    for (Parameter param : parameters) {
        parameter = new ParameterDef();
        parameter.setIsBody(false);
        switch(param.getIn()) {
            case "path":
                parameter.setInPath(true);
                break;
            case "query":
                parameter.setInQuery(true);
                break;
            case "header":
                parameter.setInHeader(true);
                break;
        }
        parameter.setName(param.getName());
        Schema schema = param.getSchema();
        Map<String, Object> constraints = extractConstraints(schema);
        if (param.isRequired()) {
            constraints.put(ModelConstant.NOTNULL, true);
        } else {
            constraints.put(ModelConstant.NOTNULL, false);
        }
        parameter.setConstraints(constraints);
        parameter.setDescription(param.getDescription());
        if (schema.getType().equals(Constants.ARRAY)) {
            parameter.setIsCollection(true);
            if (schema.getItemsSchema() != null) {
                parameter.setIsEntity(true);
            }
        }
        try {
            if (Overlay.isReference(operationOverlay.getOverlay(), param.getKey())) {
                parameter.setIsEntity(true);
                parameter.setType(schema.getName());
            } else {
                parameter.setType(schema.getType());
                parameter.setFormat(schema.getFormat());
            }
        } catch (NullPointerException e) {
            throw new CobiGenRuntimeException("Error at parameter " + param.getName() + ". Invalid OpenAPI file, path parameters need to have a schema defined.");
        }
        parametersList.add(parameter);
    }
    if (requestBody != null) {
        Schema mediaSchema;
        for (String media : requestBody.getContentMediaTypes().keySet()) {
            parameter = new ParameterDef();
            parameter.setIsBody(true);
            parameter.setMediaType(media);
            if (tags.contains(Constants.SEARCH_CRITERIA) || tags.contains(Constants.SEARCH_CRITERIA.toLowerCase())) {
                parameter.setIsSearchCriteria(true);
                parameter.setName("criteria");
            }
            if (requestBody.getContentMediaTypes().get(media).getSchema() != null) {
                mediaSchema = requestBody.getContentMediaTypes().get(media).getSchema();
                parameter.setIsEntity(true);
                parameter.setType(requestBody.getContentMediaType(media).getSchema().getName());
                if (!parameter.getIsSearchCriteria()) {
                    char[] c = mediaSchema.getName().toCharArray();
                    c[0] = Character.toLowerCase(c[0]);
                    parameter.setName(new String(c));
                }
            }
            if (parameter.getType() != null) {
                Map<String, Object> constraints = new HashMap<>();
                constraints.put(ModelConstant.NOTNULL, true);
                parameter.setConstraints(constraints);
                parametersList.add(parameter);
            }
        }
    }
    return parametersList;
}
Also used : CobiGenRuntimeException(com.devonfw.cobigen.api.exception.CobiGenRuntimeException) ParameterDef(com.devonfw.cobigen.openapiplugin.model.ParameterDef) HashMap(java.util.HashMap) Schema(com.reprezen.kaizen.oasparser.model3.Schema) LinkedList(java.util.LinkedList) Parameter(com.reprezen.kaizen.oasparser.model3.Parameter) RequestBody(com.reprezen.kaizen.oasparser.model3.RequestBody)

Example 20 with Schema

use of com.google.pubsub.v1.Schema in project ets-ogcapi-features10 by opengeospatial.

the class FeaturesTime method timeParameterDefinition.

/**
 * <pre>
 * Abstract Test 18: /ats/core/fc-time-definition
 * Test Purpose: Validate that the dateTime query parameters are constructed correctly.
 * Requirement: /req/core/fc-time-definition
 *
 * Test Method: Verify that the datetime query parameter complies with the following definition (using an OpenAPI Specification 3.0 fragment):
 *
 * name: datetime
 * in: query
 * required: false
 * schema:
 *   type: string
 * style: form
 * explode: false
 * </pre>
 *
 * @param testPoint
 *            the testPoint under test, never <code>null</code>
 */
@Test(description = "A.2.7. Features {root}/collections/{collectionId}/items - Datetime, Abstract Test 18: (Requirement /req/core/fc-time-definition)", dataProvider = "collectionPaths", dependsOnGroups = "featuresBase", alwaysRun = true)
public void timeParameterDefinition(TestPoint testPoint) {
    Parameter time = retrieveParameterByName(testPoint.getPath(), getApiModel(), "datetime");
    assertNotNull(time, "Required datetime parameter for collections with path '" + testPoint.getPath() + "'  in OpenAPI document is missing");
    String msg = "Expected property '%s' with value '%s' but was '%s'";
    assertEquals(time.getName(), "datetime", String.format(msg, "name", "datetime", time.getName()));
    assertEquals(time.getIn(), "query", String.format(msg, "in", "query", time.getIn()));
    assertFalse(isRequired(time), String.format(msg, "required", "false", time.getRequired()));
    assertEquals(time.getStyle(), "form", String.format(msg, "style", "form", time.getStyle()));
    assertFalse(isExplode(time), String.format(msg, "explode", "false", time.getExplode()));
    Schema schema = time.getSchema();
    assertEquals(schema.getType(), "string", String.format(msg, "schema -> type", "string", schema.getType()));
}
Also used : Schema(com.reprezen.kaizen.oasparser.model3.Schema) Parameter(com.reprezen.kaizen.oasparser.model3.Parameter) Test(org.testng.annotations.Test)

Aggregations

Test (org.junit.Test)65 Schema (com.google.pubsub.v1.Schema)38 Schema (org.molgenis.emx2.Schema)38 ByteString (com.google.protobuf.ByteString)19 SchemaServiceClient (com.google.cloud.pubsub.v1.SchemaServiceClient)18 AbstractMessage (com.google.protobuf.AbstractMessage)18 QName (javax.xml.namespace.QName)16 SchemaName (com.google.pubsub.v1.SchemaName)15 File (java.io.File)15 Schema (org.geosdi.geoplatform.xml.xsd.v2001.Schema)15 ProjectName (com.google.pubsub.v1.ProjectName)14 IOException (java.io.IOException)14 URL (java.net.URL)14 LayerSchemaDTO (org.geosdi.geoplatform.connector.wfs.response.LayerSchemaDTO)14 StringWriter (java.io.StringWriter)13 Schema (org.oasisopen.odata.csdl.v4.Schema)13 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)12 StatusRuntimeException (io.grpc.StatusRuntimeException)12 Schema (com.reprezen.kaizen.oasparser.model3.Schema)11 JAXBElement (javax.xml.bind.JAXBElement)10