Search in sources :

Example 21 with Schema

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

the class OpenApiUtils method collectTemplateReplacements.

private static List<Map<String, String>> collectTemplateReplacements(PathItemAndServer pathItemAndServer, UriTemplate uriTemplate) {
    List<Map<String, String>> templateReplacements = new ArrayList<>();
    Collection<Parameter> parameters = pathItemAndServer.operationObject.getParameters();
    for (String templateVariable : uriTemplate.getTemplateVariables()) {
        for (Parameter parameter : parameters) {
            if (templateVariable.equals(parameter.getName())) {
                Schema schema = parameter.getSchema();
                if (schema.hasEnums()) {
                    addEnumTemplateValues(templateReplacements, templateVariable, schema);
                } else if (schema.getDefault() != null) {
                    addDefaultTemplateValue(templateReplacements, templateVariable, schema);
                } else {
                // TODO: What should be done if the parameter does not have a default value and no
                // enumerated set of valid values?
                }
            }
        }
    }
    return templateReplacements;
}
Also used : Schema(com.reprezen.kaizen.oasparser.model3.Schema) ArrayList(java.util.ArrayList) Parameter(com.reprezen.kaizen.oasparser.model3.Parameter) HashMap(java.util.HashMap) Map(java.util.Map)

Example 22 with Schema

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

the class FeaturesBBox method boundingBoxParameterDefinition.

/**
 * <pre>
 * Abstract Test 14: /ats/core/fc-bbox-definition
 * Test Purpose: Validate that the bounding box query parameters are constructed correctly.
 * Requirement: /req/core/fc-bbox-definition
 *
 * Test Method: Verify that the bbox query parameter complies with the following definition (using an OpenAPI Specification 3.0 fragment):
 *
 * name: bbox
 * in: query
 * required: false
 * schema:
 *   type: array
 *   minItems: 4
 *   maxItems: 6
 *   items:
 *     type: number
 * style: form
 * explode: false
 *
 * Use a bounding box with four numbers in all requests:
 *  * Lower left corner, WGS 84 longitude
 *  * Lower left corner, WGS 84 latitude
 *  * Upper right corner, WGS 84 longitude
 *  * Upper right corner, WGS 84 latitude
 * </pre>
 *
 * @param testPoint
 *            the testPoint under test, never <code>null</code>
 */
@Test(description = "A.2.7. Features {root}/collections/{collectionId}/items - BoundingBox, Abstract Test 14: (Requirement /req/core/fc-bbox-definition)", dataProvider = "collectionPaths", dependsOnGroups = "featuresBase", alwaysRun = true)
public void boundingBoxParameterDefinition(TestPoint testPoint) {
    Parameter bbox = retrieveParameterByName(testPoint.getPath(), getApiModel(), "bbox");
    assertNotNull(bbox, "Required bbox parameter for collections path '" + testPoint.getPath() + "'  in OpenAPI document is missing");
    String msg = "Expected property '%s' with value '%s' for collections path '" + testPoint.getPath() + "' but was '%s'.";
    assertEquals(bbox.getName(), "bbox", String.format(msg, "name", "bbox", bbox.getName()));
    assertEquals(bbox.getIn(), "query", String.format(msg, "in", "query", bbox.getIn()));
    assertFalse(isRequired(bbox), String.format(msg, "required", "false", bbox.getRequired()));
    assertEquals(bbox.getStyle(), "form", String.format(msg, "style", "form", bbox.getStyle()));
    assertFalse(isExplode(bbox), String.format(msg, "explode", "false", bbox.getExplode()));
    Schema schema = bbox.getSchema();
    assertNotNull(schema, "Expected schema for bbox parameter for collections path '" + testPoint.getPath());
    assertEquals(schema.getType(), "array", String.format(msg, "schema -> type", "array", schema.getType()));
    assertNotNull(schema.getMinItems(), String.format(msg, "schema -> minItems", "null", schema.getMinItems()));
    assertEquals(schema.getMinItems().intValue(), 4, String.format(msg, "schema -> minItems", "4", schema.getMinItems()));
    assertNotNull(schema.getMaxItems(), String.format(msg, "schema -> maxItems", "null", schema.getMaxItems()));
    assertEquals(schema.getMaxItems().intValue(), 6, String.format(msg, "schema -> maxItems", "6", schema.getMaxItems()));
    String itemsType = schema.getItemsSchema().getType();
    assertEquals(itemsType, "number", String.format(msg, "schema -> items -> type", "number", itemsType));
}
Also used : Schema(com.reprezen.kaizen.oasparser.model3.Schema) Parameter(com.reprezen.kaizen.oasparser.model3.Parameter) Test(org.testng.annotations.Test)

Example 23 with Schema

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

the class FeaturesLimit method limitParameterDefinition.

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

Example 24 with Schema

use of com.google.pubsub.v1.Schema in project molgenis-emx2 by molgenis.

the class TestCohortCatalogue method importStagingSchemas.

@Test
public void importStagingSchemas() {
    // import cdm that uses schemaRef to ontologies
    Schema cdmSchema = database.dropCreateSchema("Catalogue_cdm");
    MolgenisIO.fromDirectory(new File("../../data/datacatalogue/Catalogue_cdm").toPath(), cdmSchema, true);
    // export cdm and then import again, to validate it works
    List<Row> metadata = Emx2.toRowList(cdmSchema.getMetadata());
    Schema cdmSchema2 = database.dropCreateSchema("Catalogue_cdm2");
    cdmSchema2.migrate(Emx2.fromRowList(metadata));
}
Also used : Schema(org.molgenis.emx2.Schema) Row(org.molgenis.emx2.Row) File(java.io.File) Test(org.junit.Test)

Example 25 with Schema

use of com.google.pubsub.v1.Schema in project divolte-collector by divolte.

the class GoogleCloudPubSubFlusherTest method testMessageBatchSentToPublisher.

@Test
public void testMessageBatchSentToPublisher() {
    final Publisher publisher = mockPublisher.orElseThrow(IllegalStateException::new);
    // Process a bunch of messages.
    final DivolteSchema schema = new DivolteSchema(MINIMAL_SCHEMA, Optional.empty());
    final GoogleCloudPubSubFlusher flusher = new GoogleCloudPubSubFlusher(publisher, schema);
    final Queue<Item<AvroRecordBuffer>> items = Stream.generate(this::generateMessage).limit(10).map(this::itemFromAvroRecordBuffer).collect(Collectors.toCollection(() -> new ArrayBlockingQueue<>(10)));
    flusher.process(items);
    // Check the messages were all forwarded to the publisher.
    verify(publisher, times(10)).publish(any(PubsubMessage.class));
    verifyNoMoreInteractions(publisher);
}
Also used : Item(io.divolte.server.processing.Item) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Publisher(com.google.cloud.pubsub.v1.Publisher) PubsubMessage(com.google.pubsub.v1.PubsubMessage) DivolteSchema(io.divolte.server.DivolteSchema) Test(org.junit.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