Search in sources :

Example 11 with Context

use of uk.gov.gchq.gaffer.store.Context in project Gaffer by gchq.

the class GetAllJobDetailsHandlerTest method shouldThrowExceptionIfJobTrackerIsNotConfigured.

@Test
public void shouldThrowExceptionIfJobTrackerIsNotConfigured() {
    // Given
    final GetAllJobDetailsHandler handler = new GetAllJobDetailsHandler();
    final GetAllJobDetails operation = mock(GetAllJobDetails.class);
    final Store store = mock(Store.class);
    final User user = mock(User.class);
    given(store.getJobTracker()).willReturn(null);
    // When / Then
    try {
        handler.doOperation(operation, new Context(user), store);
        fail("Exception expected");
    } catch (final OperationException e) {
        assertNotNull(e.getMessage());
    }
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetAllJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetAllJobDetails) User(uk.gov.gchq.gaffer.user.User) Store(uk.gov.gchq.gaffer.store.Store) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Test(org.junit.Test)

Example 12 with Context

use of uk.gov.gchq.gaffer.store.Context in project Gaffer by gchq.

the class GetJobDetailsHandlerTest method shouldGetJobDetailsByDelegatingToJobTrackerWithContextJobId.

@Test
public void shouldGetJobDetailsByDelegatingToJobTrackerWithContextJobId() throws OperationException {
    // Given
    final String jobId = "jobId";
    final GetJobDetailsHandler handler = new GetJobDetailsHandler();
    final GetJobDetails operation = new GetJobDetails();
    final Store store = mock(Store.class);
    final JobTracker jobTracker = mock(JobTracker.class);
    final User user = mock(User.class);
    final JobDetail jobsDetail = mock(JobDetail.class);
    final Context context = new Context(user, jobId);
    given(store.getJobTracker()).willReturn(jobTracker);
    given(jobTracker.getJob(jobId, user)).willReturn(jobsDetail);
    // When
    final JobDetail result = handler.doOperation(operation, context, store);
    // Then
    assertSame(jobsDetail, result);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails) 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)

Example 13 with Context

use of uk.gov.gchq.gaffer.store.Context in project Gaffer by gchq.

the class ExportToGafferResultCacheHandlerTest method shouldHandleOperationByDelegatingToAnExistingExporter.

@Test
public void shouldHandleOperationByDelegatingToAnExistingExporter() throws OperationException {
    // Given
    final List<?> results = Arrays.asList(1, 2, 3);
    final ExportToGafferResultCache export = new ExportToGafferResultCache.Builder().key("key").input(results).build();
    final Context context = new Context();
    final Store store = mock(Store.class);
    final JSONSerialiser jsonSerialiser = mock(JSONSerialiser.class);
    final Long timeToLive = 10000L;
    final String visibility = "visibility value";
    final GafferResultCacheExporter exporter = mock(GafferResultCacheExporter.class);
    context.addExporter(exporter);
    final ExportToGafferResultCacheHandler handler = new ExportToGafferResultCacheHandler();
    handler.setStorePropertiesPath(StreamUtil.STORE_PROPERTIES);
    handler.setJsonSerialiser(jsonSerialiser);
    handler.setTimeToLive(timeToLive);
    handler.setVisibility(visibility);
    // When
    final Object handlerResult = handler.doOperation(export, context, store);
    // Then
    verify(exporter).add("key", results);
    assertSame(handlerResult, results);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GafferResultCacheExporter(uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter) JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) ExportToGafferResultCache(uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) Store(uk.gov.gchq.gaffer.store.Store) Test(org.junit.Test)

Example 14 with Context

use of uk.gov.gchq.gaffer.store.Context in project Gaffer by gchq.

the class GenerateElementsHandlerTest method shouldReturnElements.

@Test
public void shouldReturnElements() throws OperationException {
    // Given
    final GenerateElementsHandler<String> handler = new GenerateElementsHandler<>();
    final Store store = mock(Store.class);
    final GenerateElements<String> operation = mock(GenerateElements.class);
    final CloseableIterable<Element> elements = mock(CloseableIterable.class);
    final ElementGenerator<String> elementGenerator = mock(ElementGenerator.class);
    final CloseableIterable<String> objs = mock(CloseableIterable.class);
    final Context context = new Context();
    final CloseableIterator<Element> elementsIter = mock(CloseableIterator.class);
    given(elements.iterator()).willReturn(elementsIter);
    given(elementGenerator.getElements(objs)).willReturn(elements);
    given(operation.getObjects()).willReturn(objs);
    given(operation.getElementGenerator()).willReturn(elementGenerator);
    // When
    final CloseableIterable<Element> result = handler.doOperation(operation, context, store);
    // Then
    assertSame(elementsIter, result.iterator());
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Element(uk.gov.gchq.gaffer.data.element.Element) Store(uk.gov.gchq.gaffer.store.Store) Test(org.junit.Test)

Example 15 with Context

use of uk.gov.gchq.gaffer.store.Context in project Gaffer by gchq.

the class GenerateObjectsHandlerTest method shouldReturnObjects.

@Test
public void shouldReturnObjects() throws OperationException {
    // Given
    final GenerateObjectsHandler<String> handler = new GenerateObjectsHandler<>();
    final Store store = mock(Store.class);
    final GenerateObjects<Element, String> operation = mock(GenerateObjects.class);
    final CloseableIterable<Element> elements = mock(CloseableIterable.class);
    final ElementGenerator<String> elementGenerator = mock(ElementGenerator.class);
    final CloseableIterable<String> objs = mock(CloseableIterable.class);
    final Context context = new Context();
    final CloseableIterator<String> objsIter = mock(CloseableIterator.class);
    given(objs.iterator()).willReturn(objsIter);
    given(elementGenerator.getObjects(elements)).willReturn(objs);
    given(operation.getElements()).willReturn(elements);
    given(operation.getElementGenerator()).willReturn(elementGenerator);
    // When
    final CloseableIterable<String> result = handler.doOperation(operation, context, store);
    // Then
    assertSame(objsIter, result.iterator());
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Element(uk.gov.gchq.gaffer.data.element.Element) 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