Search in sources :

Example 6 with Context

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));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) Test(org.junit.Test)

Example 7 with Context

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));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) Test(org.junit.Test)

Example 8 with Context

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());
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) Element(uk.gov.gchq.gaffer.data.element.Element) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) Validate(uk.gov.gchq.gaffer.operation.impl.Validate) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) Test(org.junit.Test)

Example 9 with Context

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);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Validate(uk.gov.gchq.gaffer.operation.impl.Validate) Element(uk.gov.gchq.gaffer.data.element.Element) Store(uk.gov.gchq.gaffer.store.Store) Test(org.junit.Test)

Example 10 with Context

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);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetAllJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetAllJobDetails) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) User(uk.gov.gchq.gaffer.user.User) JobTracker(uk.gov.gchq.gaffer.jobtracker.JobTracker) Store(uk.gov.gchq.gaffer.store.Store) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)19 Context (uk.gov.gchq.gaffer.store.Context)19 Store (uk.gov.gchq.gaffer.store.Store)17 Element (uk.gov.gchq.gaffer.data.element.Element)7 WrappedCloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable)5 User (uk.gov.gchq.gaffer.user.User)5 GroupCounts (uk.gov.gchq.gaffer.data.GroupCounts)4 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)4 JSONSerialiser (uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser)4 GafferResultCacheExporter (uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter)4 CountGroups (uk.gov.gchq.gaffer.operation.impl.CountGroups)4 CountGroupsHandler (uk.gov.gchq.gaffer.store.operation.handler.CountGroupsHandler)4 JobDetail (uk.gov.gchq.gaffer.jobtracker.JobDetail)3 JobTracker (uk.gov.gchq.gaffer.jobtracker.JobTracker)3 GetJobDetails (uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails)3 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)2 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)2 OperationException (uk.gov.gchq.gaffer.operation.OperationException)2 Validate (uk.gov.gchq.gaffer.operation.impl.Validate)2 ExportToGafferResultCache (uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache)2