@Test( expected = InvalidPathException.class ) public void shouldNotFindRelativePathToAnotherRelativePath() { Path other = mock(Path.class); when(other.isAbsolute()).thenReturn(false); path.relativeTo(other); }
@Test( expected = InvalidPathException.class ) public void shouldNotResolveRelativePathUsingAnAbsolutePath() { Path other = mock(Path.class); when(other.isAbsolute()).thenReturn(true); root.resolve(other); }
@Test public void shouldConsiderAsNotNormalizedAnAbsolutePathWithParentSegmentAtFront() { List<Path.Segment> segments = new ArrayList<Path.Segment>(); segments.add(Path.PARENT_SEGMENT); segments.addAll(validSegmentsList); path = new BasicPath(segments, true); assertThat(path.isAbsolute(), is(true)); assertThat(path.isNormalized(), is(false)); assertThat(path.getSegmentsList(), is(segments)); assertThat(path.size(), is(segments.size())); }
@Test public void shouldCreateRelativePathWithSelfSegment() { validSegmentsList.add(Path.SELF_SEGMENT); path = new BasicPath(validSegmentsList, false); assertThat(path.isAbsolute(), is(false)); assertThat(path.isNormalized(), is(false)); assertThat(path.getSegmentsList(), is(validSegmentsList)); assertThat(path.size(), is(validSegmentsList.size())); }
@Test public void shouldCreateAbsolutePathWithSelfSegment() { validSegmentsList.add(Path.SELF_SEGMENT); path = new BasicPath(validSegmentsList, true); assertThat(path.isAbsolute(), is(true)); assertThat(path.isNormalized(), is(false)); assertThat(path.getSegmentsList(), is(validSegmentsList)); assertThat(path.size(), is(validSegmentsList.size())); }
@Test public void shouldCreateRelativePathWithOnlySelf() { path = paths.create("."); assertThat(path.isAbsolute(), is(false)); assertThat(path.getSegment(0), is(Path.SELF_SEGMENT)); assertThat(path.size(), is(1)); }
@Test public void shouldParsePathFromStringWithRootSegmentAndSelfSegment() { path = paths.create("/."); assertThat(path.isAbsolute(), is(true)); assertThat(path.getSegment(0), is(Path.SELF_SEGMENT)); assertThat(path.size(), is(1)); }
@Test public void shouldCreateAbsolutePathWithOnlySelf() { path = paths.create("/."); assertThat(path.isAbsolute(), is(true)); assertThat(path.getSegment(0), is(Path.SELF_SEGMENT)); assertThat(path.size(), is(1)); }
protected Path getAbsolutePath( Path absoluteOrRelative ) { Path result = absoluteOrRelative; if (!result.isAbsolute()) { result = getGraph().getContext().getValueFactories().getPathFactory().create(getLocation().getPath(), result); result = result.getNormalizedPath(); } return result; }
@Test public void shouldCreateRelativePathWithSingleSegment() { path = paths.create("A"); assertThat(path.isAbsolute(), is(false)); assertThat(path.getSegment(0), is(segment("A[1]"))); assertThat(path.size(), is(1)); }
@Test public void shouldParsePathFromStringWithNamespacesAndWithSingleChildSegmentWithSameNameSiblingIndex() { path = paths.create("/ex:A[2]"); assertThat(path.isAbsolute(), is(true)); assertThat(path.getSegment(0), is(segment("ex:A[2]"))); assertThat(path.size(), is(1)); }
@Test public void shouldCreateAbsolutePathWithSingleSegment() { path = paths.create("/A"); assertThat(path.isAbsolute(), is(true)); assertThat(path.getSegment(0), is(segment("A[1]"))); assertThat(path.size(), is(1)); }
@Test public void shouldResolveRelativePathToAbsolutePath() { path = pathFactory.create("/a/b/c/d"); path2 = path.resolve(pathFactory.create("../../e/f")); assertThat(path2, is(pathFactory.create("/a/b/e/f"))); assertThat(path2.isAbsolute(), is(true)); assertThat(path2.isNormalized(), is(true)); }
@Test public void shouldParsePathFromStringWithNamespacesAndWithMultipleChildSegmentsWithSameNameSiblingIndex() { path = paths.create("/ex:A/ex:B[2]/ex:C"); assertThat(path.isAbsolute(), is(true)); assertThat(path.getSegment(0), is(segment("ex:A[1]"))); assertThat(path.getSegment(1), is(segment("ex:B[2]"))); assertThat(path.getSegment(2), is(segment("ex:C[1]"))); assertThat(path.size(), is(3)); }
@Test public void shouldParsePathFromStringWithoutTrailingSlash() { path = paths.create("/A/B/C/D"); assertThat(path.isAbsolute(), is(true)); assertThat(path.getSegment(0), is(segment("A[1]"))); assertThat(path.getSegment(1), is(segment("B[1]"))); assertThat(path.getSegment(2), is(segment("C[1]"))); assertThat(path.getSegment(3), is(segment("D[1]"))); assertThat(path.size(), is(4)); }
@Test public void shouldParsePathFromStringEndingWithSameNameSiblingIndexButWithoutTrailingSlash() { path = paths.create("/A/B/C/D[3]"); assertThat(path.isAbsolute(), is(true)); assertThat(path.getSegment(0), is(segment("A[1]"))); assertThat(path.getSegment(1), is(segment("B[1]"))); assertThat(path.getSegment(2), is(segment("C[1]"))); assertThat(path.getSegment(3), is(segment("D[3]"))); assertThat(path.size(), is(4)); }
@Test public void shouldParsePathFromStringWithRootSegmentAndIdentifierSegment() { path = paths.create("/A/B/C/D[3]"); assertThat(path.isAbsolute(), is(true)); assertThat(path.getSegment(0), is(segment("A[1]"))); assertThat(path.getSegment(1), is(segment("B[1]"))); assertThat(path.getSegment(2), is(segment("C[1]"))); assertThat(path.getSegment(3), is(segment("D[3]"))); assertThat(path.size(), is(4)); }
@Test public void shouldParsePathFromStringWithNamespacesAndEndingWithSameNameSiblingIndexButWithoutTrailingSlash() { path = paths.create("/A/ex:B/ex:C/ex:D[3]"); assertThat(path.isAbsolute(), is(true)); assertThat(path.getSegment(0), is(segment("A[1]"))); assertThat(path.getSegment(1), is(segment("ex:B[1]"))); assertThat(path.getSegment(2), is(segment("ex:C[1]"))); assertThat(path.getSegment(3), is(segment("ex:D[3]"))); assertThat(path.size(), is(4)); }
@Test public void shouldParsePathFromStringWithNamespacesAndRootSegmentAndIdentifierSegment() { path = paths.create("/A/B/C/D[3]"); assertThat(path.isAbsolute(), is(true)); assertThat(path.getSegment(0), is(segment("A[1]"))); assertThat(path.getSegment(1), is(segment("B[1]"))); assertThat(path.getSegment(2), is(segment("C[1]"))); assertThat(path.getSegment(3), is(segment("D[3]"))); assertThat(path.size(), is(4)); }
@Test public void shouldParsePathFromStringWithoutRootSegmentAndIdentifierSegment() { path = paths.create("[f81d4fae-7dec-11d0-a765-00a0c91e6bf6]"); assertThat(path.isAbsolute(), is(true)); assertThat(path.isIdentifier(), is(true)); assertThat(path.size(), is(1)); assertThat(path.getSegment(0), is(segment("[f81d4fae-7dec-11d0-a765-00a0c91e6bf6]"))); assertThat(path.getSegment(0).getName(), is(name("f81d4fae-7dec-11d0-a765-00a0c91e6bf6"))); assertThat(path.getSegment(0).getIndex(), is(1)); assertThat(path.getSegment(0).isIdentifier(), is(true)); }