@Test public void testLookup() { MatchRule matchRule1 = new MatchBody(); MatchRule matchRule2 = new MatchBody(); MatchRule matchRule3 = new MatchHeaders(); Set<MatchRule> matchRuleSet = new HashSet<>(); matchRuleSet.add(matchRule1); Assert.assertTrue(matchRuleSet.contains(matchRule2)); Assert.assertFalse(matchRuleSet.contains(matchRule3)); } }
@Test public void testInsertion() { Set<MatchRule> matchRuleSet = new HashSet<>(); matchRuleSet.add(new MatchBody()); Assert.assertEquals(matchRuleSet.size(), 1); matchRuleSet.add(new MatchBody()); Assert.assertEquals(matchRuleSet.size(), 1); matchRuleSet.add(new MatchHeaders()); matchRuleSet.add(MatchRuleUtils.matchHeadersWithBlacklist(null)); matchRuleSet.add(MatchRuleUtils.matchHeadersWithWhitelist(null)); Assert.assertEquals(matchRuleSet.size(), 4); }
@Test public void testBothNullBodyMatch() { RecordedHttpRequest recordedHttpRequest1 = new RecordedHttpRequest(null, null, null, null); RecordedHttpRequest recordedHttpRequest2 = new RecordedHttpRequest(null, null, null, null); MatchRule matchRule = new MatchBody(); Assert.assertTrue(matchRule.test(recordedHttpRequest1, recordedHttpRequest2)); }
/** * @return rule to match request URI, Body and Method */ public static MatchRule matchMethodBodyUri() { CompositeMatchRule compositeMatchRule = new CompositeMatchRule(); compositeMatchRule.addRule(new MatchBody()); compositeMatchRule.addRule(new MatchMethod()); compositeMatchRule.addRule(new MatchUri()); return compositeMatchRule; }
@Test public void testNullAndNonEmptyBodyNotMatch() { RecordedStringHttpBody stringHttpBody2 = new RecordedStringHttpBody("abc"); RecordedHttpRequest recordedHttpRequest1 = new RecordedHttpRequest(null, null, null, null); RecordedHttpRequest recordedHttpRequest2 = new RecordedHttpRequest(null, null, null, stringHttpBody2); MatchRule matchRule = new MatchBody(); Assert.assertFalse(matchRule.test(recordedHttpRequest1, recordedHttpRequest2)); }
@Test public void testIsStringBodyNotMatchWithDiffCharset() throws Exception { RecordedStringHttpBody stringHttpBody1 = new RecordedStringHttpBody("造字"); RecordedStringHttpBody stringHttpBody2 = new RecordedStringHttpBody("造字"); Multimap<String, String> headers1 = LinkedHashMultimap.create(); headers1.put(HttpHeaders.CONTENT_TYPE, "text/html; charset=euc-kr"); Multimap<String, String> headers2 = LinkedHashMultimap.create(); headers2.put(HttpHeaders.CONTENT_TYPE, "text/html; charset=big5"); RecordedHttpRequest recordedHttpRequest1 = new RecordedHttpRequest(null, null, headers1, stringHttpBody1); RecordedHttpRequest recordedHttpRequest2 = new RecordedHttpRequest(null, null, headers2, stringHttpBody2); MatchRule matchRule = new MatchBody(); Assert.assertFalse(matchRule.test(recordedHttpRequest1, recordedHttpRequest2)); } }
@Test public void testNullAndEmptyBodyMatch() { RecordedStringHttpBody stringHttpBody2 = new RecordedStringHttpBody(""); RecordedHttpRequest recordedHttpRequest1 = new RecordedHttpRequest(null, null, null, null); RecordedHttpRequest recordedHttpRequest2 = new RecordedHttpRequest(null, null, null, stringHttpBody2); MatchRule matchRule = new MatchBody(); Assert.assertTrue(matchRule.test(recordedHttpRequest1, recordedHttpRequest2)); }
@Test public void testIsStringBodyMatch() throws Exception { RecordedStringHttpBody stringHttpBody1 = new RecordedStringHttpBody("abc"); RecordedStringHttpBody stringHttpBody2 = new RecordedStringHttpBody("abc"); RecordedHttpRequest recordedHttpRequest1 = new RecordedHttpRequest(null, null, null, stringHttpBody1); RecordedHttpRequest recordedHttpRequest2 = new RecordedHttpRequest(null, null, null, stringHttpBody2); MatchRule matchRule = new MatchBody(); Assert.assertTrue(matchRule.test(recordedHttpRequest1, recordedHttpRequest2)); }
@Test public void testIsStringBodyNotMatch() throws Exception { RecordedStringHttpBody stringHttpBody1 = new RecordedStringHttpBody("abc"); RecordedStringHttpBody stringHttpBody2 = new RecordedStringHttpBody("abcd"); RecordedHttpRequest recordedHttpRequest1 = new RecordedHttpRequest(null, null, null, stringHttpBody1); RecordedHttpRequest recordedHttpRequest2 = new RecordedHttpRequest(null, null, null, stringHttpBody2); MatchRule matchRule = new MatchBody(); Assert.assertFalse(matchRule.test(recordedHttpRequest1, recordedHttpRequest2)); }
/** * @return rule to match request URI, Method, Headers, and Body */ public static MatchRule matchEntireRequest() { CompositeMatchRule compositeMatchRule = new CompositeMatchRule(); compositeMatchRule.addRule(new MatchMethod()); compositeMatchRule.addRule(new MatchUri()); compositeMatchRule.addRule(new MatchHeaders()); compositeMatchRule.addRule(new MatchBody()); return compositeMatchRule; }