01: // Copyright 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.services;
16:
17: import java.util.Collection;
18: import java.util.Iterator;
19:
20: import org.apache.tapestry.internal.test.InternalBaseTestCase;
21: import org.apache.tapestry.services.PersistentFieldChange;
22: import org.apache.tapestry.services.PersistentFieldStrategy;
23: import org.apache.tapestry.services.Request;
24: import org.apache.tapestry.services.Session;
25: import org.testng.annotations.Test;
26:
27: /**
28: * A more minimal test, since common behavior is already tested by
29: * {@link SessionPersistentFieldStrategyTest}.
30: */
31: public class FlashPersistentFieldStrategyTest extends
32: InternalBaseTestCase {
33: @Test
34: public void post_change_to_root_component() {
35: Session session = mockSession();
36: Request request = mockRequest();
37: Object value = new Object();
38:
39: train_getSession(request, true, session);
40:
41: session.setAttribute("flash:foo.Bar::field", value);
42:
43: replay();
44:
45: PersistentFieldStrategy strategy = new FlashPersistentFieldStrategy(
46: request);
47:
48: strategy.postChange("foo.Bar", null, "field", value);
49:
50: verify();
51: }
52:
53: @Test
54: public void gather_changes_with_active_session() {
55: Session session = mockSession();
56: Request request = mockRequest();
57:
58: train_getSession(request, false, session);
59: train_getAttributeNames(session, "flash:foo.Bar:",
60: "flash:foo.Bar::root", "flash:foo.Bar:nested:down");
61:
62: train_getAttribute(session, "flash:foo.Bar::root", "ROOT");
63: session.setAttribute("flash:foo.Bar::root", null);
64:
65: train_getAttribute(session, "flash:foo.Bar:nested:down", "DOWN");
66: session.setAttribute("flash:foo.Bar:nested:down", null);
67:
68: replay();
69:
70: PersistentFieldStrategy strategy = new FlashPersistentFieldStrategy(
71: request);
72:
73: Collection<PersistentFieldChange> changes = strategy
74: .gatherFieldChanges("foo.Bar");
75:
76: assertEquals(changes.size(), 2);
77:
78: Iterator<PersistentFieldChange> i = changes.iterator();
79:
80: PersistentFieldChange change1 = i.next();
81:
82: assertEquals(change1.getComponentId(), "");
83: assertEquals(change1.getFieldName(), "root");
84: assertEquals(change1.getValue(), "ROOT");
85:
86: PersistentFieldChange change2 = i.next();
87:
88: assertEquals(change2.getComponentId(), "nested");
89: assertEquals(change2.getFieldName(), "down");
90: assertEquals(change2.getValue(), "DOWN");
91:
92: verify();
93: }
94: }
|