Project

General

Profile

« Previous | Next » 

Revision 6564

SystemMetadataManager's functionality is handled by IdentifierManager. Removing it and it's test.

View differences:

test/edu/ucsb/nceas/metacat/dataone/SystemMetadataManagerTest.java
1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2010 Regents of the University of California and the
4
 *              National Center for Ecological Analysis and Synthesis
5
 *  Purpose: To test the Access Controls in metacat by JUnit
6
 *
7
 *   '$Author: berkley $'
8
 *     '$Date: 2010-05-03 14:26:08 -0700 (Fri, 14 Aug 2009) $'
9
 * '$Revision: 5027 $'
10
 *
11
 * This program is free software; you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation; either version 2 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24
 */
25

  
26
package edu.ucsb.nceas.metacat.dataone;
27

  
28
import java.io.StringBufferInputStream;
29
import java.security.MessageDigest;
30

  
31
import junit.framework.Test;
32
import junit.framework.TestSuite;
33
import edu.ucsb.nceas.MCTestCase;
34

  
35
/**
36
 * A JUnit test for testing the dataone SystemMetadataManager class
37
 */
38
public class SystemMetadataManagerTest extends MCTestCase 
39
{   
40
    /**
41
    * consstructor for the test
42
    */
43
    public SystemMetadataManagerTest(String name)
44
    {
45
        super(name);
46
    }
47
  
48
    /**
49
	 * Establish a testing framework by initializing appropriate objects
50
	 */
51
	public void setUp() throws Exception 
52
	{
53
		super.setUp();
54
	}
55

  
56
	/**
57
	 * Release any objects after tests are complete
58
	 */
59
	public void tearDown() 
60
	{
61
	}
62

  
63
	/**
64
	 * Create a suite of tests to be run together
65
	 */
66
	public static Test suite() 
67
	{
68
		TestSuite suite = new TestSuite();
69
		suite.addTest(new SystemMetadataManagerTest("initialize"));
70
		suite.addTest(new SystemMetadataManagerTest("testSingletonAccessor"));
71

  
72
		//suite.addTest(new CrudServiceTest(""));
73
		return suite;
74
	}
75
	
76
	
77
	/**
78
	 * getInstance()
79
	 */
80
	public void testSingletonAccessor()
81
	{
82
	    printTestHeader("testSingletonAccessor");
83
	    SystemMetadataManager smm = SystemMetadataManager.getInstance();
84
	    assertNotNull(smm);
85
	}
86
	
87
	/**
88
	 * Run an initial test that always passes to check that the test harness is
89
	 * working.
90
	 */
91
	public void initialize() 
92
	{
93
	    printTestHeader("initialize");
94
		assertTrue(1 == 1);
95
	}
96
	
97
	/**
98
	 * print a header to start each test
99
	 */
100
	private void printTestHeader(String testName)
101
	{
102
	    System.out.println();
103
	    System.out.println("********************************** " + testName + " **********************************");
104
	}
105
  
106
	/**
107
	 * produce an md5 checksum for item
108
	 */
109
	private String checksum(String item)
110
	  throws Exception
111
	{
112
        StringBufferInputStream fis =  new StringBufferInputStream(item);
113
        
114
        byte[] buffer = new byte[1024];
115
        MessageDigest complete = MessageDigest.getInstance("MD5");
116
        int numRead;
117
        
118
        do 
119
        {
120
          numRead = fis.read(buffer);
121
          if (numRead > 0) 
122
          {
123
            complete.update(buffer, 0, numRead);
124
          }
125
        } while (numRead != -1);
126
        
127
        
128
        return getHex(complete.digest());
129
	}
130
	
131
	/**
132
	 * convert a byte array to a hex string
133
	 */
134
	private static String getHex( byte [] raw ) 
135
	{
136
	    final String HEXES = "0123456789ABCDEF";
137
        if ( raw == null ) {
138
          return null;
139
        }
140
        final StringBuilder hex = new StringBuilder( 2 * raw.length );
141
        for ( final byte b : raw ) {
142
          hex.append(HEXES.charAt((b & 0xF0) >> 4))
143
             .append(HEXES.charAt((b & 0x0F)));
144
        }
145
        return hex.toString();
146
    }
147
}
src/edu/ucsb/nceas/metacat/dataone/SystemMetadataManager.java
1
/**
2
 * 
3
 */
4
package edu.ucsb.nceas.metacat.dataone;
5

  
6
import org.dataone.service.types.v1.SystemMetadata;
7

  
8
import edu.ucsb.nceas.metacat.IdentifierManager;
9
import edu.ucsb.nceas.metacat.McdbDocNotFoundException;
10

  
11
/**
12
 * @author berkley
13
 *
14
 * Class to handle SystemMetadata object in the metacat system
15
 */
16
public class SystemMetadataManager
17
{
18
    //singleton instance
19
    private static SystemMetadataManager manager = null;
20
    private IdentifierManager idManager = null;
21
    
22
    /**
23
     * private constructor.  Use the singleton getInstance() method to use
24
     * this class
25
     */
26
    private SystemMetadataManager()
27
    {
28
        idManager = IdentifierManager.getInstance();
29
    }
30
    
31
    /**
32
     * get a singleton instance of this class
33
     */
34
    public static SystemMetadataManager getInstance()
35
    {
36
        if(manager == null)
37
        {
38
            manager = new SystemMetadataManager();
39
        }
40
        return manager;
41
    }
42
    
43
    /**
44
     * return true if the document represented by guid has a system metadata
45
     * document registered in the systemmetadata table
46
     * @param guid
47
     * @return
48
     */
49
    public boolean documentHasSystemMetadata(String guid)
50
    {
51
        boolean hassm = false;
52
        try
53
        {
54
            SystemMetadata sm = idManager.getSystemMetadata(guid);
55
            if(sm != null && !sm.getIdentifier().getValue().equals(""))
56
            {
57
                hassm = true;
58
            }
59
        }
60
        catch(McdbDocNotFoundException me)
61
        {
62
            //if this exception is thrown, the doc with guid does not have
63
            //sys metadata
64
        }
65
        
66
        return hassm;
67
    }
68
}

Also available in: Unified diff