Project

General

Profile

« Previous | Next » 

Revision 10282

Added by Jing Tao almost 7 years ago

Add a new test method to test the miss-matched checksum for the data object.

View differences:

test/edu/ucsb/nceas/metacat/dataone/MNodeServiceTest.java
28 28

  
29 29

  
30 30

  
31
import edu.ucsb.nceas.metacat.IdentifierManager;
31 32
import edu.ucsb.nceas.metacat.dataone.CNodeService;
32 33
import edu.ucsb.nceas.metacat.dataone.MNodeService;
33 34
import edu.ucsb.nceas.metacat.properties.SkinPropertyService;
......
95 96
import org.dataone.service.types.v1.ObjectList;
96 97
import org.dataone.service.types.v1.Permission;
97 98
import org.dataone.service.types.v1.Person;
99
import org.dataone.service.types.v1.ReplicationPolicy;
98 100
import org.dataone.service.types.v1.Session;
99 101
import org.dataone.service.types.v1.Subject;
100 102
import org.dataone.service.types.v1.SubjectInfo;
......
142 144
    TestSuite suite = new TestSuite();
143 145
    suite.addTest(new MNodeServiceTest("initialize"));
144 146
    // MNStorage tests
147
    
148
    suite.addTest(new MNodeServiceTest("testMissMatchChecksumInCreate"));
145 149
    suite.addTest(new MNodeServiceTest("testCreate"));
146 150
    suite.addTest(new MNodeServiceTest("testCreateInvalidIdentifier"));
147 151
    suite.addTest(new MNodeServiceTest("testUpdate"));
......
436 440
    }
437 441
      
438 442
  }
443
  
444
  /**
445
   * Test object creation
446
   */
447
  public void testMissMatchChecksumInCreate() {
448
    printTestHeader("testMissMatchChecksumInCreate");
449
    Identifier guid = new Identifier();
450
    guid.setValue("testCreate." + System.currentTimeMillis());
451
    Session session = null;
452
    try {
453
      session = getTestSession();
454
      InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
455
      SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
456
      Node localNode = MNodeService.getInstance(request).getCapabilities();
457
      ReplicationPolicy rePolicy = new ReplicationPolicy();
458
      rePolicy.setReplicationAllowed(true);
459
      rePolicy.setNumberReplicas(new Integer(3));
460
      rePolicy.addPreferredMemberNode(localNode.getIdentifier());
461
      sysmeta.setReplicationPolicy(rePolicy);
462
      Checksum checksum = new Checksum();
463
      checksum.setAlgorithm("md5");
464
      checksum.setValue("098F6BCD4621D373CADE4E832627B4F9");
465
      sysmeta.setChecksum(checksum);
466
      Identifier pid = MNodeService.getInstance(request).create(session, guid, object, sysmeta);
467
      fail("It should fail since the checksum doesn't match.");
468
    } catch (InvalidSystemMetadata ee) {
469
      //ee.printStackTrace();
470
      try {
471
          Thread.sleep(5000);
472
          MNodeService.getInstance(request).getSystemMetadata(session, guid);
473
          fail("We shouldn't get here since the guid "+guid.getValue()+" was deleted.");
474
      } catch (NotFound e) {
475
         //here is okay.
476
      } catch (Exception e) {
477
          fail("Unexpected error: " + e.getMessage());
478
      }
479
      try {
480
          assertTrue(!IdentifierManager.getInstance().identifierExists(guid.getValue()));
481
      } catch (Exception e) {
482
          fail("Unexpected error: " + e.getMessage());
483
      }
484
      
485
    } catch (Exception e) {
486
        fail("Unexpected error: " + e.getMessage());
487
    }
488
  }
439 489

  
440 490
  /**
441 491
   * test object deletion

Also available in: Unified diff