use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class CountGroupsHandlerTest method shouldReturnGroupCountsWithoutLimit.
@Test
public void shouldReturnGroupCountsWithoutLimit() 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 Context context = new Context();
given(countGroups.getLimit()).willReturn(null);
given(countGroups.getElements()).willReturn(elements);
// When
final GroupCounts counts = handler.doOperation(countGroups, context, store);
// Then
assertFalse(counts.isLimitHit());
assertEquals(2, counts.getEntityGroups().size());
assertEquals(3, (int) counts.getEntityGroups().get(GROUP1));
assertEquals(1, (int) counts.getEntityGroups().get(GROUP2));
assertEquals(2, counts.getEdgeGroups().size());
assertEquals(1, (int) counts.getEdgeGroups().get(GROUP1));
assertEquals(3, (int) counts.getEdgeGroups().get(GROUP2));
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class CountGroupsHandlerTest method shouldReturnAllGroupCountsWhenLessThanLimit.
@Test
public void shouldReturnAllGroupCountsWhenLessThanLimit() 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 = 10;
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
assertFalse(counts.isLimitHit());
assertEquals(2, counts.getEntityGroups().size());
assertEquals(3, (int) counts.getEntityGroups().get(GROUP1));
assertEquals(1, (int) counts.getEntityGroups().get(GROUP2));
assertEquals(2, counts.getEdgeGroups().size());
assertEquals(1, (int) counts.getEdgeGroups().get(GROUP1));
assertEquals(3, (int) counts.getEdgeGroups().get(GROUP2));
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class ElementValidatorTest method shouldReturnFalseWhenSchemaValidateWithInvalidElement.
@Test
public void shouldReturnFalseWhenSchemaValidateWithInvalidElement() {
// Given
final Schema schema = mock(Schema.class);
final String group = TestGroups.EDGE;
final Element elm = mock(Element.class);
final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
final ElementFilter filter = mock(ElementFilter.class);
final boolean includeIsA = true;
final ElementValidator validator = new ElementValidator(schema, includeIsA);
given(elm.getGroup()).willReturn(group);
given(schema.getElement(group)).willReturn(elementDef);
given(elementDef.getValidator(includeIsA)).willReturn(filter);
given(filter.filter(elm)).willReturn(false);
// When
final boolean isValid = validator.validate(elm);
// Then
assertFalse(isValid);
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class ElementValidatorTest method shouldReturnFalseWhenViewValidateWithInvalidElement.
@Test
public void shouldReturnFalseWhenViewValidateWithInvalidElement() {
// Given
final View view = mock(View.class);
final String group = TestGroups.EDGE;
final Element elm = mock(Element.class);
final ViewElementDefinition elementDef = mock(ViewElementDefinition.class);
final ElementFilter filter = mock(ElementFilter.class);
final ElementValidator validator = new ElementValidator(view);
given(elm.getGroup()).willReturn(group);
given(view.getElement(group)).willReturn(elementDef);
given(elementDef.getPreAggregationFilter()).willReturn(filter);
given(filter.filter(elm)).willReturn(false);
// When
final boolean isValid = validator.validate(elm);
// Then
assertFalse(isValid);
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class ElementValidatorTest method shouldReturnFalseWhenNoViewElementDefinition.
@Test
public void shouldReturnFalseWhenNoViewElementDefinition() {
// Given
final View view = mock(View.class);
final String group = TestGroups.EDGE;
final Element elm = mock(Element.class);
final ElementValidator validator = new ElementValidator(view);
given(elm.getGroup()).willReturn(group);
given(view.getElement(group)).willReturn(null);
// When
final boolean isValid = validator.validate(elm);
// Then
assertFalse(isValid);
}
Aggregations