Search in sources :

Example 1 with MessageDeserializerFactory

use of org.apache.apex.malhar.lib.appdata.query.serde.MessageDeserializerFactory in project apex-malhar by apache.

the class SchemaQueryTest method jsonToSchemaQueryWithSchemaKeysTest.

@Test
public void jsonToSchemaQueryWithSchemaKeysTest() throws Exception {
    final Map<String, String> expectedSchemaKeys = Maps.newHashMap();
    expectedSchemaKeys.put("publisher", "google");
    expectedSchemaKeys.put("advertiser", "microsoft");
    expectedSchemaKeys.put("location", "CA");
    final String id = "12345";
    final String schemaQueryJSON = "{" + "\"id\":\"" + id + "\"," + "\"type\":\"" + SchemaQuery.TYPE + "\"," + "\"context\":{" + "\"schemaKeys\":" + "{\"publisher\":\"google\",\"advertiser\":\"microsoft\",\"location\":\"CA\"}" + "}}";
    @SuppressWarnings("unchecked") MessageDeserializerFactory qb = new MessageDeserializerFactory(SchemaQuery.class);
    SchemaQuery schemaQuery = (SchemaQuery) qb.deserialize(schemaQueryJSON);
    Assert.assertEquals("Id's must match", id, schemaQuery.getId());
    Assert.assertEquals("Types must match", SchemaQuery.TYPE, schemaQuery.getType());
    Assert.assertEquals("Schema keys must match", expectedSchemaKeys, schemaQuery.getSchemaKeys());
}
Also used : MessageDeserializerFactory(org.apache.apex.malhar.lib.appdata.query.serde.MessageDeserializerFactory) Test(org.junit.Test)

Example 2 with MessageDeserializerFactory

use of org.apache.apex.malhar.lib.appdata.query.serde.MessageDeserializerFactory in project apex-malhar by apache.

the class SchemaQueryTest method jsonToSchemaQueryTest.

@Test
public void jsonToSchemaQueryTest() throws Exception {
    final String id = "12345";
    final String schemaQueryJSON = "{" + "\"id\":\"" + id + "\"," + "\"type\":\"" + SchemaQuery.TYPE + "\"" + "}";
    @SuppressWarnings("unchecked") MessageDeserializerFactory qb = new MessageDeserializerFactory(SchemaQuery.class);
    SchemaQuery schemaQuery = (SchemaQuery) qb.deserialize(schemaQueryJSON);
    Assert.assertEquals("Id's must match", id, schemaQuery.getId());
    Assert.assertEquals("Types must match", SchemaQuery.TYPE, schemaQuery.getType());
}
Also used : MessageDeserializerFactory(org.apache.apex.malhar.lib.appdata.query.serde.MessageDeserializerFactory) Test(org.junit.Test)

Example 3 with MessageDeserializerFactory

use of org.apache.apex.malhar.lib.appdata.query.serde.MessageDeserializerFactory in project apex-malhar by apache.

the class SchemaQueryTest method jsonToSchemaWithKeysAndSchemaKeys.

@Test
public void jsonToSchemaWithKeysAndSchemaKeys() throws Exception {
    final Map<String, String> expectedSchemaKeys = Maps.newHashMap();
    expectedSchemaKeys.put("publisher", "google");
    expectedSchemaKeys.put("advertiser", "microsoft");
    expectedSchemaKeys.put("location", "CA");
    final Map<String, String> expectedKeys = Maps.newHashMap();
    expectedKeys.put("publisher", "google");
    expectedKeys.put("advertiser", "microsoft");
    final String id = "12345";
    final String schemaQueryJSON = "{" + "\"id\":\"" + id + "\"," + "\"type\":\"" + SchemaQuery.TYPE + "\"," + "\"context\":{" + "\"schemaKeys\":" + "{\"publisher\":\"google\",\"advertiser\":\"microsoft\",\"location\":\"CA\"}," + "\"keys\":{\"publisher\":\"google\",\"advertiser\":\"microsoft\"}" + "}}";
    @SuppressWarnings("unchecked") MessageDeserializerFactory qb = new MessageDeserializerFactory(SchemaQuery.class);
    SchemaQuery schemaQuery = (SchemaQuery) qb.deserialize(schemaQueryJSON);
    Assert.assertEquals("Id's must match", id, schemaQuery.getId());
    Assert.assertEquals("Types must match", SchemaQuery.TYPE, schemaQuery.getType());
    Assert.assertEquals("Schema keys must match", expectedSchemaKeys, schemaQuery.getSchemaKeys());
    Assert.assertEquals("Expected keys must match", expectedKeys, schemaQuery.getContextKeys());
}
Also used : MessageDeserializerFactory(org.apache.apex.malhar.lib.appdata.query.serde.MessageDeserializerFactory) Test(org.junit.Test)

Example 4 with MessageDeserializerFactory

use of org.apache.apex.malhar.lib.appdata.query.serde.MessageDeserializerFactory in project apex-malhar by apache.

the class AbstractAppDataSnapshotServer method setup.

@SuppressWarnings("unchecked")
@Override
public void setup(OperatorContext context) {
    super.setup(context);
    setupSchema();
    schemaRegistry = new SchemaRegistrySingle(schema);
    // Setup for query processing
    setupQueryProcessor();
    queryDeserializerFactory = new MessageDeserializerFactory(SchemaQuery.class, DataQuerySnapshot.class);
    queryDeserializerFactory.setContext(DataQuerySnapshot.class, schemaRegistry);
    resultSerializerFactory = new MessageSerializerFactory(resultFormatter);
    queryProcessor.setup(context);
}
Also used : DataQuerySnapshot(org.apache.apex.malhar.lib.appdata.schemas.DataQuerySnapshot) SchemaRegistrySingle(org.apache.apex.malhar.lib.appdata.schemas.SchemaRegistrySingle) MessageSerializerFactory(org.apache.apex.malhar.lib.appdata.query.serde.MessageSerializerFactory) MessageDeserializerFactory(org.apache.apex.malhar.lib.appdata.query.serde.MessageDeserializerFactory) SchemaQuery(org.apache.apex.malhar.lib.appdata.schemas.SchemaQuery)

Aggregations

MessageDeserializerFactory (org.apache.apex.malhar.lib.appdata.query.serde.MessageDeserializerFactory)4 Test (org.junit.Test)3 MessageSerializerFactory (org.apache.apex.malhar.lib.appdata.query.serde.MessageSerializerFactory)1 DataQuerySnapshot (org.apache.apex.malhar.lib.appdata.schemas.DataQuerySnapshot)1 SchemaQuery (org.apache.apex.malhar.lib.appdata.schemas.SchemaQuery)1 SchemaRegistrySingle (org.apache.apex.malhar.lib.appdata.schemas.SchemaRegistrySingle)1