use of uk.gov.gchq.gaffer.operation.impl.compare.Sort in project Gaffer by gchq.
the class OperationAuthoriserTest method shouldAcceptOperationChainWhenUserHasAllOpAuths.
@Test
public void shouldAcceptOperationChainWhenUserHasAllOpAuths() {
// Given
final OperationAuthoriser hook = fromJson(OP_AUTHS_PATH);
final OperationChain opChain = new OperationChain.Builder().first(new GetElements()).then(new GenerateObjects<>()).then(new DiscardOutput()).then(new TestOperationsImpl(Collections.singletonList(new Sort()))).build();
final User user = new User.Builder().opAuths("SuperUser", "ReadUser", "User").build();
// When
hook.preExecute(opChain, new Context(user));
// Then - no exceptions
}
use of uk.gov.gchq.gaffer.operation.impl.compare.Sort in project Gaffer by gchq.
the class SortHandlerTest method shouldSortBasedOnProperty_reversed.
@Test
public void shouldSortBasedOnProperty_reversed() throws OperationException, JsonProcessingException {
// Given
final Entity entity1 = new Entity.Builder().group(TestGroups.ENTITY).property("property", 1).build();
final Entity entity2 = new Entity.Builder().group(TestGroups.ENTITY).property("property", 2).build();
final Entity entity3 = new Entity.Builder().group(TestGroups.ENTITY).property("property", 3).build();
final Entity entity4 = new Entity.Builder().group(TestGroups.ENTITY).property("property", 4).build();
final List<Entity> input = Lists.newArrayList(entity1, entity2, entity3, entity4);
final Sort sort = new Sort.Builder().input(input).comparators(new ElementPropertyComparator.Builder().groups(TestGroups.ENTITY).property("property").comparator(new PropertyComparatorImpl()).reverse(true).build()).build();
final SortHandler handler = new SortHandler();
// When
final Iterable<? extends Element> result = handler.doOperation(sort, null, null);
// Then
assertEquals(Arrays.asList(entity4, entity3, entity2, entity1), Lists.newArrayList(result));
}
use of uk.gov.gchq.gaffer.operation.impl.compare.Sort in project Gaffer by gchq.
the class SortHandlerTest method shouldSortBasedOnElement.
@Test
public void shouldSortBasedOnElement() throws OperationException {
// Given
final Entity entity1 = new Entity.Builder().group(TestGroups.ENTITY).property("property1", 1).property("property2", 1).build();
final Entity entity2 = new Entity.Builder().group(TestGroups.ENTITY).property("property1", 2).property("property2", 2).build();
final Entity entity3 = new Entity.Builder().group(TestGroups.ENTITY).property("property1", 3).property("property2", 3).build();
final Entity entity4 = new Entity.Builder().group(TestGroups.ENTITY).property("property1", 4).property("property2", 4).build();
final List<Entity> input = Lists.newArrayList(entity1, entity3, entity2, entity4);
final Sort sort = new Sort.Builder().input(input).comparators(new ElementComparatorImpl()).build();
final SortHandler handler = new SortHandler();
// When
final Iterable<? extends Element> result = handler.doOperation(sort, null, null);
// Then
int prev = Integer.MIN_VALUE;
for (final Element element : result) {
final int curr = (int) element.getProperty("property1");
assertTrue(curr > prev);
prev = curr;
}
}
use of uk.gov.gchq.gaffer.operation.impl.compare.Sort in project Gaffer by gchq.
the class SortHandlerTest method shouldReturnOriginalListIfBothComparatorsAreNull.
@Test
public void shouldReturnOriginalListIfBothComparatorsAreNull() throws OperationException {
// Given
final List<Entity> input = Lists.newArrayList();
final Sort sort = new Sort.Builder().input(input).build();
final SortHandler handler = new SortHandler();
// When
final Iterable<? extends Element> result = handler.doOperation(sort, null, null);
// Then
assertNull(result);
}
use of uk.gov.gchq.gaffer.operation.impl.compare.Sort in project Gaffer by gchq.
the class SortHandlerTest method shouldNotThrowExceptionIfIterableIsEmpty.
@Test
public void shouldNotThrowExceptionIfIterableIsEmpty() throws OperationException {
// Given
final List<Entity> input = Lists.newArrayList();
final Sort sort = new Sort.Builder().input(input).comparators(new ElementPropertyComparator.Builder().groups(TestGroups.ENTITY).property("property").build()).build();
final SortHandler handler = new SortHandler();
// When
final Iterable<? extends Element> result = handler.doOperation(sort, null, null);
// Then
assertTrue(Streams.toStream(result).collect(Collectors.toList()).isEmpty());
}
Aggregations