01: // Copyright 2006, 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.internal.test;
16:
17: import java.util.Arrays;
18: import java.util.Collections;
19:
20: import org.apache.tapestry.internal.test.PageTesterSession;
21: import org.testng.Assert;
22: import org.testng.annotations.BeforeMethod;
23: import org.testng.annotations.Test;
24:
25: public class PageTesterSessionTest extends Assert {
26: private PageTesterSession _session;
27:
28: @BeforeMethod
29: public void before() {
30: _session = new PageTesterSession();
31: }
32:
33: @Test
34: public void empty() {
35: assertEquals(_session.getAttributeNames(),
36: Collections.EMPTY_LIST);
37: assertNull(_session.getAttribute("x"));
38: }
39:
40: @Test
41: public void set_attributes() {
42: _session.setAttribute("b", 10);
43: _session.setAttribute("a", 20);
44: assertEquals(_session.getAttribute("a"), 20);
45: assertEquals(_session.getAttribute("b"), 10);
46: }
47:
48: @Test
49: public void remove_if_value_is_null() {
50: _session.setAttribute("b", 10);
51: _session.setAttribute("a", 20);
52: assertEquals(_session.getAttributeNames().size(), 2);
53: _session.setAttribute("b", null);
54: assertEquals(_session.getAttributeNames().size(), 1);
55: }
56:
57: @Test
58: public void names_sorted() {
59: _session.setAttribute("b", 10);
60: _session.setAttribute("a", 20);
61: _session.setAttribute("c", 50);
62: assertEquals(_session.getAttributeNames(), Arrays.asList("a",
63: "b", "c"));
64: }
65: }
|