Search in sources :

Example 1 with CustomVertex

use of uk.gov.gchq.gaffer.operation.data.CustomVertex in project Gaffer by gchq.

the class InputImplTest method builderShouldCreatePopulatedOperation.

@Test
@Override
public void builderShouldCreatePopulatedOperation() {
    // Given / When
    final String requiredField1 = "value1";
    final CustomVertex requiredField2 = new CustomVertex("type1", "value1");
    final Date optionalField1 = new Date(1L);
    final CustomVertex optionalField2 = new CustomVertex("type2", "value2");
    final List<String> input = Arrays.asList("1", "2", "3", "4");
    final InputImpl op = new InputImpl.Builder().requiredField1(requiredField1).requiredField2(requiredField2).optionalField1(optionalField1).optionalField2(optionalField2).input(input).build();
    // Then
    assertEquals(requiredField1, op.getRequiredField1());
    assertEquals(requiredField2, op.getRequiredField2());
    assertEquals(optionalField1, op.getOptionalField1());
    assertEquals(optionalField2, op.getOptionalField2());
    assertEquals(input, op.getInput());
}
Also used : CustomVertex(uk.gov.gchq.gaffer.operation.data.CustomVertex) Date(java.util.Date) Test(org.junit.jupiter.api.Test) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest)

Example 2 with CustomVertex

use of uk.gov.gchq.gaffer.operation.data.CustomVertex in project Gaffer by gchq.

the class InputImplTest method shouldSerialiseAndDeserialiseOperation.

@Test
public void shouldSerialiseAndDeserialiseOperation() {
    // Given
    final String requiredField1 = "value1";
    final CustomVertex requiredField2 = new CustomVertex("type1", "value1");
    final Date optionalField1 = new Date(1L);
    final CustomVertex optionalField2 = new CustomVertex("type2", "value2");
    final List<String> input = Arrays.asList("1", "2", "3", "4");
    final InputImpl op = new InputImpl.Builder().requiredField1(requiredField1).requiredField2(requiredField2).optionalField1(optionalField1).optionalField2(optionalField2).input(input).build();
    // When
    byte[] json = toJson(op);
    final InputImpl deserialisedOp = fromJson(json);
    // Then
    assertEquals(requiredField1, deserialisedOp.getRequiredField1());
    assertEquals(requiredField2, deserialisedOp.getRequiredField2());
    assertEquals(optionalField1, deserialisedOp.getOptionalField1());
    assertEquals(optionalField2, deserialisedOp.getOptionalField2());
    assertEquals(input, deserialisedOp.getInput());
}
Also used : CustomVertex(uk.gov.gchq.gaffer.operation.data.CustomVertex) Date(java.util.Date) Test(org.junit.jupiter.api.Test) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest)

Example 3 with CustomVertex

use of uk.gov.gchq.gaffer.operation.data.CustomVertex in project Gaffer by gchq.

the class InputImplTest method shouldValidateASingleMissingRequiredField.

@Test
public void shouldValidateASingleMissingRequiredField() {
    // Given
    final String requiredField1 = "value1";
    final Date optionalField1 = new Date(1L);
    final CustomVertex optionalField2 = new CustomVertex("type2", "value2");
    final List<String> input = Arrays.asList("1", "2", "3", "4");
    final InputImpl op = new InputImpl.Builder().requiredField1(requiredField1).optionalField1(optionalField1).optionalField2(optionalField2).input(input).build();
    // When
    final ValidationResult validationResult = op.validate();
    // Then
    assertTrue(validationResult.getErrorString().contains("requiredField2 is required"));
}
Also used : CustomVertex(uk.gov.gchq.gaffer.operation.data.CustomVertex) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Date(java.util.Date) Test(org.junit.jupiter.api.Test) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest)

Example 4 with CustomVertex

use of uk.gov.gchq.gaffer.operation.data.CustomVertex in project Gaffer by gchq.

the class OperationImplTest method shouldShallowCloneOperation.

@Test
@Override
public void shouldShallowCloneOperation() {
    // Given
    final String requiredField1 = "value1";
    final CustomVertex requiredField2 = new CustomVertex("type1", "value1");
    final Date optionalField1 = new Date(1L);
    final CustomVertex optionalField2 = new CustomVertex("type2", "value2");
    final OperationImpl op = new OperationImpl.Builder().requiredField1(requiredField1).requiredField2(requiredField2).optionalField1(optionalField1).optionalField2(optionalField2).build();
    // When
    OperationImpl clone = op.shallowClone();
    // Then
    assertNotSame(op, clone);
    assertEquals(requiredField1, clone.getRequiredField1());
    assertEquals(requiredField2, clone.getRequiredField2());
    assertEquals(optionalField1, clone.getOptionalField1());
    assertEquals(optionalField2, clone.getOptionalField2());
}
Also used : CustomVertex(uk.gov.gchq.gaffer.operation.data.CustomVertex) Date(java.util.Date) Test(org.junit.jupiter.api.Test) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest)

Example 5 with CustomVertex

use of uk.gov.gchq.gaffer.operation.data.CustomVertex in project Gaffer by gchq.

the class OperationImplTest method shouldJSONSerialiseAndDeserialise.

@Test
public void shouldJSONSerialiseAndDeserialise() throws SerialisationException {
    // Given
    final String requiredField1 = "value1";
    final CustomVertex requiredField2 = new CustomVertex("type1", "value1");
    final Date optionalField1 = new Date(1L);
    final CustomVertex optionalField2 = new CustomVertex("type2", "value2");
    final OperationImpl op = new OperationImpl.Builder().requiredField1(requiredField1).requiredField2(requiredField2).optionalField1(optionalField1).optionalField2(optionalField2).build();
    // When
    byte[] json = JSONSerialiser.serialise(op, true);
    final OperationImpl deserialisedOp = JSONSerialiser.deserialise(json, OperationImpl.class);
    // Then
    assertEquals(requiredField1, deserialisedOp.getRequiredField1());
    assertEquals(requiredField2, deserialisedOp.getRequiredField2());
    assertEquals(optionalField1, deserialisedOp.getOptionalField1());
    assertEquals(optionalField2, deserialisedOp.getOptionalField2());
}
Also used : CustomVertex(uk.gov.gchq.gaffer.operation.data.CustomVertex) Date(java.util.Date) Test(org.junit.jupiter.api.Test) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest)

Aggregations

Date (java.util.Date)8 Test (org.junit.jupiter.api.Test)8 OperationTest (uk.gov.gchq.gaffer.operation.OperationTest)8 CustomVertex (uk.gov.gchq.gaffer.operation.data.CustomVertex)8 ValidationResult (uk.gov.gchq.koryphe.ValidationResult)2