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());
}
}
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);
}
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);
}
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());
}
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());
}
Aggregations