Identify bad responses coming back from the server, and throw a specific exception...
[frank.git] / test / net / jaekl / qd / http / RequestBrokerTest.java
index 037e079040deba3b6bd0cc8365510f8c87031eef..2892a1775dc667afd5deb76ed13e64d841d930ee 100644 (file)
@@ -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<NameValuePair> emptyParams = new ArrayList<NameValuePair>();
                
                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<NameValuePair> emptyParams = new ArrayList<NameValuePair>();
                
                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<NameValuePair> emptyParams = new ArrayList<NameValuePair>();
+               
+               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<NameValuePair> emptyParams = new ArrayList<NameValuePair>();
+               
+               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));
+               }
+       }
 }