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());
}
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());
}
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());
}
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);
}
Aggregations