use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class StoreTest method setup.
@BeforeEach
public void setup() {
System.clearProperty(JSONSerialiser.JSON_SERIALISER_CLASS_KEY);
System.clearProperty(JSONSerialiser.JSON_SERIALISER_MODULES);
JSONSerialiser.update();
schemaOptimiser = mock(SchemaOptimiser.class);
operationChainValidator = mock(OperationChainValidator.class);
store = new StoreImpl();
given(operationChainValidator.validate(any(OperationChain.class), any(User.class), any(Store.class))).willReturn(new ValidationResult());
addElementsHandler = mock(OperationHandler.class);
getElementsHandler = mock(OutputOperationHandler.class);
getAllElementsHandler = mock(OutputOperationHandler.class);
getAdjacentIdsHandler = mock(OutputOperationHandler.class);
validateHandler = mock(OperationHandler.class);
exportToGafferResultCacheHandler = mock(OperationHandler.class);
getGafferResultCacheExportHandler = mock(OperationHandler.class);
jobTracker = mock(JobTracker.class);
schema = new Schema.Builder().edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().source("string").destination("string").directed("true").property(TestPropertyNames.PROP_1, "string").property(TestPropertyNames.PROP_2, "string").build()).edge(TestGroups.EDGE_2, new SchemaEdgeDefinition.Builder().source("string").destination("string").directed("true").property(TestPropertyNames.PROP_1, "string").property(TestPropertyNames.PROP_2, "string").build()).entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().vertex("string").property(TestPropertyNames.PROP_1, "string").property(TestPropertyNames.PROP_2, "string").build()).entity(TestGroups.ENTITY_2, new SchemaEntityDefinition.Builder().vertex("string").property(TestPropertyNames.PROP_1, "string").property(TestPropertyNames.PROP_2, "string").build()).type("string", new TypeDefinition.Builder().clazz(String.class).serialiser(new StringSerialiser()).aggregateFunction(new StringConcat()).build()).type("true", Boolean.class).build();
}
use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class StoreTest method shouldThrowExceptionIfOperationChainIsInvalid.
@Test
public void shouldThrowExceptionIfOperationChainIsInvalid() throws OperationException, StoreException {
// Given
// Given
final Schema schema = createSchemaMock();
final StoreProperties properties = mock(StoreProperties.class);
final OperationChain opChain = new OperationChain();
final StoreImpl store = new StoreImpl();
given(properties.getJobExecutorThreadCount()).willReturn(1);
given(schema.validate()).willReturn(new ValidationResult());
ValidationResult validationResult = new ValidationResult();
validationResult.addError("error");
given(operationChainValidator.validate(opChain, user, store)).willReturn(validationResult);
store.initialise("graphId", schema, properties);
// When / Then
try {
store.execute(opChain, context);
fail("Exception expected");
} catch (final IllegalArgumentException e) {
verify(operationChainValidator).validate(opChain, user, store);
assertTrue(e.getMessage().contains("Operation chain"));
}
}
use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class ValidatedElementsTest method setup.
@BeforeEach
public void setup() {
elements = new ArrayList<>();
filters = new ArrayList<>();
for (int i = 0; i < 3; i++) {
elements.add(mock(Element.class));
filters.add(mock(ElementFilter.class));
final String group = "group " + i;
lenient().when(elements.get(i).getGroup()).thenReturn(group);
lenient().when(filters.get(i).test(elements.get(i))).thenReturn(true);
lenient().when(filters.get(i).testWithValidationResult(elements.get(i))).thenReturn(new ValidationResult());
final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
lenient().when(schema.getElement(group)).thenReturn(elementDef);
lenient().when(elementDef.getValidator(true)).thenReturn(filters.get(i));
}
lenient().when(filters.get(1).test(elements.get(1))).thenReturn(false);
lenient().when(filters.get(1).testWithValidationResult(elements.get(1))).thenReturn(new ValidationResult("Some error"));
}
use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class AggregateValidator method validateOperation.
@Override
protected ValidationResult validateOperation(final Aggregate operation, final Schema schema) {
final ValidationResult result = new ValidationResult();
final Map<String, ?> entities = null != operation.getEntities() ? operation.getEntities() : new HashMap<>();
final Map<String, ?> edges = null != operation.getEdges() ? operation.getEdges() : new HashMap<>();
for (final Map.Entry<String, ?> entry : edges.entrySet()) {
result.add(validateEdge(entry, schema));
result.add(validateElementAggregator(entry, schema));
result.add(validateAggregatePropertyClasses(schema.getEdge(entry.getKey()), (AggregatePair) entry.getValue()));
}
for (final Map.Entry<String, ?> entry : entities.entrySet()) {
result.add(validateEntity(entry, schema));
result.add(validateElementAggregator(entry, schema));
result.add(validateAggregatePropertyClasses(schema.getEntity(entry.getKey()), (AggregatePair) entry.getValue()));
}
return result;
}
use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class FunctionValidator method validate.
public ValidationResult validate(final T operation, final Schema schema) {
final ValidationResult result = new ValidationResult();
if (null == operation) {
result.addError("Operation cannot be null.");
}
if (null == schema) {
result.addError("Schema cannot be null.");
}
result.add(validateOperation(operation, schema));
return result;
}
Aggregations