View Javadoc

1   /*
2    * Atlassian Source Code Template.
3    * User: owen
4    * Date: Oct 15, 2002
5    * Time: 1:44:24 PM
6    * CVS Revision: $Revision: 1.5 $
7    * Last CVS Commit: $Date: 2003/09/30 07:05:53 $
8    * Author of last CVS Commit: $Author: mcannon $
9    */
10  package com.atlassian.core.util;
11  
12  import com.atlassian.core.util.PropertyUtils;
13  import com.opensymphony.module.propertyset.PropertySet;
14  import com.opensymphony.module.propertyset.PropertySetManager;
15  import junit.framework.TestCase;
16  
17  import java.util.Calendar;
18  import java.util.Date;
19  
20  public class TestPropertyUtils extends TestCase
21  {
22      public TestPropertyUtils(String s)
23      {
24          super(s);
25      }
26  
27      public void testIdenticalWithNulls()
28      {
29          //Check to see if the first Property set is null false is returned
30          assertTrue(!PropertyUtils.identical(null, PropertySetManager.getInstance("memory", null)));
31          //Check to see if the second Property set is null false is returned
32          assertTrue(!PropertyUtils.identical(PropertySetManager.getInstance("memory", null), null));
33          //Check to see if the both Property set is null true is returned
34          assertTrue(PropertyUtils.identical(null, null));
35      }
36  
37      public void testIdenticalWithDifferentKeys()
38      {
39          PropertySet propertySet1 = PropertySetManager.getInstance("memory", null);
40          propertySet1.setString("TEST_KEY_1", "");
41  
42          PropertySet propertySet2 = PropertySetManager.getInstance("memory", null);
43          propertySet2.setString("TEST_KEY_2", "");
44  
45          assertTrue(!PropertyUtils.identical(propertySet1, propertySet2));
46      }
47  
48      public void testIdenticalWithBooleans()
49      {
50          PropertySet propertySet1 = PropertySetManager.getInstance("memory", null);
51          propertySet1.setBoolean("TEST_BOOLEAN", true);
52  
53          PropertySet propertySet2 = PropertySetManager.getInstance("memory", null);
54          propertySet2.setBoolean("TEST_BOOLEAN", false);
55  
56          //Ensure that it returns false when the booleans are different
57          assertTrue(!PropertyUtils.identical(propertySet1, propertySet2));
58  
59          propertySet2.setBoolean("TEST_BOOLEAN", true);
60  
61          //Ensure that it returns true when the booleans are the same
62          assertTrue(PropertyUtils.identical(propertySet1, propertySet2));
63      }
64  
65      public void testIdenticalWithDates()
66      {
67          Calendar cal = Calendar.getInstance();
68          cal.set(2000, 1, 1, 1, 1, 1);
69          Date testDate1 = cal.getTime();
70  
71          cal.set(2001, 1, 1, 1, 1, 1);
72          Date testDate2 = cal.getTime();
73  
74          PropertySet propertySet1 = PropertySetManager.getInstance("memory", null);
75          propertySet1.setDate("TEST_DATE", testDate1);
76  
77          PropertySet propertySet2 = PropertySetManager.getInstance("memory", null);
78          propertySet2.setDate("TEST_DATE", testDate2);
79  
80          //Ensure that it returns false when the dates are different
81          assertTrue(!PropertyUtils.identical(propertySet1, propertySet2));
82  
83          cal.set(2000, 1, 1, 1, 1, 1);
84          testDate2 = cal.getTime();
85  
86          propertySet2.setDate("TEST_DATE", testDate2);
87  
88          //Ensure that is return true when the dates are the same
89          assertTrue(PropertyUtils.identical(propertySet1, propertySet2));
90      }
91  
92      public void testIdenticalWithDoubles()
93      {
94          PropertySet propertySet1 = PropertySetManager.getInstance("memory", null);
95          propertySet1.setDouble("TEST_DOUBLE", 10);
96  
97          PropertySet propertySet2 = PropertySetManager.getInstance("memory", null);
98          propertySet2.setDouble("TEST_DOUBLE", 11);
99  
100         //Ensure that it returns false when the doubles are different
101         assertTrue(!PropertyUtils.identical(propertySet1, propertySet2));
102 
103         propertySet2.setDouble("TEST_DOUBLE", 10);
104 
105         //Ensure that it returns true when the doubles are the same
106         assertTrue(PropertyUtils.identical(propertySet1, propertySet2));
107     }
108 
109     public void testIdenticalWithInts()
110     {
111         PropertySet propertySet1 = PropertySetManager.getInstance("memory", null);
112         propertySet1.setInt("TEST_INT", 10);
113 
114         PropertySet propertySet2 = PropertySetManager.getInstance("memory", null);
115         propertySet2.setInt("TEST_INT", 11);
116 
117         //Ensure that it returns false when the ints are different
118         assertTrue(!PropertyUtils.identical(propertySet1, propertySet2));
119 
120         propertySet2.setInt("TEST_INT", 10);
121 
122         //Ensure that it returns true when the ints are the same
123         assertTrue(PropertyUtils.identical(propertySet1, propertySet2));
124     }
125 
126     public void testIdenticalWithLongs()
127     {
128         PropertySet propertySet1 = PropertySetManager.getInstance("memory", null);
129         propertySet1.setLong("TEST_LONG", 10);
130 
131         PropertySet propertySet2 = PropertySetManager.getInstance("memory", null);
132         propertySet2.setLong("TEST_LONG", 11);
133 
134         //Ensure that it returns false when the longs are different
135         assertTrue(!PropertyUtils.identical(propertySet1, propertySet2));
136 
137         propertySet2.setLong("TEST_LONG", 10);
138 
139         //Ensure that it returns true when the longs are the same
140         assertTrue(PropertyUtils.identical(propertySet1, propertySet2));
141     }
142 
143     public void testIdenticalWithStrings()
144     {
145         PropertySet propertySet1 = PropertySetManager.getInstance("memory", null);
146         propertySet1.setString("TEST_STRING", "STRING1");
147 
148         PropertySet propertySet2 = PropertySetManager.getInstance("memory", null);
149         propertySet2.setString("TEST_STRING", "STRING2");
150 
151         //Ensure that it returns false when the strings are different
152         assertTrue(!PropertyUtils.identical(propertySet1, propertySet2));
153 
154         propertySet2.setString("TEST_STRING", "STRING1");
155 
156         //Ensure that it returns true when the strings are the same
157         assertTrue(PropertyUtils.identical(propertySet1, propertySet2));
158     }
159 
160     public void testIdenticalWithTexts()
161     {
162         PropertySet propertySet1 = PropertySetManager.getInstance("memory", null);
163         propertySet1.setText("TEST_TEXT", "SOME TEXT 1");
164 
165         PropertySet propertySet2 = PropertySetManager.getInstance("memory", null);
166         propertySet2.setText("TEST_TEXT", "SOME TEXT 2");
167 
168         //Ensure that it returns false when the texts are different
169         assertTrue(!PropertyUtils.identical(propertySet1, propertySet2));
170 
171         propertySet2.setText("TEST_TEXT", "SOME TEXT 1");
172 
173         //Ensure that it returns true when the texts are the same
174         assertTrue(PropertyUtils.identical(propertySet1, propertySet2));
175     }
176 
177     public void testIdenticalWithAllMultipleValues()
178     {
179         PropertySet propertySet1 = PropertySetManager.getInstance("memory", null);
180         propertySet1.setBoolean("TEST_BOOLEAN", true);
181         Calendar cal = Calendar.getInstance();
182         cal.set(2000, 1, 1, 1, 1, 1);
183         Date testDate1 = cal.getTime();
184         propertySet1.setDate("TEST_DATE", testDate1);
185         propertySet1.setDouble("TEST_DOUBLE", 10);
186         propertySet1.setInt("TEST_INT", 10);
187         propertySet1.setLong("TEST_LONG", 10);
188         propertySet1.setString("TEST_STRING", "STRING1");
189         propertySet1.setText("TEST_TEXT", "SOME TEXT 1");
190 
191 
192         PropertySet propertySet2 = PropertySetManager.getInstance("memory", null);
193         propertySet2.setBoolean("TEST_BOOLEAN", true);
194         cal.set(2000, 1, 1, 1, 1, 1);
195         Date testDate2 = cal.getTime();
196         propertySet2.setDate("TEST_DATE", testDate2);
197         propertySet2.setDouble("TEST_DOUBLE", 10);
198         propertySet2.setInt("TEST_INT", 10);
199         propertySet2.setLong("TEST_LONG", 10);
200         propertySet2.setString("TEST_STRING", "STRING1");
201         propertySet2.setText("TEST_TEXT", "SOME TEXT 2");
202 
203         //Ensure that it returns false when the text are different
204         assertTrue(!PropertyUtils.identical(propertySet1, propertySet2));
205 
206         propertySet2.setText("TEST_TEXT", "SOME TEXT 1");
207 
208         //Ensure that it returns true when the booleans are the same
209         assertTrue(PropertyUtils.identical(propertySet1, propertySet2));
210     }
211 }