Search in sources :

Example 1 with GetVariable

use of uk.gov.gchq.gaffer.operation.impl.GetVariable in project Gaffer by gchq.

the class GetVariableHandlerTest method shouldNotThrowNPEWhenVariablesSet.

@Test
public void shouldNotThrowNPEWhenVariablesSet() throws OperationException {
    // Given
    final Context context = new Context(new User());
    final GetVariableHandler handler = new GetVariableHandler();
    final GetVariable op = new GetVariable.Builder().variableName(varName).build();
    // When
    final Object variableValueFromOp = handler.doOperation(op, context, store);
    // Then
    assertNull(variableValueFromOp);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) GetVariable(uk.gov.gchq.gaffer.operation.impl.GetVariable) Test(org.junit.jupiter.api.Test)

Example 2 with GetVariable

use of uk.gov.gchq.gaffer.operation.impl.GetVariable in project Gaffer by gchq.

the class GetVariableHandlerTest method shouldReturnNullWhenVariableDoesntExist.

@Test
public void shouldReturnNullWhenVariableDoesntExist() throws OperationException {
    // Given
    final Context context = mock(Context.class);
    final GetVariableHandler handler = new GetVariableHandler();
    final GetVariable op = new GetVariable.Builder().variableName(varName).build();
    given(context.getVariable(varName)).willReturn(null);
    // When
    final Object variableValueFromOp = handler.doOperation(op, context, store);
    // Then
    assertNull(variableValueFromOp);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetVariable(uk.gov.gchq.gaffer.operation.impl.GetVariable) Test(org.junit.jupiter.api.Test)

Example 3 with GetVariable

use of uk.gov.gchq.gaffer.operation.impl.GetVariable in project Gaffer by gchq.

the class GetVariableHandlerTest method shouldThrowExceptionWhenVariableKeyIsNull.

@Test
public void shouldThrowExceptionWhenVariableKeyIsNull() throws OperationException {
    // Given
    final Context context = mock(Context.class);
    final GetVariableHandler handler = new GetVariableHandler();
    final GetVariable op = new GetVariable.Builder().variableName(null).build();
    // When / Then
    assertThatIllegalArgumentException().isThrownBy(() -> handler.doOperation(op, context, store)).withMessage("Variable name cannot be null");
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetVariable(uk.gov.gchq.gaffer.operation.impl.GetVariable) Test(org.junit.jupiter.api.Test)

Example 4 with GetVariable

use of uk.gov.gchq.gaffer.operation.impl.GetVariable in project Gaffer by gchq.

the class GetVariableHandlerTest method shouldGetVariableWhenExists.

@Test
public void shouldGetVariableWhenExists() throws OperationException {
    // Given
    final Context context = mock(Context.class);
    final GetVariableHandler handler = new GetVariableHandler();
    final GetVariable op = new GetVariable.Builder().variableName(varName).build();
    given(context.getVariable(varName)).willReturn(varVal);
    // When
    final Object variableValueFromOp = handler.doOperation(op, context, store);
    // Then
    assertEquals(varVal, variableValueFromOp);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetVariable(uk.gov.gchq.gaffer.operation.impl.GetVariable) Test(org.junit.jupiter.api.Test)

Aggregations

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