Project

General

Profile

« Previous | Next » 

Revision 10284

Added by Jing Tao over 7 years ago

Add a method to test the miss-matched checksum for creating a metadata object.

View differences:

test/edu/ucsb/nceas/metacat/dataone/MNodeServiceTest.java
144 144
    TestSuite suite = new TestSuite();
145 145
    suite.addTest(new MNodeServiceTest("initialize"));
146 146
    // MNStorage tests
147
    
147
    suite.addTest(new MNodeServiceTest("testMissMatchMetadataCreate"));
148 148
    suite.addTest(new MNodeServiceTest("testMissMatchChecksumInCreate"));
149 149
    suite.addTest(new MNodeServiceTest("testCreate"));
150 150
    suite.addTest(new MNodeServiceTest("testCreateInvalidIdentifier"));
......
486 486
        fail("Unexpected error: " + e.getMessage());
487 487
    }
488 488
  }
489
  
490
  
491
  /**
492
   * Test miss-match checksum for metacat object.
493
   */
494
  public void testMissMatchMetadataCreate() {
495
      printTestHeader("testMissMatchMetadataCreate");
496
      Identifier guid = new Identifier();
497
      guid.setValue("testCreate." + System.currentTimeMillis());
498
      Session session = null;
499
      try {
500
        session = getTestSession();
501
        InputStream object = new FileInputStream(new File(MockReplicationMNode.replicationSourceFile));
502
        SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
503
        ObjectFormatIdentifier formatId = new ObjectFormatIdentifier();
504
        formatId.setValue("eml://ecoinformatics.org/eml-2.0.1");
505
        sysmeta.setFormatId(formatId);
506
        Node localNode = MNodeService.getInstance(request).getCapabilities();
507
        ReplicationPolicy rePolicy = new ReplicationPolicy();
508
        rePolicy.setReplicationAllowed(true);
509
        rePolicy.setNumberReplicas(new Integer(3));
510
        rePolicy.addPreferredMemberNode(localNode.getIdentifier());
511
        sysmeta.setReplicationPolicy(rePolicy);
512
        Checksum checksum = new Checksum();
513
        checksum.setAlgorithm("md5");
514
        checksum.setValue("098F6BCD4621D373CADE4E832627B4F9");
515
        sysmeta.setChecksum(checksum);
516
        object = new FileInputStream(new File(MockReplicationMNode.replicationSourceFile));
517
        Identifier pid = MNodeService.getInstance(request).create(session, guid, object, sysmeta);
518
        fail("It should fail since the checksum doesn't match.");
519
      } catch (ServiceFailure ee) {
520
        //ee.printStackTrace();
521
        try {
522
            Thread.sleep(5000);
523
            MNodeService.getInstance(request).getSystemMetadata(session, guid);
524
            fail("We shouldn't get here since the guid "+guid.getValue()+" was deleted.");
525
        } catch (NotFound e) {
526
           //here is okay.
527
        } catch (Exception e) {
528
            fail("Unexpected error: " + e.getMessage());
529
        }
530
        try {
531
            assertTrue(!IdentifierManager.getInstance().identifierExists(guid.getValue()));
532
        } catch (Exception e) {
533
            fail("Unexpected error: " + e.getMessage());
534
        }
535
        
536
      } catch (Exception e) {
537
          fail("Unexpected error: " + e.getMessage());
538
      }
539
  }
489 540

  
490 541
  /**
491 542
   * test object deletion
......
740 791
  }
741 792

  
742 793
  /**
743
   * We currently expect this unit test to fail because it should rely on a different member node
744
   * to retrieve the object from. Currently it gets the object from itself and throws 
745
   * and expected error for duplicate entry.
746
   * 
794
   * Test the replicate method. The getReplica method is from a MockMN.
747 795
   */
748 796
  public void testReplicate() {
749 797
      printTestHeader("testReplicate");

Also available in: Unified diff