Project

General

Profile

« Previous | Next » 

Revision 9082

Added by Jing Tao almost 10 years ago

Added the more test cases to get the head version of a SID.
See https://epad.dataone.org/pad/p/201501-MaintenanceStandup

View differences:

test/edu/ucsb/nceas/metacat/dataone/SIDTest.java
119 119
	
120 120
	public void testCases() throws Exception {
121 121
	    testCase1();
122
	    testCase2();
123
	    testCase3();
124
	    testCase4();
125
	    testCase5();
122 126
	    testCase14();
123 127
	}
124 128
	
......
135 139
        Identifier p2 = new Identifier();
136 140
        p2.setValue("P2");
137 141
       
142
        SystemMetadata p1Sys = new SystemMetadata();
143
        p1Sys.setIdentifier(p1);
144
        p1Sys.setSeriesId(s1);
145
        p1Sys.setObsoletedBy(p2);
146
        p1Sys.setDateUploaded(new Date(100));
138 147
        
148
        SystemMetadata p2Sys = new SystemMetadata();
149
        p2Sys.setIdentifier(p2);
150
        p2Sys.setSeriesId(s1);
151
        p2Sys.setObsoletes(p1);
152
        p2Sys.setDateUploaded(new Date(200));
153
        
154
        Vector<SystemMetadata> chain = new Vector<SystemMetadata>();
155
        chain.add(p1Sys);
156
        chain.add(p2Sys);
157
      
158
        System.out.println("Case 1:");
159
        Identifier head = getHeadVersion(s1, chain);
160
        //System.out.println("The head is "+head.getValue());
161
        assertTrue(head.equals(p2));
162
	}
163
	
164
	
165
	/**
166
     * Case 2. P1(S1) ? P2(S1), S1 = P2, Error condition, P2 not allowed (should not exist) (Rule 2)
167
     */
168
    private void testCase2() throws Exception {
169
        Identifier s1 = new Identifier();
170
        s1.setValue("S1");
171
        Identifier s2 = new Identifier();
172
        s2.setValue("S2");
173
        Identifier p1 = new Identifier();
174
        p1.setValue("P1");
175
        Identifier p2 = new Identifier();
176
        p2.setValue("P2");
177
       
178
        
139 179
        SystemMetadata p1Sys = new SystemMetadata();
140 180
        p1Sys.setIdentifier(p1);
141 181
        p1Sys.setSeriesId(s1);
182
        p1Sys.setDateUploaded(new Date(100));
183
        
184
        SystemMetadata p2Sys = new SystemMetadata();
185
        p2Sys.setIdentifier(p2);
186
        p2Sys.setSeriesId(s1);
187
        p2Sys.setDateUploaded(new Date(200));
188
        
189
        Vector<SystemMetadata> chain = new Vector<SystemMetadata>();
190
        chain.add(p1Sys);
191
        chain.add(p2Sys);
192
      
193
        System.out.println("Case 2:");
194
        Identifier head = getHeadVersion(s1, chain);
195
        //System.out.println("The head is "+head.getValue());
196
        assertTrue(head.equals(p2));
197
    }
198
    
199
    /**
200
     * case 3. P1(S1) <- P2(S1), S1 = P2, Discouraged, but not error condition, S1 = P2 (Rule 2, missingFields)
201
     */
202
    private void testCase3() throws Exception {
203
        Identifier s1 = new Identifier();
204
        s1.setValue("S1");
205
        Identifier s2 = new Identifier();
206
        s2.setValue("S2");
207
        Identifier p1 = new Identifier();
208
        p1.setValue("P1");
209
        Identifier p2 = new Identifier();
210
        p2.setValue("P2");
211
       
212
        
213
        SystemMetadata p1Sys = new SystemMetadata();
214
        p1Sys.setIdentifier(p1);
215
        p1Sys.setSeriesId(s1);
216
        p1Sys.setDateUploaded(new Date(100));
217
        
218
        SystemMetadata p2Sys = new SystemMetadata();
219
        p2Sys.setIdentifier(p2);
220
        p2Sys.setSeriesId(s1);
221
        p2Sys.setObsoletes(p1);
222
        p2Sys.setDateUploaded(new Date(200));
223
        
224
        Vector<SystemMetadata> chain = new Vector<SystemMetadata>();
225
        chain.add(p1Sys);
226
        chain.add(p2Sys);
227
      
228
        System.out.println("Case 3:");
229
        Identifier head = getHeadVersion(s1, chain);
230
        //System.out.println("The head is "+head.getValue());
231
        assertTrue(head.equals(p2));
232
    }
233
    
234
    /**
235
     * case 4. P1(S1) <-> P2(S1) <-> P3(S2), S1 = P2(use Rule 3), S2 = P3 (use Rule 1)
236
     */
237
    private void testCase4() throws Exception {
238
        Identifier s1 = new Identifier();
239
        s1.setValue("S1");
240
        Identifier s2 = new Identifier();
241
        s2.setValue("S2");
242
        Identifier p1 = new Identifier();
243
        p1.setValue("P1");
244
        Identifier p2 = new Identifier();
245
        p2.setValue("P2");
246
        Identifier p3 = new Identifier();
247
        p3.setValue("P3");
248
       
249
        
250
        SystemMetadata p1Sys = new SystemMetadata();
251
        p1Sys.setIdentifier(p1);
252
        p1Sys.setSeriesId(s1);
142 253
        p1Sys.setObsoletedBy(p2);
143 254
        p1Sys.setDateUploaded(new Date(100));
144 255
        
......
146 257
        p2Sys.setIdentifier(p2);
147 258
        p2Sys.setSeriesId(s1);
148 259
        p2Sys.setObsoletes(p1);
260
        p2Sys.setObsoletedBy(p3);
149 261
        p2Sys.setDateUploaded(new Date(200));
150 262
        
263
        SystemMetadata p3Sys = new SystemMetadata();
264
        p3Sys.setIdentifier(p3);
265
        p3Sys.setSeriesId(s2);
266
        p3Sys.setObsoletes(p2);
267

  
268
        Vector<SystemMetadata> chain = new Vector<SystemMetadata>();
269
        chain.add(p1Sys);
270
        chain.add(p2Sys);
271
        chain.add(p3Sys);
272
      
273
        System.out.println("Case 4:");
274
        Identifier head = getHeadVersion(s1, chain);
275
        //System.out.println("The head is "+head.getValue());
276
        assertTrue(head.equals(p2));
277
        Identifier head2 = getHeadVersion(s2, chain);
278
        //System.out.println("The head is "+head.getValue());
279
        assertTrue(head2.equals(p3));
280
    }
281
    
282
    /**
283
     * case 5. P1(S1) <- P2(S1) <- P3(S2), S1 = P2 (use Rule 2 or have missing field), S2 = P3  (use Rule 1)
284
     */
285
    private void testCase5() throws Exception {
286
        Identifier s1 = new Identifier();
287
        s1.setValue("S1");
288
        Identifier s2 = new Identifier();
289
        s2.setValue("S2");
290
        Identifier p1 = new Identifier();
291
        p1.setValue("P1");
292
        Identifier p2 = new Identifier();
293
        p2.setValue("P2");
294
        Identifier p3 = new Identifier();
295
        p3.setValue("P3");
151 296
       
152 297
        
298
        SystemMetadata p1Sys = new SystemMetadata();
299
        p1Sys.setIdentifier(p1);
300
        p1Sys.setSeriesId(s1);
301
        p1Sys.setDateUploaded(new Date(100));
302
        
303
        SystemMetadata p2Sys = new SystemMetadata();
304
        p2Sys.setIdentifier(p2);
305
        p2Sys.setSeriesId(s1);
306
        p2Sys.setObsoletes(p1);
307
        p2Sys.setDateUploaded(new Date(200));
308
        
309
        SystemMetadata p3Sys = new SystemMetadata();
310
        p3Sys.setIdentifier(p3);
311
        p3Sys.setSeriesId(s2);
312
        p3Sys.setObsoletes(p2);
313

  
153 314
        Vector<SystemMetadata> chain = new Vector<SystemMetadata>();
154 315
        chain.add(p1Sys);
155 316
        chain.add(p2Sys);
317
        chain.add(p3Sys);
156 318
      
157
        System.out.println("Case 1:");
319
        System.out.println("Case 5:");
158 320
        Identifier head = getHeadVersion(s1, chain);
159 321
        //System.out.println("The head is "+head.getValue());
160 322
        assertTrue(head.equals(p2));
161
	}
323
        Identifier head2 = getHeadVersion(s2, chain);
324
        //System.out.println("The head is "+head.getValue());
325
        assertTrue(head2.equals(p3));
326
    }
162 327
	
163 328
	/**
164 329
	 * Case 14: P1(S1) <- P2(S1) -> P3(S2).
......
313 478
            for(SystemMetadata sysmeta :chain) {
314 479
                Identifier obsoletedBy = sysmeta.getObsoletedBy();
315 480
                if(obsoletedBy != null && obsoletedBy.equals(target)) {
316
                    System.out.println("missing obsoleteds");
481
                    System.out.println("missing obsoletes");
317 482
                    found = true;
318 483
                }
319 484
            }

Also available in: Unified diff