/webugger-core-demo/src/test/java/no/lau/web/page/TestPageTest.java

http://webugger.googlecode.com/ · Java · 83 lines · 68 code · 10 blank · 5 comment · 0 complexity · 9b9a11dc9e4714e55804fcb5ed95665d MD5 · raw file

  1. package no.lau.web.page;
  2. import org.junit.*;
  3. import no.lau.web.fixture.AbstractWebTestFixture;
  4. /**
  5. * @author Stig Lau
  6. * Checks that the Groovy Web Debugger renders correctly
  7. * and works as expected
  8. */
  9. public class TestPageTest extends AbstractWebTestFixture {
  10. @Before
  11. public void beforeEach() {
  12. tester.beginAt("/test.jsp");
  13. }
  14. @Test
  15. public void testRendersCorrectly() {
  16. tester.assertTextPresent("Run Groovy Code");
  17. tester.assertFormPresent("groovyform");
  18. }
  19. @Test
  20. public void testAddingSomeNumbersSimple() {
  21. tester.setTextField("groovyscript",
  22. "print 5+10");
  23. tester.submit("submitbutton");
  24. tester.assertTextPresent("15");
  25. }
  26. @Test
  27. public void testAddingSomeNumbers() {
  28. tester.setTextField("groovyscript",
  29. "def somenumbers = 5+10\n" +
  30. "print \"result = $somenumbers\"");
  31. tester.submit("submitbutton");
  32. tester.assertTextPresent("result = 15");
  33. }
  34. @Test
  35. public void testPrintingRequestLocalAddress() {
  36. tester.setTextField("groovyscript", "print \"address = $request.localAddr\"");
  37. tester.submit("submitbutton");
  38. tester.assertTextPresent("address = 127.0.0.1");
  39. }
  40. @Test
  41. public void testPrintingRequest() {
  42. tester.setTextField("groovyscript",
  43. "print request");
  44. tester.submit("submitbutton");
  45. tester.assertTextPresent("POST /webugger/test.jsp"); //And much more
  46. }
  47. @Test
  48. public void testPrintingPersonWithCarsObject() {
  49. String groovyScript = "class Person {\n" +
  50. " String name\n" +
  51. " int age\n" +
  52. " List cars\n" +
  53. "}\n" +
  54. "\n" +
  55. "class Car {\n" +
  56. " String type\n" +
  57. " int topSpeed\n" +
  58. "}\n" +
  59. "\n" +
  60. "\n" +
  61. "def johnny = new Person(name:\"Johnny B. Good\", age:28, cars:\n" +
  62. " [new Car(type:\"Ferrari\", topSpeed:320),\n" +
  63. " new Car(type:\"Porsche 911 Turbo\", topSpeed:280)])\n" +
  64. "\n" +
  65. "print \"$johnny.name is $johnny.age and owns $johnny.cars.size car(s):<br/>\"\n" +
  66. "johnny.cars.each{Car car -> print \"$car.type with a top speed of $car.topSpeed km/h<br/>\"}";
  67. tester.setTextField("groovyscript",groovyScript);
  68. tester.submit("submitbutton");
  69. tester.assertTextPresent("Johnny B. Good is 28 and owns 2 car(s):");
  70. tester.assertTextPresent("Ferrari with a top speed of 320 km/h");
  71. tester.assertTextPresent("Porsche 911 Turbo with a top speed of 280 km/h");
  72. }
  73. }