Search in sources :

Example 1 with SetVariable

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());
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) Store(uk.gov.gchq.gaffer.store.Store) SetVariable(uk.gov.gchq.gaffer.operation.impl.SetVariable) Test(org.junit.jupiter.api.Test)

Example 2 with SetVariable

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");
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) Store(uk.gov.gchq.gaffer.store.Store) SetVariable(uk.gov.gchq.gaffer.operation.impl.SetVariable) Test(org.junit.jupiter.api.Test)

Example 3 with SetVariable

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)));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) Store(uk.gov.gchq.gaffer.store.Store) SetVariable(uk.gov.gchq.gaffer.operation.impl.SetVariable) Test(org.junit.jupiter.api.Test)

Example 4 with SetVariable

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");
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) Store(uk.gov.gchq.gaffer.store.Store) SetVariable(uk.gov.gchq.gaffer.operation.impl.SetVariable) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)4 SetVariable (uk.gov.gchq.gaffer.operation.impl.SetVariable)4 Context (uk.gov.gchq.gaffer.store.Context)4 Store (uk.gov.gchq.gaffer.store.Store)4 User (uk.gov.gchq.gaffer.user.User)4