Search in sources :

Example 1 with StringSerialiser

use of uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser in project Gaffer by gchq.

the class SchemaOptimiserTest method shouldAddDefaultSerialisers.

@Test
public void shouldAddDefaultSerialisers() {
    //Given
    final SerialisationFactory serialisationFactory = mock(SerialisationFactory.class);
    final SchemaOptimiser optimiser = new SchemaOptimiser(serialisationFactory);
    final boolean isOrdered = true;
    final StringSerialiser stringSerialiser = mock(StringSerialiser.class);
    final StringSerialiser intSerialiser = mock(StringSerialiser.class);
    final JavaSerialiser javaSerialiser = mock(JavaSerialiser.class);
    given(serialisationFactory.getSerialiser(String.class, true)).willReturn(stringSerialiser);
    given(serialisationFactory.getSerialiser(Integer.class, false)).willReturn(intSerialiser);
    given(serialisationFactory.getSerialiser(Serializable.class, true)).willReturn(javaSerialiser);
    given(javaSerialiser.canHandle(Mockito.any(Class.class))).willReturn(true);
    schema = new Schema.Builder().merge(schema).type("obj", Serializable.class).entity(TestGroups.ENTITY_2, new SchemaEntityDefinition.Builder().vertex("obj").build()).build();
    // When
    final Schema optimisedSchema = optimiser.optimise(schema, isOrdered);
    // Then
    assertSame(stringSerialiser, optimisedSchema.getType("string").getSerialiser());
    assertSame(intSerialiser, optimisedSchema.getType("int").getSerialiser());
    assertSame(javaSerialiser, optimisedSchema.getVertexSerialiser());
    verify(serialisationFactory, never()).getSerialiser(String.class, false);
    verify(serialisationFactory, never()).getSerialiser(Serializable.class, false);
}
Also used : StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) Serializable(java.io.Serializable) JavaSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.JavaSerialiser) SerialisationFactory(uk.gov.gchq.gaffer.serialisation.implementation.SerialisationFactory) Test(org.junit.Test)

Example 2 with StringSerialiser

use of uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser in project Gaffer by gchq.

the class StoreTest method shouldThrowExceptionWhenPropertyIsNotSerialisable.

@Test
public void shouldThrowExceptionWhenPropertyIsNotSerialisable() throws StoreException {
    // Given
    final Schema mySchema = new Schema.Builder().edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().property(TestPropertyNames.PROP_1, "invalidType").build()).type("invalidType", new TypeDefinition.Builder().clazz(Object.class).serialiser(new StringSerialiser()).build()).build();
    final StoreProperties properties = mock(StoreProperties.class);
    final StoreImpl store = new StoreImpl();
    // When
    try {
        store.initialise(mySchema, properties);
        fail();
    } catch (final SchemaException exception) {
        assertNotNull(exception.getMessage());
    }
}
Also used : SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) Schema(uk.gov.gchq.gaffer.store.schema.Schema) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 StringSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser)2 Serializable (java.io.Serializable)1 SchemaException (uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException)1 JavaSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.JavaSerialiser)1 SerialisationFactory (uk.gov.gchq.gaffer.serialisation.implementation.SerialisationFactory)1 Schema (uk.gov.gchq.gaffer.store.schema.Schema)1 SchemaEdgeDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition)1 TypeDefinition (uk.gov.gchq.gaffer.store.schema.TypeDefinition)1