use of uk.gov.gchq.gaffer.operation.impl.compare.Max in project Gaffer by gchq.
the class MaxHandlerTest method shouldFindMaxBasedOnElement.
@Test
public void shouldFindMaxBasedOnElement() 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 Max max = new Max.Builder().input(input).comparators(new SimpleElementComparator()).build();
final MaxHandler handler = new MaxHandler();
// When
final Element result = handler.doOperation(max, null, null);
// Then
assertTrue(result instanceof Entity);
assertEquals(4, result.getProperty("property1"));
assertEquals(4, result.getProperty("property2"));
}
use of uk.gov.gchq.gaffer.operation.impl.compare.Max in project Gaffer by gchq.
the class MaxHandlerTest method shouldFindMaxBasedOnPropertyWithMissingProperty.
@Test
public void shouldFindMaxBasedOnPropertyWithMissingProperty() 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 Max max1 = new Max.Builder().input(input).comparators(new ElementPropertyComparator.Builder().groups(TestGroups.ENTITY).property("property1").build()).build();
final Max max2 = new Max.Builder().input(input).comparators(new ElementPropertyComparator.Builder().groups(TestGroups.ENTITY).property("property2").build()).build();
final MaxHandler handler = new MaxHandler();
// When
final Element result1 = handler.doOperation(max1, null, null);
final Element result2 = handler.doOperation(max2, null, null);
// Then
assertTrue(result1 instanceof Entity);
assertTrue(result2 instanceof Entity);
assertEquals(3, result1.getProperty("property1"));
assertEquals(2, result2.getProperty("property2"));
}
use of uk.gov.gchq.gaffer.operation.impl.compare.Max in project Gaffer by gchq.
the class MaxHandlerTest method shouldFindMaxBasedOnProperty.
@Test
public void shouldFindMaxBasedOnProperty() 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 Max max = new Max.Builder().input(input).comparators(new ElementPropertyComparator.Builder().groups(TestGroups.ENTITY).property("property").build()).build();
final MaxHandler handler = new MaxHandler();
// When
final Element result = handler.doOperation(max, null, null);
// Then
assertTrue(result instanceof Entity);
assertEquals(3, result.getProperty("property"));
}
use of uk.gov.gchq.gaffer.operation.impl.compare.Max in project Gaffer by gchq.
the class OperationChainValidatorTest method shouldInValidateNullElementDef.
@Test
public void shouldInValidateNullElementDef() {
// Given
final ViewValidator viewValidator = mock(ViewValidator.class);
final OperationChainValidator validator = new OperationChainValidator(viewValidator);
final Store store = mock(Store.class);
Schema schema = mock(Schema.class);
given(store.getSchema()).willReturn(schema);
given(schema.getElement(Mockito.anyString())).willReturn(null);
Max max = new Max();
max.setComparators(Lists.newArrayList(new ElementPropertyComparator.Builder().groups(TestGroups.ENTITY).property("property").build()));
ValidationResult validationResult = new ValidationResult();
// When
validator.validateComparables(max, null, store, validationResult);
// Then
assertEquals(false, validationResult.isValid());
Set<String> errors = validationResult.getErrors();
assertThat(errors).hasSize(1);
errors.contains(Max.class.getName() + " references BasicEntity group that does not exist in the schema");
}
use of uk.gov.gchq.gaffer.operation.impl.compare.Max in project Gaffer by gchq.
the class MaxHandlerTest method shouldFindMaxBasedOnMultipleProperties.
@Test
public void shouldFindMaxBasedOnMultipleProperties() throws OperationException {
// Given
final Entity entity1 = makeEntity(1, 1);
final Entity entity2 = makeEntity(1, 2);
final Entity entity3 = makeEntity(2, 2);
final Entity entity4 = makeEntity(2, 1);
final List<Entity> input = Lists.newArrayList(entity1, entity2, entity3, entity4);
final Max max = new Max.Builder().input(input).comparators(new ElementPropertyComparator.Builder().groups(TestGroups.ENTITY).property("property1").build(), new ElementPropertyComparator.Builder().groups(TestGroups.ENTITY).property("property2").build()).build();
final MaxHandler handler = new MaxHandler();
// When
final Element result = handler.doOperation(max, null, null);
// Then
assertSame(entity3, result);
}
Aggregations