use of uk.gov.gchq.gaffer.operation.impl.compare.Min in project Gaffer by gchq.
the class MinHandlerTest method shouldFindMinBasedOnProperty.
@Test
public void shouldFindMinBasedOnProperty() throws OperationException {
// Given
final Entity entity1 = makeEntity("property", 1);
final Entity entity2 = makeEntity("property", 2);
final Entity entity3 = makeEntity("property", 3);
final Entity entity4 = makeEntity("property", 1);
final List<Entity> input = Lists.newArrayList(entity1, entity2, entity3, entity4);
final Min min = new Min.Builder().input(input).comparators(new ElementPropertyComparator.Builder().groups(TestGroups.ENTITY).property("property").build()).build();
final MinHandler handler = new MinHandler();
// When
final Element result = handler.doOperation(min, null, null);
// Then
assertTrue(result instanceof Entity);
assertEquals(1, result.getProperty("property"));
}
use of uk.gov.gchq.gaffer.operation.impl.compare.Min in project Gaffer by gchq.
the class MinHandlerTest method shouldFindMinBasedOnElement.
@Test
public void shouldFindMinBasedOnElement() throws OperationException {
// Given
final Entity entity1 = makeEntity(1, 1);
final Entity entity2 = makeEntity(2, 2);
final Entity entity3 = makeEntity(3, 3);
final Entity entity4 = makeEntity(4, 4);
final List<Entity> input = Lists.newArrayList(entity1, entity2, entity3, entity4);
final Min min = new Min.Builder().input(input).comparators(new SimpleElementComparator()).build();
final MinHandler handler = new MinHandler();
// When
final Element result = handler.doOperation(min, null, null);
// Then
assertTrue(result instanceof Entity);
assertEquals(1, result.getProperty("property1"));
assertEquals(1, result.getProperty("property2"));
}
use of uk.gov.gchq.gaffer.operation.impl.compare.Min in project Gaffer by gchq.
the class AbstractExamplesFactoryTest method shouldUseSchemaForMinOperation.
@Test
public void shouldUseSchemaForMinOperation() throws InstantiationException, IllegalAccessException {
// Given
TestExamplesFactory examplesFactory = new TestExamplesFactory(SCHEMA);
// When
Min operation = (Min) examplesFactory.generateExample(Min.class);
// Then
// Min has no equals method
assertEquals(1, operation.getComparators().size());
assertEquals(Sets.newHashSet("BasicEdge"), ((ElementPropertyComparator) operation.getComparators().get(0)).getGroups());
assertEquals("count", ((ElementPropertyComparator) operation.getComparators().get(0)).getProperty());
}
use of uk.gov.gchq.gaffer.operation.impl.compare.Min in project Gaffer by gchq.
the class MinHandlerTest method shouldReturnNullIfBothComparatorsAreNull.
@Test
public void shouldReturnNullIfBothComparatorsAreNull() throws OperationException {
// Given
final List<Entity> input = Lists.newArrayList();
final Min min = new Min.Builder().input(input).build();
final MinHandler handler = new MinHandler();
// When
final Element result = handler.doOperation(min, null, null);
// Then
assertNull(result);
}
use of uk.gov.gchq.gaffer.operation.impl.compare.Min in project Gaffer by gchq.
the class MinHandlerTest method shouldFindMinBasedOnPropertyWithMissingProperty.
@Test
public void shouldFindMinBasedOnPropertyWithMissingProperty() throws OperationException {
// Given
final Entity entity1 = makeEntity("property1", 1);
final Entity entity2 = makeEntity("property1", 2);
final Entity entity3 = makeEntity("property1", 3);
final Entity entity4 = makeEntity("property2", 1);
final Entity entity5 = makeEntity("property2", 2);
final List<Entity> input = Lists.newArrayList(entity1, entity2, entity3, entity4, entity5);
final Min min1 = new Min.Builder().input(input).comparators(new ElementPropertyComparator.Builder().groups(TestGroups.ENTITY).property("property1").build()).build();
final Min min2 = new Min.Builder().input(input).comparators(new ElementPropertyComparator.Builder().groups(TestGroups.ENTITY).property("property2").build()).build();
final MinHandler handler = new MinHandler();
// When
final Element result1 = handler.doOperation(min1, null, null);
final Element result2 = handler.doOperation(min2, null, null);
// Then
assertTrue(result1 instanceof Entity);
assertTrue(result2 instanceof Entity);
assertEquals(1, result1.getProperty("property1"));
assertEquals(1, result2.getProperty("property2"));
}
Aggregations