Search in sources :

Example 1 with OperationChainValidator

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);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) Store(uk.gov.gchq.gaffer.store.Store) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) OperationChainValidator(uk.gov.gchq.gaffer.store.operation.OperationChainValidator) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) OperationChainOptimiser(uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 2 with OperationChainValidator

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"));
}
Also used : ViewValidator(uk.gov.gchq.gaffer.store.schema.ViewValidator) ValidateOperationChain(uk.gov.gchq.gaffer.operation.impl.ValidateOperationChain) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ValidateOperationChain(uk.gov.gchq.gaffer.operation.impl.ValidateOperationChain) AddElementsFromSocket(uk.gov.gchq.gaffer.operation.impl.add.AddElementsFromSocket) OperationChainValidator(uk.gov.gchq.gaffer.store.operation.OperationChainValidator) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 3 with OperationChainValidator

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();
}
Also used : StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) StringToStringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.tostring.StringToStringSerialiser) StringConcat(uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat) User(uk.gov.gchq.gaffer.user.User) JobTracker(uk.gov.gchq.gaffer.jobtracker.JobTracker) OutputOperationHandler(uk.gov.gchq.gaffer.store.operation.handler.OutputOperationHandler) SchemaEntityDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition) OperationChainValidator(uk.gov.gchq.gaffer.store.operation.OperationChainValidator) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) SchemaOptimiser(uk.gov.gchq.gaffer.store.schema.SchemaOptimiser) ValidateOperationChain(uk.gov.gchq.gaffer.operation.impl.ValidateOperationChain) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) OutputOperationHandler(uk.gov.gchq.gaffer.store.operation.handler.OutputOperationHandler) OperationHandler(uk.gov.gchq.gaffer.store.operation.handler.OperationHandler) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with OperationChainValidator

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);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) Store(uk.gov.gchq.gaffer.store.Store) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) OperationChainValidator(uk.gov.gchq.gaffer.store.operation.OperationChainValidator) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) OperationChainOptimiser(uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 5 with OperationChainValidator

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);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) Store(uk.gov.gchq.gaffer.store.Store) OperationChainValidator(uk.gov.gchq.gaffer.store.operation.OperationChainValidator) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) OperationChainOptimiser(uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Aggregations

OperationChainValidator (uk.gov.gchq.gaffer.store.operation.OperationChainValidator)8 ValidationResult (uk.gov.gchq.koryphe.ValidationResult)8 Test (org.junit.jupiter.api.Test)7 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)6 OperationChainOptimiser (uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser)5 User (uk.gov.gchq.gaffer.user.User)4 Entity (uk.gov.gchq.gaffer.data.element.Entity)3 ValidateOperationChain (uk.gov.gchq.gaffer.operation.impl.ValidateOperationChain)3 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)3 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)3 Context (uk.gov.gchq.gaffer.store.Context)3 Store (uk.gov.gchq.gaffer.store.Store)3 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)3 Set (java.util.Set)2 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)2 Map (uk.gov.gchq.gaffer.operation.impl.Map)2 ToSet (uk.gov.gchq.gaffer.operation.impl.output.ToSet)2 ToVertices (uk.gov.gchq.gaffer.operation.impl.output.ToVertices)2 ViewValidator (uk.gov.gchq.gaffer.store.schema.ViewValidator)2 FirstItem (uk.gov.gchq.koryphe.impl.function.FirstItem)2