/** * {@inheritDoc} * <p> * This method does not clone the results. * </p> */ @Override public FunctionRequest clone() { return new FunctionRequest(function, at, workspaceName, inputs); }
@Override protected Request createRequest() { return new FunctionRequest(function, validPathLocation1, workspace1, inputs); }
/** * Create a request to run the supplied function at the given location in the named workspace, using the supplied inputs. * * @param function the function to be run * @param inputs the input parameters * @param to the scope of the function * @param workspaceName the name of the workspace containing the node * @return this builder for method chaining; never null * @throws IllegalArgumentException if any of the parameters are null */ public BatchRequestBuilder applyFunction( Function function, Map<String, Serializable> inputs, Location to, String workspaceName ) { return add(new FunctionRequest(function, to, workspaceName, inputs)); }
/** * Create a request to run the supplied function at the given location in the named workspace, using the supplied inputs. * * @param function the function to be run * @param inputs the input parameters * @param to the scope of the function * @param workspaceName the name of the workspace containing the node * @return the request; never null * @throws IllegalArgumentException if any of the parameters are null */ public FunctionRequest applyFunction( Function function, Map<String, Serializable> inputs, Location to, String workspaceName ) { return process(new FunctionRequest(function, to, workspaceName, inputs)); } }
@Test public void shouldConsiderEqualTwoRequestsWithSameLocationAndFunctionAndWorkspace() { request = new FunctionRequest(function, validPathLocation1, workspace1, inputs); request2 = new FunctionRequest(function, validPathLocation1, workspace1, inputs); assertThat(request, is(request2)); }
@Test public void shouldAllowCreatingRequestWithNullInputMap() { new FunctionRequest(function, validPathLocation1, workspace1, null); }
@Test( expected = IllegalArgumentException.class ) public void shouldNotAllowCreatingRequestWithNullFunction() { new FunctionRequest(null, validPathLocation1, workspace1, inputs); }
@Test( expected = IllegalArgumentException.class ) public void shouldNotAllowCreatingRequestWithNullWorkspaceName() { new FunctionRequest(function, validPathLocation1, null, inputs); }
@Test( expected = IllegalArgumentException.class ) public void shouldNotAllowCreatingRequestWithNullLocation() { new FunctionRequest(function, null, workspace1, inputs); }
@Test public void shouldConsiderNotEqualTwoRequestsWithDifferentLocations() { request = new FunctionRequest(function, validPathLocation1, workspace1, inputs); request2 = new FunctionRequest(function, validPathLocation2, workspace1, inputs); assertThat(request.equals(request2), is(false)); }
@Test public void shouldConsiderNotEqualTwoRequestsWithDifferentWorkspaceNames() { request = new FunctionRequest(function, validPathLocation1, workspace1, inputs); request2 = new FunctionRequest(function, validPathLocation1, workspace2, inputs); assertThat(request.equals(request2), is(false)); } }
@Test public void shouldConsiderNotEqualTwoRequestsWithDifferentInputs() { inputs2.put("Some input", "value"); request = new FunctionRequest(function, validPathLocation1, workspace1, inputs); request2 = new FunctionRequest(function, validPathLocation1, workspace1, inputs2); assertThat(request.equals(request2), is(false)); }
@Test public void shouldConsiderNotEqualTwoRequestsWithDifferentFunctions() { @SuppressWarnings( "serial" ) Function function2 = new Function() { @Override public void run( FunctionContext context ) { ran = true; context.setOutput("success", Boolean.TRUE); } }; request = new FunctionRequest(function, validPathLocation1, workspace1, inputs); request2 = new FunctionRequest(function2, validPathLocation1, workspace1, inputs); assertThat(request.equals(request2), is(false)); }
@Test public void shouldCreateValidRequestWithValidLocation() { request = new FunctionRequest(function, validPathLocation1, workspace1, inputs); assertThat(request.function(), is(sameInstance(function))); assertThat(request.at(), is(sameInstance(validPathLocation1))); assertThat(request.inWorkspace(), is(sameInstance(workspace1))); assertThat(request.inputs().isEmpty(), is(true)); assertThat(request.hasError(), is(false)); assertThat(request.getError(), is(nullValue())); }