@Override public SequencerDefinition<ReturnType> andOutputtingTo( String into ) { CheckArg.isNotEmpty(into, "into"); return sequencingFrom(PathExpression.compile(fromPathExpression + " => " + into)); } };
@Test( expected = IllegalArgumentException.class ) public void shouldNotCompileNullExpression() { PathExpression.compile(null); }
@Test( expected = InvalidPathExpressionException.class ) public void shouldNotCompileZeroLengthExpression() { PathExpression.compile(""); }
@Test( expected = InvalidPathExpressionException.class ) public void shouldNotCompileBlankExpression() { PathExpression.compile(" "); }
@Test public void shouldDetermineIfPatternMatchesAnything() { assertThat(PathExpression.compile("/.").matchesAnything(), is(true)); assertThat(PathExpression.compile("//").matchesAnything(), is(true)); assertThat(PathExpression.compile("///").matchesAnything(), is(true)); assertThat(PathExpression.compile("///").matchesAnything(), is(true)); assertThat(PathExpression.compile("/*").matchesAnything(), is(true)); assertThat(PathExpression.compile("*").matchesAnything(), is(true)); assertThat(PathExpression.compile("*[*]").matchesAnything(), is(true)); assertThat(PathExpression.compile("*[]").matchesAnything(), is(true)); assertThat(PathExpression.compile("/a").matchesAnything(), is(false)); assertThat(PathExpression.compile("/*[3]").matchesAnything(), is(false)); assertThat(PathExpression.compile("/a/b/c").matchesAnything(), is(false)); }
@Test public void shouldCompileExpressionWithRepositoryAndWorkspaceNames() { assertThat(PathExpression.compile("repo:ws:/a/b/c"), is(notNullValue())); }
@Test public void shouldCompileExpressionWithNoRepositoryAndNoWorkspaceNames() { assertThat(PathExpression.compile("::/a/b/c"), is(notNullValue())); }
@Test public void shouldCompileExpressionWithRepositoryAndNoWorkspaceNames() { assertThat(PathExpression.compile("repo::/a/b/c"), is(notNullValue())); }
@Test public void shouldCompileExpressionWithExtraWhitespace() { expr = PathExpression.compile(" /a/b/c "); assertThat(expr, is(notNullValue())); assertThat(expr.getSelectExpression(), is("/a/b/c")); expr = PathExpression.compile(" /a/b/c "); assertThat(expr, is(notNullValue())); assertThat(expr.getSelectExpression(), is("/a/b/c")); }
@Test public void shouldMatchExpressionsWithRepositoryInSelectionPath() { expr = PathExpression.compile("reposA::/a/b/c[d/e/@something]"); assertThat(expr.matcher("reposA::/a/b/c/d/e/@something").matches(), is(true)); }
@Test public void shouldMatchExpressionWithFilenamePatternAndChildProperty() { expr = PathExpression.compile("//(*.(jpeg|gif|bmp|pcx|png|iff|ras|pbm|pgm|ppm|psd))[*]/jcr:content[@jcr:data]"); assertThat(expr.matcher("/a/b/caution.png/jcr:content/@jcr:data").matches(), is(true)); }
@Test public void shouldCompileExpressionWithAnyNode() { expr = PathExpression.compile("/*"); assertThat(expr.getSelectExpression(), is("/*")); assertThat(expr.matcher("/a").matches(), is(true)); assertThat(expr.matcher("/a").getInputPath(), is("/a")); assertThat(expr.matcher("/a").getSelectedNodePath(), is("/a")); assertThat(expr.matcher("/a").groupCount(), is(0)); }
@Test public void shouldMatchExpressionsWithExtraLargeSegmentWildcardAtEnd() { expr = PathExpression.compile("/a/b/c////"); assertThat(expr.matcher("/a/b/c").matches(), is(true)); assertThat(expr.matcher("/a/b/c").getInputPath(), is("/a/b/c")); assertThat(expr.matcher("/a/b/c").getSelectedNodePath(), is("/a/b/c")); assertThat(expr.matcher("/a/b/c").groupCount(), is(0)); }
@Test public void shouldMatchExpressionsWithExactFullPathAndExtraPathInsideMatch() { expr = PathExpression.compile("/a/b/c[d/e/@something]"); assertThat(expr.matcher("/a/b/c/d/e/@something").matches(), is(true)); assertThat(expr.matcher("/a/b/c/d/e/@something").getInputPath(), is("/a/b/c/d/e/@something")); assertThat(expr.matcher("/a/b/c/d/e/@something").getSelectedNodePath(), is("/a/b/c")); assertThat(expr.matcher("/a/b/c/d/e/@something").groupCount(), is(0)); assertThat(expr.matcher("/a/b/c/d/E/@something2").matches(), is(false)); assertThat(expr.matcher("/a/b/c/d/ex/@something").matches(), is(false)); assertThat(expr.matcher("/a/b[1]/c/d/e/@something").matches(), is(false)); }
@Test public void shouldMatchStringWithRepositoryAndWorkspaceUsingExpressionWithoutRepositoryOrWorkspace() { expr = PathExpression.compile("//a/b"); assertThat(expr.matcher("repo:workspace:/a").matches(), is(false)); assertThat(expr.matcher("repo:workspace:/a/b").matches(), is(true)); assertThat(expr.matcher("repo:workspace:/x/a/b").matches(), is(true)); assertThat(expr.matcher("repo:workspace:/x/y/a/b").matches(), is(true)); assertThat(expr.matcher("repo1:workspace2:/a").matches(), is(false)); assertThat(expr.matcher("repo1:workspace2:/a/b").matches(), is(true)); assertThat(expr.matcher("repo1:workspace2:/x/a/b").matches(), is(true)); assertThat(expr.matcher("repo1:workspace2:/x/y/a/b").matches(), is(true)); }
@Test public void shouldMatchExpressionsWithExactFullPath() { expr = PathExpression.compile("/a/b/c/d/e[@something]"); assertThat(expr.matcher("/a/b/c/d/e/@something").matches(), is(true)); assertThat(expr.matcher("/a/b/c/d/e/@something").getInputPath(), is("/a/b/c/d/e/@something")); assertThat(expr.matcher("/a/b/c/d/e/@something").getSelectedNodePath(), is("/a/b/c/d/e")); assertThat(expr.matcher("/a/b/c/d/e/@something").groupCount(), is(0)); assertThat(expr.matcher("/a/b/c/d/E/@something2").matches(), is(false)); assertThat(expr.matcher("/a/b/c/d/ex/@something").matches(), is(false)); assertThat(expr.matcher("/a/b[1]/c/d/e/@something").matches(), is(false)); }
@Test public void shouldMatchStringWithRepositoryAndWorkspaceUsingExpressionWithBlankRepositoryAndBlankWorkspace() { expr = PathExpression.compile(":://a/b"); assertThat(expr.matcher("repo:workspace:/a").matches(), is(false)); assertThat(expr.matcher("repo:workspace:/a/b").matches(), is(true)); assertThat(expr.matcher("repo:workspace:/x/a/b").matches(), is(true)); assertThat(expr.matcher("repo:workspace:/x/y/a/b").matches(), is(true)); assertThat(expr.matcher("repo1:workspace2:/a").matches(), is(false)); assertThat(expr.matcher("repo1:workspace2:/a/b").matches(), is(true)); assertThat(expr.matcher("repo1:workspace2:/x/a/b").matches(), is(true)); assertThat(expr.matcher("repo1:workspace2:/x/y/a/b").matches(), is(true)); }
@Test public void shouldMatchExpressionsWithoutRegardToCase() { expr = PathExpression.compile("/a/b/c/d/e[@something]"); assertThat(expr.matcher("/a/b/c/d/e/@something").matches(), is(true)); assertThat(expr.matcher("/a/b/c/d/e/@something").getInputPath(), is("/a/b/c/d/e/@something")); assertThat(expr.matcher("/a/b/c/d/e/@something").getSelectedNodePath(), is("/a/b/c/d/e")); assertThat(expr.matcher("/a/b/c/d/e/@something").groupCount(), is(0)); assertThat(expr.matcher("/a/b/c/d/E/@something").matches(), is(true)); assertThat(expr.matcher("/a/b/c/d/E/@something").getInputPath(), is("/a/b/c/d/E/@something")); assertThat(expr.matcher("/a/b/c/d/E/@something").getSelectedNodePath(), is("/a/b/c/d/E")); assertThat(expr.matcher("/a/b/c/d/E/@something").groupCount(), is(0)); }
@Test public void shouldMatchStringWithRepositoryAndWorkspaceUsingExpressionWithRepositoryAndWorkspace() { expr = PathExpression.compile("repo:workspace://a/b"); assertThat(expr.matcher("repo:workspace:/a").matches(), is(false)); assertThat(expr.matcher("repo:workspace:/a/b").matches(), is(true)); assertThat(expr.matcher("repo:workspace:/x/a/b").matches(), is(true)); assertThat(expr.matcher("repo:workspace:/x/y/a/b").matches(), is(true)); assertThat(expr.matcher("repo:workspace2:/a").matches(), is(false)); assertThat(expr.matcher("repo:workspace2:/a/b").matches(), is(false)); assertThat(expr.matcher("repo:workspace2:/x/a/b").matches(), is(false)); assertThat(expr.matcher("repo:workspace2:/x/y/a/b").matches(), is(false)); assertThat(expr.matcher("repo1:workspace2:/a").matches(), is(false)); assertThat(expr.matcher("repo1:workspace2:/a/b").matches(), is(false)); assertThat(expr.matcher("repo1:workspace2:/x/a/b").matches(), is(false)); assertThat(expr.matcher("repo1:workspace2:/x/y/a/b").matches(), is(false)); }