XmlMessageTypeChecker implements ConditionChecker { @Override public boolean checkCondition(final WilmaHttpRequest request, final ParameterList parameterList) { boolean result = false; String contentType = request.getHeader(CONTENT_TYPE_HEADER); if (checkContentTypeIsXml(contentType)) { result = Boolean.valueOf(evaluateQueryWithParamCheck(request, parameterList)); } return result; }  @Override boolean checkCondition(final WilmaHttpRequest request, final ParameterList parameterList);  }
@Test public void testCheckConditionShouldReturnFalseWhenContentTypeIsNotXMLType() { given(request.getHeader(CONTENT_TYPE_HEADER)).willReturn(TEXT_PLAIN); boolean actual = underTest.checkCondition(request, parameterList); assertFalse(actual); }
@Test public void testCheckConditionShouldReturnFalseWhenContentTypeIsNullWhenHttpGetProcessing() { given(request.getHeader(CONTENT_TYPE_HEADER)).willReturn(null); boolean actual = underTest.checkCondition(request, parameterList); assertFalse(actual); }
@Test(expectedExceptions = ConditionEvaluationFailedException.class) public void testCheckConditionShouldThrowExceptionWhenNoParameterIsDefinedInConfig() { given(request.getHeader(CONTENT_TYPE_HEADER)).willReturn(HEADER_VAL_XML); underTest.checkCondition(request, parameterList); }
@Test(expectedExceptions = ConditionEvaluationFailedException.class) public void testCheckConditionShouldThrowExceptionWhenTooMuchParametersAreDefinedInConfig() { given(request.getHeader(CONTENT_TYPE_HEADER)).willReturn(HEADER_VAL_FASTINFOSET); parameterList.addParameter(new Parameter(TEXT_PLAIN, HEADER_VAL_XML)); parameterList.addParameter(new Parameter(CONTENT_TYPE_HEADER, HEADER_VAL_XML)); underTest.checkCondition(request, parameterList); }
@Test(expectedExceptions = ConditionEvaluationFailedException.class) public void testCheckConditionShouldThrowExceptionWhenXQueryEvaulationFailed() throws SaxonApiException { given(request.getHeader(CONTENT_TYPE_HEADER)).willReturn(HEADER_VAL_XML); parameterList.addParameter(new Parameter(TEXT_PLAIN, HEADER_VAL_XML)); given(xQueryEvaluator.evaluateXQuery(anyString(), anyString())).willThrow(new SaxonApiException("")); underTest.checkCondition(request, parameterList); }
@Test public void testCheckConditionShouldReturnFalseWhenQueryResultFalse() throws SaxonApiException { given(request.getHeader(CONTENT_TYPE_HEADER)).willReturn(HEADER_VAL_XML); parameterList.addParameter(new Parameter(TEXT_PLAIN, HEADER_VAL_XML)); given(xQueryEvaluator.evaluateXQuery(anyString(), anyString())).willReturn("false"); boolean actual = underTest.checkCondition(request, parameterList); assertFalse(actual); }
@Test public void testCheckConditionShouldReturnTrueWhenQueryResultFalse() throws SaxonApiException { given(request.getHeader(CONTENT_TYPE_HEADER)).willReturn(HEADER_VAL_XML); parameterList.addParameter(new Parameter(TEXT_PLAIN, HEADER_VAL_XML)); given(xQueryEvaluator.evaluateXQuery(anyString(), anyString())).willReturn("true"); boolean actual = underTest.checkCondition(request, parameterList); assertTrue(actual); }