HeaderParameterChecker 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 header = request.getHeader(parameter.getName()); if (header != null) { result = result && header.contains(parameter.getValue()); } else { result = false; } } return result; }  @Override boolean checkCondition(final WilmaHttpRequest request, final ParameterList parameterList);  }
@Test public void testCheckConditionWhenConditionIsFulfilledShouldReturnTrue() { parameterList.addParameter(new Parameter(CONTENT_TYPE_HEADER, XML_CONTENT)); given(request.getHeader(CONTENT_TYPE_HEADER)).willReturn(XML_CONTENT); given(request.getBody()).willReturn(XML_CONTENT); boolean actual = underTest.checkCondition(request, parameterList); assertEquals(actual, true); }
@Test public void testCheckConditionWhenMultipleConditionsAreFulfilledShouldReturnTrue() { parameterList.addParameter(new Parameter(CONTENT_TYPE_HEADER, XML_CONTENT)); parameterList.addParameter(new Parameter(CONTENT_ENCODING_HEADER, GZIP_CONTENT)); given(request.getHeader(CONTENT_TYPE_HEADER)).willReturn(XML_CONTENT); given(request.getHeader(CONTENT_ENCODING_HEADER)).willReturn(GZIP_CONTENT); boolean actual = underTest.checkCondition(request, parameterList); assertEquals(actual, true); }
@Test public void testCheckConditionWhenOneConditionIsFulfilledShouldReturnFalse() { parameterList.addParameter(new Parameter(CONTENT_TYPE_HEADER, XML_CONTENT)); parameterList.addParameter(new Parameter(CONTENT_ENCODING_HEADER, GZIP_CONTENT)); given(request.getHeader(CONTENT_TYPE_HEADER)).willReturn(XML_CONTENT); given(request.getHeader(CONTENT_ENCODING_HEADER)).willReturn("something else"); boolean actual = underTest.checkCondition(request, parameterList); assertEquals(actual, false); }
@Test public void testCheckConditionWhenOneConditionIsNotFulfilledShouldReturnFalse() { parameterList.addParameter(new Parameter(CONTENT_TYPE_HEADER, XML_CONTENT)); parameterList.addParameter(new Parameter(CONTENT_ENCODING_HEADER, GZIP_CONTENT)); given(request.getHeader(CONTENT_TYPE_HEADER)).willReturn("something else"); given(request.getHeader(CONTENT_ENCODING_HEADER)).willReturn(GZIP_CONTENT); boolean actual = underTest.checkCondition(request, parameterList); assertEquals(actual, false); }
@Test public void testCheckConditionWhenNoConditionIsFulfilledShouldReturnFalse() { parameterList.addParameter(new Parameter(CONTENT_TYPE_HEADER, XML_CONTENT)); parameterList.addParameter(new Parameter(CONTENT_ENCODING_HEADER, GZIP_CONTENT)); given(request.getHeader(CONTENT_TYPE_HEADER)).willReturn("something else"); given(request.getHeader(CONTENT_ENCODING_HEADER)).willReturn("something else"); boolean actual = underTest.checkCondition(request, parameterList); assertEquals(actual, false); }
@Test public void testCheckConditionWhenParameterMapIsEmptyShouldReturnFalse() { boolean actual = underTest.checkCondition(request, parameterList); assertEquals(actual, false); }
@Test public void testCheckConditionWhenThereIsNoHeaderWithGivenParameterShouldReturnFalse() { parameterList.addParameter(new Parameter(CONTENT_TYPE_HEADER, XML_CONTENT)); given(request.getHeader(CONTENT_TYPE_HEADER)).willReturn(null); boolean actual = underTest.checkCondition(request, parameterList); assertEquals(actual, false); }