use of uk.gov.gchq.gaffer.operation.impl.If in project Gaffer by gchq.
the class IfScoreResolverTest method shouldGetScoreWithFullyPopulatedOperation.
@Test
public void shouldGetScoreWithFullyPopulatedOperation() {
// Given
final Count count = mock(Count.class);
final GetAllElements getAllElements = mock(GetAllElements.class);
final GetWalks getWalks = mock(GetWalks.class);
final Conditional conditional = mock(Conditional.class);
given(conditional.getTransform()).willReturn(count);
final If operation = new If.Builder<>().conditional(conditional).then(getWalks).otherwise(getAllElements).build();
final LinkedHashMap<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
opScores.put(Count.class, 1);
opScores.put(GetAllElements.class, 3);
opScores.put(GetWalks.class, 4);
final DefaultScoreResolver defaultResolver = new DefaultScoreResolver(opScores);
final IfScoreResolver resolver = new IfScoreResolver();
// When
final int score = resolver.getScore(operation, defaultResolver);
// Then
assertEquals(4, score);
}
use of uk.gov.gchq.gaffer.operation.impl.If in project Gaffer by gchq.
the class Store method validateSchemas.
public void validateSchemas() {
final ValidationResult validationResult = new ValidationResult();
if (null == schema) {
validationResult.addError("Schema is missing");
} else {
validationResult.add(schema.validate());
getSchemaElements().forEach((key, value) -> value.getProperties().forEach(propertyName -> {
final Class propertyClass = value.getPropertyClass(propertyName);
final Serialiser serialisation = value.getPropertyTypeDef(propertyName).getSerialiser();
if (null == serialisation) {
validationResult.addError(String.format("Could not find a serialiser for property '%s' in the group '%s'.", propertyName, key));
} else if (!serialisation.canHandle(propertyClass)) {
validationResult.addError(String.format("Schema serialiser (%s) for property '%s' in the group '%s' cannot handle property found in the schema", serialisation.getClass().getName(), propertyName, key));
}
}));
validateSchema(validationResult, getSchema().getVertexSerialiser());
getSchema().getTypes().forEach((k, v) -> validateSchema(validationResult, v.getSerialiser()));
}
if (!validationResult.isValid()) {
throw new SchemaException("Schema is not valid. " + validationResult.getErrorString());
}
}
use of uk.gov.gchq.gaffer.operation.impl.If in project Gaffer by gchq.
the class IfIT method shouldReturnOriginalInputWhenConditionIsFalseAndNoOtherwise.
@Test
public void shouldReturnOriginalInputWhenConditionIsFalseAndNoOtherwise() throws OperationException {
// Given
final If<Object, Object> ifOperation = new If<>();
ifOperation.setInput(INPUT_CAMEL_CASE);
ifOperation.setConditional(new Conditional(new IsA("java.lang.Integer")));
ifOperation.setThen(new Map<>(Lists.newArrayList(new ToLong(), new ToList())));
// When
final Object output = graph.execute(ifOperation, getUser());
// Then
assertThat(output).isEqualTo(INPUT_CAMEL_CASE).isInstanceOf(String.class);
}
use of uk.gov.gchq.gaffer.operation.impl.If in project Gaffer by gchq.
the class IfIT method shouldReturnOriginalInputWhenConditionIsTrueAndNoThen.
@Test
public void shouldReturnOriginalInputWhenConditionIsTrueAndNoThen() throws OperationException {
// Given
final If<Object, Object> ifOperation = new If<>();
ifOperation.setInput(INPUT_CAMEL_CASE);
ifOperation.setConditional(new Conditional(new IsA("java.lang.String")));
ifOperation.setOtherwise(new Map<>(Lists.newArrayList(new ToLong(), new ToList())));
// When
final Object output = graph.execute(ifOperation, getUser());
// Then
assertThat(output).isEqualTo(INPUT_CAMEL_CASE).isInstanceOf(String.class);
}
use of uk.gov.gchq.gaffer.operation.impl.If in project Gaffer by gchq.
the class IfIT method shouldRunThenOperationWhenConditionIsTrue.
@Test
public void shouldRunThenOperationWhenConditionIsTrue() throws OperationException {
// Given
final If<Object, Object> ifOperation = new If<>();
ifOperation.setInput(INPUT_CAMEL_CASE);
ifOperation.setConditional(new Conditional(new IsA("java.lang.String")));
ifOperation.setThen(new Map<>(Lists.newArrayList(new ToUpperCase(), new ToList())));
ifOperation.setOtherwise(new Map<>(Lists.newArrayList(new ToLowerCase(), new ToList())));
// When
final Object output = graph.execute(ifOperation, getUser());
// Then
assertThat(output).isEqualTo(Lists.newArrayList(INPUT_CAMEL_CASE.toUpperCase())).isInstanceOf(List.class);
}
Aggregations