Project

General

Profile

« Previous | Next » 

Revision 10125

Added by Jing Tao about 8 years ago

Add the test method for the new methods to determine if an object file does exist or not for the given local id.

View differences:

test/edu/ucsb/nceas/metacattest/IdentifierManagerTest.java
26 26

  
27 27
import java.io.ByteArrayInputStream;
28 28
import java.io.InputStream;
29
import java.io.File;
29 30
import java.math.BigInteger;
30 31
import java.sql.SQLException;
31 32
import java.util.*;
......
33 34
import junit.framework.Test;
34 35
import junit.framework.TestSuite;
35 36

  
37
import org.apache.commons.io.FileUtils;
38

  
36 39
import org.dataone.client.v2.itk.D1Client;
37 40
import org.dataone.configuration.Settings;
38 41
import org.dataone.service.types.v1.Identifier;
......
91 94
        suite.addTest(new IdentifierManagerTest("testQuerySystemMetadata"));
92 95
        suite.addTest(new IdentifierManagerTest("testSystemMetadataPIDExists"));
93 96
        suite.addTest(new IdentifierManagerTest("testSystemMetadataSIDExists"));
97
        suite.addTest(new IdentifierManagerTest("testObjectFileExist"));
94 98
        return suite;
95 99
    }
96 100
    /**
......
1686 1690
        assertTrue(size4 > 0);
1687 1691
    }
1688 1692
    
1693
    public void testObjectFileExist() throws Exception {
1694
        //test the data object
1695
        Session session = getTestSession();
1696
        Identifier guid = new Identifier();
1697
        guid.setValue(generateDocumentId());
1698
        InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
1699
        SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
1700
        MNodeService.getInstance(request).create(session, guid, object, sysmeta);
1701
        String localId =  IdentifierManager.getInstance().getLocalId(guid.getValue());
1702
        boolean isScienceMetadata = false;
1703
        assertTrue("The data file "+localId+" should exists.", IdentifierManager.getInstance().objectFileExists(localId, isScienceMetadata));
1704
        
1705
        localId = "boo.foo.12w3d";
1706
        assertTrue("The data file "+localId+" should exists.", !IdentifierManager.getInstance().objectFileExists(localId, isScienceMetadata));
1707
        
1708
        Thread.sleep(500);
1709
        //test the medata object
1710
        guid = new Identifier();
1711
        guid.setValue(generateDocumentId());
1712
        object = new ByteArrayInputStream(FileUtils.readFileToByteArray(new File("./test/eml-sample.xml")));
1713
        sysmeta = createSystemMetadata(guid, session.getSubject(), object);
1714
        ObjectFormatIdentifier formatId = new ObjectFormatIdentifier();
1715
        formatId.setValue("eml://ecoinformatics.org/eml-2.0.1");
1716
        sysmeta.setFormatId(formatId);
1717
        MNodeService.getInstance(request).create(session, guid, object, sysmeta);
1718
        localId =  IdentifierManager.getInstance().getLocalId(guid.getValue());
1719
        isScienceMetadata = true;
1720
        assertTrue("The science data file "+localId+" should exists.", IdentifierManager.getInstance().objectFileExists(localId, isScienceMetadata));
1721
        
1722
        localId = "boo.foo.12w3d";
1723
        assertTrue("The science data file "+localId+" should exists.", !IdentifierManager.getInstance().objectFileExists(localId, isScienceMetadata));
1724
        
1725
        Thread.sleep(500);
1726
        //test the medata object
1727
        guid = new Identifier();
1728
        guid.setValue(generateDocumentId());
1729
        object = new ByteArrayInputStream(FileUtils.readFileToByteArray(new File("./test/resourcemap.xml")));
1730
        sysmeta = createSystemMetadata(guid, session.getSubject(), object);
1731
        formatId = new ObjectFormatIdentifier();
1732
        formatId.setValue("http://www.openarchives.org/ore/terms");
1733
        sysmeta.setFormatId(formatId);
1734
        MNodeService.getInstance(request).create(session, guid, object, sysmeta);
1735
        localId =  IdentifierManager.getInstance().getLocalId(guid.getValue());
1736
        System.out.println("The local id for resource map ================================= is "+localId);
1737
        isScienceMetadata = false;
1738
        assertTrue("The science data file "+localId+" should exists.", IdentifierManager.getInstance().objectFileExists(localId, isScienceMetadata));
1739
        
1740
     
1741
        
1742
    }
1689 1743
    /**
1690 1744
     * We want to act as the CN itself
1691 1745
     * @throws ServiceFailure 

Also available in: Unified diff