/** * @return rule to match the request POST body parameters contained in the whitelist */ public static MatchRule matchBodyPostParametersWithWhitelist(Set<String> whiteList) { return new MatchBodyPostParameters(new MatchRuleWhitelistTransform(whiteList)); }
/** * @return rule to match the request POST body parameters, except for those in the blacklist */ public static MatchRule matchBodyPostParametersWithBlacklist(Set<String> blackList) { return new MatchBodyPostParameters(new MatchRuleBlacklistTransform(blackList)); } }
@Test public void testDifferentParameters() throws Exception { RecordedStringHttpBody stringHttpBody1 = new RecordedStringHttpBody("a=a&b=b&c=c"); RecordedStringHttpBody stringHttpBody2 = new RecordedStringHttpBody("a=a&b=b&c=ccc"); Multimap<String, String> headers = LinkedHashMultimap.create(); headers.put("Content-Type", "application/x-www-form-urlencoded"); RecordedHttpRequest recordedHttpRequest1 = new RecordedHttpRequest(null, null, headers, stringHttpBody1); RecordedHttpRequest recordedHttpRequest2 = new RecordedHttpRequest(null, null, headers, stringHttpBody2); MatchRule matchRule = new MatchBodyPostParameters(); Assert.assertFalse(matchRule.test(recordedHttpRequest1, recordedHttpRequest2)); }
@Test public void testExactMatch() throws Exception { RecordedStringHttpBody stringHttpBody1 = new RecordedStringHttpBody("a=a&b=b&c=c"); RecordedStringHttpBody stringHttpBody2 = new RecordedStringHttpBody("a=a&b=b&c=c"); Multimap<String, String> headers = LinkedHashMultimap.create(); headers.put("Content-Type", "application/x-www-form-urlencoded"); RecordedHttpRequest recordedHttpRequest1 = new RecordedHttpRequest(null, null, headers, stringHttpBody1); RecordedHttpRequest recordedHttpRequest2 = new RecordedHttpRequest(null, null, headers, stringHttpBody2); MatchRule matchRule = new MatchBodyPostParameters(); Assert.assertTrue(matchRule.test(recordedHttpRequest1, recordedHttpRequest2)); }
@Test public void testNotMatchDifferentOrder() throws Exception { RecordedStringHttpBody stringHttpBody1 = new RecordedStringHttpBody("a=a&b=b&c=c"); RecordedStringHttpBody stringHttpBody2 = new RecordedStringHttpBody("a=a&c=c&b=b"); Multimap<String, String> headers = LinkedHashMultimap.create(); headers.put("Content-Type", "application/x-www-form-urlencoded"); RecordedHttpRequest recordedHttpRequest1 = new RecordedHttpRequest(null, null, headers, stringHttpBody1); RecordedHttpRequest recordedHttpRequest2 = new RecordedHttpRequest(null, null, headers, stringHttpBody2); MatchRule matchRule = new MatchBodyPostParameters(); Assert.assertFalse(matchRule.test(recordedHttpRequest1, recordedHttpRequest2)); }
@Test public void testMatchWithSomeNullParameters() throws Exception { RecordedStringHttpBody stringHttpBody1 = new RecordedStringHttpBody("a=a&b=&c=c&d="); RecordedStringHttpBody stringHttpBody2 = new RecordedStringHttpBody("a=a&b=&c=c&d="); Multimap<String, String> headers = LinkedHashMultimap.create(); headers.put("Content-Type", "application/x-www-form-urlencoded"); RecordedHttpRequest recordedHttpRequest1 = new RecordedHttpRequest(null, null, headers, stringHttpBody1); RecordedHttpRequest recordedHttpRequest2 = new RecordedHttpRequest(null, null, headers, stringHttpBody2); MatchRule matchRule = new MatchBodyPostParameters(); Assert.assertTrue(matchRule.test(recordedHttpRequest1, recordedHttpRequest2)); } }