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: leinfelder $'
|
8
|
* '$Date: 2011-06-06 15:28:54 -0700 (Mon, 06 Jun 2011) $'
|
9
|
* '$Revision: 6122 $'
|
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.util.Date;
|
29
|
|
30
|
import junit.framework.Test;
|
31
|
import junit.framework.TestSuite;
|
32
|
|
33
|
import org.dataone.service.types.Checksum;
|
34
|
import org.dataone.service.types.ChecksumAlgorithm;
|
35
|
import org.dataone.service.types.Identifier;
|
36
|
import org.dataone.service.types.NodeReference;
|
37
|
import org.dataone.service.types.ObjectFormat;
|
38
|
import org.dataone.service.types.Session;
|
39
|
import org.dataone.service.types.Subject;
|
40
|
import org.dataone.service.types.SystemMetadata;
|
41
|
|
42
|
import edu.ucsb.nceas.MCTestCase;
|
43
|
|
44
|
/**
|
45
|
* A JUnit test for testing the dataone CNCore implementation
|
46
|
*/
|
47
|
public class CNCoreTest extends MCTestCase {
|
48
|
|
49
|
/**
|
50
|
* constructor for the test
|
51
|
*/
|
52
|
public CNCoreTest(String name)
|
53
|
{
|
54
|
super(name);
|
55
|
}
|
56
|
|
57
|
/**
|
58
|
* Establish a testing framework by initializing appropriate objects
|
59
|
*/
|
60
|
public void setUp() throws Exception
|
61
|
{
|
62
|
super.setUp();
|
63
|
}
|
64
|
|
65
|
/**
|
66
|
* Release any objects after tests are complete
|
67
|
*/
|
68
|
public void tearDown()
|
69
|
{
|
70
|
}
|
71
|
|
72
|
/**
|
73
|
* Create a suite of tests to be run together
|
74
|
*/
|
75
|
public static Test suite()
|
76
|
{
|
77
|
TestSuite suite = new TestSuite();
|
78
|
suite.addTest(new CNCoreTest("initialize"));
|
79
|
|
80
|
suite.addTest(new CNCoreTest("testRegisterSystemMetadata"));
|
81
|
|
82
|
return suite;
|
83
|
}
|
84
|
|
85
|
/**
|
86
|
* test for registering standalone system metadata
|
87
|
*/
|
88
|
public void testRegisterSystemMetadata()
|
89
|
{
|
90
|
printTestHeader("testRegisterSystemMetadata");
|
91
|
|
92
|
try {
|
93
|
Session session = new Session();
|
94
|
Subject subject = new Subject();
|
95
|
subject.setValue("cn=test,dc=dataone,dc=org");
|
96
|
session.setSubject(subject);
|
97
|
Identifier guid = new Identifier();
|
98
|
guid.setValue("testRegisterSystemMetadata." + System.currentTimeMillis());
|
99
|
SystemMetadata sysmeta = createSystemMetadata(guid, subject);
|
100
|
CNCoreImpl.getInstance().registerSystemMetaData(session, guid, sysmeta);
|
101
|
}
|
102
|
catch(Exception e)
|
103
|
{
|
104
|
fail("Unexpected error in testDescribe: " + e.getMessage());
|
105
|
}
|
106
|
}
|
107
|
|
108
|
/**
|
109
|
* Run an initial test that always passes to check that the test harness is
|
110
|
* working.
|
111
|
*/
|
112
|
public void initialize()
|
113
|
{
|
114
|
printTestHeader("initialize");
|
115
|
assertTrue(1 == 1);
|
116
|
}
|
117
|
|
118
|
|
119
|
/**
|
120
|
* create system metadata with a specified id
|
121
|
*/
|
122
|
private SystemMetadata createSystemMetadata(Identifier id, Subject owner)
|
123
|
throws Exception
|
124
|
{
|
125
|
SystemMetadata sm = new SystemMetadata();
|
126
|
//set the id
|
127
|
sm.setIdentifier(id);
|
128
|
sm.setObjectFormat(ObjectFormat.OCTET_STREAM);
|
129
|
//create the checksum
|
130
|
String checksumS = "test";
|
131
|
ChecksumAlgorithm ca = ChecksumAlgorithm.convert("MD5");
|
132
|
Checksum checksum = new Checksum();
|
133
|
checksum.setValue(checksumS);
|
134
|
checksum.setAlgorithm(ca);
|
135
|
sm.setChecksum(checksum);
|
136
|
//set the size
|
137
|
sm.setSize(0);
|
138
|
sm.setSubmitter(owner);
|
139
|
sm.setRightsHolder(owner);
|
140
|
sm.setDateUploaded(new Date());
|
141
|
sm.setDateSysMetadataModified(new Date());
|
142
|
NodeReference nr = new NodeReference();
|
143
|
nr.setValue("metacat");
|
144
|
sm.setOriginMemberNode(nr);
|
145
|
sm.setAuthoritativeMemberNode(nr);
|
146
|
return sm;
|
147
|
}
|
148
|
|
149
|
/**
|
150
|
* print a header to start each test
|
151
|
*/
|
152
|
private void printTestHeader(String testName)
|
153
|
{
|
154
|
System.out.println();
|
155
|
System.out.println("*************** " + testName + " ***************");
|
156
|
}
|
157
|
|
158
|
}
|