Changeset 1938
- Timestamp:
- 2011-09-01 07:08:10 (9 months ago)
- Location:
- trunk
- Files:
-
- 5 edited
-
core/kauri-runtime-testfw/src/main/java/org/kauriproject/runtime/testfw/AbstractRuntimeTest.java (modified) (2 diffs)
-
modules/kauri-routing/kauri-routing-impl/src/test/java/org/kauriproject/routing/test/Routing1Test.java (modified) (1 diff)
-
modules/kauri-template/kauri-template-service-impl/src/test/java/org/kauriproject/template/service/test/TemplateConfTest.java (modified) (2 diffs)
-
modules/kauri-template/kauri-template-service-impl/src/test/java/org/kauriproject/template/service/test/TemplateServiceHostIdentifierTest.java (modified) (1 diff)
-
modules/kauri-template/kauri-template-service-impl/src/test/java/org/kauriproject/template/service/test/TemplateUriResolvingTest.java (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/core/kauri-runtime-testfw/src/main/java/org/kauriproject/runtime/testfw/AbstractRuntimeTest.java
r1367 r1938 37 37 import org.kauriproject.runtime.repository.RepoArtifactRef; 38 38 import org.kauriproject.runtime.repository.ResolvedArtifact; 39 import org.restlet.Client; 40 import org.restlet.Request; 41 import org.restlet.Response; 42 import org.restlet.data.Method; 39 43 import org.apache.log4j.ConsoleAppender; 40 44 import org.apache.log4j.PatternLayout; … … 294 298 file.delete(); 295 299 } 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 } 296 352 } -
trunk/modules/kauri-routing/kauri-routing-impl/src/test/java/org/kauriproject/routing/test/Routing1Test.java
r1524 r1938 52 52 public void testRouting() throws Exception { 53 53 // Just a test for filters and closure-defined restlets 54 testRequest("/test1", "Message: message from filter");54 assertedResponseFor("/test1", "Message: message from filter"); 55 55 56 56 // Test Spring-based auto-wiring 57 testRequest("/wiringtest", "Message: message from service");57 assertedResponseFor("/wiringtest", "Message: message from service"); 58 58 59 59 // Test read instruction 60 testRequest("/readtest/foo/bar.txt", "Foobar");60 assertedResponseFor("/readtest/foo/bar.txt", "Foobar"); 61 61 } 62 62 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 }70 63 } -
trunk/modules/kauri-template/kauri-template-service-impl/src/test/java/org/kauriproject/template/service/test/TemplateConfTest.java
r1937 r1938 48 48 49 49 public void testConf() throws Exception { 50 Response response = testRequest("/templates/conftest.xml");50 Response response = assertedResponseFor("/templates/conftest.xml"); 51 51 Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(response.getEntity().getStream()); 52 52 … … 55 55 assertEquals("CONF_UNDEFINED", XPathUtils.evalString("/root/nodefault", document)); 56 56 } 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.org62 if (response.getStatus().getCode() != 200) {63 // dump response body before assertion to retrieve some more detail in the logs on hudson64 System.out.println("Unexpected response code. Dumping BODY:--\n" + response.getEntityAsText() + "\n--");65 }66 // end temp-code67 68 assertEquals(200, response.getStatus().getCode());69 return response;70 }71 57 } -
trunk/modules/kauri-template/kauri-template-service-impl/src/test/java/org/kauriproject/template/service/test/TemplateServiceHostIdentifierTest.java
r1936 r1938 68 68 69 69 public void testT() throws Exception { 70 Response response = testRequest("/templates/snippet.xml");70 Response response = assertedResponseFor("/templates/snippet.xml"); 71 71 Document doc = parseDocument(response); 72 72 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.org79 if (response.getStatus().getCode() != 200) {80 // dump response body before assertion to retrieve some more detail in the logs on hudson81 System.out.println("Unexpected response code. Dumping BODY:--\n" + response.getEntityAsText() + "\n--");82 }83 // end temp-code84 85 assertEquals(200, response.getStatus().getCode());86 return response;87 73 } 88 74 -
trunk/modules/kauri-template/kauri-template-service-impl/src/test/java/org/kauriproject/template/service/test/TemplateUriResolvingTest.java
r1526 r1938 84 84 // 85 85 { 86 Response response = testRequest("/templates/template1.xml");86 Response response = assertedResponseFor("/templates/template1.xml"); 87 87 Document doc = parseDocument(response); 88 88 assertEquals("/A1/foobar", XPathUtils.evalString("/root/publicPath[1]/text()", doc)); … … 95 95 // 96 96 { 97 Response response = testRequest("/templates/template2.xml");97 Response response = assertedResponseFor("/templates/template2.xml"); 98 98 Document doc = parseDocument(response); 99 99 assertEquals("subincluded1", XPathUtils.evalString("/root/root/root", doc)); … … 104 104 // 105 105 { 106 Response response = testRequest("/templates/template3.xml");106 Response response = assertedResponseFor("/templates/template3.xml"); 107 107 Document doc = parseDocument(response); 108 108 assertEquals("subincluded2", XPathUtils.evalString("/root/root/root", doc)); … … 113 113 // 114 114 { 115 Response response = testRequest("/templates/template4.xml");115 Response response = assertedResponseFor("/templates/template4.xml"); 116 116 Document doc = parseDocument(response); 117 117 assertEquals("dummy", XPathUtils.evalString("local-name(/root/*[1])", doc)); … … 125 125 // 126 126 { 127 Response response = testRequest("/templates/template5.xml");127 Response response = assertedResponseFor("/templates/template5.xml"); 128 128 Document doc = parseDocument(response); 129 129 assertEquals("dummy", XPathUtils.evalString("local-name(/root/*[1])", doc)); … … 140 140 // 141 141 { 142 Response response = testRequest("/templates/template6.xml");142 Response response = assertedResponseFor("/templates/template6.xml"); 143 143 Document doc = parseDocument(response); 144 144 assertEquals("subincluded2", XPathUtils.evalString("/root/root/root", doc)); 145 145 } 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;152 146 } 153 147
Note: See TracChangeset
for help on using the changeset viewer.