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 |
|
}
|
SystemMetadataManager's functionality is handled by IdentifierManager. Removing it and it's test.