@Test public void shouldReturnEmptySegmentsArray() { assertThat(root.getSegmentsArray(), is(notNullValue())); assertThat(root.getSegmentsArray().length, is(0)); }
@Test public void shouldReturnNonNullSegmentsArray() { assertThat(path.getSegmentsArray(), is(notNullValue())); }
@Test public void shouldCreateRootPathWithNoSegments() { assertThat(paths.createRootPath().getSegmentsList().isEmpty(), is(true)); assertThat(paths.createRootPath().getSegmentsList().size(), is(0)); assertThat(paths.createRootPath().getSegmentsArray().length, is(0)); assertThat(paths.createRootPath().size(), is(0)); }
public void testSegmentsByIteratorAndListAndArray( String pathStr, String... expectedSegmentStrings ) { path = pathFactory.create(pathStr); assertThat(expectedSegmentStrings.length, is(path.size())); Path.Segment[] segmentArray = path.getSegmentsArray(); List<Path.Segment> segmentList = path.getSegmentsList(); assertThat(segmentArray.length, is(path.size())); assertThat(segmentList.size(), is(path.size())); Iterator<Path.Segment> iter = path.iterator(); Iterator<Path.Segment> listIter = segmentList.iterator(); for (int i = 0; i != path.size(); ++i) { Path.Segment expected = pathFactory.createSegment(expectedSegmentStrings[i]); assertThat(path.getSegment(i), is(expected)); assertThat(segmentArray[i], is(expected)); assertThat(segmentList.get(i), is(expected)); assertThat(iter.next(), is(expected)); assertThat(listIter.next(), is(expected)); } assertThat(iter.hasNext(), is(false)); assertThat(listIter.hasNext(), is(false)); }
public void testSegmentsByIteratorAndListAndArray( String pathStr, String... expectedSegmentStrings ) { path = pathFactory.create(pathStr); assertThat(expectedSegmentStrings.length, is(path.size())); Path.Segment[] segmentArray = path.getSegmentsArray(); List<Path.Segment> segmentList = path.getSegmentsList(); assertThat(segmentArray.length, is(path.size())); assertThat(segmentList.size(), is(path.size())); Iterator<Path.Segment> iter = path.iterator(); Iterator<Path.Segment> listIter = segmentList.iterator(); for (int i = 0; i != path.size(); ++i) { Path.Segment expected = pathFactory.createSegment(expectedSegmentStrings[i]); assertThat(path.getSegment(i), is(expected)); assertThat(segmentArray[i], is(expected)); assertThat(segmentList.get(i), is(expected)); assertThat(iter.next(), is(expected)); assertThat(listIter.next(), is(expected)); } assertThat(iter.hasNext(), is(false)); assertThat(listIter.hasNext(), is(false)); }
/** * Creates all nodes along the given node path if they are missing. Ensures that nodePath is a valid path to a node. * * @param targetPath the node path to create * @param context the sequencer context under which it should be created * @param builtPaths a set of the paths that have already been created but not submitted in this batch */ private void buildPathTo( Path targetPath, SequencerContext context, Set<Path> builtPaths ) { PathFactory pathFactory = context.getExecutionContext().getValueFactories().getPathFactory(); PropertyFactory propFactory = context.getExecutionContext().getPropertyFactory(); if (targetPath.isRoot()) return; Path workingPath = pathFactory.createRootPath(); Path.Segment[] segments = targetPath.getSegmentsArray(); int i = 0; Property primaryType = propFactory.create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.UNSTRUCTURED); for (int max = segments.length; i < max; i++) { workingPath = pathFactory.create(workingPath, segments[i]); if (!builtPaths.contains(workingPath)) { try { context.destinationGraph().getNodeAt(workingPath); } catch (PathNotFoundException pnfe) { context.getDestination().create(NodeConflictBehavior.DO_NOT_REPLACE, workingPath, primaryType); builtPaths.add(workingPath); } } } }