| 1 |
/* |
| 2 |
* Licensed to the Apache Software Foundation (ASF) under one |
| 3 |
* or more contributor license agreements. See the NOTICE file |
| 4 |
* distributed with this work for additional information |
| 5 |
* regarding copyright ownership. The ASF licenses this file |
| 6 |
* to you under the Apache License, Version 2.0 (the |
| 7 |
* "License"); you may not use this file except in compliance |
| 8 |
* with the License. You may obtain a copy of the License at |
| 9 |
* |
| 10 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
* |
| 12 |
* Unless required by applicable law or agreed to in writing, |
| 13 |
* software distributed under the License is distributed on an |
| 14 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 |
* KIND, either express or implied. See the License for the |
| 16 |
* specific language governing permissions and limitations |
| 17 |
* under the License. |
| 18 |
*/ |
| 19 |
package servlet |
| 20 |
|
| 21 |
import gls.CompilableTestSupport |
| 22 |
|
| 23 |
class GroovyServletTest extends CompilableTestSupport { |
| 24 |
|
| 25 |
void testExample() { |
| 26 |
shouldCompile ''' |
| 27 |
// tag::example[] |
| 28 |
if (!session) { |
| 29 |
session = request.getSession(true) |
| 30 |
} |
| 31 |
|
| 32 |
if (!session.counter) { |
| 33 |
session.counter = 1 |
| 34 |
} |
| 35 |
|
| 36 |
println """ |
| 37 |
<html> |
| 38 |
<head> |
| 39 |
<title>Groovy Servlet</title> |
| 40 |
</head> |
| 41 |
<body> |
| 42 |
<p> |
| 43 |
Hello, ${request.remoteHost}: ${session.counter}! ${new Date()} |
| 44 |
</p> |
| 45 |
</body> |
| 46 |
</html> |
| 47 |
""" |
| 48 |
session.counter = session.counter + 1 |
| 49 |
// end::example[] |
| 50 |
''' |
| 51 |
} |
| 52 |
|
| 53 |
void testExampleMarkupBuilder() { |
| 54 |
shouldCompile ''' |
| 55 |
// tag::example_markup_builder[] |
| 56 |
if (!session) { |
| 57 |
session = request.getSession(true) |
| 58 |
} |
| 59 |
|
| 60 |
if (!session.counter) { |
| 61 |
session.counter = 1 |
| 62 |
} |
| 63 |
|
| 64 |
html.html { // html is implicitly bound to new MarkupBuilder(out) |
| 65 |
head { |
| 66 |
title('Groovy Servlet') |
| 67 |
} |
| 68 |
body { |
| 69 |
p("Hello, ${request.remoteHost}: ${session.counter}! ${new Date()}") |
| 70 |
} |
| 71 |
} |
| 72 |
session.counter = session.counter + 1 |
| 73 |
// end::example_markup_builder[] |
| 74 |
''' |
| 75 |
} |
| 76 |
} |