@Override public Map<String, String> apply(Object key) { if (template == null) { return null; } Map<String, String> headers = template.match(key.toString()); if (null != headers && !headers.isEmpty()) { return headers; } return null; }
@Override public Map<String, String> apply(Object key) { if (template == null) { return null; } Map<String, String> headers = template.match(key.toString()); if (null != headers && !headers.isEmpty()) { return headers; } return null; }
@Test public void pathVariableShouldNotMatchTrailingSegments() { UriPathTemplate template = new UriPathTemplate("/tags/{tag}/commits"); assertThat(template.matches("/tags/v1.0.0"), is(false)); assertThat(template.match("/tags/v1.0.0").entrySet(), empty()); }
@Test public void parametrizedPathWithStaticSuffixShouldBeMatched() { UriPathTemplate template = new UriPathTemplate("/comments/{id}/author"); assertThat(template.matches("/comments/1/author"), is(true)); assertThat(template.match("/comments/1/author"), hasEntry("id", "1")); }
@Test public void staticPathShouldBeMatched() { UriPathTemplate template = new UriPathTemplate("/comments"); assertThat(template.matches("/comments"), is(true)); assertThat(template.match("/comments").entrySet(), empty()); } @Test
@Test public void parameterizedPatternShouldMatchPathWithQueryParams() { UriPathTemplate uriPathTemplate = new UriPathTemplate("/test/{order}"); // does not match, the query parameter breaks matching // expected: a map containing {"order": "3"}, found: a map containing {"order": "3?q=reactor"} assertEquals("3", uriPathTemplate.match("/test/3?q=reactor") .get("order")); // assertThat(uriPathTemplate.match("/test/3?q=reactor").get("order"), is("3")); }
@Test public void parametrizedPathWithMultipleParametersShouldBeMatched() { UriPathTemplate template = new UriPathTemplate("/{collection}/{id}"); assertThat(template.matches("/comments/1"), is(true)); assertThat(template.match("/comments/1"), allOf(Arrays.asList(hasEntry("id", "1"), hasEntry("collection", "comments")))); }
@Test public void staticPathWithDotShouldBeMatched() { UriPathTemplate template = new UriPathTemplate("/1.0/comments"); assertThat(template.matches("/1.0/comments"), is(true)); assertThat(template.match("/1.0/comments").entrySet(), empty()); }
@Test public void patternShouldMatchPathWithDots() { UriPathTemplate uriPathTemplate = new UriPathTemplate("/test/{order}"); // does not match, the dot in the segment parameter breaks matching // expected: a map containing {"order": "2.0"}, found: empty map assertThat(uriPathTemplate.match("/test/2.0").get("order"), is("2.0")); }
@Test public void patternShouldMatchPathWithOnlyLetters() { UriPathTemplate uriPathTemplate = new UriPathTemplate("/test/{order}"); // works as expected assertThat(uriPathTemplate.match("/test/1").get("order"), is("1")); }
@Test public void pathWithDotShouldBeMatched() { UriPathTemplate template = new UriPathTemplate("/tags/{tag}"); assertThat(template.matches("/tags/v1.0.0"), is(true)); assertThat(template.match("/tags/v1.0.0"), hasEntry("tag", "v1.0.0")); }
@Test public void parametrizedPathShouldBeMatched() { UriPathTemplate template = new UriPathTemplate("/comments/{id}"); assertThat(template.matches("/comments/1"), is(true)); assertThat(template.match("/comments/1"), hasEntry("id", "1")); }