use of uk.gov.gchq.gaffer.operation.impl.SetVariable in project Gaffer by gchq.
the class SetVariableHandlerTest method setTwoVarsWithoutFailure.
@Test
public void setTwoVarsWithoutFailure() throws OperationException {
// Given
final Context context = new Context(new User());
final Store store = mock(Store.class);
final String varName = "testVarName";
final String varVal = "varVal";
final String varName1 = "testVarName1";
final String varVal1 = "varVal1";
SetVariableHandler handler = new SetVariableHandler();
SetVariable op = new SetVariable.Builder().variableName(varName).input(varVal).build();
SetVariable op1 = new SetVariable.Builder().variableName(varName1).input(varVal1).build();
// When
handler.doOperation(op, context, store);
handler.doOperation(op1, context, store);
// Then
assertEquals(2, context.getVariables().size());
assertEquals(ImmutableMap.of(varName, varVal, varName1, varVal1), context.getVariables());
}
use of uk.gov.gchq.gaffer.operation.impl.SetVariable in project Gaffer by gchq.
the class SetVariableHandlerTest method shouldNotAllowNullInputVariableToBeAdded.
@Test
public void shouldNotAllowNullInputVariableToBeAdded() throws OperationException {
// Given
final Context context = new Context(new User());
final Store store = mock(Store.class);
final String testVarName = "testVarName";
final Object testVarValue = null;
SetVariableHandler handler = new SetVariableHandler();
SetVariable op = new SetVariable.Builder().variableName(testVarName).input(testVarValue).build();
// When / Then
assertThatIllegalArgumentException().isThrownBy(() -> handler.doOperation(op, context, store)).withMessage("Variable input value cannot be null");
}
use of uk.gov.gchq.gaffer.operation.impl.SetVariable in project Gaffer by gchq.
the class SetVariableHandlerTest method shouldSetVariableInContext.
@Test
public void shouldSetVariableInContext() throws OperationException {
// Given
final Context context = new Context(new User());
final Store store = mock(Store.class);
final String testVarName = "testVarName";
final int testVarValue = 4;
SetVariableHandler handler = new SetVariableHandler();
SetVariable op = new SetVariable.Builder().variableName(testVarName).input(testVarValue).build();
// When
handler.doOperation(op, context, store);
// Then
assertTrue(context.getVariable(testVarName).equals(testVarValue));
assertTrue(context.getVariables().equals(ImmutableMap.of(testVarName, testVarValue)));
}
use of uk.gov.gchq.gaffer.operation.impl.SetVariable in project Gaffer by gchq.
the class SetVariableHandlerTest method shouldThrowExceptionWithNullVariableKey.
@Test
public void shouldThrowExceptionWithNullVariableKey() throws OperationException {
// Given
final Context context = new Context(new User());
final Store store = mock(Store.class);
SetVariableHandler handler = new SetVariableHandler();
SetVariable op = new SetVariable();
// When / Then
assertThatIllegalArgumentException().isThrownBy(() -> handler.doOperation(op, context, store)).withMessage("Variable name cannot be null");
}
Aggregations