@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 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())); }
if (readNode.hasError()) { request.setError(readNode.getError()); return;
@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))); }
/** * {@inheritDoc} * * @see org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.ReadNodeRequest) */ @Override public void process( ReadNodeRequest request ) { WorkspaceType workspace = getWorkspace(request, request.inWorkspace()); NodeType node = getTargetNode(workspace, request, request.at()); if (node == null) { assert request.hasError(); return; } Location actualLocation = getActualLocation(workspace, request.at(), node); assert actualLocation != null; // Get the locations of the children ... List<Location> childLocations = txn.getChildrenLocations(workspace, node); request.addChildren(childLocations); // Get the properties of the node ... request.addProperty(propertyFactory.create(ModeShapeLexicon.UUID, node.getUuid())); request.addProperties(node.getProperties().values()); request.setActualLocationOfNode(actualLocation); setCacheableInfo(request); }
@Test public void shouldSubmitSingleSourceRequestWhenProcessingSingleReadNodeRequest() throws Exception { // Stub the workspace to have a projection ... Location locationInFed = location("/a/x/y"); Location locationInSource = location("/x/y"); ProjectedNode projectedNode = new ProxyNode(projectionA, locationInSource, locationInFed, false); when(workspace.project(context, locationInFed, false)).thenReturn(projectedNode); ReadNodeRequest request = new ReadNodeRequest(locationInFed, workspaceName); processor.process(request); assertThat(request.hasError(), is(false)); // Check that the federated request has the right information ... FederatedRequest fedRequest = federatedRequests.poll(); ReadNodeRequest projectedRequest = (ReadNodeRequest)fedRequest.getFirstProjectedRequest().getRequest(); assertThat(projectedRequest.at(), is(locationInSource)); assertThat(fedRequest.getFirstProjectedRequest().hasNext(), is(false)); // Close the processor ... processor.close(); processor.await(); // Verify the source saw the expected read ... ReadNodeRequest sourceRequest = (ReadNodeRequest)connectionForSourceA.getProcessedRequests().poll(); assertThat(sourceRequest.at().getPath(), is(locationInSource.getPath())); assertThat(connectionForSourceB.getProcessedRequests().isEmpty(), is(true)); assertThat(connectionForSourceC.getProcessedRequests().isEmpty(), is(true)); }
assertThat(request.hasError(), is(false));