/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
- package no.lau.web.page;
- import org.junit.*;
- import no.lau.web.fixture.AbstractWebTestFixture;
- /**
- * @author Stig Lau
- * Checks that the Groovy Web Debugger renders correctly
- * and works as expected
- */
- public class TestPageTest extends AbstractWebTestFixture {
- @Before
- public void beforeEach() {
- tester.beginAt("/test.jsp");
- }
-
- @Test
- public void testRendersCorrectly() {
- tester.assertTextPresent("Run Groovy Code");
- tester.assertFormPresent("groovyform");
- }
- @Test
- public void testAddingSomeNumbersSimple() {
- tester.setTextField("groovyscript",
- "print 5+10");
- tester.submit("submitbutton");
- tester.assertTextPresent("15");
- }
-
- @Test
- public void testAddingSomeNumbers() {
- tester.setTextField("groovyscript",
- "def somenumbers = 5+10\n" +
- "print \"result = $somenumbers\"");
- tester.submit("submitbutton");
- tester.assertTextPresent("result = 15");
- }
- @Test
- public void testPrintingRequestLocalAddress() {
- tester.setTextField("groovyscript", "print \"address = $request.localAddr\"");
- tester.submit("submitbutton");
- tester.assertTextPresent("address = 127.0.0.1");
- }
-
- @Test
- public void testPrintingRequest() {
- tester.setTextField("groovyscript",
- "print request");
- tester.submit("submitbutton");
- tester.assertTextPresent("POST /webugger/test.jsp"); //And much more
- }
- @Test
- public void testPrintingPersonWithCarsObject() {
- String groovyScript = "class Person {\n" +
- " String name\n" +
- " int age\n" +
- " List cars\n" +
- "}\n" +
- "\n" +
- "class Car {\n" +
- " String type\n" +
- " int topSpeed\n" +
- "}\n" +
- "\n" +
- "\n" +
- "def johnny = new Person(name:\"Johnny B. Good\", age:28, cars:\n" +
- " [new Car(type:\"Ferrari\", topSpeed:320),\n" +
- " new Car(type:\"Porsche 911 Turbo\", topSpeed:280)])\n" +
- "\n" +
- "print \"$johnny.name is $johnny.age and owns $johnny.cars.size car(s):<br/>\"\n" +
- "johnny.cars.each{Car car -> print \"$car.type with a top speed of $car.topSpeed km/h<br/>\"}";
- tester.setTextField("groovyscript",groovyScript);
- tester.submit("submitbutton");
- tester.assertTextPresent("Johnny B. Good is 28 and owns 2 car(s):");
- tester.assertTextPresent("Ferrari with a top speed of 320 km/h");
- tester.assertTextPresent("Porsche 911 Turbo with a top speed of 280 km/h");
- }
- }