/** * Convenience function to create a MultiMatcher from a Collection of patterns and varargs of HttpMethod. * First match is used so and ordered collection may be needed if a path could match a more general pattern. */ static Matcher multiMatch(Collection<String> matchingPathTemplates, HttpMethod... matchingMethods) { return MultiMatcher.match(matchingPathTemplates, matchingMethods); }
@Test public void matchesMethod_returns_false_if_request_is_null() { // given MultiMatcher matcher = MultiMatcher.match(Collections.singleton("/foo"), HttpMethod.GET); // expect assertThat(matcher.matchesMethod(null), is(false)); }
@Test public void static_factory_with_path_arg_only_sets_values_as_expected() { // given String path = "/" + UUID.randomUUID().toString(); Collection<String> paths = new ArrayList<String>() {{ add(path); }}; // when MultiMatcher matcher = MultiMatcher.match(paths); // then assertThat(matcher.matchingPathTemplates(), is(paths)); assertThat(matcher.matchingMethods(), notNullValue()); assertThat(matcher.matchingMethods().isEmpty(), is(true)); assertThat(matcher.isMatchAllMethods(), is(true)); }
@Test public void matchesPath_returns_empty_if_request_is_null() { // given String path = "/some/path"; Collection<String> paths = new ArrayList<String>() {{ add(path); }}; MultiMatcher matcher = MultiMatcher.match(paths); // expect assertThat(matcher.matchesPath(null), is(Optional.empty())); }
@Test public void static_factory_with_path_and_methods_collection_sets_values_as_expected() { // given String path = "/" + UUID.randomUUID().toString(); Collection<String> paths = new ArrayList<String>() {{ add(path); }}; Collection<HttpMethod> methodCollection = Arrays.asList(HttpMethod.GET, HttpMethod.PUT); // when MultiMatcher matcher = MultiMatcher.match(paths, methodCollection); // then assertThat(matcher.matchingPathTemplates(), is(paths)); assertThat(matcher.matchingMethods(), is(methodCollection)); assertThat(matcher.isMatchAllMethods(), is(false)); }
/** * Convenience function to create a MultiMatcher from a Collection of patterns and collection of HttpMethods. * First match is used so and ordered collection may be needed if a path could match a more general pattern. */ static Matcher multiMatch(Collection<String> matchingPathTemplates, Collection<HttpMethod> matchingMethods) { return MultiMatcher.match(matchingPathTemplates, matchingMethods); } }
@Test public void matchesMethod_returns_true_if_matchAllMethods_is_true() { // given MultiMatcher matcher = MultiMatcher.match(Collections.singleton("/foo")); // expect assertThat(matcher.matchesMethod(null), is(true)); }
@Test @UseDataProvider("knownData") public void matchesPath_works_as_expected_for_known_data(List<String> matcherPathTemplates, String requestPath, Optional<String> expectedMatchValue) { // given MultiMatcher matcher = MultiMatcher.match(matcherPathTemplates); RequestInfo<?> requestInfo = RequestInfoImpl.dummyInstanceForUnknownRequests(); Whitebox.setInternalState(requestInfo, "path", requestPath); // expect assertThat(matcher.matchesPath(requestInfo), is(expectedMatchValue)); }
@Test public void static_factory_with_path_and_methods_varargs_sets_values_as_expected() { // given String path = "/" + UUID.randomUUID().toString(); Collection<String> paths = new ArrayList<String>() {{ add(path); }}; HttpMethod[] methodVarargs = new HttpMethod[]{HttpMethod.GET, HttpMethod.PUT}; // when MultiMatcher matcher = MultiMatcher.match(paths, methodVarargs); // then assertThat(matcher.matchingPathTemplates(), is(paths)); assertThat(matcher.matchingMethods(), notNullValue()); assertThat(matcher.matchingMethods().size(), is(methodVarargs.length)); for (HttpMethod expectedMethod : methodVarargs) { assertThat(matcher.matchingMethods().contains(expectedMethod), is(true)); } assertThat(matcher.isMatchAllMethods(), is(false)); }
/** * Convenience function to create a MultiMatcher from a Collection of patterns. First match is used so and ordered * collection may be needed if a path could match a more general pattern. */ static Matcher multiMatch(Collection<String> matchingPathTemplates) { return MultiMatcher.match(matchingPathTemplates); }
@Test @DataProvider(value = { "GET,POST | GET | true", "GET,POST | POST | true", "GET,POST | PUT | false", "GET,POST | null | false" }, splitBy = "\\|") public void matchesMethod_works_as_expected_for_known_data(String matcherMethodStrings, String requestMethodString, boolean expectedMatchValue) { // given List<HttpMethod> matcherMethods = Arrays.asList(matcherMethodStrings.split(",")).stream().map(HttpMethod::valueOf).collect(Collectors.toList()); Collection<String> paths = new ArrayList<String>() {{ add("/foo"); }}; MultiMatcher matcher = MultiMatcher.match(paths, matcherMethods); RequestInfo<?> requestInfo = RequestInfoImpl.dummyInstanceForUnknownRequests(); if (requestMethodString == null) Whitebox.setInternalState(requestInfo, "method", null); else Whitebox.setInternalState(requestInfo, "method", HttpMethod.valueOf(requestMethodString)); // expect assertThat(matcher.matchesMethod(requestInfo), is(expectedMatchValue)); } }
@Override public Matcher requestMatcher() { return MultiMatcher.match(Arrays.asList(INTERNAL_MATCHING_PATH, EXTERNAL_MATCHING_PATH)); } }
@Override public Matcher requestMatcher() { return MultiMatcher.match(Arrays.asList(INTERNAL_MATCHING_PATH, NON_INTERNAL_MATCHING_PATH)); }
@Override public Matcher requestMatcher() { return MultiMatcher.match(Arrays.asList(NON_INTERNAL_MATCHING_PATH, INTERNAL_MATCHING_PATH)); } }
@Test(expected = IllegalArgumentException.class) public void static_factory_with_path_and_methods_collection_throws_IllegalArgumentException_if_passed_empty_collection() { // given String path = "/" + UUID.randomUUID().toString(); Collection<String> paths = new ArrayList<String>() {{ add(path); }}; Collection<HttpMethod> methodCollection = Collections.emptyList(); // expect MultiMatcher.match(paths, methodCollection); }
@Test(expected = IllegalArgumentException.class) public void static_factory_with_path_and_methods_varargs_throws_IllegalArgumentException_if_passed_null_vararg_array() { // given String path = "/" + UUID.randomUUID().toString(); Collection<String> paths = new ArrayList<String>() {{ add(path); }}; // expect MultiMatcher.match(paths, (HttpMethod[]) null); }
@Test(expected = IllegalArgumentException.class) public void static_factory_with_path_and_methods_collection_throws_IllegalArgumentException_if_passed_null_collection() { // given String path = "/" + UUID.randomUUID().toString(); Collection<String> paths = new ArrayList<String>() {{ add(path); }}; // expect MultiMatcher.match(paths, (Collection<HttpMethod>) null); }
@Test(expected = IllegalArgumentException.class) public void static_factory_with_path_and_methods_varargs_throws_IllegalArgumentException_if_passed_empty_vararg_array() { // given String path = "/" + UUID.randomUUID().toString(); Collection<String> paths = new ArrayList<String>() {{ add(path); }}; HttpMethod[] methodVarargs = new HttpMethod[0]; // expect MultiMatcher.match(paths, methodVarargs); }