Project

General

Profile

« Previous | Next » 

Revision 4302

Added by daigle over 15 years ago

Add more PropertyService tests

View differences:

PropertyServiceTest.java
70 70
        TestSuite suite = new TestSuite();
71 71
        suite.addTest(new PropertyServiceTest("initialize"));
72 72
        // Test basic functions
73
        suite.addTest(new PropertyServiceTest("readTest"));
73
        suite.addTest(new PropertyServiceTest("mainPropertiesTest"));
74 74

  
75 75
        return suite;
76 76
    }
......
85 85
    
86 86
    
87 87
    /**
88
     * Tests when permission order is allowFirst, the combination of allow and deny rules  affect 
89
     * user to read, update and delete a document. Here are test cases
90
     *1.An user inserts a document with access  rules (allowFirst) - allow READ rule for another user,
91
     *   deny  READ rule for public. 
92
     *      Another user reads this document - failure
93
     *      Another user updates this document(except access part) -failure
94
     *      Another user updates this document(access part) -failure
95
     *      Another user deletes this document - failure
96
     *2. The user updates this documents with access rules (allowFirst) - allow READ and WRITE rule for another user,
97
     *    deny READ and WRITE rule for public. 
98
     *       Another user reads this document - failure
99
     *       Another user updates this document(except access part) -failure
100
     *       Another user updates this document(access part) -failure
101
     *       Another user deletes this document - failure
102
     *3. The user updates this documents with access rules (allowFirst) - allow ALL rule for another user,
103
     *     deny ALL rule for public. 
104
     *         Another user reads this document - failure
105
     *         Another user updates this document(except access part) -failure
106
     *         Another user updates this document(access part) -failure
107
     *         Another user deletes this document - failure
108
     *4. The user updates this documents with access rules (allowFirst) - allow READ and WRITE rule for another user,
109
     *    deny  WRITE rule for public. 
110
     *       Another user reads this document - success
111
     *       Another user updates this document(except access part) -failure
112
     *       Another user updates this document(access part) -failure
113
     *       Another user deletes this document - failure
114
     *5. The user updates this documents with access rules (allowFirst) - allow READ and WRITE rule for another user,
115
     *    deny READ rule for public. 
116
     *       Another user reads this document - failure
117
     *       Another user updates this document(except access part) - success
118
     *       Another user updates this document(access part) -failure
119
     *       Another user deletes this document - failure
120
     *6. The user updates this documents with access rules (allowFirst) - allow READ rule for another user,
121
     *     deny READ rule for a group (which another user is in the group)
122
     *         Another user reads this document - failure
123
     *         Another user updates this document(except access part) -failure
124
     *         Another user updates this document(access part) -failure
125
     *         Another user deletes this document - failure
126
     *7. The user updates this documents with access rules (allowFirst) - allow READ and WRITE rule for another user,
127
     *      deny READ and WRITE rule for a group (which another user is in the group)
128
     *         Another user reads this document - failure
129
     *         Another user updates this document(except access part) -failure
130
     *         Another user updates this document(access part) -failure
131
     *         Another user deletes this document - failure
132
     *8. The user updates this documents with access rules (allowFirst) - allow ALL rule for another user,
133
     *     deny ALL rule for a group (which another user is in the group)
134
     *          Another user reads this document - failure
135
     *          Another user updates this document(except access part) -failure
136
     *          Another user updates this document(access part) -failure
137
     *          Another user deletes this document - failure
138
     *9. The user updates this documents with access rules (allowFirst) - allow READ and WRITE rule for another user,
139
     *     deny WRITE rule for a group (which another user is in the group)
140
     *          Another user reads this document - success
141
     *          Another user updates this document(except access part) -failure
142
     *          Another user updates this document(access part) -failure
143
     *          Another user deletes this document - failure
144
     *10. The user updates this documents with access rules (allowFirst) - allow READ and WRITE rule for another user,
145
     *     deny READ rule for a group (which another user is in the group)
146
     *          Another user reads this document - failure
147
     *          Another user updates this document(except access part) - success
148
     *          Another user updates this document(access part) -failure
149
     *          Another user deletes this document - failure
88
     * Tests reading and writing from properties using the PropertyService class
89
     *1. read a single property from the properties file that should exist
90
     *   Read a test property from the PropertyService.  The value should be read 
91
     *   successfully.  If PropertyNotFoundException is thrown, the test case fails.
92
     *   Also, if the value returned is null, the test case fails.  Strictly speaking,
93
     *   it is not a failure for getProperty to return null, but we know that 
94
     *   'test.metacatURL' should have a value.
95
     *2. read a single property from the main properties that shouldn't exist
96
     *   Expect a PropertyNotFoundException here.  If the exception is not thrown,
97
     *   the test case fails.
98
     *3. read group property names from the main properties
99
     *   read an existing group of property names.  If the result set is zero
100
     *   length, the test case fails.
101
     *4. read group properties from the main properties
102
     *   Get the property values for the group names retrieved in test case 3.  If
103
     *   the properties map retrieved is empty, the test case fails.
104
     *5. write property to main properties
105
     *   Write a property that already exists to the metacat.properties file.  The 
106
     *   value is randomly generated.  The value is then retrieved from the 
107
     *   metacat.properties file.  If the retrieved value does not match the 
108
     *   generated value, or if an exception is thrown, the test case fails.
109
     *6. set property and persist to main properties
110
     *   This does the same as test case 5, but instead of using setProperty which
111
     *   sets the property in memory and persists it to file, this case uses 
112
     *   setPropertyNoPersist and persistProperties to do the set and persist
113
     *   atomically. 
114
     *7. try to write property to main properties that doesn't exist
115
     *   Attempt to set a property that doesn't exist in the properties
116
     *   file.  This should throw a PropertyNotFoundException.  Anything else
117
     *   causes the test case to fail.
118
     *8. try to write property nonPersistant to main properties that doesn't exist
119
     *   This does the same as test case 7, but uses the setPropertyNoPersist method.
150 120
     */
151 121
    public void mainPropertiesTest()
152 122
    {
153 123
    	Random random = new Random();
154 124
    	try {
155
    		debug("\nRunning: readTest test");
125
    		debug("\nRunning: mainPropertiesTest test");
156 126
      
157 127
	        //====1 read a single property from the properties file that should exist
158 128
        	debug("Test 1: read a single property from the properties file that should exist");
159 129
	        try {
160 130
	        	String metacatURL = PropertyService.getProperty("test.metacatUrl");
161
	        	debug("Test 1: read the metacatURL: " + metacatURL);
131
	        	if (metacatURL == null || metacatURL.equals("")) {
132
	        		fail("Test 1: Reading property 'test.metacatURL' returned no value.");
133
	        	}
134
	        	debug("Test 1: read property 'test.metacatURL': " + metacatURL);
162 135
	        } catch (PropertyNotFoundException pnfe) {
163
	        	fail("Test 1: Could not read property: metacatURL : " + pnfe.getMessage());
136
	        	fail("Test 1: Could not read property 'test.metacatURL' : " + pnfe.getMessage());
164 137
	        }
165 138
	        
166 139
	        //====2 read a single property from the main properties  that shouldn't exist
......
174 147
	        			+ pnfe.getMessage());
175 148
	        }
176 149
	        
177
	        //====3 read a group property names from the main properties  
150
	        //====3 read group property names from the main properties  
178 151
	        debug("Test 3: read property group names 'organization.org'");
179 152
			Vector<String> orgList = 
180 153
				PropertyService.getPropertyNamesByGroup("organization.org");
......
185 158
	        // ====4 read group properties from the main properties
186 159
	        try {
187 160
	        	debug("Test 4: read property group 'organization.org'");
188
	        	Map<String, String> metacatURL = PropertyService.getPropertiesByGroup("organization.org");
189
	        	if (metacatURL == null || metacatURL.size() == 0) {
161
	        	Map<String, String> metacatProps = PropertyService.getPropertiesByGroup("organization.org");
162
	        	if (metacatProps == null || metacatProps.size() == 0) {
190 163
	        		fail("Test 4: Empty map returned when reading property group names 'organization.org'");
191 164
	        	}
192 165
	        } catch (PropertyNotFoundException pnfe) {
......
199 172
	        	debug("Test 5: set property 'test.testProperty' : " + testValue);
200 173
	        	PropertyService.setProperty("test.testProperty", testValue);
201 174
	        	String testValue2 = PropertyService.getProperty("test.testProperty");
202
	        	if (testValue.equals(testValue2)) {
175
	        	if (!testValue.equals(testValue2)) {
203 176
	        		fail("Test 5: couldn't set 'test.testProperty' to " + testValue);
204 177
	        	}
205 178
	        } catch (PropertyNotFoundException pnfe) {
......
213 186
	        	PropertyService.setPropertyNoPersist("test.testProperty", testValue);
214 187
	        	PropertyService.persistProperties();
215 188
	        	String testValue2 = PropertyService.getProperty("test.testProperty");
216
	        	if (testValue.equals(testValue2)) {
189
	        	if (!testValue.equals(testValue2)) {
217 190
	        		fail("Test 6: couldn't set 'test.testProperty' to " + testValue);
218 191
	        	}
219 192
	        } catch (PropertyNotFoundException pnfe) {
220 193
	        	fail("Test 6: Could not set property 'test.testProperty' : " + pnfe.getMessage());
221 194
	        }  
222 195
	        
196
	        // ====7 try to write property to main properties that doesn't exist
197
	        String testValue;
198
	        try {
199
	        	testValue = "testing" + random.nextInt();
200
	        	debug("Test 7: set property 'test.property.nonexistant' : " + testValue);
201
	        	PropertyService.setProperty("test.property.nonexistant", testValue);
202
		        fail("Test 7: shouldn't have been able to set 'test.property.nonexistant' to "
203
		        		+ testValue + " since 'test.property.nonexistant' doesn't exist.");
204
	        } catch (PropertyNotFoundException pnfe) {
205
	        	debug("Test 7: expected failure writing to property:'test.property.nonexistant' : " 
206
                        + pnfe.getMessage());
207
	        }  
223 208
	        
209
	        // ====8 try to write property nonPersistant to main properties that doesn't exist
210
	        try {
211
	        	testValue = "testing" + random.nextInt();
212
	        	debug("Test 8: set property 'test.property.nonexistant' : " + testValue);
213
	        	PropertyService.setPropertyNoPersist("test.property.nonexistant", testValue);
214
		        fail("Test 8: shouldn't have been able to set 'test.property.nonexistant' to "
215
		        		+ testValue + " since 'test.property.nonexistant' doesn't exist.");
216
	        } catch (PropertyNotFoundException pnfe) {
217
	        	debug("Test 8: expected failure writing to property:'test.property.nonexistant' : " 
218
                        + pnfe.getMessage());
219
	        }  
224 220
	        
225 221
	        
226
	        
227
	        
228 222
	    } catch (Exception e) {
229 223
	        fail("General exception:\n" + e.getMessage());
230 224
	    }

Also available in: Unified diff