X-Git-Url: http://jaekl.net/gitweb/?p=frank.git;a=blobdiff_plain;f=test%2Fnet%2Fjaekl%2Fqd%2Fhttp%2FRequestBrokerTest.java;h=2892a1775dc667afd5deb76ed13e64d841d930ee;hp=037e079040deba3b6bd0cc8365510f8c87031eef;hb=d870b8b1ca2e633b0f2b58969cc042888d07db6e;hpb=07c8e189128f4fb3be7f49db75b48cf9e2e3de6e diff --git a/test/net/jaekl/qd/http/RequestBrokerTest.java b/test/net/jaekl/qd/http/RequestBrokerTest.java index 037e079..2892a17 100644 --- a/test/net/jaekl/qd/http/RequestBrokerTest.java +++ b/test/net/jaekl/qd/http/RequestBrokerTest.java @@ -9,6 +9,7 @@ import net.jaekl.qd.xml.XmlParseException; import org.apache.http.NameValuePair; import org.junit.Test; +import org.xml.sax.SAXParseException; public class RequestBrokerTest { @@ -83,11 +84,11 @@ public class RequestBrokerTest { // Try submitting a request (with a mocked-out http post component) // and validate that we do, in fact, return the expected text (XML). @Test - public void test_sumbit() throws QDException { + public void test_submit() throws QDException { ArrayList emptyParams = new ArrayList(); RequestBrokerMock rbm = new RequestBrokerMock(GATEWAY, emptyParams); - rbm.setOutput(METHOD, emptyParams, ROUTE_SUMMARY_FOR_STOP); + rbm.setResult(METHOD, emptyParams, ROUTE_SUMMARY_FOR_STOP); String actual = rbm.submit(METHOD, emptyParams); @@ -101,7 +102,7 @@ public class RequestBrokerTest { ArrayList emptyParams = new ArrayList(); RequestBrokerMock rbm = new RequestBrokerMock(GATEWAY, emptyParams); - rbm.setOutput(METHOD, emptyParams, ROUTE_SUMMARY_FOR_STOP); + rbm.setResult(METHOD, emptyParams, ROUTE_SUMMARY_FOR_STOP); ParseResult pr = rbm.submitAndParse(METHOD, emptyParams, RouteSummaryParse.class); @@ -167,4 +168,42 @@ public class RequestBrokerTest { Assert.assertEquals(passedParams, rbpem.getParamsPassed()); Assert.assertEquals(ParseResult.class, rbpem.getParserClassPassed()); } + + @Test + public void test_submitAndParse_nonXmlResponse() { + ArrayList emptyParams = new ArrayList(); + + RequestBrokerMock rbm = new RequestBrokerMock(GATEWAY, emptyParams); + rbm.setResult(METHOD, emptyParams, "No stop number specified"); + + try { + rbm.submitAndParse(METHOD, emptyParams, RouteSummaryParse.class); + Assert.fail("Should have thrown an InvalidResultException"); + } + catch (QDException qde) { + Assert.assertTrue(qde instanceof InvalidResponseException); + Assert.assertTrue(qde.toString().contains(GATEWAY)); + Assert.assertTrue(qde.toString().contains(METHOD)); + } + } + + @Test + public void test_submitAndParse_throwsInvalidResultException() { + InvalidResponseException ire = new InvalidResponseException(GATEWAY, METHOD, new SAXParseException("dummy", null)); + ArrayList emptyParams = new ArrayList(); + + RequestBrokerMock rbm = new RequestBrokerMock(GATEWAY, emptyParams); + rbm.setResult(METHOD, emptyParams, ire); + + try { + rbm.submitAndParse(METHOD, emptyParams, RouteSummaryParse.class); + Assert.fail("Should have thrown an exception"); + } + catch (QDException qde) { + Assert.assertTrue(qde instanceof InvalidResponseException); + Assert.assertEquals(ire, qde); + Assert.assertTrue(ire.toString().contains(GATEWAY)); + Assert.assertTrue(ire.toString().contains(METHOD)); + } + } }