Search in sources :

Example 1 with MapGenerator

use of uk.gov.gchq.gaffer.data.generator.MapGenerator in project Gaffer by gchq.

the class MapGeneratorTest method shouldGenerateAnEmptyMap.

@Test
public void shouldGenerateAnEmptyMap() {
    // Given
    final Object vertex = "source vertex";
    final String prop1 = "property 1";
    final int count = 10;
    final Element element = new Entity.Builder().group(TestGroups.ENTITY).vertex(vertex).property(TestPropertyNames.PROP_1, prop1).property(TestPropertyNames.COUNT, count).build();
    final MapGenerator generator = new MapGenerator();
    // When
    final Map<String, Object> map = generator.getObject(element);
    // Then
    final Map<String, Object> expectedMap = new LinkedHashMap<>();
    assertEquals(expectedMap, map);
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) MapGenerator(uk.gov.gchq.gaffer.data.generator.MapGenerator) Element(uk.gov.gchq.gaffer.data.element.Element) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 2 with MapGenerator

use of uk.gov.gchq.gaffer.data.generator.MapGenerator in project Gaffer by gchq.

the class MapGeneratorTest method shouldGenerateMapFromASingleProperty.

@Test
public void shouldGenerateMapFromASingleProperty() {
    // Given
    final Object vertex = "source vertex";
    final String prop1 = "property 1";
    final int count = 10;
    final Element element = new Entity.Builder().group(TestGroups.ENTITY).vertex(vertex).property(TestPropertyNames.PROP_1, prop1).property(TestPropertyNames.COUNT, count).build();
    final MapGenerator generator = new MapGenerator.Builder().property(TestPropertyNames.PROP_1, "field1").build();
    // When
    final Map<String, Object> map = generator.getObject(element);
    // Then
    final Map<String, Object> expectedMap = new LinkedHashMap<>();
    expectedMap.put("field1", prop1);
    assertEquals(expectedMap, map);
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) MapGenerator(uk.gov.gchq.gaffer.data.generator.MapGenerator) Element(uk.gov.gchq.gaffer.data.element.Element) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 3 with MapGenerator

use of uk.gov.gchq.gaffer.data.generator.MapGenerator in project Gaffer by gchq.

the class MapGeneratorTest method shouldGenerateMapFromElementFieldsAndConstants.

@Test
public void shouldGenerateMapFromElementFieldsAndConstants() {
    // Given
    final Object vertex = "source vertex";
    final String prop1 = "property 1";
    final int count = 10;
    final Element element = new Entity.Builder().group(TestGroups.ENTITY).vertex(vertex).property(TestPropertyNames.PROP_1, prop1).property(TestPropertyNames.COUNT, count).build();
    final MapGenerator generator = new MapGenerator.Builder().vertex("field1").group("field2").property(TestPropertyNames.COUNT, "field3").property(TestPropertyNames.PROP_1, "field4").source(// the entity does not have a source so this should be skipped
    "field5").property("unknown property", "field6").constant("constant1", "constantValue1").build();
    // When
    final Map<String, Object> map = generator.getObject(element);
    // Then
    final Map<String, Object> expectedMap = new LinkedHashMap<>();
    expectedMap.put("field1", vertex);
    expectedMap.put("field2", TestGroups.ENTITY);
    expectedMap.put("field3", count);
    expectedMap.put("field4", prop1);
    expectedMap.put("constant1", "constantValue1");
    assertEquals(expectedMap, map);
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) MapGenerator(uk.gov.gchq.gaffer.data.generator.MapGenerator) Element(uk.gov.gchq.gaffer.data.element.Element) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)3 Test (org.junit.Test)3 Element (uk.gov.gchq.gaffer.data.element.Element)3 Entity (uk.gov.gchq.gaffer.data.element.Entity)3 MapGenerator (uk.gov.gchq.gaffer.data.generator.MapGenerator)3