Search in sources :

Example 1 with Max

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"));
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) Max(uk.gov.gchq.gaffer.operation.impl.compare.Max) Element(uk.gov.gchq.gaffer.data.element.Element) Test(org.junit.jupiter.api.Test)

Example 2 with Max

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"));
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) Max(uk.gov.gchq.gaffer.operation.impl.compare.Max) Element(uk.gov.gchq.gaffer.data.element.Element) ElementPropertyComparator(uk.gov.gchq.gaffer.data.element.comparison.ElementPropertyComparator) Test(org.junit.jupiter.api.Test)

Example 3 with Max

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"));
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) Max(uk.gov.gchq.gaffer.operation.impl.compare.Max) Element(uk.gov.gchq.gaffer.data.element.Element) ElementPropertyComparator(uk.gov.gchq.gaffer.data.element.comparison.ElementPropertyComparator) Test(org.junit.jupiter.api.Test)

Example 4 with Max

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");
}
Also used : Max(uk.gov.gchq.gaffer.operation.impl.compare.Max) ViewValidator(uk.gov.gchq.gaffer.store.schema.ViewValidator) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) ElementPropertyComparator(uk.gov.gchq.gaffer.data.element.comparison.ElementPropertyComparator) Test(org.junit.jupiter.api.Test)

Example 5 with Max

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);
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) Max(uk.gov.gchq.gaffer.operation.impl.compare.Max) Element(uk.gov.gchq.gaffer.data.element.Element) ElementPropertyComparator(uk.gov.gchq.gaffer.data.element.comparison.ElementPropertyComparator) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)8 Max (uk.gov.gchq.gaffer.operation.impl.compare.Max)8 Element (uk.gov.gchq.gaffer.data.element.Element)6 Entity (uk.gov.gchq.gaffer.data.element.Entity)5 ElementPropertyComparator (uk.gov.gchq.gaffer.data.element.comparison.ElementPropertyComparator)4 Store (uk.gov.gchq.gaffer.store.Store)1 Schema (uk.gov.gchq.gaffer.store.schema.Schema)1 ViewValidator (uk.gov.gchq.gaffer.store.schema.ViewValidator)1 ValidationResult (uk.gov.gchq.koryphe.ValidationResult)1