@Override public void run( FunctionContext context ) { // Read the input parameter(s) ... int maxDepth = context.input("maxDepth", PropertyType.LONG, new Long(Integer.MAX_VALUE)).intValue(); // Read the subgraph under the location ... ReadBranchRequest readSubgraph = context.builder().readBranch(context.appliedAt(), context.workspace(), maxDepth); // Process that request ... if (readSubgraph.hasError()) { readSubgraph.getError().printStackTrace(); context.setError(readSubgraph.getError()); } else { // And count the number of nodes within the subgraph ... int counter = 0; for (Location location : readSubgraph) { if (location != null) ++counter; } // And write the count as an output parameter ... context.setOutput("nodeCount", counter); } } }
@Test public void shouldCreateValidRequestWithValidLocationAndMaximumDepth() { request = new ReadBranchRequest(validPathLocation1, workspace1, 10); assertThat(request.at(), is(sameInstance(validPathLocation1))); assertThat(request.hasError(), is(false)); assertThat(request.getError(), is(nullValue())); assertThat(request.maximumDepth(), is(10)); }
@Test public void shouldCreateValidRequestWithValidLocation() { request = new ReadBranchRequest(validPathLocation1, workspace1); assertThat(request.at(), is(sameInstance(validPathLocation1))); assertThat(request.inWorkspace(), is(sameInstance(workspace1))); assertThat(request.hasError(), is(false)); assertThat(request.getError(), is(nullValue())); assertThat(request.maximumDepth(), is(ReadBranchRequest.DEFAULT_MAXIMUM_DEPTH)); }