/** * Add a request to read the properties and number of children of a node at the supplied location. * * @param at the location of the node to be read * @param workspaceName the name of the workspace containing the node * @return the request; never null * @throws IllegalArgumentException if the location or workspace name is null */ public ReadNodeRequest readNode( Location at, String workspaceName ) { return process(new ReadNodeRequest(at, workspaceName)); }
/** * Add a request to read the properties and number of children of a node at the supplied location. * * @param at the location of the node to be read * @param workspaceName the name of the workspace containing the node * @return this builder for method chaining; never null * @throws IllegalArgumentException if the location or workspace name is null */ public BatchRequestBuilder readNode( Location at, String workspaceName ) { return add(new ReadNodeRequest(at, workspaceName)); }
@Override protected Request createRequest() { return new ReadNodeRequest(validPathLocation1, workspace1); }
@Test public void shouldConsiderEqualTwoRequestsWithSameLocations() { request = new ReadNodeRequest(validPathLocation1, workspace1); ReadNodeRequest request2 = new ReadNodeRequest(validPathLocation1, new String(workspace1)); assertThat(request, is(request2)); }
@Test( expected = IllegalArgumentException.class ) public void shouldNotAllowCreatingRequestWithNullLocation() { new ReadNodeRequest(null, workspace1); }
@Test( expected = IllegalArgumentException.class ) public void shouldNotAllowCreatingRequestWithNullWorkspaceName() { new ReadNodeRequest(validPathLocation, null); }
@Test public void shouldConsiderNotEqualTwoRequestsWithDifferentWorkspaceNames() { request = new ReadNodeRequest(validPathLocation1, workspace1); ReadNodeRequest request2 = new ReadNodeRequest(validPathLocation1, workspace2); assertThat(request.equals(request2), is(false)); }
@Test public void shouldConsiderNotEqualTwoRequestsWithDifferentLocations() { request = new ReadNodeRequest(validPathLocation1, workspace1); ReadNodeRequest request2 = new ReadNodeRequest(validPathLocation2, workspace1); assertThat(request.equals(request2), is(false)); }
@Test public void shouldReturnFromAwaitAfterChannelsAreCompleted() throws Exception { ReadNodeRequest requestA = new ReadNodeRequest(location("/a/some"), workspaceNameA); ReadNodeRequest requestB = new ReadNodeRequest(location("/b/some"), workspaceNameB); ReadNodeRequest requestC = new ReadNodeRequest(location("/c/some"), workspaceNameC); processor.submit(requestA, sourceNameA); processor.submit(requestB, sourceNameB); processor.submit(requestC, sourceNameC); processor.close(); processor.await(); }
@Test public void shouldNotForkReadNodeRequestIfWorkspaceNameIsInvalid() { // Stub the workspace to have no projection ... Location locationInFed = location("/a/b"); when(workspace.project(context, locationInFed, false)).thenReturn(null); ReadNodeRequest request = new ReadNodeRequest(locationInFed, nonExistantWorkspaceName); processor.process(request); assertThat(request.hasError(), is(true)); assertThat(request.getError(), is(instanceOf(InvalidWorkspaceException.class))); }
@Test public void shouldNotForkReadNodeRequestIfThereIsNoProjection() { // Stub the workspace to have no projection ... Location locationInFed = location("/a/b"); when(workspace.project(context, locationInFed, false)).thenReturn(null); ReadNodeRequest request = new ReadNodeRequest(locationInFed, workspaceName); processor.process(request); assertThat(request.hasError(), is(true)); assertThat(request.getError(), is(instanceOf(PathNotFoundException.class))); }
@Test( expected = InvalidWorkspaceException.class ) public void shouldNotReadNodesInWorkspacesThatDoNotExist() { // Generate the name of a workspace that is not an existing node ... String nonExistantWorkspaceName = generateNonExistantWorkspaceName(); // Now try to get the root ... ReadNodeRequest request = new ReadNodeRequest(location("/"), nonExistantWorkspaceName); execute(request); }
@Test public void shouldAllowAddingProperties() { request = new ReadNodeRequest(validPathLocation, workspace1); request.addProperty(validProperty1); request.addProperty(validProperty2); assertThat(request.getProperties().size(), is(2)); assertThat(request.getProperties(), hasItems(validProperty1, validProperty2)); assertThat(request.getPropertiesByName().get(validProperty1.getName()), is(validProperty1)); assertThat(request.getPropertiesByName().get(validProperty2.getName()), is(validProperty2)); } }
@Test public void shouldAllowAddingChildren() { request = new ReadNodeRequest(validPathLocation, workspace1); request.addChild(validPathLocation1); request.addChild(validPathLocation2); assertThat(request.getChildren().size(), is(2)); assertThat(request.getChildren(), hasItems(validPathLocation1, validPathLocation2)); }
@Test public void shouldCreateValidRequestWithValidLocation() { request = new ReadNodeRequest(validPathLocation1, workspace1); assertThat(request.at(), is(sameInstance(validPathLocation1))); assertThat(request.inWorkspace(), is(sameInstance(workspace1))); assertThat(request.hasError(), is(false)); assertThat(request.getError(), is(nullValue())); }
@Test public void shouldIncludeTimeLoadedInReadNodeRequests() { String workspaceName = graph.getCurrentWorkspaceName(); // Don't use the graph so that we can obtain and interrogate the request ... CacheableRequest request = new ReadNodeRequest(location("/"), workspaceName); execute(request); assertThat(request.getTimeLoaded(), is(notNullValue())); }
@Test public void shouldRecordErrorOnRequestIfFederatedWorkspaceCouldNotBeFoundByName() { ReadNodeRequest request = new ReadNodeRequest(location("/some"), nonExistantWorkspaceName); FederatedWorkspace workspace = processor.getWorkspace(request, request.inWorkspace()); assertThat(workspace, is(nullValue())); assertThat(request.hasError(), is(true)); assertThat(request.getError(), is(instanceOf(InvalidWorkspaceException.class))); }
@Test public void shouldFindFederatedWorkspaceByName() { ReadNodeRequest request = new ReadNodeRequest(location("/some"), this.workspace.getName()); FederatedWorkspace workspace = processor.getWorkspace(request, request.inWorkspace()); assertThat(workspace, is(sameInstance(this.workspace))); }
@Test public void shouldMakeAvailablePredefinedWorkspaces() { RepositoryConnection connection = source.getConnection(); GetWorkspacesRequest request = new GetWorkspacesRequest(); connection.execute(context, request); Set<String> workspaces = request.getAvailableWorkspaceNames(); Set<String> graphWorkspaces = new HashSet<String>(Arrays.asList(predefinedWorkspaces)); assertThat(workspaces, is(graphWorkspaces)); // Use each workspace ... for (String workspaceName : predefinedWorkspaces) { ReadNodeRequest readRoot = new ReadNodeRequest(locationFor("/"), workspaceName); connection.execute(context, readRoot); assertThat(readRoot.getActualLocationOfNode().getPath(), is(pathFor("/"))); } }
@Test public void shouldSubmitToSourcesTheSingleRequestInFederatedRequestAndAddFederatedRequestToQueue() throws Exception { ReadNodeRequest original = new ReadNodeRequest(location("/a/some"), this.workspace.getName()); FederatedRequest request = new FederatedRequest(original); // Create the projection and the source request ... ReadNodeRequest sourceRequest = new ReadNodeRequest(location("/some"), workspaceNameA); request.add(sourceRequest, false, false, projectionA); assertThat(request.getFirstProjectedRequest().getProjection(), is(sameInstance(projectionA))); assertThat(request.getFirstProjectedRequest().hasNext(), is(false)); // Submit the federated request ... processor.submit(request); assertThat(federatedRequests.size(), is(1)); assertThat(federatedRequests.get(0), is(sameInstance(request))); // Wait for the processor to complete all source channels ... processor.close(); processor.await(); // The source should have received something like the original assertThat(connectionForSourceA.getProcessedRequests().contains(sourceRequest), is(true)); }