use of uk.gov.gchq.gaffer.serialisation.Serialiser in project Gaffer by gchq.
the class SerialisationFactoryTest method shouldReturnSerialiserForAString.
@Test
public void shouldReturnSerialiserForAString() throws SerialisationException {
// Given
final SerialisationFactory factory = new SerialisationFactory();
final Class<?> clazz = String.class;
// When
final Serialiser serialiser = factory.getSerialiser(clazz);
// Then
assertTrue(serialiser.canHandle(clazz));
assertEquals(StringSerialiser.class, serialiser.getClass());
}
use of uk.gov.gchq.gaffer.serialisation.Serialiser in project Gaffer by gchq.
the class SerialisationFactoryTest method shouldReturnOrderedSerialiserForAString.
@Test
public void shouldReturnOrderedSerialiserForAString() throws SerialisationException {
// Given
final SerialisationFactory factory = new SerialisationFactory();
final Class<?> clazz = String.class;
final boolean ordered = true;
// When
final Serialiser serialiser = factory.getSerialiser(clazz, ordered, true);
// Then
assertTrue(serialiser.canHandle(clazz));
assertEquals(StringSerialiser.class, serialiser.getClass());
}
use of uk.gov.gchq.gaffer.serialisation.Serialiser in project Gaffer by gchq.
the class SerialisationFactoryTest method shouldReturnSerialiserForAnInteger.
@Test
public void shouldReturnSerialiserForAnInteger() throws SerialisationException {
// Given
final SerialisationFactory factory = new SerialisationFactory();
final Class<?> clazz = Integer.class;
// When
final Serialiser serialiser = factory.getSerialiser(clazz);
// Then
assertTrue(serialiser.canHandle(clazz));
assertEquals(OrderedIntegerSerialiser.class, serialiser.getClass());
}
use of uk.gov.gchq.gaffer.serialisation.Serialiser in project gaffer-doc by gchq.
the class PropertiesWalkthrough method listToBytesSerialisers.
protected boolean listToBytesSerialisers(final Class<?> clazz) {
final List<Class> toBytesSerialiserClasses = new ArrayList<>();
for (final Serialiser serialise : TO_BYTES_SERIALISERS) {
if (serialise.canHandle(clazz)) {
toBytesSerialiserClasses.add(serialise.getClass());
}
}
if (toBytesSerialiserClasses.contains(JavaSerialiser.class)) {
if (toBytesSerialiserClasses.contains(AvroSerialiser.class)) {
if (toBytesSerialiserClasses.size() > 2) {
toBytesSerialiserClasses.remove(JavaSerialiser.class);
toBytesSerialiserClasses.remove(AvroSerialiser.class);
}
} else {
if (toBytesSerialiserClasses.size() > 1) {
toBytesSerialiserClasses.remove(JavaSerialiser.class);
}
}
} else if (toBytesSerialiserClasses.contains(AvroSerialiser.class)) {
if (toBytesSerialiserClasses.size() > 1) {
toBytesSerialiserClasses.remove(AvroSerialiser.class);
}
}
final List<String> toBytesSerialiserClassNames = new ArrayList<>();
for (final Class toBytesSerialiserClass : toBytesSerialiserClasses) {
toBytesSerialiserClassNames.add(WalkthroughStrSubstitutor.getJavaDocLink(toBytesSerialiserClass, false, 3));
}
if (!toBytesSerialiserClasses.isEmpty()) {
print(SERIALISERS_KEY, "\nTo Bytes Serialisers:");
print(SERIALISERS_KEY, "\n- " + StringUtils.join(toBytesSerialiserClassNames, "\n- "));
}
return !toBytesSerialiserClasses.isEmpty();
}
use of uk.gov.gchq.gaffer.serialisation.Serialiser in project Gaffer by gchq.
the class SchemaTest method shouldMergeDifferentSchemas.
@Test
public void shouldMergeDifferentSchemas() {
// Given
final String typeShared = "typeShared";
final String type1 = "type1";
final String type2 = "type2";
final Serialiser vertexSerialiser = new StringSerialiser();
final Schema schema1 = new Schema.Builder().edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().property(TestPropertyNames.PROP_1, type1).build()).entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().property(TestPropertyNames.COUNT, typeShared).build()).vertexSerialiser(vertexSerialiser).type(typeShared, Long.class).type(type1, Integer.class).visibilityProperty(TestPropertyNames.VISIBILITY).config("key1a", "value1a").config("key1b", "value1b").build();
final Schema schema2 = new Schema.Builder().entity(TestGroups.ENTITY_2, new SchemaEntityDefinition.Builder().property(TestPropertyNames.COUNT, typeShared).build()).edge(TestGroups.EDGE_2, new SchemaEdgeDefinition.Builder().property(TestPropertyNames.PROP_2, type2).build()).type(type2, String.class).type(typeShared, Long.class).config("key1b", "value1c").config("key2", "value2").build();
// When
final Schema mergedSchema = new Schema.Builder().merge(schema1).merge(schema1).merge(schema2).merge(// should be able to merge a duplicate schema
schema2).build();
// Then
assertEquals(2, mergedSchema.getEdges().size());
assertEquals(1, mergedSchema.getEdge(TestGroups.EDGE).getPropertyMap().size());
assertEquals(type1, mergedSchema.getEdge(TestGroups.EDGE).getPropertyMap().get(TestPropertyNames.PROP_1));
assertEquals(1, mergedSchema.getEdge(TestGroups.EDGE_2).getPropertyMap().size());
assertEquals(type2, mergedSchema.getEdge(TestGroups.EDGE_2).getPropertyMap().get(TestPropertyNames.PROP_2));
assertEquals(2, mergedSchema.getEntities().size());
assertEquals(1, mergedSchema.getEntity(TestGroups.ENTITY).getPropertyMap().size());
assertEquals(typeShared, mergedSchema.getEntity(TestGroups.ENTITY).getPropertyMap().get(TestPropertyNames.COUNT));
assertEquals(1, mergedSchema.getEntity(TestGroups.ENTITY_2).getPropertyMap().size());
assertEquals(typeShared, mergedSchema.getEntity(TestGroups.ENTITY_2).getPropertyMap().get(TestPropertyNames.COUNT));
assertEquals(Integer.class, mergedSchema.getType(type1).getClazz());
assertEquals(String.class, mergedSchema.getType(type2).getClazz());
assertEquals(vertexSerialiser, mergedSchema.getVertexSerialiser());
assertEquals(TestPropertyNames.VISIBILITY, mergedSchema.getVisibilityProperty());
assertEquals("value1a", mergedSchema.getConfig("key1a"));
assertEquals("value1c", mergedSchema.getConfig("key1b"));
assertEquals("value2", mergedSchema.getConfig("key2"));
}
Aggregations