GetWalks implements
        InputOutput<Iterable<? extends EntityId>, Iterable<Walk>>,
        MultiEntityIdInput,
        Operations<OperationChain<Iterable<Element>>> { @Override public ValidationResult validate() { final ValidationResult result = InputOutput.super.validate(); final int getEdgeOperations = getNumberOfGetEdgeOperations(); if (getEdgeOperations < 1) { result.addError("No hops were provided. " + HOP_DEFINITION); } else { int i = 0; for (final OperationChain<Iterable<Element>> operation : operations) { if (operation.getOperations().isEmpty()) { result.addError("Operation chain " + i + " contains no operations"); } else { final Operation firstOp = operation.getOperations().get(0); if (firstOp instanceof Input) { if (null != ((Input) firstOp).getInput()) { result.addError("The input for operations must be null."); } } else { result.addError("The first operation in operation chain " + i + ": " + firstOp.getClass().getName() + " is not be able to accept the input seeds. It must implement " + Input.class.getName()); } } if (getNumberOfGetEdgeOperationsWithoutRepeats(operation) < 1 && i < (operations.size() - 1)) { result.addError("All operations must contain a single hop. Operation " + i + " does not contain a hop. The only exception is the last operation, which is allowed to just fetch Entities. " + HOP_DEFINITION); } else if (getNumberOfGetEdgeOperationsWithoutRepeats(operation) > 1) { result.addError("All operations must contain a single hop. Operation " + i + " contains multiple hops."); } i++; } } return result; }  @Override Iterable<? extends EntityId> getInput(); @Override void setInput(final Iterable<? extends EntityId> input); @Override List<OperationChain<Iterable<Element>>> getOperations(); void setOperations(final List<Output<Iterable<Element>>> operations); void addOperations(final List<Output<Iterable<Element>>> operations); @Override ValidationResult validate(); @JsonIgnore int getNumberOfGetEdgeOperations(); @Override TypeReference<Iterable<Walk>> getOutputTypeReference(); @Override GetWalks shallowClone(); boolean isIncludePartial(); void setIncludePartial(final boolean includePartial); @Override Map<String, String> getOptions(); @Override void setOptions(final Map<String, String> options); Integer getResultsLimit(); void setResultsLimit(final Integer resultsLimit); static final String HOP_DEFINITION; static final int DEFAULT_RESULTS_LIMIT; }
@Test public void shouldFailValidationWithNoHops() { final GetWalks operation = getTestObject(); ValidationResult result = operation.validate(); Set<String> expectedErrors = Sets.newHashSet("No hops were provided. " + HOP_DEFINITION); assertEquals(result.getErrors(), expectedErrors); }
@Test public void shouldValidateOperationWhenNoOperationsProvided() { final GetWalks getWalks = new GetWalks.Builder().input(new EntitySeed("1"), new EntitySeed("2")) .build(); assertFalse(getWalks.validate().isValid()); }
@Test public void shouldValidateOperationWhenFirstOperationContainsNonNullInput() { final GetWalks getWalks = new GetWalks.Builder().input(new EntitySeed("1"), new EntitySeed("2")) .operations(new GetElements.Builder().input(new EntitySeed("some value")) .view(new View.Builder().edge(TestGroups.EDGE).build()).build()) .build(); assertFalse(getWalks.validate().isValid()); }
@Test public void shouldValidateWhenPreFiltersContainsAnOperationWhichDoesNotAllowAnInput() { final GetWalks getWalks = new GetWalks.Builder().input(new EntitySeed("1"), new EntitySeed("2")) .operations(new OperationChain.Builder().first(new ScoreOperationChain()) .then(new DiscardOutput()) .then(new GetElements.Builder().input() .view(new View.Builder().edge(TestGroups.EDGE).build()) .build()) .build()) .build(); final ValidationResult result = getWalks.validate(); assertFalse(result.isValid()); assertTrue(result.getErrorString().contains("The first operation in operation chain 0: " + ScoreOperationChain.class.getName() + " is not be able to accept the input seeds."), result.getErrorString()); }
@Test public void shouldValidateWhenOperationListContainsAnEmptyOperationChain() { final GetWalks getWalks = new GetWalks.Builder().input(new EntitySeed("1"), new EntitySeed("2")) .operations(new GetElements.Builder().input((Iterable<? extends ElementId>) null) .view(new View.Builder().edge(TestGroups.EDGE).build()).build(), new OperationChain()) .build(); final ValidationResult result = getWalks.validate(); assertFalse(result.isValid()); assertTrue(result.getErrorString().contains("Operation chain 1 contains no operations"), result.getErrorString()); }
@Test public void shouldValidateWhenOperationListDoesNotContainAGetElementsOperation() { final GetWalks getWalks = new GetWalks.Builder().input(new EntitySeed("1"), new EntitySeed("2")) .operations(new GetElements.Builder().input((Iterable<? extends ElementId>) null) .view(new View.Builder().edge(TestGroups.EDGE).build()).build(), new OperationChain.Builder().first(new AddElements()).build(), new GetElements.Builder().input((Iterable<? extends ElementId>) null) .view(new View.Builder().edge(TestGroups.EDGE).build()) .build()) .build(); final ValidationResult result = getWalks.validate(); assertFalse(result.isValid()); assertTrue(result.getErrorString().contains( "All operations must contain a single hop. Operation 1 does not contain a hop."), result.getErrorString()); }
@Test public void shouldValidateWhenOperationContainsMultipleHops() { final GetWalks getWalks = new GetWalks.Builder().input(new EntitySeed("1"), new EntitySeed("2")) .operations(new OperationChain.Builder().first(new GetElements.Builder() .input((Iterable<? extends ElementId>) null) .view(new View.Builder().edge(TestGroups.EDGE).build()).build()) .then(new GetElements.Builder() .input((Iterable<? extends ElementId>) null) .view(new View.Builder().edge(TestGroups.EDGE).build()) .build()) .build()) .build(); final ValidationResult result = getWalks.validate(); assertFalse(result.isValid()); assertTrue(result.getErrorString().contains("All operations must contain a single hop. Operation ") && result.getErrorString().contains(" contains multiple hops"), result.getErrorString()); }