Search in sources :

Example 26 with Store

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

the class GraphTest method shouldExposeGetTraitsMethod.

@Test
public void shouldExposeGetTraitsMethod() throws OperationException {
    // Given
    final Store store = mock(Store.class);
    final View view = mock(View.class);
    final Graph graph = new Graph.Builder().store(store).view(view).build();
    // When
    final Set<StoreTrait> storeTraits = new HashSet<>(Arrays.asList(StoreTrait.STORE_AGGREGATION, StoreTrait.TRANSFORMATION));
    given(store.getTraits()).willReturn(storeTraits);
    final Collection<StoreTrait> returnedTraits = graph.getStoreTraits();
    // Then
    assertEquals(returnedTraits, storeTraits);
}
Also used : StoreTrait(uk.gov.gchq.gaffer.store.StoreTrait) Store(uk.gov.gchq.gaffer.store.Store) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 27 with Store

use of uk.gov.gchq.gaffer.store.Store 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 28 with Store

use of uk.gov.gchq.gaffer.store.Store 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 29 with Store

use of uk.gov.gchq.gaffer.store.Store 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)

Example 30 with Store

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

the class GetJobDetailsHandlerTest method shouldGetJobDetailsByDelegatingToJobTrackerWithOperationJobId.

@Test
public void shouldGetJobDetailsByDelegatingToJobTrackerWithOperationJobId() throws OperationException {
    // Given
    final String jobId = "jobId";
    final GetJobDetailsHandler handler = new GetJobDetailsHandler();
    final GetJobDetails operation = new GetJobDetails.Builder().jobId(jobId).build();
    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);
    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)

Aggregations

Store (uk.gov.gchq.gaffer.store.Store)37 Test (org.junit.Test)35 Context (uk.gov.gchq.gaffer.store.Context)17 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)13 User (uk.gov.gchq.gaffer.user.User)11 Element (uk.gov.gchq.gaffer.data.element.Element)10 Schema (uk.gov.gchq.gaffer.store.schema.Schema)9 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)6 GetIterableOperation (uk.gov.gchq.gaffer.operation.GetIterableOperation)5 GroupCounts (uk.gov.gchq.gaffer.data.GroupCounts)4 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)4 Graph (uk.gov.gchq.gaffer.graph.Graph)4 JobDetail (uk.gov.gchq.gaffer.jobtracker.JobDetail)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 HashSet (java.util.HashSet)3 InOrder (org.mockito.InOrder)3 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)3