@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 shouldProjectPathBelowSourcePathIntoPathBelowRepositoryPath() { Path pathInRepository = pathFactory.create(repositoryPath, "m/n"); Path pathInSource = pathFactory.create(sourcePath, "m/n"); assertThat(rule.projectPathInSourceToPathInRepository(pathInSource, pathFactory), is(pathInRepository)); pathInRepository = pathFactory.create(repositoryPath, "m"); pathInSource = pathFactory.create(sourcePath, "m"); assertThat(rule.projectPathInSourceToPathInRepository(pathInSource, pathFactory), is(pathInRepository)); pathInRepository = pathFactory.create(repositoryPath, "m/n[3]"); pathInSource = pathFactory.create(sourcePath, "m/n[3]"); assertThat(rule.projectPathInSourceToPathInRepository(pathInSource, pathFactory), is(pathInRepository)); }
@Test public void shouldGetPathsInRepositoryGivenPathInSourceAndMultipleApplicableRulesReturningDuplicatePathsInRepository() { Path pathInSource = pathFactory.create("/a/b/c"); Path pathInRepository1 = pathFactory.create("/d/e/f"); Path pathInRepository23 = pathFactory.create("/d/e/g"); when(mockRule1.getPathInRepository(pathInSource, pathFactory)).thenReturn(pathInRepository1); when(mockRule2.getPathInRepository(pathInSource, pathFactory)).thenReturn(pathInRepository23); when(mockRule3.getPathInRepository(pathInSource, pathFactory)).thenReturn(pathInRepository23); Set<Path> pathsInRepository = projection.getPathsInRepository(pathInSource, pathFactory); assertThat(pathsInRepository, hasItems(pathInRepository1, pathInRepository23)); }
@Before public void beforeEach() { context = new ExecutionContext(); pathFactory = context.getValueFactories().getPathFactory(); registry = context.getNamespaceRegistry(); encoder = new UrlEncoder(); repositoryPath = pathFactory.create("/a/b/c"); sourcePath = pathFactory.create("/x/y"); validExceptions = new Path[] {pathFactory.create("e/f"), pathFactory.create("e/g")}; rule = new Projection.PathRule(repositoryPath, sourcePath, validExceptions); }
@Test public void shouldIncludeRepositoryPathsBelowPathInRepositoryThatAreNotExcluded() { assertThat(rule.includes(pathFactory.create(sourcePath, "m")), is(true)); assertThat(rule.includes(pathFactory.create(sourcePath, "m/n")), is(true)); assertThat(rule.includes(pathFactory.create(sourcePath, "o/p")), is(true)); assertThat(rule.includes(pathFactory.create(sourcePath, "e/e")), is(true)); assertThat(rule.includes(pathFactory.create(sourcePath, "e")), is(true)); }
@Test public void shouldConvertToString() { assertThat(rule.getString(registry, encoder), is("/a/b/c => /x/y $ e/f $ e/g")); repositoryPath = pathFactory.create("/a/b/c"); sourcePath = pathFactory.create("/"); rule = new Projection.PathRule(repositoryPath, sourcePath, validExceptions); assertThat(rule.getString(registry, encoder), is("/a/b/c => / $ e/f $ e/g")); repositoryPath = pathFactory.create("/"); sourcePath = pathFactory.create("/"); rule = new Projection.PathRule(repositoryPath, sourcePath, validExceptions); assertThat(rule.getString(registry, encoder), is("/ => / $ e/f $ e/g")); }
@Test( expected = IllegalArgumentException.class ) public void shouldFailToGetPathsInSourceGivenValidPathAndNullPathFactory() { Path pathInRepository = pathFactory.create("/a/b/c"); projection.getPathsInSource(pathInRepository, null); }
@Test public void shouldHaveToString() { assertThat(rule.toString(), is("/{}a/{}b/{}c => /{}x/{}y $ {}e/{}f $ {}e/{}g")); repositoryPath = pathFactory.create("/a/b/c"); sourcePath = pathFactory.create("/"); rule = new Projection.PathRule(repositoryPath, sourcePath, validExceptions); assertThat(rule.toString(), is("/{}a/{}b/{}c => / $ {}e/{}f $ {}e/{}g")); }
@Test public void shouldGetNullPathInSourceGivenPathsInRepositoryAtOrBelowRepositoryPathIfExcluded() { assertThat(rule.getPathInSource(pathFactory.create(repositoryPath, "e/f"), pathFactory), is(nullValue())); assertThat(rule.getPathInSource(pathFactory.create(repositoryPath, "e/g"), pathFactory), is(nullValue())); assertThat(rule.getPathInSource(pathFactory.create(repositoryPath, "e/f/h"), pathFactory), is(nullValue())); assertThat(rule.getPathInSource(pathFactory.create(repositoryPath, "e/g/h"), pathFactory), is(nullValue())); }
public void addChild( Location parent, String childName ) { Path path = context.getValueFactories().getPathFactory().create(parent.getPath(), segment(childName)); Map<Name, Property> properties = Collections.emptyMap(); List<ProjectedNode> grandChildren = Collections.emptyList(); PlaceholderNode child = new PlaceholderNode(Location.create(path), properties, grandChildren); this.children.add(child); }
public PathNode createNode( ExecutionContext context, String pathToNewNode, Map<Name, Property> properties, NodeConflictBehavior conflictBehavior ) { PathFactory pathFactory = context.getValueFactories().getPathFactory(); Path newPath = pathFactory.create(pathToNewNode); return createNode(context, getNode(newPath.getParent()), newPath.getLastSegment().getName(), properties, conflictBehavior); }
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 shouldParsePathFromStringWithNamespacesAndWithSingleChildSegment() { path = paths.create("/ex:A"); assertThat(path.isAbsolute(), is(true)); assertThat(path.getSegment(0), is(segment("ex:A[1]"))); assertThat(path.size(), is(1)); }
@Test public void shouldParsePathFromStringWithMultipleChildSegments() { path = paths.create("/A/B/C"); 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.size(), is(3)); }
@Test public void shouldParsePathFromStringWithMultipleChildSegmentsWithSameNameSiblingIndex() { path = paths.create("/A/B[2]/C"); assertThat(path.isAbsolute(), is(true)); assertThat(path.getSegment(0), is(segment("A[1]"))); assertThat(path.getSegment(1), is(segment("B[2]"))); assertThat(path.getSegment(2), is(segment("C[1]"))); assertThat(path.size(), is(3)); }
@Test public void shouldParsePathFromStringWithTrailingSlash() { 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)); }
public Location child( Location parent, String childName ) { Path path = context.getValueFactories().getPathFactory().create(parent.getPath(), segment(childName)); return Location.create(path); }
@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 shouldProvidePathToInput() throws Exception { this.sequencedProperty = mock(Property.class); graph.create("/a").and().create("/a/b").and().create("/a/b/c").and(); Node input = graph.getNodeAt("/a/b/c"); StreamSequencerContext sequencerContext = sequencer.createStreamSequencerContext(input, sequencedProperty, seqContext, problems); assertThat(sequencerContext.getInputPath(), is(context.getValueFactories().getPathFactory().create("/a/b/c"))); }