KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > record > TestPersistentPropertyData


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// 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.record;
16
17 import java.util.Collections JavaDoc;
18 import java.util.List JavaDoc;
19
20 import org.apache.hivemind.test.HiveMindTestCase;
21 import org.easymock.MockControl;
22
23 /**
24  * Tests for {@link org.apache.tapestry.record.PersistentPropertyData}.
25  *
26  * @author Howard M. Lewis Ship
27  * @since 4.0
28  */

29 public class TestPersistentPropertyData extends HiveMindTestCase
30 {
31
32     public void testStoreChange()
33     {
34         Object JavaDoc newObject1 = new Object JavaDoc();
35         Object JavaDoc newObject2 = new Object JavaDoc();
36
37         PersistentPropertyDataEncoder encoder = (PersistentPropertyDataEncoder) newMock(PersistentPropertyDataEncoder.class);
38
39         replayControls();
40
41         PersistentPropertyData ppd = new PersistentPropertyData(encoder);
42
43         ppd.store("foo", "bar", newObject1);
44
45         assertListsEqual(new Object JavaDoc[]
46         { new PropertyChangeImpl("foo", "bar", newObject1) }, ppd.getPageChanges());
47
48         // Check for overwriting.
49

50         ppd.store("foo", "bar", newObject2);
51
52         assertListsEqual(new Object JavaDoc[]
53         { new PropertyChangeImpl("foo", "bar", newObject2) }, ppd.getPageChanges());
54
55         // We only add the one value, because the output order
56
// is indeterminate.
57

58         verifyControls();
59     }
60
61     public void testDecode()
62     {
63         Object JavaDoc newObject = new Object JavaDoc();
64         String JavaDoc encoded = "ENCODED";
65         List JavaDoc decoded = Collections.singletonList(new PropertyChangeImpl("foo", "bar", newObject));
66
67         MockControl control = newControl(PersistentPropertyDataEncoder.class);
68         PersistentPropertyDataEncoder encoder = (PersistentPropertyDataEncoder) control.getMock();
69
70         encoder.decodePageChanges(encoded);
71         control.setReturnValue(decoded);
72
73         replayControls();
74
75         PersistentPropertyData ppd = new PersistentPropertyData(encoder);
76
77         ppd.storeEncoded(encoded);
78
79         List JavaDoc l1 = ppd.getPageChanges();
80
81         assertListsEqual(new Object JavaDoc[]
82         { new PropertyChangeImpl("foo", "bar", newObject) }, l1);
83
84         List JavaDoc l2 = ppd.getPageChanges();
85
86         assertNotSame(l1, l2);
87
88         assertListsEqual(new Object JavaDoc[]
89         { new PropertyChangeImpl("foo", "bar", newObject) }, l2);
90
91         verifyControls();
92     }
93
94     public void testEncode()
95     {
96         String JavaDoc encoded = "ENCODED";
97         Object JavaDoc newObject = new Object JavaDoc();
98         List JavaDoc changes = Collections.singletonList(new PropertyChangeImpl("foo", "bar", newObject));
99
100         MockControl control = newControl(PersistentPropertyDataEncoder.class);
101         PersistentPropertyDataEncoder encoder = (PersistentPropertyDataEncoder) control.getMock();
102
103         encoder.encodePageChanges(changes);
104         control.setReturnValue(encoded);
105
106         replayControls();
107
108         PersistentPropertyData ppd = new PersistentPropertyData(encoder);
109
110         ppd.store("foo", "bar", newObject);
111
112         assertSame(encoded, ppd.getEncoded());
113         assertSame(encoded, ppd.getEncoded());
114
115         verifyControls();
116     }
117 }
Popular Tags