PathTemplateFilter { public static Builder create(String pathTemplate) { return new BuilderImpl(pathTemplate); }  abstract boolean hasPathTemplate(String pathTemplateName); static PathTemplateFilter parse(List<String> attributes); static Builder create(String pathTemplate);  }
@Test public void testFilterMultipleExclusion() { PathTemplateFilter filter = PathTemplateFilter.create("foo").exclude("bar").and("abc").exclude("123").build(); PathAddress address = PathAddress.pathAddress("some", "path"); address.addPathTemplateResolver(new PathTemplateResolver() { @Override public String resolve(String templateName) { if (templateName.equals("foo")) return "bar"; return null; } }); Assert.assertFalse(address.accepts(filter)); address = PathAddress.pathAddress("some", "path"); address.addPathTemplateResolver(new PathTemplateResolver() { @Override public String resolve(String templateName) { if (templateName.equals("abc")) return "123"; return null; } }); Assert.assertFalse(address.accepts(filter)); }
@Test public void testFilterExclusionPriority() { PathTemplateFilter filter = PathTemplateFilter.create("foo").include("bar").and("abc").exclude("123").build(); PathAddress address = PathAddress.pathAddress("blah"); address.addPathTemplateResolver(new PathTemplateResolver() { @Override public String resolve(String templateName) { if (templateName.equals("foo")) return "bar"; return null; } }); Assert.assertTrue(address.accepts(filter)); address.addPathTemplateResolver(new PathTemplateResolver() { @Override public String resolve(String templateName) { if (templateName.equals("abc")) return "123"; return null; } }); Assert.assertFalse(address.accepts(filter)); }
@Test public void testFilterWildcard() { PathTemplateFilter filter = PathTemplateFilter.create("foo").includeAll().build(); PathAddress address = PathAddress.pathAddress("blah"); address.addPathTemplateResolver(new PathTemplateResolver() { @Override public String resolve(String templateName) { if (templateName.equals("foo")) return "bar"; return null; } }); Assert.assertTrue(address.accepts(filter)); }
@Test public void testFilterNoTemplate() { PathTemplateFilter filter = PathTemplateFilter.create("foo").include("bar").build(); PathAddress address = PathAddress.pathAddress("blah"); Assert.assertTrue(address.accepts(filter)); }
@Test public void testNoTemplateWithExclusion() { PathTemplateFilter filter = PathTemplateFilter.create("foo").exclude("bar").build(); PathAddress address = PathAddress.pathAddress("blah"); Assert.assertTrue(address.accepts(filter)); }
@Test public void testFilterNoMatch() { PathTemplateFilter filter = PathTemplateFilter.create("foo").include("bar").build(); PathAddress address = PathAddress.pathAddress("some", "path"); address.addPathTemplateResolver(new PathTemplateResolver() { @Override public String resolve(String templateName) { if (templateName.equals("foo")) return "blah"; return null; } }); Assert.assertFalse(address.accepts(filter)); filter = PathTemplateFilter.create("foo").include("foo").and("abc").include("123").build(); address = PathAddress.pathAddress("some", "path"); address.addPathTemplateResolver(new PathTemplateResolver() { @Override public String resolve(String templateName) { if (templateName.equals("foo")) return "blah"; return null; } }); Assert.assertFalse(address.accepts(filter)); }
@Test public void testFilterMultiple() { PathTemplateFilter filter = PathTemplateFilter.create("foo").include("bar").and("abc").include("123").build(); PathAddress address = PathAddress.pathAddress("some", "path"); address.addPathTemplateResolver(new PathTemplateResolver() { @Override public String resolve(String templateName) { if (templateName.equals("foo")) return "bar"; return null; } }); Assert.assertTrue(address.accepts(filter)); address.addPathTemplateResolver(new PathTemplateResolver() { @Override public String resolve(String templateName) { if (templateName.equals("abc")) return "123"; return null; } }); Assert.assertTrue(address.accepts(filter)); }
@Test public void testFilterMultipleNoMatch() { PathTemplateFilter filter = PathTemplateFilter.create("foo").include("bar").and("abc").include("123").build(); PathAddress address = PathAddress.pathAddress("some", "path"); address.addPathTemplateResolver(new PathTemplateResolver() { @Override public String resolve(String templateName) { if (templateName.equals("foo")) return "bar"; return null; } }); address.addPathTemplateResolver(new PathTemplateResolver() { @Override public String resolve(String templateName) { if (templateName.equals("abc")) return "1234"; return null; } }); Assert.assertFalse(address.accepts(filter)); }
@Test public void testFilterExclusion() { PathTemplateFilter filter = PathTemplateFilter.create("foo").exclude("bar").build(); PathAddress address = PathAddress.pathAddress("some", "path"); address.addPathTemplateResolver(new PathTemplateResolver() { @Override public String resolve(String templateName) { if (templateName.equals("foo")) return "bar"; return null; } }); Assert.assertFalse(address.accepts(filter)); address = PathAddress.pathAddress("some", "path"); address.addPathTemplateResolver(new PathTemplateResolver() { @Override public String resolve(String templateName) { if (templateName.equals("foo")) return "foobar"; return null; } }); Assert.assertTrue(address.accepts(filter)); }