@Test public void shouldNotHaveAnyParentOrSelfReferencesInTheNormalizedPathOfAnAbsolutePath() { path = pathFactory.create("/a/b/c/../d/./e/../.."); assertThat(path.isNormalized(), is(false)); assertThat(path.getNormalizedPath(), hasSegments(pathFactory, "a", "b")); assertThat(path.getNormalizedPath().isAbsolute(), is(true)); assertThat(path.getNormalizedPath().isNormalized(), is(true)); }
@Test public void shouldNormalizeRelativePathWithMultipleSegmentIncludingSelfAndParent() { assertThat(paths.create("A/B/C[1]/../D[2]/./E/..").getNormalizedPath(), is(paths.create("A/B/D[2]"))); assertThat(paths.create("A/B/C[1]/././D[2]").getNormalizedPath(), is(paths.create("A/B/C/D[2]"))); assertThat(paths.create("A/../../../B").getNormalizedPath(), is(paths.create("../../B"))); assertThat(paths.create("../../B").getNormalizedPath(), is(paths.create("../../B"))); assertThat(paths.create("./B").getNormalizedPath(), is(paths.create("B"))); assertThat(paths.create("A/./../../B/.").getNormalizedPath(), is(paths.create("../B"))); }
@Test public void shouldNormalizePathWithSelfAndParentReferences() { path = pathFactory.create("/a/b/c/../d/./e/../.."); assertThat(path.isNormalized(), is(false)); assertThat(path.getNormalizedPath(), hasSegments(pathFactory, "a", "b")); assertThat(path.getNormalizedPath().isAbsolute(), is(true)); assertThat(path.getNormalizedPath().isNormalized(), is(true)); path = pathFactory.create("a/b/c/../d/./e/../.."); assertThat(path.isNormalized(), is(false)); assertThat(path.getNormalizedPath(), hasSegments(pathFactory, "a", "b")); assertThat(path.getNormalizedPath().isAbsolute(), is(false)); assertThat(path.getNormalizedPath().isNormalized(), is(true)); }
@Test public void shouldGetNormalizedPathWithParentReferences() { assertThat(pathFactory.create("..").getNormalizedPath(), is(pathFactory.create(".."))); assertThat(pathFactory.create("../").getNormalizedPath(), is(pathFactory.create("../"))); assertThat(pathFactory.create("../../../../../..").getNormalizedPath(), is(pathFactory.create("../../../../../.."))); }
@Test public void shouldNotHaveAnyParentReferencesInTheNormalizedPathOfARelativePath() { path = pathFactory.create("a/b/c/../d/./e/../.."); assertThat(path.isNormalized(), is(false)); assertThat(path.getNormalizedPath(), hasSegments(pathFactory, "a", "b")); assertThat(path.getNormalizedPath().isAbsolute(), is(false)); assertThat(path.getNormalizedPath().isNormalized(), is(true)); }
@Test public void shouldGetNormalizedPathOfSelfShouldBeSame() { assertThat(pathFactory.create(".").getNormalizedPath(), is(pathFactory.create("."))); assertThat(pathFactory.create("./").getNormalizedPath(), is(pathFactory.create("."))); assertThat(pathFactory.create("./././").getNormalizedPath(), is(pathFactory.create("."))); }
@Test public void shouldNotHaveAnyParentReferencesInTheNormalizedPathOfARelativePath() { path = pathFactory.create("a/b/c/../d/./e/../.."); assertThat(path.isNormalized(), is(false)); assertThat(path.getNormalizedPath(), hasSegments(pathFactory, "a", "b")); assertThat(path.getNormalizedPath().isAbsolute(), is(false)); assertThat(path.getNormalizedPath().isNormalized(), is(true)); }
@Test public void shouldGetNormalizedPathWithParentReferences() { assertThat(pathFactory.create("..").getNormalizedPath(), is(pathFactory.create(".."))); assertThat(pathFactory.create("../").getNormalizedPath(), is(pathFactory.create("../"))); assertThat(pathFactory.create("../../../../../..").getNormalizedPath(), is(pathFactory.create("../../../../../.."))); }
@Test public void shouldNotHaveAnyParentOrSelfReferencesInTheNormalizedPathOfAnAbsolutePath() { path = pathFactory.create("/a/b/c/../d/./e/../.."); assertThat(path.isNormalized(), is(false)); assertThat(path.getNormalizedPath(), hasSegments(pathFactory, "a", "b")); assertThat(path.getNormalizedPath().isAbsolute(), is(true)); assertThat(path.getNormalizedPath().isNormalized(), is(true)); }
@Test public void shouldGetNormalizedPathOfSelfShouldBeSame() { assertThat(pathFactory.create(".").getNormalizedPath(), is(pathFactory.create("."))); assertThat(pathFactory.create("./").getNormalizedPath(), is(pathFactory.create("."))); assertThat(pathFactory.create("./././").getNormalizedPath(), is(pathFactory.create("."))); }
@Test public void shouldReturnRootPathAsTheNormalizedPathForAnAbsolutePathWithZeroSegmentsAfterParentAndSelfReferencesRemoved() { // "/a/../b/../c/.." => "/" path = pathFactory.create("/a/../b/../c/../"); assertThat(path.isNormalized(), is(false)); assertThat(path.getNormalizedPath(), is(ROOT)); }
@Test public void shouldReturnRootPathAsTheNormalizedPathForAnAbsolutePathWithZeroSegmentsAfterParentAndSelfReferencesRemoved() { // "/a/../b/../c/.." => "/" path = pathFactory.create("/a/../b/../c/../"); assertThat(path.isNormalized(), is(false)); assertThat(path.getNormalizedPath(), is(ROOT)); }
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( expected = InvalidPathException.class ) public void shouldFailToReturnNormalizedPathIfPathContainsReferencesToParentsAboveRoot() { path = pathFactory.create("/a/../../../.."); assertThat(path.isNormalized(), is(false)); path.getNormalizedPath(); }
public SubgraphNode getNode( Segment childSegment ) { Path path = getContext().getValueFactories().getPathFactory().create(location.getPath(), childSegment); path = path.getNormalizedPath(); Location location = request.getLocationFor(path); if (location == null) return null; return new SubgraphNodeImpl(location, request); }
@Test public void shouldReturnSelfPathAsTheNormalizedPathForARelativePathWithZeroSegmentsAfterParentAndSelfReferencesRemoved() { // "a/../b/../c/.." => "." path = pathFactory.create("a/../b/../c/../"); assertThat(path.isNormalized(), is(false)); assertThat(path.getNormalizedPath().size(), is(1)); assertThat(path.getNormalizedPath(), hasSegments(pathFactory, ".")); }
@Test public void shouldReturnSelfPathAsTheNormalizedPathForARelativePathWithZeroSegmentsAfterParentAndSelfReferencesRemoved() { // "a/../b/../c/.." => "." path = pathFactory.create("a/../b/../c/../"); assertThat(path.isNormalized(), is(false)); assertThat(path.getNormalizedPath().size(), is(1)); assertThat(path.getNormalizedPath(), hasSegments(pathFactory, ".")); }
public SubgraphNode getNode( Path relativePath ) { Path path = getContext().getValueFactories().getPathFactory().create(location.getPath(), relativePath); path = path.getNormalizedPath(); Location location = request.getLocationFor(path); if (location == null) return null; return new SubgraphNodeImpl(location, request); }
@Test( expected = InvalidPathException.class ) public void shouldFailToReturnNormalizedPathIfPathContainsReferencesToParentsAboveRoot() { path = pathFactory.create("/a/../../../.."); assertThat(path.isNormalized(), is(false)); path.getNormalizedPath(); }
public SubgraphNode getNode( Name relativePath ) { Path path = getGraph().getContext() .getValueFactories() .getPathFactory() .create(getLocation().getPath(), relativePath); path = path.getNormalizedPath(); return getNode(path); }