Search in sources :

Example 16 with Context

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

Example 17 with Context

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

the class GetJobDetailsHandlerTest method shouldThrowExceptionIfJobTrackerIsNotConfigured.

@Test
public void shouldThrowExceptionIfJobTrackerIsNotConfigured() {
    // Given
    final GetJobDetailsHandler handler = new GetJobDetailsHandler();
    final GetJobDetails operation = mock(GetJobDetails.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) GetJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails) 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 18 with Context

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

the class CountGroupsHandlerTest method shouldReturnGroupCountsUpToLimit.

@Test
public void shouldReturnGroupCountsUpToLimit() throws OperationException {
    // Given
    final CountGroupsHandler handler = new CountGroupsHandler();
    final Store store = mock(Store.class);
    final CountGroups countGroups = mock(CountGroups.class);
    final CloseableIterable<Element> elements = getElements();
    final Integer limit = 3;
    final Context context = new Context();
    given(countGroups.getLimit()).willReturn(limit);
    given(countGroups.getElements()).willReturn(elements);
    // When
    final GroupCounts counts = handler.doOperation(countGroups, context, store);
    // Then
    assertTrue(counts.isLimitHit());
    assertEquals(2, counts.getEntityGroups().size());
    assertEquals(2, (int) counts.getEntityGroups().get(GROUP1));
    assertEquals(1, (int) counts.getEntityGroups().get(GROUP2));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) Element(uk.gov.gchq.gaffer.data.element.Element) CountGroupsHandler(uk.gov.gchq.gaffer.store.operation.handler.CountGroupsHandler) Store(uk.gov.gchq.gaffer.store.Store) GroupCounts(uk.gov.gchq.gaffer.data.GroupCounts) Test(org.junit.Test)

Example 19 with Context

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

the class CountGroupsHandlerTest method shouldReturnNoCountsIfElementsAreNull.

@Test
public void shouldReturnNoCountsIfElementsAreNull() throws OperationException {
    // Given
    final CountGroupsHandler handler = new CountGroupsHandler();
    final Store store = mock(Store.class);
    final CountGroups countGroups = mock(CountGroups.class);
    final Context context = new Context();
    given(countGroups.getElements()).willReturn(null);
    // When
    final GroupCounts counts = handler.doOperation(countGroups, context, store);
    // Then
    assertFalse(counts.isLimitHit());
    assertEquals(0, counts.getEntityGroups().size());
    assertEquals(0, counts.getEdgeGroups().size());
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) CountGroupsHandler(uk.gov.gchq.gaffer.store.operation.handler.CountGroupsHandler) Store(uk.gov.gchq.gaffer.store.Store) GroupCounts(uk.gov.gchq.gaffer.data.GroupCounts) 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