use of uk.gov.gchq.gaffer.store.operation.OperationChainValidator in project Gaffer by gchq.
the class OperationChainHandlerTest method shouldHandleNestedOperationChain.
@Test
public void shouldHandleNestedOperationChain() throws OperationException {
// Given
final OperationChainValidator opChainValidator = mock(OperationChainValidator.class);
final List<OperationChainOptimiser> opChainOptimisers = Collections.emptyList();
final OperationChainHandler opChainHandler = new OperationChainHandler(opChainValidator, opChainOptimisers);
final Context context = mock(Context.class);
final Store store = mock(Store.class);
final User user = mock(User.class);
final StoreProperties storeProperties = new StoreProperties();
final GetAdjacentIds op1 = mock(GetAdjacentIds.class);
final GetElements op2 = mock(GetElements.class);
final Limit op3 = mock(Limit.class);
final OperationChain opChain1 = new OperationChain(Arrays.asList(op1, op2));
final OperationChain opChain2 = new OperationChain(Arrays.asList(opChain1, op3));
final Entity entityA = new Entity.Builder().group(TestGroups.ENTITY).vertex("A").build();
final Entity entityB = new Entity.Builder().group(TestGroups.ENTITY).vertex("B").build();
given(context.getUser()).willReturn(user);
given(store.getProperties()).willReturn(storeProperties);
given(opChainValidator.validate(any(), any(), any())).willReturn(new ValidationResult());
given(store.handleOperation(op1, context)).willReturn(new WrappedCloseableIterable<>(Lists.newArrayList(new EntitySeed("A"), new EntitySeed("B"))));
given(store.handleOperation(op2, context)).willReturn(new WrappedCloseableIterable<>(Lists.newArrayList(entityA, entityB)));
given(store.handleOperation(op3, context)).willReturn(entityA);
// When
final Object result = opChainHandler.doOperation(opChain2, context, store);
// Then
assertSame(entityA, result);
}
use of uk.gov.gchq.gaffer.store.operation.OperationChainValidator in project Gaffer by gchq.
the class ValidateOperationChainHandlerTest method shouldReturnValidationResultWithErrorsIfOperationChainInvalid.
@Test
public void shouldReturnValidationResultWithErrorsIfOperationChainInvalid() throws OperationException {
// Given
final AddElementsFromSocket addElementsFromSocket = new AddElementsFromSocket();
OperationChain chain = new OperationChain.Builder().first(addElementsFromSocket).build();
ValidateOperationChain validateOperationChain = new ValidateOperationChain.Builder().operationChain(chain).build();
given(store.getOperationChainValidator()).willReturn(new OperationChainValidator(new ViewValidator()));
ValidateOperationChainHandler handler = new ValidateOperationChainHandler();
// When
ValidationResult result = handler.doOperation(validateOperationChain, context, store);
// Then
assertFalse(result.isValid());
assertTrue(result.getErrorString().contains("elementGenerator is required for: AddElementsFromSocket"));
assertTrue(result.getErrorString().contains("hostname is required for: AddElementsFromSocket"));
}
use of uk.gov.gchq.gaffer.store.operation.OperationChainValidator 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.gaffer.store.operation.OperationChainValidator in project Gaffer by gchq.
the class OperationChainHandlerTest method shouldHandleOperationChain.
@Test
public void shouldHandleOperationChain() throws OperationException {
// Given
final OperationChainValidator opChainValidator = mock(OperationChainValidator.class);
final List<OperationChainOptimiser> opChainOptimisers = Collections.emptyList();
final OperationChainHandler opChainHandler = new OperationChainHandler(opChainValidator, opChainOptimisers);
final Context context = mock(Context.class);
final Store store = mock(Store.class);
final User user = mock(User.class);
final StoreProperties storeProperties = new StoreProperties();
final GetAdjacentIds op1 = mock(GetAdjacentIds.class);
final GetElements op2 = mock(GetElements.class);
final OperationChain opChain = new OperationChain(Arrays.asList(op1, op2));
final Entity expectedResult = new Entity(TestGroups.ENTITY);
given(context.getUser()).willReturn(user);
given(store.getProperties()).willReturn(storeProperties);
given(opChainValidator.validate(any(), any(), any())).willReturn(new ValidationResult());
given(store.handleOperation(op1, context)).willReturn(new WrappedCloseableIterable<>(Collections.singletonList(new EntitySeed())));
given(store.handleOperation(op2, context)).willReturn(expectedResult);
// When
final Object result = opChainHandler.doOperation(opChain, context, store);
// Then
assertSame(expectedResult, result);
}
use of uk.gov.gchq.gaffer.store.operation.OperationChainValidator in project Gaffer by gchq.
the class OperationChainHandlerTest method shouldHandleNonInputOperation.
@Test
public void shouldHandleNonInputOperation() throws OperationException {
// Given
final OperationChainValidator opChainValidator = mock(OperationChainValidator.class);
final List<OperationChainOptimiser> opChainOptimisers = Collections.emptyList();
final OperationChainHandler opChainHandler = new OperationChainHandler(opChainValidator, opChainOptimisers);
final Context context = mock(Context.class);
final Store store = mock(Store.class);
final User user = mock(User.class);
final StoreProperties storeProperties = new StoreProperties();
final GetAllElements op = mock(GetAllElements.class);
final OperationChain opChain = new OperationChain(Collections.singletonList(op));
final Entity expectedResult = new Entity(TestGroups.ENTITY);
given(context.getUser()).willReturn(user);
given(store.getProperties()).willReturn(storeProperties);
given(opChainValidator.validate(any(), any(), any())).willReturn(new ValidationResult());
given(store.handleOperation(op, context)).willReturn(expectedResult);
// When
final Object result = opChainHandler.doOperation(opChain, context, store);
// Then
assertSame(expectedResult, result);
}
Aggregations