/** * {@inheritDoc} * * @see java.lang.Object#toString() */ @Override public String toString() { String workspaceName = this.workspaceName != null ? "'" + this.workspaceName + "'" : "default"; return "read " + printable(at()) + " (in " + workspaceName + " workspace) to depth " + maximumDepth(); }
/** * {@inheritDoc} * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals( Object obj ) { if (obj == this) return true; if (this.getClass().isInstance(obj)) { ReadBranchRequest that = (ReadBranchRequest)obj; if (!this.at().isSame(that.at())) return false; if (this.maximumDepth() != that.maximumDepth()) return false; if (!this.inWorkspace().equals(that.inWorkspace())) return false; return true; } return false; }
@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 shouldIterateOverNodesInBranchOfDepthOne() { request = new ReadBranchRequest(location("/a"), workspace1, 1); request.setActualLocationOfNode(request.at()); request.setChildren(location("/a"), location("/a/b"), location("/a/c")); Iterator<Location> actual = request.iterator(); assertThat(actual.hasNext(), is(true)); assertThat(actual.next(), is(location("/a"))); assertThat(actual.hasNext(), is(false)); }
@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)); }
locationsToRead.add(new LocationWithDepth(request.at(), 1)); int maxDepthPerRead = Math.min(request.maximumDepth(), absoluteMaximumDepthForBranchReads());
@Test public void shouldIterateOverNodesInBranchOfDepthTwo() { request = new ReadBranchRequest(location("/a"), workspace1, 2); request.setActualLocationOfNode(request.at()); request.setChildren(location("/a"), location("/a/b"), location("/a/c"), location("/a/d")); request.setChildren(location("/a/b"), location("/a/b/j"), location("/a/b/k")); request.setChildren(location("/a/c"), location("/a/c/j"), location("/a/c/k")); request.setChildren(location("/a/d")); Iterator<Location> actual = request.iterator(); assertThat(actual.hasNext(), is(true)); assertThat(actual.next(), is(location("/a"))); assertThat(actual.hasNext(), is(true)); assertThat(actual.next(), is(location("/a/b"))); assertThat(actual.hasNext(), is(true)); assertThat(actual.next(), is(location("/a/c"))); assertThat(actual.hasNext(), is(true)); assertThat(actual.next(), is(location("/a/d"))); assertThat(actual.hasNext(), is(false)); }
/** * {@inheritDoc} * <p> * This implementation creates a single {@link FederatedRequest} and a {@link ReadBranchRequest} for each {@link ProxyNode} * and one {@link ReadNodeRequest} for each {@link PlaceholderNode}. * </p> * * @see org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.ReadBranchRequest) */ @Override public void process( ReadBranchRequest request ) { // Figure out where this request is projected ... ProjectedNode projectedNode = project(request.at(), request.inWorkspace(), request, false); // Create the federated request ... FederatedRequest federatedRequest = new FederatedRequest(request); if (projectedNode != null) { FederatedWorkspace workspace = getWorkspace(request, request.inWorkspace()); // And process the branch, creating ReadNodeRequests for each placeholder, and ReadBranchRequests for each proxy // node... if (request.maximumDepth() > 0) { processBranch(federatedRequest, projectedNode, workspace, request.maximumDepth()); } } // Submit the requests for processing ... submit(federatedRequest); }
@Test public void shouldIterateOverNodesInBranchOfDepthThree() { request = new ReadBranchRequest(location("/a"), workspace1, 3); request.setActualLocationOfNode(request.at()); request.setChildren(location("/a"), location("/a/b"), location("/a/c"), location("/a/d")); request.setChildren(location("/a/b"), location("/a/b/j"), location("/a/b/k"));