Search in sources :

Example 1 with ElementValidator

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());
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) Schema(uk.gov.gchq.gaffer.store.schema.Schema) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) Store(uk.gov.gchq.gaffer.store.Store) ElementValidator(uk.gov.gchq.gaffer.store.ElementValidator) Test(org.junit.Test)

Example 2 with ElementValidator

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());
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) Schema(uk.gov.gchq.gaffer.store.schema.Schema) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) Store(uk.gov.gchq.gaffer.store.Store) ElementValidator(uk.gov.gchq.gaffer.store.ElementValidator) Test(org.junit.Test)

Example 3 with ElementValidator

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());
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) Schema(uk.gov.gchq.gaffer.store.schema.Schema) ElementValidator(uk.gov.gchq.gaffer.store.ElementValidator) Test(org.junit.Test)

Example 4 with ElementValidator

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());
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) Schema(uk.gov.gchq.gaffer.store.schema.Schema) ElementValidator(uk.gov.gchq.gaffer.store.ElementValidator) Test(org.junit.Test)

Example 5 with ElementValidator

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);
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) ElementValidator(uk.gov.gchq.gaffer.store.ElementValidator)

Aggregations

ElementValidator (uk.gov.gchq.gaffer.store.ElementValidator)5 Test (org.junit.Test)4 Graph (uk.gov.gchq.gaffer.graph.Graph)4 Schema (uk.gov.gchq.gaffer.store.schema.Schema)4 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)2 Store (uk.gov.gchq.gaffer.store.Store)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1