use of uk.gov.gchq.gaffer.store.Store 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());
}
}
use of uk.gov.gchq.gaffer.store.Store 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));
}
use of uk.gov.gchq.gaffer.store.Store 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());
}
use of uk.gov.gchq.gaffer.store.Store in project Gaffer by gchq.
the class CoreOperationChainOptimiserTest method shouldNotAddValidateOperationWhenValidatableHasValidateSetToFalse.
@Test
public void shouldNotAddValidateOperationWhenValidatableHasValidateSetToFalse() throws Exception {
// Given
final Store store = mock(Store.class);
final CoreOperationChainOptimiser optimiser = new CoreOperationChainOptimiser(store);
final Validatable<Integer> validatable1 = mock(Validatable.class);
final boolean skipInvalidElements = true;
final CloseableIterable<Element> elements = mock(CloseableIterable.class);
final OperationChain<Integer> opChain = new OperationChain<>(validatable1);
given(validatable1.isSkipInvalidElements()).willReturn(skipInvalidElements);
given(validatable1.isValidate()).willReturn(false);
given(validatable1.getElements()).willReturn(elements);
// When
final OperationChain<Integer> optimisedOpChain = optimiser.optimise(opChain);
// Then
assertEquals(1, optimisedOpChain.getOperations().size());
assertSame(validatable1, optimisedOpChain.getOperations().get(0));
verify(validatable1, never()).setElements(null);
}
use of uk.gov.gchq.gaffer.store.Store in project Gaffer by gchq.
the class CoreOperationChainOptimiserTest method shouldThrowExceptionIfValidatableHasValidateSetToFalseAndStoreRequiresValidation.
@Test
public void shouldThrowExceptionIfValidatableHasValidateSetToFalseAndStoreRequiresValidation() throws Exception {
// Given
final Store store = mock(Store.class);
final CoreOperationChainOptimiser optimiser = new CoreOperationChainOptimiser(store);
final Schema schema = mock(Schema.class);
final Validatable<Integer> validatable1 = mock(Validatable.class);
final OperationChain<Integer> opChain = new OperationChain<>(validatable1);
given(schema.validate()).willReturn(true);
given(store.isValidationRequired()).willReturn(true);
given(validatable1.isValidate()).willReturn(false);
// When / then
try {
optimiser.optimise(opChain);
} catch (UnsupportedOperationException e) {
assertNotNull(e);
}
}
Aggregations