Project

General

Profile

« Previous | Next » 

Revision 6354

Added by Chris Jones over 13 years ago

Return the new pid (not the obsoleted pid) on update(), and set the correct system metadata.

View differences:

test/edu/ucsb/nceas/metacat/dataone/MNodeServiceTest.java
33 33
import java.text.SimpleDateFormat;
34 34
import java.util.Calendar;
35 35
import java.util.Date;
36
import java.util.List;
36 37

  
37 38
import junit.framework.Test;
38 39
import junit.framework.TestSuite;
......
80 81
 */
81 82
public class MNodeServiceTest extends D1NodeServiceTest {
82 83

  
83
	/**
84
	 * Set up the test fixtures
85
	 * 
86
	 * @throws Exception
87
	 */
88
	@Before
89
	public void setUp() throws Exception {
90
		super.setUp();
91
		// set up the configuration for d1client
92
		Settings.getConfiguration().setProperty("D1Client.cnClassName", MockCNode.class.getName());
93
	}
84
  /**
85
   * Set up the test fixtures
86
   * 
87
   * @throws Exception
88
   */
89
  @Before
90
  public void setUp() throws Exception {
91
    super.setUp();
92
    // set up the configuration for d1client
93
    Settings.getConfiguration().setProperty("D1Client.cnClassName", MockCNode.class.getName());
94
  }
94 95

  
95
	/**
96
	 * Remove the test fixtures
97
	 */
98
	@After
99
	public void tearDown() {
100
	}
101
	
102
	/**
103
	 * Build the test suite
104
	 * @return
105
	 */
106
	public static Test suite() {
107
		
108
		TestSuite suite = new TestSuite();
96
  /**
97
   * Remove the test fixtures
98
   */
99
  @After
100
  public void tearDown() {
101
  }
102
  
103
  /**
104
   * Build the test suite
105
   * @return
106
   */
107
  public static Test suite() {
108
    
109
    TestSuite suite = new TestSuite();
109 110
    suite.addTest(new MNodeServiceTest("initialize"));
110 111
    // MNStorage tests
111 112
    suite.addTest(new MNodeServiceTest("testCreate"));
......
132 133
    // MNreplication tests
133 134
    suite.addTest(new MNodeServiceTest("testReplicate"));
134 135
    
135
		
136
		return suite;
137
		
138
	}
139
	
140
	/**
141
	 * Constructor for the tests
142
	 * 
143
	 * @param name - the name of the test
144
	 */
145
	public MNodeServiceTest(String name) {
146
		super(name);
147
		
148
	}
136
    
137
    return suite;
138
    
139
  }
140
  
141
  /**
142
   * Constructor for the tests
143
   * 
144
   * @param name - the name of the test
145
   */
146
  public MNodeServiceTest(String name) {
147
    super(name);
148
    
149
  }
149 150

  
150
	/**
151
	 * Initial blank test
152
	 */
153
	public void initialize() {
154
		assertTrue(1 == 1);
155
		
156
	}
157
	
158
	/**
159
	 * Test getting a known object
160
	 */
161
	public void testGet() {
151
  /**
152
   * Initial blank test
153
   */
154
  public void initialize() {
155
    assertTrue(1 == 1);
156
    
157
  }
158
  
159
  /**
160
   * Test getting a known object
161
   */
162
  public void testGet() {
162 163
    printTestHeader("testGet");
163 164

  
164
		try {
165
	    Session session = getTestSession();
166
	    Identifier guid = new Identifier();
167
	    guid.setValue("testGet." + System.currentTimeMillis());
168
	    InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
169
	    SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
170
	    Identifier pid = MNodeService.getInstance().create(session, guid, object, sysmeta);
171
	    InputStream result = MNodeService.getInstance().get(session, guid);
172
	    // go back to beginning of original stream
173
	    object.reset();
174
	    // check
175
	    assertTrue(object.available() > 0);
176
	    assertTrue(result.available() > 0);
177
	    assertTrue(IOUtils.contentEquals(result, object));
178
	    
165
    try {
166
      Session session = getTestSession();
167
      Identifier guid = new Identifier();
168
      guid.setValue("testGet." + System.currentTimeMillis());
169
      InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
170
      SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
171
      Identifier pid = MNodeService.getInstance().create(session, guid, object, sysmeta);
172
      InputStream result = MNodeService.getInstance().get(session, guid);
173
      // go back to beginning of original stream
174
      object.reset();
175
      // check
176
      assertTrue(object.available() > 0);
177
      assertTrue(result.available() > 0);
178
      assertTrue(IOUtils.contentEquals(result, object));
179
      
179 180
    } catch (UnsupportedEncodingException e) {
180
	    e.printStackTrace();
181
	    fail("Unexpected error: " + e.getMessage());
181
      e.printStackTrace();
182
      fail("Unexpected error: " + e.getMessage());
182 183

  
183 184
    } catch (InvalidToken e) {
184
	    e.printStackTrace();
185
	    fail("Unexpected error: " + e.getMessage());
186
	    
185
      e.printStackTrace();
186
      fail("Unexpected error: " + e.getMessage());
187
      
187 188
    } catch (ServiceFailure e) {
188
	    e.printStackTrace();
189
	    fail("Unexpected error: " + e.getMessage());
190
	    
189
      e.printStackTrace();
190
      fail("Unexpected error: " + e.getMessage());
191
      
191 192
    } catch (NotAuthorized e) {
192
	    e.printStackTrace();
193
	    fail("Unexpected error: " + e.getMessage());
194
	    
193
      e.printStackTrace();
194
      fail("Unexpected error: " + e.getMessage());
195
      
195 196
    } catch (IdentifierNotUnique e) {
196
	    e.printStackTrace();
197
	    fail("Unexpected error: " + e.getMessage());
198
	    
197
      e.printStackTrace();
198
      fail("Unexpected error: " + e.getMessage());
199
      
199 200
    } catch (UnsupportedType e) {
200
	    e.printStackTrace();
201
	    fail("Unexpected error: " + e.getMessage());
202
	    
201
      e.printStackTrace();
202
      fail("Unexpected error: " + e.getMessage());
203
      
203 204
    } catch (InsufficientResources e) {
204
	    e.printStackTrace();
205
	    fail("Unexpected error: " + e.getMessage());
206
	    
205
      e.printStackTrace();
206
      fail("Unexpected error: " + e.getMessage());
207
      
207 208
    } catch (InvalidSystemMetadata e) {
208
	    e.printStackTrace();
209
	    fail("Unexpected error: " + e.getMessage());
210
	    
209
      e.printStackTrace();
210
      fail("Unexpected error: " + e.getMessage());
211
      
211 212
    } catch (NotImplemented e) {
212
	    e.printStackTrace();
213
	    fail("Unexpected error: " + e.getMessage());
214
	    
213
      e.printStackTrace();
214
      fail("Unexpected error: " + e.getMessage());
215
      
215 216
    } catch (InvalidRequest e) {
216
	    e.printStackTrace();
217
	    fail("Unexpected error: " + e.getMessage());
218
	    
217
      e.printStackTrace();
218
      fail("Unexpected error: " + e.getMessage());
219
      
219 220
    } catch (NotFound e) {
220
	    e.printStackTrace();
221
	    fail("Unexpected error: " + e.getMessage());
222
	    
221
      e.printStackTrace();
222
      fail("Unexpected error: " + e.getMessage());
223
      
223 224
    } catch (Exception e) {
224
	    e.printStackTrace();
225
	    fail("Unexpected error: " + e.getMessage());
226
	    
225
      e.printStackTrace();
226
      fail("Unexpected error: " + e.getMessage());
227
      
227 228
    }
228 229

  
229
	}
230
  }
230 231

  
231
	/**
232
	 * Test getting the system metadata of an object
233
	 */
234
	public void testGetSystemMetadata() {    
232
  /**
233
   * Test getting the system metadata of an object
234
   */
235
  public void testGetSystemMetadata() {    
235 236
    printTestHeader("testGetSystemMetadata");
236 237

  
237 238
    try {
238
	    Session session = getTestSession();
239
	    Identifier guid = new Identifier();
240
	    guid.setValue("testGetSystemMetadata." + System.currentTimeMillis());
241
	    InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
242
	    SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
243
	    Identifier pid = MNodeService.getInstance().create(session, guid, object, sysmeta);
244
	    SystemMetadata newsysmeta = MNodeService.getInstance().getSystemMetadata(session, pid);
245
	    assertEquals(newsysmeta.getIdentifier().getValue(), sysmeta.getIdentifier().getValue());
246
	    
239
      Session session = getTestSession();
240
      Identifier guid = new Identifier();
241
      guid.setValue("testGetSystemMetadata." + System.currentTimeMillis());
242
      InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
243
      SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
244
      Identifier pid = MNodeService.getInstance().create(session, guid, object, sysmeta);
245
      SystemMetadata newsysmeta = MNodeService.getInstance().getSystemMetadata(session, pid);
246
      assertEquals(newsysmeta.getIdentifier().getValue(), sysmeta.getIdentifier().getValue());
247
      
247 248
    } catch (UnsupportedEncodingException e) {
248
	    e.printStackTrace();
249
	    fail("Unexpected error: " + e.getMessage());
249
      e.printStackTrace();
250
      fail("Unexpected error: " + e.getMessage());
250 251

  
251 252
    } catch (InvalidToken e) {
252
	    e.printStackTrace();	    
253
	    fail("Unexpected error: " + e.getMessage());
253
      e.printStackTrace();      
254
      fail("Unexpected error: " + e.getMessage());
254 255

  
255 256
    } catch (ServiceFailure e) {
256
	    e.printStackTrace();
257
	    fail("Unexpected error: " + e.getMessage());
257
      e.printStackTrace();
258
      fail("Unexpected error: " + e.getMessage());
258 259

  
259 260
    } catch (NotAuthorized e) {
260
	    e.printStackTrace();
261
	    fail("Unexpected error: " + e.getMessage());
261
      e.printStackTrace();
262
      fail("Unexpected error: " + e.getMessage());
262 263

  
263 264
    } catch (IdentifierNotUnique e) {
264
	    e.printStackTrace();
265
	    fail("Unexpected error: " + e.getMessage());
266
	    
265
      e.printStackTrace();
266
      fail("Unexpected error: " + e.getMessage());
267
      
267 268
    } catch (UnsupportedType e) {
268
	    e.printStackTrace();
269
	    fail("Unexpected error: " + e.getMessage());
269
      e.printStackTrace();
270
      fail("Unexpected error: " + e.getMessage());
270 271

  
271 272
    } catch (InsufficientResources e) {
272
	    e.printStackTrace();
273
	    fail("Unexpected error: " + e.getMessage());
273
      e.printStackTrace();
274
      fail("Unexpected error: " + e.getMessage());
274 275

  
275 276
    } catch (InvalidSystemMetadata e) {
276
	    e.printStackTrace();
277
	    fail("Unexpected error: " + e.getMessage());
277
      e.printStackTrace();
278
      fail("Unexpected error: " + e.getMessage());
278 279

  
279 280
    } catch (NotImplemented e) {
280
	    e.printStackTrace();
281
	    fail("Unexpected error: " + e.getMessage());
281
      e.printStackTrace();
282
      fail("Unexpected error: " + e.getMessage());
282 283

  
283 284
    } catch (InvalidRequest e) {
284
	    e.printStackTrace();
285
	    fail("Unexpected error: " + e.getMessage());
285
      e.printStackTrace();
286
      fail("Unexpected error: " + e.getMessage());
286 287

  
287 288
    } catch (NotFound e) {
288
	    e.printStackTrace();
289
	    fail("Unexpected error: " + e.getMessage());
289
      e.printStackTrace();
290
      fail("Unexpected error: " + e.getMessage());
290 291

  
291 292
    } catch (Exception e) {
292
	    e.printStackTrace();
293
	    fail("Unexpected error: " + e.getMessage());
293
      e.printStackTrace();
294
      fail("Unexpected error: " + e.getMessage());
294 295

  
295 296
    }
296 297
    
297
	}
298
  }
298 299

  
299
	/**
300
	 * Test object creation
301
	 */
302
	public void testCreate() {
300
  /**
301
   * Test object creation
302
   */
303
  public void testCreate() {
303 304
    printTestHeader("testCreate");
304 305
    
305
		try {
306
	    Session session = getTestSession();
307
	    Identifier guid = new Identifier();
308
	    guid.setValue("testCreate." + System.currentTimeMillis());
309
	    InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
310
	    SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
311
	    Identifier pid = MNodeService.getInstance().create(session, guid, object, sysmeta);
312
	    assertEquals(guid.getValue(), pid.getValue());
306
    try {
307
      Session session = getTestSession();
308
      Identifier guid = new Identifier();
309
      guid.setValue("testCreate." + System.currentTimeMillis());
310
      InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
311
      SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
312
      Identifier pid = MNodeService.getInstance().create(session, guid, object, sysmeta);
313
      assertEquals(guid.getValue(), pid.getValue());
313 314
    } catch (UnsupportedEncodingException e) {
314
	    e.printStackTrace();
315
	    fail("Unexpected error: " + e.getMessage());
315
      e.printStackTrace();
316
      fail("Unexpected error: " + e.getMessage());
316 317

  
317 318
    } catch (InvalidToken e) {
318
	    e.printStackTrace();
319
	    fail("Unexpected error: " + e.getMessage());
319
      e.printStackTrace();
320
      fail("Unexpected error: " + e.getMessage());
320 321

  
321 322
    } catch (ServiceFailure e) {
322
	    e.printStackTrace();
323
	    fail("Unexpected error: " + e.getMessage());
323
      e.printStackTrace();
324
      fail("Unexpected error: " + e.getMessage());
324 325

  
325 326
    } catch (NotAuthorized e) {
326
	    e.printStackTrace();
327
	    fail("Unexpected error: " + e.getMessage());
327
      e.printStackTrace();
328
      fail("Unexpected error: " + e.getMessage());
328 329

  
329 330
    } catch (IdentifierNotUnique e) {
330
	    e.printStackTrace();
331
	    fail("Unexpected error: " + e.getMessage());
331
      e.printStackTrace();
332
      fail("Unexpected error: " + e.getMessage());
332 333

  
333 334
    } catch (UnsupportedType e) {
334
	    e.printStackTrace();
335
	    fail("Unexpected error: " + e.getMessage());
335
      e.printStackTrace();
336
      fail("Unexpected error: " + e.getMessage());
336 337

  
337 338
    } catch (InsufficientResources e) {
338
	    e.printStackTrace();
339
	    fail("Unexpected error: " + e.getMessage());
339
      e.printStackTrace();
340
      fail("Unexpected error: " + e.getMessage());
340 341

  
341 342
    } catch (InvalidSystemMetadata e) {
342
	    e.printStackTrace();
343
	    fail("Unexpected error: " + e.getMessage());
343
      e.printStackTrace();
344
      fail("Unexpected error: " + e.getMessage());
344 345

  
345 346
    } catch (NotImplemented e) {
346
	    e.printStackTrace();
347
	    fail("Unexpected error: " + e.getMessage());
347
      e.printStackTrace();
348
      fail("Unexpected error: " + e.getMessage());
348 349

  
349 350
    } catch (InvalidRequest e) {
350
	    e.printStackTrace();
351
	    fail("Unexpected error: " + e.getMessage());
351
      e.printStackTrace();
352
      fail("Unexpected error: " + e.getMessage());
352 353

  
353 354
    } catch (Exception e) {
354
	    e.printStackTrace();
355
	    fail("Unexpected error: " + e.getMessage());
355
      e.printStackTrace();
356
      fail("Unexpected error: " + e.getMessage());
356 357

  
357 358
    }
358 359
      
359 360
  }
360 361

  
361
	/**
362
	 * test object deletion
363
	 */
364
	public void testDelete() {
362
  /**
363
   * test object deletion
364
   */
365
  public void testDelete() {
365 366
    printTestHeader("testDelete");
366 367

  
367
		try {
368
	    Session session = getTestSession();
369
	    Identifier guid = new Identifier();
370
	    guid.setValue("testDelete." + System.currentTimeMillis());
371
	    InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
372
	    SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
373
	    Identifier pid = MNodeService.getInstance().create(session, guid, object, sysmeta);
368
    try {
369
      Session session = getTestSession();
370
      Identifier guid = new Identifier();
371
      guid.setValue("testDelete." + System.currentTimeMillis());
372
      InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
373
      SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
374
      Identifier pid = MNodeService.getInstance().create(session, guid, object, sysmeta);
374 375
      Identifier deletedPid = MNodeService.getInstance().delete(session, pid);
375 376
      assertEquals(pid.getValue(), deletedPid.getValue());
376 377
      
377
		} catch (UnsupportedEncodingException e) {
378
	    e.printStackTrace();
379
	    
378
    } catch (UnsupportedEncodingException e) {
379
      e.printStackTrace();
380
      
380 381
    } catch (Exception e) {
381
	    e.printStackTrace();
382
	    fail("Unexpected error: " + e.getMessage());
382
      e.printStackTrace();
383
      fail("Unexpected error: " + e.getMessage());
383 384

  
384 385
    } 
385 386

  
386
	}
387
  }
387 388

  
388
	/**
389
	 * Test object updating
390
	 */
391
	public void testUpdate() {
389
  /**
390
   * Test object updating
391
   */
392
  public void testUpdate() {
392 393
    printTestHeader("testUpdate");
393 394
    
394
		try {
395
	    Session session = getTestSession();
396
	    Identifier guid = new Identifier();
397
	    guid.setValue("testUpdate." + System.currentTimeMillis());
398
	    InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
399
	    SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
400
	    Identifier newPid = new Identifier();
401
	    newPid.setValue("testUpdate." + System.currentTimeMillis());
402
	    Identifier pid = 
403
	    	MNodeService.getInstance().create(session, guid, object, sysmeta);
395
    try {
396
      Session session = getTestSession();
397
      Identifier guid = new Identifier();
398
      guid.setValue("testUpdate." + System.currentTimeMillis());
399
      InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
400
      SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
401
      Identifier newPid = new Identifier();
402
      newPid.setValue("testUpdate." + System.currentTimeMillis());
403
      Identifier pid = 
404
        MNodeService.getInstance().create(session, guid, object, sysmeta);
404 405
      
405
	    SystemMetadata newSysMeta = 
406
	    	MNodeService.getInstance().getSystemMetadata(session, pid);
406
      SystemMetadata newSysMeta = createSystemMetadata(newPid, session.getSubject(), object);
407
            
408
      // do the update
409
      Identifier updatedPid = 
410
        MNodeService.getInstance().update(session, pid, object, newPid, newSysMeta);
407 411
      
408
      // update the obsoletesList
409
      newSysMeta.addObsolete(pid);
410
      
411
      // update the derivedFrom list
412
      newSysMeta.addDerivedFrom(pid);
413
      
414
	    // do the update
415
	    Identifier updatedPid = 
416
	    	MNodeService.getInstance().update(session, pid, object, newPid, newSysMeta);
417
      
418
	    // get the updated system metadata
412
      // get the updated system metadata
419 413
      SystemMetadata updatedSysMeta = 
420
      	MNodeService.getInstance().getSystemMetadata(session, updatedPid);
414
        MNodeService.getInstance().getSystemMetadata(session, updatedPid);
421 415

  
422
	    assertEquals(updatedPid.getValue(), newPid.getValue());
416
      assertEquals(updatedPid.getValue(), newPid.getValue());
423 417
      assertTrue(updatedSysMeta.getObsolete(0).getValue().equals(pid.getValue()));
424
      assertTrue(updatedSysMeta.getDerivedFrom(0).getValue().equals(pid.getValue()));	      
425
	    
418
      assertTrue(updatedSysMeta.getDerivedFrom(0).getValue().equals(pid.getValue()));        
419
      
426 420
    } catch (UnsupportedEncodingException e) {
427
	    e.printStackTrace();
428
	    fail("Unexpected error: " + e.getMessage());
421
      e.printStackTrace();
422
      fail("Unexpected error: " + e.getMessage());
429 423

  
430 424
    } catch (InvalidToken e) {
431
	    e.printStackTrace();
432
	    fail("Unexpected error: " + e.getMessage());
425
      e.printStackTrace();
426
      fail("Unexpected error: " + e.getMessage());
433 427

  
434 428
    } catch (ServiceFailure e) {
435
	    e.printStackTrace();
436
	    fail("Unexpected error: " + e.getMessage());
429
      e.printStackTrace();
430
      fail("Unexpected error: " + e.getMessage());
437 431

  
438 432
    } catch (NotAuthorized e) {
439
	    e.printStackTrace();
440
	    fail("Unexpected error: " + e.getMessage());
433
      e.printStackTrace();
434
      fail("Unexpected error: " + e.getMessage());
441 435

  
442 436
    } catch (IdentifierNotUnique e) {
443
	    e.printStackTrace();
444
	    fail("Unexpected error: " + e.getMessage());
437
      e.printStackTrace();
438
      fail("Unexpected error: " + e.getMessage());
445 439

  
446 440
    } catch (UnsupportedType e) {
447
	    e.printStackTrace();
448
	    fail("Unexpected error: " + e.getMessage());
441
      e.printStackTrace();
442
      fail("Unexpected error: " + e.getMessage());
449 443

  
450 444
    } catch (InsufficientResources e) {
451
	    e.printStackTrace();
452
	    fail("Unexpected error: " + e.getMessage());
445
      e.printStackTrace();
446
      fail("Unexpected error: " + e.getMessage());
453 447

  
454 448
    } catch (InvalidSystemMetadata e) {
455
	    e.printStackTrace();
456
	    fail("Unexpected error: " + e.getMessage());
449
      e.printStackTrace();
450
      fail("Unexpected error: " + e.getMessage());
457 451

  
458 452
    } catch (NotImplemented e) {
459
	    e.printStackTrace();
460
	    fail("Unexpected error: " + e.getMessage());
453
      e.printStackTrace();
454
      fail("Unexpected error: " + e.getMessage());
461 455

  
462 456
    } catch (InvalidRequest e) {
463
	    e.printStackTrace();
464
	    fail("Unexpected error: " + e.getMessage());
457
      e.printStackTrace();
458
      fail("Unexpected error: " + e.getMessage());
465 459

  
466 460
    } catch (Exception e) {
467
	    e.printStackTrace();
468
	    fail("Unexpected error: " + e.getMessage());
461
      e.printStackTrace();
462
      fail("Unexpected error: " + e.getMessage());
469 463

  
470 464
    }
471
	}
465
  }
472 466

  
473
	/**
474
	 * We currently expect this unit test to fail because it should rely on a different member node
475
	 * to retrieve the object from. Currently it gets the object from itself and throws 
476
	 * and expected error for duplicate entry.
477
	 * 
478
	 */
479
	public void testReplicate() {
480
	    printTestHeader("testReplicate");
481
	    try {
482
		    Session session = getTestSession();
483
		    Identifier guid = new Identifier();
484
		    guid.setValue("testReplicate." + System.currentTimeMillis());
485
		    InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
486
		    SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
487
		    // save locally
488
		    Identifier pid = MNodeService.getInstance().create(session, guid, object, sysmeta);
489
		    // get our node reference (attempting to replicate with self)
490
		    NodeReference sourceNode = MNodeService.getInstance().getCapabilities().getIdentifier();
491
		    // attempt to replicate with ourselves -- this should fail!
492
			boolean result = false;
493
			try {
494
				result = MNodeService.getInstance().replicate(session, sysmeta, sourceNode);
495
			} catch (Exception inu) {
496
				// we are expecting this to fail since we already have the doc
497
				result = true;
498
			}
499
			assertTrue(result);
500
	    } catch (Exception e) {
501
	    	e.printStackTrace();
502
			fail("Probably not yet implemented: " + e.getMessage());
503
		}
504
	}
467
  /**
468
   * We currently expect this unit test to fail because it should rely on a different member node
469
   * to retrieve the object from. Currently it gets the object from itself and throws 
470
   * and expected error for duplicate entry.
471
   * 
472
   */
473
  public void testReplicate() {
474
      printTestHeader("testReplicate");
475
      try {
476
        Session session = getTestSession();
477
        Identifier guid = new Identifier();
478
        guid.setValue("testReplicate." + System.currentTimeMillis());
479
        InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
480
        SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
481
        // save locally
482
        Identifier pid = MNodeService.getInstance().create(session, guid, object, sysmeta);
483
        // get our node reference (attempting to replicate with self)
484
        NodeReference sourceNode = MNodeService.getInstance().getCapabilities().getIdentifier();
485
        // attempt to replicate with ourselves -- this should fail!
486
      boolean result = false;
487
      try {
488
        result = MNodeService.getInstance().replicate(session, sysmeta, sourceNode);
489
      } catch (Exception inu) {
490
        // we are expecting this to fail since we already have the doc
491
        result = true;
492
      }
493
      assertTrue(result);
494
      } catch (Exception e) {
495
        e.printStackTrace();
496
      fail("Probably not yet implemented: " + e.getMessage());
497
    }
498
  }
505 499

  
506
	/**
507
	 * Test describing an object
508
	 */
509
	public void testDescribe() {
500
  /**
501
   * Test describing an object
502
   */
503
  public void testDescribe() {
510 504
    printTestHeader("testDescribe");
511 505

  
512 506
    try {
513
	    Session session = getTestSession();
514
	    Identifier guid = new Identifier();
515
	    guid.setValue("testGetSystemMetadata." + System.currentTimeMillis());
516
	    InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
517
	    SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
518
	    Identifier pid = MNodeService.getInstance().create(session, guid, object, sysmeta);
519
	    DescribeResponse describeResponse = MNodeService.getInstance().describe(session, pid);
520
	    assertEquals(describeResponse.getDataONE_Checksum().getValue(), sysmeta.getChecksum().getValue());
521
	    assertEquals(describeResponse.getDataONE_ObjectFormat().getFormatName(), sysmeta.getObjectFormat().getFormatName());
522
	    
507
      Session session = getTestSession();
508
      Identifier guid = new Identifier();
509
      guid.setValue("testGetSystemMetadata." + System.currentTimeMillis());
510
      InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
511
      SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
512
      Identifier pid = MNodeService.getInstance().create(session, guid, object, sysmeta);
513
      DescribeResponse describeResponse = MNodeService.getInstance().describe(session, pid);
514
      assertEquals(describeResponse.getDataONE_Checksum().getValue(), sysmeta.getChecksum().getValue());
515
      assertEquals(describeResponse.getDataONE_ObjectFormat().getFormatName(), sysmeta.getObjectFormat().getFormatName());
516
      
523 517
    } catch (UnsupportedEncodingException e) {
524
	    e.printStackTrace();
525
	    fail("Unexpected error: " + e.getMessage());
518
      e.printStackTrace();
519
      fail("Unexpected error: " + e.getMessage());
526 520

  
527 521
    } catch (InvalidToken e) {
528
	    e.printStackTrace();	    
529
	    fail("Unexpected error: " + e.getMessage());
522
      e.printStackTrace();      
523
      fail("Unexpected error: " + e.getMessage());
530 524

  
531 525
    } catch (ServiceFailure e) {
532
	    e.printStackTrace();
533
	    fail("Unexpected error: " + e.getMessage());
526
      e.printStackTrace();
527
      fail("Unexpected error: " + e.getMessage());
534 528

  
535 529
    } catch (NotAuthorized e) {
536
	    e.printStackTrace();
537
	    fail("Unexpected error: " + e.getMessage());
530
      e.printStackTrace();
531
      fail("Unexpected error: " + e.getMessage());
538 532

  
539 533
    } catch (IdentifierNotUnique e) {
540
	    e.printStackTrace();
541
	    fail("Unexpected error: " + e.getMessage());
542
	    
534
      e.printStackTrace();
535
      fail("Unexpected error: " + e.getMessage());
536
      
543 537
    } catch (UnsupportedType e) {
544
	    e.printStackTrace();
545
	    fail("Unexpected error: " + e.getMessage());
538
      e.printStackTrace();
539
      fail("Unexpected error: " + e.getMessage());
546 540

  
547 541
    } catch (InsufficientResources e) {
548
	    e.printStackTrace();
549
	    fail("Unexpected error: " + e.getMessage());
542
      e.printStackTrace();
543
      fail("Unexpected error: " + e.getMessage());
550 544

  
551 545
    } catch (InvalidSystemMetadata e) {
552
	    e.printStackTrace();
553
	    fail("Unexpected error: " + e.getMessage());
546
      e.printStackTrace();
547
      fail("Unexpected error: " + e.getMessage());
554 548

  
555 549
    } catch (NotImplemented e) {
556
	    e.printStackTrace();
557
	    fail("Unexpected error: " + e.getMessage());
550
      e.printStackTrace();
551
      fail("Unexpected error: " + e.getMessage());
558 552

  
559 553
    } catch (InvalidRequest e) {
560
	    e.printStackTrace();
561
	    fail("Unexpected error: " + e.getMessage());
554
      e.printStackTrace();
555
      fail("Unexpected error: " + e.getMessage());
562 556

  
563 557
    } catch (NotFound e) {
564
	    e.printStackTrace();
565
	    fail("Unexpected error: " + e.getMessage());
558
      e.printStackTrace();
559
      fail("Unexpected error: " + e.getMessage());
566 560

  
567 561
    } catch (Exception e) {
568
	    e.printStackTrace();
569
	    fail("Unexpected error: " + e.getMessage());
562
      e.printStackTrace();
563
      fail("Unexpected error: " + e.getMessage());
570 564

  
571 565
    }
572
	}
566
  }
573 567

  
574
	/**
575
	 * Test getting the checksum of an object
576
	 */
577
	public void testGetChecksum() {
568
  /**
569
   * Test getting the checksum of an object
570
   */
571
  public void testGetChecksum() {
578 572
    printTestHeader("testGetChecksum");
579 573

  
580
	  try {
581
	    Session session = getTestSession();
582
	    Identifier guid = new Identifier();
583
	    guid.setValue("testGetChecksum." + System.currentTimeMillis());
584
	    InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
585
	    SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
586
	    Identifier pid = MNodeService.getInstance().create(session, guid, object, sysmeta);
587
	    Checksum checksum = MNodeService.getInstance().getChecksum(session, pid, "MD5");
588
	    assertEquals(checksum.getValue(), sysmeta.getChecksum().getValue());
574
    try {
575
      Session session = getTestSession();
576
      Identifier guid = new Identifier();
577
      guid.setValue("testGetChecksum." + System.currentTimeMillis());
578
      InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
579
      SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
580
      Identifier pid = MNodeService.getInstance().create(session, guid, object, sysmeta);
581
      Checksum checksum = MNodeService.getInstance().getChecksum(session, pid, "MD5");
582
      assertEquals(checksum.getValue(), sysmeta.getChecksum().getValue());
589 583
    
590
	  } catch (UnsupportedEncodingException e) {
591
	    e.printStackTrace();
592
	    fail("Unexpected error: " + e.getMessage());
584
    } catch (UnsupportedEncodingException e) {
585
      e.printStackTrace();
586
      fail("Unexpected error: " + e.getMessage());
593 587

  
594 588
    } catch (InvalidToken e) {
595
	    e.printStackTrace();
596
	    fail("Unexpected error: " + e.getMessage());
589
      e.printStackTrace();
590
      fail("Unexpected error: " + e.getMessage());
597 591

  
598 592
    } catch (ServiceFailure e) {
599
	    e.printStackTrace();
600
	    fail("Unexpected error: " + e.getMessage());
593
      e.printStackTrace();
594
      fail("Unexpected error: " + e.getMessage());
601 595

  
602 596
    } catch (NotAuthorized e) {
603
	    e.printStackTrace();
604
	    fail("Unexpected error: " + e.getMessage());
597
      e.printStackTrace();
598
      fail("Unexpected error: " + e.getMessage());
605 599

  
606 600
    } catch (IdentifierNotUnique e) {
607
	    e.printStackTrace();
608
	    fail("Unexpected error: " + e.getMessage());
601
      e.printStackTrace();
602
      fail("Unexpected error: " + e.getMessage());
609 603

  
610 604
    } catch (UnsupportedType e) {
611
	    e.printStackTrace();
612
	    fail("Unexpected error: " + e.getMessage());
605
      e.printStackTrace();
606
      fail("Unexpected error: " + e.getMessage());
613 607

  
614 608
    } catch (InsufficientResources e) {
615
	    e.printStackTrace();
616
	    fail("Unexpected error: " + e.getMessage());
609
      e.printStackTrace();
610
      fail("Unexpected error: " + e.getMessage());
617 611

  
618 612
    } catch (InvalidSystemMetadata e) {
619
	    e.printStackTrace();
620
	    fail("Unexpected error: " + e.getMessage());
613
      e.printStackTrace();
614
      fail("Unexpected error: " + e.getMessage());
621 615

  
622 616
    } catch (NotImplemented e) {
623
	    e.printStackTrace();
624
	    fail("Unexpected error: " + e.getMessage());
617
      e.printStackTrace();
618
      fail("Unexpected error: " + e.getMessage());
625 619

  
626 620
    } catch (InvalidRequest e) {
627
	    e.printStackTrace();
628
	    fail("Unexpected error: " + e.getMessage());
621
      e.printStackTrace();
622
      fail("Unexpected error: " + e.getMessage());
629 623

  
630 624
    } catch (NotFound e) {
631
	    e.printStackTrace();
632
	    fail("Unexpected error: " + e.getMessage());
625
      e.printStackTrace();
626
      fail("Unexpected error: " + e.getMessage());
633 627

  
634 628
    } catch (Exception e) {
635
	    e.printStackTrace();
636
	    fail("Unexpected error: " + e.getMessage());
629
      e.printStackTrace();
630
      fail("Unexpected error: " + e.getMessage());
637 631

  
638 632
    }
639
	  
640
	}
633
    
634
  }
641 635

  
642
	/**
643
	 * Testing listing objects on the Member Node
644
	 */
645
	public void testListObjects() {
646
	    printTestHeader("testListObjects");
647
	
648
	    try {
649
	
650
		    Session session = getTestSession();
651
		    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
652
		    Date startTime = sdf.parse("2010-01-01");
653
		    Date endTime = new Date();
654
		    ObjectFormatIdentifier objectFormatId = null;
655
		    boolean replicaStatus = false;
656
		    int start = 0;
657
		    int count = 1;
658
	    
659
		    // insert at least one object 
660
		    testCreate();
661
		    // now check that we have at least one
662
		    ObjectList objectList = 
663
		    	MNodeService.getInstance().listObjects(session, startTime, endTime, 
664
		    			objectFormatId, replicaStatus, start, count);
665
		    assertNotNull(objectList);
666
		    assertTrue(objectList.getCount() == count);
667
		    assertTrue(objectList.getStart() == 0);
668
		    assertTrue(objectList.getTotal() > 1);
669
		    
670
	    } catch (Exception e) {
671
		    e.printStackTrace();
672
		    fail("Unexpected error: " + e.getMessage());
673
	
674
	    }
675
	}
636
  /**
637
   * Testing listing objects on the Member Node
638
   */
639
  public void testListObjects() {
640
      printTestHeader("testListObjects");
641
  
642
      try {
643
  
644
        Session session = getTestSession();
645
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
646
        Date startTime = sdf.parse("2010-01-01");
647
        Date endTime = new Date();
648
        ObjectFormatIdentifier objectFormatId = null;
649
        boolean replicaStatus = false;
650
        int start = 0;
651
        int count = 1;
652
      
653
        // insert at least one object 
654
        testCreate();
655
        // now check that we have at least one
656
        ObjectList objectList = 
657
          MNodeService.getInstance().listObjects(session, startTime, endTime, 
658
              objectFormatId, replicaStatus, start, count);
659
        assertNotNull(objectList);
660
        assertTrue(objectList.getCount() == count);
661
        assertTrue(objectList.getStart() == 0);
662
        assertTrue(objectList.getTotal() > 1);
663
        
664
      } catch (Exception e) {
665
        e.printStackTrace();
666
        fail("Unexpected error: " + e.getMessage());
667
  
668
      }
669
  }
676 670

  
677
	public void testGetCapabilities() {
678
	    printTestHeader("testGetCapabilities");
679
		try {
680
			Node node = MNodeService.getInstance().getCapabilities();
681
			assertNotNull(node);
682
			// TODO: should probably test other parts of the node information
683
		} catch (Exception e) {
684
			e.printStackTrace();
685
			fail("Probably not yet implemented: " + e.getMessage());
686
		}
687
		
688
	}
671
  public void testGetCapabilities() {
672
      printTestHeader("testGetCapabilities");
673
    try {
674
      Node node = MNodeService.getInstance().getCapabilities();
675
      assertNotNull(node);
676
      // TODO: should probably test other parts of the node information
677
    } catch (Exception e) {
678
      e.printStackTrace();
679
      fail("Probably not yet implemented: " + e.getMessage());
680
    }
681
    
682
  }
689 683

  
690
	public void testGetOperationStatistics() {
691
	    printTestHeader("testGetOperationStatistics");
692
		try {
693
			Session session = getTestSession();
694
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
695
		    Date startTime = sdf.parse("2010-01-01");
696
		    Date endTime = new Date();
697
			MonitorList monitorList = 
698
				MNodeService.getInstance().getOperationStatistics(
699
						session, 
700
						startTime, 
701
						endTime, 
702
						session.getSubject(), 
703
						Event.CREATE, 
704
						null //formatId
705
						);
706
			
707
			assertNotNull(monitorList);
708
			// TODO: should probably test other parts of the information
709
		} catch (Exception e) {
710
			e.printStackTrace();
711
			fail("Probably not yet implemented: " + e.getMessage());
712
		}
713
	}
684
  public void testGetOperationStatistics() {
685
      printTestHeader("testGetOperationStatistics");
686
    try {
687
      Session session = getTestSession();
688
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
689
        Date startTime = sdf.parse("2010-01-01");
690
        Date endTime = new Date();
691
      MonitorList monitorList = 
692
        MNodeService.getInstance().getOperationStatistics(
693
            session, 
694
            startTime, 
695
            endTime, 
696
            session.getSubject(), 
697
            Event.CREATE, 
698
            null //formatId
699
            );
700
      
701
      assertNotNull(monitorList);
702
      // TODO: should probably test other parts of the information
703
    } catch (Exception e) {
704
      e.printStackTrace();
705
      fail("Probably not yet implemented: " + e.getMessage());
706
    }
707
  }
714 708

  
715
	public void testPing() {
709
  public void testPing() {
716 710

  
717
		try {
718
	    boolean pingable = MNodeService.getInstance().ping();
719
	    assertTrue(pingable);
720
	    
711
    try {
712
      boolean pingable = MNodeService.getInstance().ping();
713
      assertTrue(pingable);
714
      
721 715
    } catch (NotImplemented e) {
722
	    e.printStackTrace();
723
	    fail("Unexpected error: " + e.getMessage());
716
      e.printStackTrace();
717
      fail("Unexpected error: " + e.getMessage());
724 718

  
725 719
    } catch (ServiceFailure e) {
726
	    e.printStackTrace();
727
	    fail("Unexpected error: " + e.getMessage());
720
      e.printStackTrace();
721
      fail("Unexpected error: " + e.getMessage());
728 722

  
729 723
    } catch (NotAuthorized e) {
730
	    e.printStackTrace();
731
	    fail("Unexpected error: " + e.getMessage());
724
      e.printStackTrace();
725
      fail("Unexpected error: " + e.getMessage());
732 726

  
733 727
    } catch (InvalidRequest e) {
734
	    e.printStackTrace();
735
	    fail("Unexpected error: " + e.getMessage());
728
      e.printStackTrace();
729
      fail("Unexpected error: " + e.getMessage());
736 730

  
737 731
    } catch (InsufficientResources e) {
738
	    e.printStackTrace();
739
	    fail("Unexpected error: " + e.getMessage());
732
      e.printStackTrace();
733
      fail("Unexpected error: " + e.getMessage());
740 734

  
741 735
    } catch (UnsupportedType e) {
742
	    e.printStackTrace();
743
	    fail("Unexpected error: " + e.getMessage());
736
      e.printStackTrace();
737
      fail("Unexpected error: " + e.getMessage());
744 738

  
745 739
    }
746
		
747
	}
740
    
741
  }
748 742

  
749
	public void testSynchronizationFailed() {
750
		printTestHeader("testSynchronizationFailed");
751
		try {
752
		    Session session = getTestSession();
753
		    
754
		    // create the object
755
		    Identifier pid = new Identifier();
756
		    pid.setValue("testSynchronizationFailed." + System.currentTimeMillis());
757
		    InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
758
		    SystemMetadata sysmeta = createSystemMetadata(pid, session.getSubject(), object);
759
		    Identifier retPid = MNodeService.getInstance().create(session, pid, object, sysmeta);
760
		    assertEquals(retPid.getValue(), pid.getValue());
761
		    
762
		    // pretend the sync failed
763
			SynchronizationFailed syncFailed = 
764
				new SynchronizationFailed("0000", "Testing Synch Failure");
765
			syncFailed.setPid(pid);
766
			MNodeService.getInstance().synchronizationFailed(session, syncFailed );
767
		} catch (Exception e) {
768
			e.printStackTrace();
769
		    fail("Unexpected error: " + e.getMessage());
770
		}
743
  public void testSynchronizationFailed() {
744
    printTestHeader("testSynchronizationFailed");
745
    try {
746
        Session session = getTestSession();
747
        
748
        // create the object
749
        Identifier pid = new Identifier();
750
        pid.setValue("testSynchronizationFailed." + System.currentTimeMillis());
751
        InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
752
        SystemMetadata sysmeta = createSystemMetadata(pid, session.getSubject(), object);
753
        Identifier retPid = MNodeService.getInstance().create(session, pid, object, sysmeta);
754
        assertEquals(retPid.getValue(), pid.getValue());
755
        
756
        // pretend the sync failed
757
      SynchronizationFailed syncFailed = 
758
        new SynchronizationFailed("0000", "Testing Synch Failure");
759
      syncFailed.setPid(pid);
760
      MNodeService.getInstance().synchronizationFailed(session, syncFailed );
761
    } catch (Exception e) {
762
      e.printStackTrace();
763
        fail("Unexpected error: " + e.getMessage());
764
    }
771 765

  
772
	}
766
  }
773 767

  
774
	public void testGetLogRecords() {
768
  public void testGetLogRecords() {
775 769
    printTestHeader("testLogRecords");
776 770

  
777 771
    Log log = null;
......
786 780
    int start = 0;
787 781
    int count = 1;
788 782
    
789
	  try {
790
	    log = MNodeService.getInstance().getLogRecords(session, fromDate, toDate, 
791
	    	event, start, count);
792
	    
793
	    assertNotNull(log);	    
794
	    assertTrue(log.getCount() == count);
795
	    assertTrue(log.getStart() == start);
796
	    assertTrue(log.getTotal() >= 1);
797
	    	
783
    try {
784
      log = MNodeService.getInstance().getLogRecords(session, fromDate, toDate, 
785
        event, start, count);
786
      
787
      assertNotNull(log);      
788
      assertTrue(log.getCount() == count);
789
      assertTrue(log.getStart() == start);
790
      assertTrue(log.getTotal() >= 1);
791
        
798 792
    } catch (InvalidToken e) {
799
	    e.printStackTrace();
800
	    fail("Unexpected error: " + e.getMessage());
793
      e.printStackTrace();
794
      fail("Unexpected error: " + e.getMessage());
801 795

  
802 796
    } catch (ServiceFailure e) {
803
	    e.printStackTrace();
804
	    fail("Unexpected error: " + e.getMessage());
805
	    
797
      e.printStackTrace();
798
      fail("Unexpected error: " + e.getMessage());
799
      
806 800
    } catch (NotAuthorized e) {
807
	    e.printStackTrace();
808
	    fail("Unexpected error: " + e.getMessage());
809
	    
801
      e.printStackTrace();
802
      fail("Unexpected error: " + e.getMessage());
803
      
810 804
    } catch (InvalidRequest e) {
811
	    e.printStackTrace();
812
	    fail("Unexpected error: " + e.getMessage());
813
	    
805
      e.printStackTrace();
806
      fail("Unexpected error: " + e.getMessage());
807
      
814 808
    } catch (NotImplemented e) {
815
	    e.printStackTrace();
816
	    fail("Unexpected error: " + e.getMessage());
817
	    
809
      e.printStackTrace();
810
      fail("Unexpected error: " + e.getMessage());
811
      
818 812
    }
819
	}
813
  }
820 814

  
821
	/**
822
	 * Testing setting access on a known object
823
	 */
824
	public void testSetAccessPolicy() {
815
  /**
816
   * Testing setting access on a known object
817
   */
818
  public void testSetAccessPolicy() {
825 819
    printTestHeader("testSetAccess");
826 820
    
827 821
    boolean accessWasSet = false;
828 822
    
829 823
    try {
830
	    // create an object to set access on
831
	    Session session = getTestSession();
832
	    Identifier guid = new Identifier();
833
	    guid.setValue("testSetAccess." + System.currentTimeMillis());
834
	    InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
835
	    SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
836
	    Identifier pid = 
837
	    	MNodeService.getInstance().create(session, guid, object, sysmeta);
838
	    // set the access
839
	    AccessPolicy accessPolicy = new AccessPolicy();
840
	    AccessRule allow = new AccessRule();
841
	    allow.addPermission(Permission.WRITE);
842
	    Subject publicSubject = new Subject();
843
	    publicSubject.setValue(Constants.PUBLIC_SUBJECT);
844
	    allow.addSubject(publicSubject);
845
	    accessPolicy.addAllow(allow);
846
	    
847
	    accessWasSet = 
848
	    	MNodeService.getInstance().setAccessPolicy(session, pid, accessPolicy);
849
	    assertTrue(accessWasSet);
850
	    // test that it is enforced
851
	    session.setSubject(publicSubject);
852
	    boolean isAuthorized = MNodeService.getInstance().isAuthorized(session, pid, Permission.WRITE);
853
	    assertTrue(isAuthorized);
824
      // create an object to set access on
825
      Session session = getTestSession();
826
      Identifier guid = new Identifier();
827
      guid.setValue("testSetAccess." + System.currentTimeMillis());
828
      InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
829
      SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
830
      Identifier pid = 
831
        MNodeService.getInstance().create(session, guid, object, sysmeta);
832
      // set the access
833
      AccessPolicy accessPolicy = new AccessPolicy();
834
      AccessRule allow = new AccessRule();
835
      allow.addPermission(Permission.WRITE);
836
      Subject publicSubject = new Subject();
837
      publicSubject.setValue(Constants.PUBLIC_SUBJECT);
838
      allow.addSubject(publicSubject);
839
      accessPolicy.addAllow(allow);
840
      
841
      accessWasSet = 
842
        MNodeService.getInstance().setAccessPolicy(session, pid, accessPolicy);
843
      assertTrue(accessWasSet);
844
      // test that it is enforced
845
      session.setSubject(publicSubject);
846
      boolean isAuthorized = MNodeService.getInstance().isAuthorized(session, pid, Permission.WRITE);
847
      assertTrue(isAuthorized);
854 848

  
855 849
    } catch (UnsupportedEncodingException e) {
856
	    e.printStackTrace();
857
	    
850
      e.printStackTrace();
851
      
858 852
    } catch (InvalidToken e) {
859
	    e.printStackTrace();
860
	    fail("Unexpected error: " + e.getMessage());
861
	    
853
      e.printStackTrace();
854
      fail("Unexpected error: " + e.getMessage());
855
      
862 856
    } catch (ServiceFailure e) {
863
	    e.printStackTrace();
864
	    fail("Unexpected error: " + e.getMessage());
865
	    
857
      e.printStackTrace();
858
      fail("Unexpected error: " + e.getMessage());
859
      
866 860
    } catch (NotAuthorized e) {
867
	    e.printStackTrace();
868
	    fail("Unexpected error: " + e.getMessage());
869
	    
861
      e.printStackTrace();
862
      fail("Unexpected error: " + e.getMessage());
863
      
870 864
    } catch (IdentifierNotUnique e) {
871
	    e.printStackTrace();
872
	    fail("Unexpected error: " + e.getMessage());
873
	    
865
      e.printStackTrace();
866
      fail("Unexpected error: " + e.getMessage());
867
      
874 868
    } catch (UnsupportedType e) {
875
	    e.printStackTrace();
876
	    fail("Unexpected error: " + e.getMessage());
877
	    
869
      e.printStackTrace();
870
      fail("Unexpected error: " + e.getMessage());
871
      
878 872
    } catch (InsufficientResources e) {
879
	    e.printStackTrace();
880
	    fail("Unexpected error: " + e.getMessage());
881
	    
873
      e.printStackTrace();
874
      fail("Unexpected error: " + e.getMessage());
875
      
882 876
    } catch (InvalidSystemMetadata e) {
883
	    e.printStackTrace();
884
	    fail("Unexpected error: " + e.getMessage());
885
	    
877
      e.printStackTrace();
878
      fail("Unexpected error: " + e.getMessage());
879
      
886 880
    } catch (NotImplemented e) {
887
	    e.printStackTrace();
888
	    fail("Unexpected error: " + e.getMessage());
889
	    
881
      e.printStackTrace();
882
      fail("Unexpected error: " + e.getMessage());
883
      
890 884
    } catch (InvalidRequest e) {
891
	    e.printStackTrace();
892
	    fail("Unexpected error: " + e.getMessage());
893
	    
885
      e.printStackTrace();
886
      fail("Unexpected error: " + e.getMessage());
887
      
894 888
    } catch (NotFound e) {
895
	    e.printStackTrace();
896
	    fail("Unexpected error: " + e.getMessage());
897
	    
889
      e.printStackTrace();
890
      fail("Unexpected error: " + e.getMessage());
891
      
898 892
    } catch (Exception e) {
899
	    e.printStackTrace();
900
	    fail("Unexpected error: " + e.getMessage());
901
	    
893
      e.printStackTrace();
894
      fail("Unexpected error: " + e.getMessage());
895
      
902 896
    }
903
	    
904
	}
897
      
898
  }
905 899

  
906
	/**
907
	 * Test if a subject is authorized to read a known object
908
	 */
909
	public void testIsAuthorized() {
900
  /**
901
   * Test if a subject is authorized to read a known object
902
   */
903
  public void testIsAuthorized() {
910 904
    printTestHeader("testIsAuthorized");
911 905
    
912
		try {
913
	    Session session = getTestSession();
914
	    Identifier guid = new Identifier();
915
	    guid.setValue("testIsAuthorized." + System.currentTimeMillis());
916
	    InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
917
	    SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
918
	    Identifier pid = 
919
	    	MNodeService.getInstance().create(session, guid, object, sysmeta);
920
	    boolean isAuthorized = 
921
	    	MNodeService.getInstance().isAuthorized(session, pid, Permission.READ);
922
	    assertEquals(isAuthorized, true);
923
	    
906
    try {
907
      Session session = getTestSession();
908
      Identifier guid = new Identifier();
909
      guid.setValue("testIsAuthorized." + System.currentTimeMillis());
910
      InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
911
      SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
912
      Identifier pid = 
913
        MNodeService.getInstance().create(session, guid, object, sysmeta);
914
      boolean isAuthorized = 
915
        MNodeService.getInstance().isAuthorized(session, pid, Permission.READ);
916
      assertEquals(isAuthorized, true);
917
      
924 918
    } catch (UnsupportedEncodingException e) {
925
	    e.printStackTrace();
926
	    fail("Unexpected error: " + e.getMessage());
919
      e.printStackTrace();
920
      fail("Unexpected error: " + e.getMessage());
927 921

  
928 922
    } catch (InvalidToken e) {
929
	    e.printStackTrace();
930
	    fail("Unexpected error: " + e.getMessage());
923
      e.printStackTrace();
924
      fail("Unexpected error: " + e.getMessage());
931 925

  
932 926
    } catch (ServiceFailure e) {
933
	    e.printStackTrace();
934
	    fail("Unexpected error: " + e.getMessage());
927
      e.printStackTrace();
928
      fail("Unexpected error: " + e.getMessage());
935 929

  
936 930
    } catch (NotAuthorized e) {
937
	    e.printStackTrace();
938
	    fail("Unexpected error: " + e.getMessage());
931
      e.printStackTrace();
932
      fail("Unexpected error: " + e.getMessage());
939 933

  
940 934
    } catch (IdentifierNotUnique e) {
941
	    e.printStackTrace();
942
	    fail("Unexpected error: " + e.getMessage());
935
      e.printStackTrace();
936
      fail("Unexpected error: " + e.getMessage());
943 937

  
944 938
    } catch (UnsupportedType e) {
945
	    e.printStackTrace();
946
	    fail("Unexpected error: " + e.getMessage());
939
      e.printStackTrace();
940
      fail("Unexpected error: " + e.getMessage());
947 941

  
948 942
    } catch (InsufficientResources e) {
949
	    e.printStackTrace();
950
	    fail("Unexpected error: " + e.getMessage());
943
      e.printStackTrace();
944
      fail("Unexpected error: " + e.getMessage());
951 945

  
952 946
    } catch (InvalidSystemMetadata e) {
953
	    e.printStackTrace();
954
	    fail("Unexpected error: " + e.getMessage());
947
      e.printStackTrace();
948
      fail("Unexpected error: " + e.getMessage());
955 949

  
956 950
    } catch (NotImplemented e) {
957
	    e.printStackTrace();
958
	    fail("Unexpected error: " + e.getMessage());
951
      e.printStackTrace();
952
      fail("Unexpected error: " + e.getMessage());
959 953

  
960 954
    } catch (InvalidRequest e) {
961
	    e.printStackTrace();
962
	    fail("Unexpected error: " + e.getMessage());
955
      e.printStackTrace();
956
      fail("Unexpected error: " + e.getMessage());
963 957

  
964 958
    } catch (Exception e) {
965
	    e.printStackTrace();
966
	    fail("Unexpected error: " + e.getMessage());
959
      e.printStackTrace();
960
      fail("Unexpected error: " + e.getMessage());
967 961

  
968 962
    }
969
	}
963
  }
970 964

  
971 965
  
972
	
973
	
966
  
967
  
974 968
}
src/edu/ucsb/nceas/metacat/dataone/MNodeService.java
312 312
      // get the existing system metadata for the object
313 313
      SystemMetadata existingSysMeta = getSystemMetadata(session, pid);
314 314
      
315
      // add the obsoleted pid to the obsoletedBy list
316
      List<Identifier> obsoletedList = existingSysMeta.getObsoletedByList();
317
      obsoletedList.add(pid);
318
      existingSysMeta.setObsoletedByList(obsoletedList);
315
      // add the newPid to the obsoletedBy list for the existing sysmeta
316
      existingSysMeta.addObsoletedBy(newPid);
319 317
      
320 318
      // then update the existing system metadata
321 319
      updateSystemMetadata(existingSysMeta);
322
      
323
      // prep the new system metadata, add pid to the obsoletes list
320
            
321
      // prep the new system metadata, add pid to the affected lists
324 322
      sysmeta.addObsolete(pid);
325
      
323
      sysmeta.addDerivedFrom(pid);
324

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff