Search in sources :

Example 1 with OperationDetail

use of uk.gov.gchq.gaffer.rest.model.OperationDetail in project Gaffer by gchq.

the class OperationControllerTest method shouldReturnOptionsAndSummariesForEnumFields.

@Test
public void shouldReturnOptionsAndSummariesForEnumFields() throws Exception {
    // Given
    when(store.getSupportedOperations()).thenReturn(Sets.newHashSet(GetElements.class));
    when(examplesFactory.generateExample(GetElements.class)).thenReturn(new GetElements());
    // When
    OperationDetail operationDetails = operationController.getOperationDetails(GetElements.class.getName());
    List<OperationField> operationFields = operationDetails.getFields();
    // Then
    final List<OperationField> fields = Arrays.asList(new OperationField("input", null, "java.lang.Object[]", null, false), new OperationField("view", null, "uk.gov.gchq.gaffer.data.elementdefinition.view.View", null, false), new OperationField("includeIncomingOutGoing", "Should the edges point towards, or away from your seeds", "java.lang.String", Sets.newHashSet("INCOMING", "EITHER", "OUTGOING"), false), new OperationField("seedMatching", "How should the seeds be matched?", "java.lang.String", Sets.newHashSet("RELATED", "EQUAL"), false), new OperationField("options", null, "java.util.Map<java.lang.String,java.lang.String>", null, false), new OperationField("directedType", "Is the Edge directed?", "java.lang.String", Sets.newHashSet("DIRECTED", "UNDIRECTED", "EITHER"), false), new OperationField("views", null, "java.util.List<uk.gov.gchq.gaffer.data.elementdefinition.view.View>", null, false));
    assertEquals(fields, operationFields);
}
Also used : OperationDetail(uk.gov.gchq.gaffer.rest.model.OperationDetail) OperationField(uk.gov.gchq.gaffer.rest.model.OperationField) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Test(org.junit.jupiter.api.Test)

Example 2 with OperationDetail

use of uk.gov.gchq.gaffer.rest.model.OperationDetail in project Gaffer by gchq.

the class OperationControllerTest method shouldNotIncludeAnyOutputClassForOperationWithoutOutput.

@Test
public void shouldNotIncludeAnyOutputClassForOperationWithoutOutput() throws Exception {
    // Given
    when(store.getSupportedOperations()).thenReturn(Sets.newHashSet(DiscardOutput.class));
    when(examplesFactory.generateExample(GetElements.class)).thenReturn(new DiscardOutput());
    // When
    OperationDetail operationDetail = operationController.getOperationDetails(DiscardOutput.class.getName());
    byte[] serialised = JSONSerialiser.serialise(operationDetail);
    // Then
    assertFalse(new String(serialised).contains("outputClassName"));
}
Also used : OperationDetail(uk.gov.gchq.gaffer.rest.model.OperationDetail) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput) Test(org.junit.jupiter.api.Test)

Example 3 with OperationDetail

use of uk.gov.gchq.gaffer.rest.model.OperationDetail in project Gaffer by gchq.

the class AbstractOperationService method getSupportedOperationDetails.

public Set<OperationDetail> getSupportedOperationDetails() {
    Set<Class<? extends Operation>> supportedOperationClasses = getSupportedOperations();
    Set<OperationDetail> operationDetails = new HashSet<>();
    for (final Class<? extends Operation> clazz : supportedOperationClasses) {
        try {
            operationDetails.add(new OperationDetail(clazz, getNextOperations(clazz), generateExampleJson(clazz)));
        } catch (final IllegalAccessException | InstantiationException e) {
            throw new GafferRuntimeException("Could not get operation details for class: " + clazz, e, Status.BAD_REQUEST);
        }
    }
    return operationDetails;
}
Also used : OperationDetail(uk.gov.gchq.gaffer.rest.model.OperationDetail) Operation(uk.gov.gchq.gaffer.operation.Operation) HashSet(java.util.HashSet) GafferRuntimeException(uk.gov.gchq.gaffer.core.exception.GafferRuntimeException)

Example 4 with OperationDetail

use of uk.gov.gchq.gaffer.rest.model.OperationDetail in project Gaffer by gchq.

the class OperationControllerTest method shouldReturnOperationDetailSummaryOfClass.

@Test
public void shouldReturnOperationDetailSummaryOfClass() {
    // Given
    when(store.getSupportedOperations()).thenReturn(Sets.newHashSet(GetElements.class));
    // When
    OperationDetail operationDetail = operationController.getOperationDetails(GetElements.class.getName());
    // Then
    final String expectedSummary = "Gets elements related to provided seeds";
    assertEquals(expectedSummary, operationDetail.getSummary());
}
Also used : OperationDetail(uk.gov.gchq.gaffer.rest.model.OperationDetail) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Test(org.junit.jupiter.api.Test)

Example 5 with OperationDetail

use of uk.gov.gchq.gaffer.rest.model.OperationDetail in project Gaffer by gchq.

the class OperationControllerTest method shouldReturnOutputClassForOperationWithOutput.

@Test
public void shouldReturnOutputClassForOperationWithOutput() throws Exception {
    // Given
    when(store.getSupportedOperations()).thenReturn(Sets.newHashSet(GetElements.class));
    when(examplesFactory.generateExample(GetElements.class)).thenReturn(new GetElements());
    // When
    OperationDetail operationDetails = operationController.getOperationDetails(GetElements.class.getName());
    // Then
    final String expectedOutputString = "uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable<uk.gov.gchq.gaffer.data.element.Element>";
    assertEquals(expectedOutputString, operationDetails.getOutputClassName());
}
Also used : OperationDetail(uk.gov.gchq.gaffer.rest.model.OperationDetail) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Test(org.junit.jupiter.api.Test)

Aggregations

OperationDetail (uk.gov.gchq.gaffer.rest.model.OperationDetail)5 Test (org.junit.jupiter.api.Test)4 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)3 HashSet (java.util.HashSet)1 GafferRuntimeException (uk.gov.gchq.gaffer.core.exception.GafferRuntimeException)1 Operation (uk.gov.gchq.gaffer.operation.Operation)1 DiscardOutput (uk.gov.gchq.gaffer.operation.impl.DiscardOutput)1 OperationField (uk.gov.gchq.gaffer.rest.model.OperationField)1