use of uk.gov.gchq.gaffer.store.ElementValidator in project Gaffer by gchq.
the class ExportToGafferResultCacheHandlerTest method shouldCreateCacheGraph.
@Test
public void shouldCreateCacheGraph() throws OperationException {
// Given
final Store store = mock(Store.class);
final long timeToLive = 10000L;
final ExportToGafferResultCacheHandler handler = new ExportToGafferResultCacheHandler();
handler.setStorePropertiesPath(StreamUtil.STORE_PROPERTIES);
handler.setTimeToLive(timeToLive);
// When
final Graph graph = handler.createGraph(store);
// Then
final Schema schema = graph.getSchema();
JsonUtil.assertEquals(GafferResultCacheUtil.createSchema(timeToLive).toJson(false), schema.toJson(true));
assertTrue(schema.validate());
assertEquals(timeToLive, ((AgeOff) (schema.getType("timestamp").getValidator().getFunctions().get(0).getFunction())).getAgeOffTime());
assertTrue(new ElementValidator(schema).validate(validEdge));
assertFalse(new ElementValidator(schema).validate(oldEdge));
assertTrue(schema.validate());
}
use of uk.gov.gchq.gaffer.store.ElementValidator in project Gaffer by gchq.
the class GetGafferResultCacheExportHandlerTest method shouldCreateCacheGraph.
@Test
public void shouldCreateCacheGraph() throws OperationException {
// Given
final Store store = mock(Store.class);
final long timeToLive = 10000L;
final GetGafferResultCacheExportHandler handler = new GetGafferResultCacheExportHandler();
handler.setStorePropertiesPath(StreamUtil.STORE_PROPERTIES);
handler.setTimeToLive(timeToLive);
// When
final Graph graph = handler.createGraph(store);
// Then
final Schema schema = graph.getSchema();
JsonUtil.assertEquals(GafferResultCacheUtil.createSchema(timeToLive).toJson(false), schema.toJson(true));
assertTrue(schema.validate());
assertEquals(timeToLive, ((AgeOff) (schema.getType("timestamp").getValidator().getFunctions().get(0).getFunction())).getAgeOffTime());
assertTrue(new ElementValidator(schema).validate(validEdge));
assertFalse(new ElementValidator(schema).validate(oldEdge));
assertTrue(schema.validate());
}
use of uk.gov.gchq.gaffer.store.ElementValidator in project Gaffer by gchq.
the class GafferResultCacheUtilTest method shouldCreateGraphWithValidSchema.
@Test
public void shouldCreateGraphWithValidSchema() {
// Given
final Graph graph = GafferResultCacheUtil.createGraph(StreamUtil.STORE_PROPERTIES, GafferResultCacheUtil.DEFAULT_TIME_TO_LIVE);
final Schema schema = graph.getSchema();
// When
final boolean isValid = schema.validate();
// Then
assertTrue(isValid);
assertEquals(GafferResultCacheUtil.DEFAULT_TIME_TO_LIVE, ((AgeOff) (schema.getType("timestamp").getValidator().getFunctions().get(0).getFunction())).getAgeOffTime());
assertTrue(new ElementValidator(schema).validate(validEdge));
assertFalse(new ElementValidator(schema).validate(oldEdge));
assertTrue(schema.validate());
}
use of uk.gov.gchq.gaffer.store.ElementValidator in project Gaffer by gchq.
the class GafferResultCacheUtilTest method shouldCreateGraphWithValidSchemaWithoutAgeOff.
@Test
public void shouldCreateGraphWithValidSchemaWithoutAgeOff() {
// Given
final Graph graph = GafferResultCacheUtil.createGraph(StreamUtil.STORE_PROPERTIES, null);
final Schema schema = graph.getSchema();
// When
final boolean isValid = schema.validate();
// Then
assertTrue(isValid);
assertNull(schema.getType("timestamp").getValidator());
assertTrue(new ElementValidator(schema).validate(validEdge));
assertTrue(new ElementValidator(schema).validate(oldEdge));
assertTrue(schema.validate());
}
use of uk.gov.gchq.gaffer.store.ElementValidator in project Gaffer by gchq.
the class AbstractAddElementsFromHdfsMapper method setup.
protected void setup(final Context context) {
doValidation = Boolean.parseBoolean(context.getConfiguration().get(AddElementsFromHdfsJobFactory.VALIDATE));
try {
schema = Schema.fromJson(context.getConfiguration().get(AddElementsFromHdfsJobFactory.SCHEMA).getBytes(CommonConstants.UTF_8));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e.getMessage(), e);
}
elementValidator = new ElementValidator(schema);
final String generatorClass = context.getConfiguration().get(AddElementsFromHdfsJobFactory.MAPPER_GENERATOR);
try {
mapperGenerator = Class.forName(generatorClass).asSubclass(MapperGenerator.class).newInstance();
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
throw new IllegalArgumentException("Element generator could be created: " + generatorClass, e);
}
}
Aggregations