use of uk.gov.gchq.gaffer.store.Context in project Gaffer by gchq.
the class DeduplicateHandlerTest method shouldDeduplicateResults.
@Test
public void shouldDeduplicateResults() throws OperationException {
// Given
final CloseableIterable<Integer> originalResults = new WrappedCloseableIterable<>(Arrays.asList(1, 2, 2, 2, 3, 4, 1, 5, 6, 7, 8, 5, 9, 1, 6, 8, 2, 10));
final DeduplicateHandler<Integer> handler = new DeduplicateHandler<>();
final Deduplicate<Integer> operation = mock(Deduplicate.class);
given(operation.getInput()).willReturn(originalResults);
// When
final Iterable<Integer> results = handler.doOperation(operation, new Context(), null);
// Then
assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), Lists.newArrayList(results));
}
use of uk.gov.gchq.gaffer.store.Context in project Gaffer by gchq.
the class DeduplicateHandlerTest method shouldDeduplicateResultsAndMaintainOrder.
@Test
public void shouldDeduplicateResultsAndMaintainOrder() throws OperationException {
// Given
final CloseableIterable<Integer> originalResults = new WrappedCloseableIterable<>(Arrays.asList(10, 9, 8, 10, 7, 8, 7, 6, 6, 5, 6, 9, 4, 5, 3, 4, 2, 2, 2, 1, 1));
final DeduplicateHandler<Integer> handler = new DeduplicateHandler<>();
final Deduplicate<Integer> operation = mock(Deduplicate.class);
given(operation.getInput()).willReturn(originalResults);
// When
final Iterable<Integer> results = handler.doOperation(operation, new Context(), null);
// Then
assertEquals(Arrays.asList(10, 9, 8, 7, 6, 5, 4, 3, 2, 1), Lists.newArrayList(results));
}
use of uk.gov.gchq.gaffer.store.Context in project Gaffer by gchq.
the class ValidateHandlerTest method shouldValidatedElements.
@Test
public void shouldValidatedElements() throws OperationException {
// Given
final ValidateHandler handler = new ValidateHandler();
final Store store = mock(Store.class);
final Validate validate = mock(Validate.class);
final Element elm1 = mock(Element.class);
final CloseableIterable<Element> elements = new WrappedCloseableIterable<>(Collections.singletonList(elm1));
final Schema schema = mock(Schema.class);
final Context context = new Context();
given(validate.getElements()).willReturn(elements);
given(validate.isSkipInvalidElements()).willReturn(false);
given(store.getSchema()).willReturn(schema);
final String group = "group";
given(elm1.getGroup()).willReturn(group);
final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
final ElementFilter validator = mock(ElementFilter.class);
given(validator.filter(elm1)).willReturn(true);
given(elementDef.getValidator(true)).willReturn(validator);
given(schema.getElement(group)).willReturn(elementDef);
// When
final Iterable<Element> result = handler.doOperation(validate, context, store);
// Then
final Iterator<Element> itr = result.iterator();
final Element elm1Result = itr.next();
assertSame(elm1, elm1Result);
assertFalse(itr.hasNext());
}
use of uk.gov.gchq.gaffer.store.Context in project Gaffer by gchq.
the class ValidateHandlerTest method shouldReturnNullIfElementsAreNull.
@Test
public void shouldReturnNullIfElementsAreNull() throws OperationException {
// Given
final ValidateHandler handler = new ValidateHandler();
final Store store = mock(Store.class);
final Validate validate = mock(Validate.class);
given(validate.getElements()).willReturn(null);
final Context context = new Context();
// When
final Iterable<Element> result = handler.doOperation(validate, context, store);
// Then
assertNull(result);
}
use of uk.gov.gchq.gaffer.store.Context in project Gaffer by gchq.
the class GetAllJobDetailsHandlerTest method shouldGetAllJobDetailsByDelegatingToJobTracker.
@Test
public void shouldGetAllJobDetailsByDelegatingToJobTracker() throws OperationException {
// Given
final GetAllJobDetailsHandler handler = new GetAllJobDetailsHandler();
final GetAllJobDetails operation = mock(GetAllJobDetails.class);
final Store store = mock(Store.class);
final JobTracker jobTracker = mock(JobTracker.class);
final User user = mock(User.class);
final CloseableIterable<JobDetail> jobsDetails = mock(CloseableIterable.class);
given(store.getJobTracker()).willReturn(jobTracker);
given(jobTracker.getAllJobs(user)).willReturn(jobsDetails);
// When
final CloseableIterable<JobDetail> results = handler.doOperation(operation, new Context(user), store);
// Then
assertSame(jobsDetails, results);
}
Aggregations