AndHeaderChecker implements ConditionChecker { @Override public boolean checkCondition(final WilmaHttpRequest request, final ParameterList parameterList) { List<Parameter> params = parameterList.getAllParameters(); Iterator<Parameter> iterator = params.iterator(); boolean result = !params.isEmpty(); while (iterator.hasNext() && result) { Parameter parameter = iterator.next(); String parameterValue = parameter.getValue(); result = evaluateParameter(request, parameterValue); } return result; } AndHeaderChecker(final ConditionCheckerOperator operator); @Override boolean checkCondition(final WilmaHttpRequest request, final ParameterList parameterList);  }
@Test public void testCheckConditionShouldReturnFalseWhenNoParameter() { given(paramList.getAllParameters()).willReturn(params); boolean actual = underTest.checkCondition(request, paramList); assertFalse(actual); }
@Test public void testCheckConditionShouldReturnFalseWhenParameterEmpty() { given(paramList.getAllParameters()).willReturn(params); params.add(new Parameter("a", "")); boolean actual = underTest.checkCondition(request, paramList); assertFalse(actual); }
@Test public void testCheckConditionShouldReturnFalseWhenHeadersEmpty() { given(paramList.getAllParameters()).willReturn(params); params.add(new Parameter("a", "aa")); boolean actual = underTest.checkCondition(request, paramList); assertFalse(actual); }
@Test public void testCheckConditionShouldReturnFalseWhenHeadersDoesNotContainParameter() { Map<String, String> headers = new HashMap<String, String>(); String headerValue = "bb"; headers.put("b", headerValue); given(request.getHeaders()).willReturn(headers); given(paramList.getAllParameters()).willReturn(params); String parameterValue = "aa"; params.add(new Parameter("a", parameterValue)); given(operator.checkTarget(parameterValue, headerValue)).willReturn(false); boolean actual = underTest.checkCondition(request, paramList); assertFalse(actual); }
@Test public void testCheckConditionShouldReturnTrueWhenHeadersContainsJustTheParameter() { Map<String, String> headers = new HashMap<String, String>(); String parameterValue = "aa"; headers.put("a", parameterValue); given(request.getHeaders()).willReturn(headers); given(paramList.getAllParameters()).willReturn(params); params.add(new Parameter("a", parameterValue)); given(operator.checkTarget(parameterValue, parameterValue)).willReturn(true); boolean actual = underTest.checkCondition(request, paramList); assertTrue(actual); }
@Test public void testCheckConditionShouldReturnTrueWhenHeadersContainsParameter() { Map<String, String> headers = new HashMap<String, String>(); String parameterValue = "aa"; headers.put("a", parameterValue); headers.put("b", "bb"); given(request.getHeaders()).willReturn(headers); given(paramList.getAllParameters()).willReturn(params); params.add(new Parameter("a", parameterValue)); given(operator.checkTarget(anyString(), anyString())).willReturn(true); boolean actual = underTest.checkCondition(request, paramList); assertTrue(actual); }
@Test public void testCheckConditionShouldReturnFalseWhenHeadersDoesNotContainSecondParameter() { Map<String, String> headers = new HashMap<String, String>(); headers.put("a", "aa"); headers.put("b", "bb"); given(request.getHeaders()).willReturn(headers); given(paramList.getAllParameters()).willReturn(params); given(operator.checkTarget(anyString(), anyString())).willReturn(false); params.add(new Parameter("a", "aa")); params.add(new Parameter("c", "aac")); boolean actual = underTest.checkCondition(request, paramList); assertFalse(actual); }
@Test public void testCheckConditionShouldReturnTrueWhenHeadersContainsAllParameter() { Map<String, String> headers = new HashMap<String, String>(); headers.put("a", "aa"); headers.put("b", "bb"); headers.put("c", "aac"); given(request.getHeaders()).willReturn(headers); given(paramList.getAllParameters()).willReturn(params); given(operator.checkTarget(anyString(), anyString())).willReturn(true, false, true); params.add(new Parameter("a", "aa")); params.add(new Parameter("c", "aac")); boolean actual = underTest.checkCondition(request, paramList); assertTrue(actual); }