Changeset 1938


Ignore:
Timestamp:
2011-09-01 07:08:10 (9 months ago)
Author:
mpo
Message:

Getting to the bottom of the testRequests copy-pasted in various tests.
Replaces r1936 and r1937
Should finally get us the data hoped for @ci.outerthought.org
Also see #461

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/kauri-runtime-testfw/src/main/java/org/kauriproject/runtime/testfw/AbstractRuntimeTest.java

    r1367 r1938  
    3737import org.kauriproject.runtime.repository.RepoArtifactRef; 
    3838import org.kauriproject.runtime.repository.ResolvedArtifact; 
     39import org.restlet.Client; 
     40import org.restlet.Request; 
     41import org.restlet.Response; 
     42import org.restlet.data.Method; 
    3943import org.apache.log4j.ConsoleAppender; 
    4044import org.apache.log4j.PatternLayout; 
     
    294298        file.delete(); 
    295299    } 
     300     
     301    /** 
     302     * Sends out request to specified path, asserts the response, then returns it. 
     303     * @param path uri of request to send 
     304     * @return the response 
     305     * @throws IOException  
     306     * @throws RuntimeException if assertion fails: response didn't contain statuscode 200 OK 
     307     */ 
     308    protected Response assertedResponseFor(final String path) throws IOException { 
     309        return assertedResponseFor(path, 200, null); 
     310    } 
     311     
     312    /** 
     313     * Sends out request to specified path, asserts the response, verifies the responseText in the body, then returns the response. 
     314     * @param path uri of request to send 
     315     * @param responseText body contents of response to assert (leave <code>null</code> to skip this assertion) 
     316     * @return the response 
     317     * @throws IOException  
     318     * @throws RuntimeException if assertion fails: response didn't contain statuscode 200 OK or text content doesn't match 
     319     */ 
     320    protected Response assertedResponseFor(final String path, final String responseText) throws IOException { 
     321        return assertedResponseFor(path, 200, responseText); 
     322    } 
     323     
     324    /** 
     325     * Sends out request to specified path, asserts the response-statuscode, verifies the responseText in the body, then returns the response. 
     326     * @param path uri of request to send 
     327     * @param statusCode to assert in the response 
     328     * @param responseText body contents of response to assert (leave <code>null</code> to skip this assertion) 
     329     * @return the response 
     330     * @throws IOException  
     331     * @throws RuntimeException if assertion fails: response didn't contain statuscode or text content doesn't match 
     332     */ 
     333    protected Response assertedResponseFor(final String path, final int statusCode, final String responseText) throws IOException { 
     334        Client client = runtime.getRestserviceManager().getComponent().getContext().getClientDispatcher(); 
     335        Request request = new Request(Method.GET, "http://localhost:" + HTTP_TEST_PORT + path); 
     336        Response response = client.handle(request); 
     337 
     338        // start temp-code for checking test failures only @ci.outerthought.org 
     339        if (response.getStatus().getCode() != statusCode) { 
     340            // dump response body before assertion to retrieve some more detail in the logs on hudson 
     341            System.out.println("Unexpected response code. Dumping BODY:--\n" + response.getEntityAsText() + "\n--"); 
     342        } 
     343        // end temp-code 
     344         
     345        assertEquals(statusCode, response.getStatus().getCode()); 
     346        if (responseText != null) { 
     347            assertEquals(responseText, response.getEntity().getText()); 
     348        } 
     349         
     350        return response; 
     351    } 
    296352} 
  • trunk/modules/kauri-routing/kauri-routing-impl/src/test/java/org/kauriproject/routing/test/Routing1Test.java

    r1524 r1938  
    5252    public void testRouting() throws Exception { 
    5353        // Just a test for filters and closure-defined restlets 
    54         testRequest("/test1", "Message: message from filter"); 
     54        assertedResponseFor("/test1", "Message: message from filter"); 
    5555 
    5656        // Test Spring-based auto-wiring 
    57         testRequest("/wiringtest", "Message: message from service"); 
     57        assertedResponseFor("/wiringtest", "Message: message from service"); 
    5858 
    5959        // Test read instruction 
    60         testRequest("/readtest/foo/bar.txt", "Foobar"); 
     60        assertedResponseFor("/readtest/foo/bar.txt", "Foobar"); 
    6161    } 
    6262 
    63     private void testRequest(String path, String responseText) throws Exception{ 
    64         Client client = runtime.getRestserviceManager().getComponent().getContext().getClientDispatcher(); 
    65         Request request = new Request(Method.GET, "http://localhost:" + HTTP_TEST_PORT + path); 
    66         Response response = client.handle(request); 
    67         assertEquals(200, response.getStatus().getCode()); 
    68         assertEquals(responseText, response.getEntity().getText()); 
    69     } 
    7063} 
  • trunk/modules/kauri-template/kauri-template-service-impl/src/test/java/org/kauriproject/template/service/test/TemplateConfTest.java

    r1937 r1938  
    4848 
    4949    public void testConf() throws Exception { 
    50         Response response = testRequest("/templates/conftest.xml"); 
     50        Response response = assertedResponseFor("/templates/conftest.xml"); 
    5151        Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(response.getEntity().getStream()); 
    5252 
     
    5555        assertEquals("CONF_UNDEFINED", XPathUtils.evalString("/root/nodefault", document)); 
    5656    } 
    57  
    58     private Response testRequest(String path) throws Exception { 
    59         Response response = runtime.getRestserviceManager().getComponent().getContext().getClientDispatcher().handle(new Request(Method.GET, "http://localhost:" + HTTP_TEST_PORT + path)); 
    60          
    61         // start temp-code for checking test failures only @ci.outerthought.org 
    62         if (response.getStatus().getCode() != 200) { 
    63             // dump response body before assertion to retrieve some more detail in the logs on hudson 
    64             System.out.println("Unexpected response code. Dumping BODY:--\n" + response.getEntityAsText() + "\n--"); 
    65         } 
    66         // end temp-code 
    67          
    68         assertEquals(200, response.getStatus().getCode()); 
    69         return response; 
    70     } 
    7157} 
  • trunk/modules/kauri-template/kauri-template-service-impl/src/test/java/org/kauriproject/template/service/test/TemplateServiceHostIdentifierTest.java

    r1936 r1938  
    6868 
    6969    public void testT() throws Exception { 
    70         Response response = testRequest("/templates/snippet.xml"); 
     70        Response response = assertedResponseFor("/templates/snippet.xml"); 
    7171        Document doc = parseDocument(response); 
    7272        assertEquals("http://dummy/A3/foobar", evalXPath("/publicPath", doc)); 
    73     } 
    74  
    75     private Response testRequest(String path) throws Exception { 
    76         Response response = runtime.getRestserviceManager().getComponent().getContext().getClientDispatcher().handle(new Request(Method.GET, "http://localhost:" + HTTP_TEST_PORT + path)); 
    77          
    78         // start temp-code for checking test failures only @ci.outerthought.org 
    79         if (response.getStatus().getCode() != 200) { 
    80             // dump response body before assertion to retrieve some more detail in the logs on hudson 
    81             System.out.println("Unexpected response code. Dumping BODY:--\n" + response.getEntityAsText() + "\n--"); 
    82         } 
    83         // end temp-code 
    84          
    85         assertEquals(200, response.getStatus().getCode()); 
    86         return response; 
    8773    } 
    8874 
  • trunk/modules/kauri-template/kauri-template-service-impl/src/test/java/org/kauriproject/template/service/test/TemplateUriResolvingTest.java

    r1526 r1938  
    8484        // 
    8585        { 
    86             Response response = testRequest("/templates/template1.xml"); 
     86            Response response = assertedResponseFor("/templates/template1.xml"); 
    8787            Document doc = parseDocument(response); 
    8888            assertEquals("/A1/foobar", XPathUtils.evalString("/root/publicPath[1]/text()", doc)); 
     
    9595        // 
    9696        { 
    97             Response response = testRequest("/templates/template2.xml"); 
     97            Response response = assertedResponseFor("/templates/template2.xml"); 
    9898            Document doc = parseDocument(response); 
    9999            assertEquals("subincluded1", XPathUtils.evalString("/root/root/root", doc)); 
     
    104104        // 
    105105        { 
    106             Response response = testRequest("/templates/template3.xml"); 
     106            Response response = assertedResponseFor("/templates/template3.xml"); 
    107107            Document doc = parseDocument(response); 
    108108            assertEquals("subincluded2", XPathUtils.evalString("/root/root/root", doc)); 
     
    113113        // 
    114114        { 
    115             Response response = testRequest("/templates/template4.xml"); 
     115            Response response = assertedResponseFor("/templates/template4.xml"); 
    116116            Document doc = parseDocument(response); 
    117117            assertEquals("dummy", XPathUtils.evalString("local-name(/root/*[1])", doc)); 
     
    125125        // 
    126126        { 
    127             Response response = testRequest("/templates/template5.xml"); 
     127            Response response = assertedResponseFor("/templates/template5.xml"); 
    128128            Document doc = parseDocument(response); 
    129129            assertEquals("dummy", XPathUtils.evalString("local-name(/root/*[1])", doc)); 
     
    140140        // 
    141141        { 
    142             Response response = testRequest("/templates/template6.xml"); 
     142            Response response = assertedResponseFor("/templates/template6.xml"); 
    143143            Document doc = parseDocument(response); 
    144144            assertEquals("subincluded2", XPathUtils.evalString("/root/root/root", doc)); 
    145145        } 
    146     } 
    147  
    148     private Response testRequest(String path) throws Exception { 
    149         Response response = runtime.getRestserviceManager().getComponent().getContext().getClientDispatcher().handle(new Request(Method.GET, "http://localhost:" + HTTP_TEST_PORT + path)); 
    150         assertEquals(200, response.getStatus().getCode()); 
    151         return response; 
    152146    } 
    153147 
Note: See TracChangeset for help on using the changeset viewer.