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: tao $'
|
8
|
* '$Date: 2015-02-09 17:44:08 -0800 (Mon, 09 Feb 2015) $'
|
9
|
* '$Revision: 9112 $'
|
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.v1;
|
27
|
|
28
|
|
29
|
import java.io.ByteArrayInputStream;
|
30
|
import java.io.InputStream;
|
31
|
import java.text.SimpleDateFormat;
|
32
|
import java.util.Calendar;
|
33
|
import java.util.Date;
|
34
|
import java.util.List;
|
35
|
|
36
|
import junit.framework.Test;
|
37
|
import junit.framework.TestSuite;
|
38
|
|
39
|
import org.apache.commons.io.IOUtils;
|
40
|
import org.dataone.client.v1.itk.D1Client;
|
41
|
import org.dataone.service.exceptions.BaseException;
|
42
|
import org.dataone.service.exceptions.InvalidSystemMetadata;
|
43
|
import org.dataone.service.exceptions.NotAuthorized;
|
44
|
import org.dataone.service.exceptions.NotFound;
|
45
|
import org.dataone.service.exceptions.NotImplemented;
|
46
|
import org.dataone.service.exceptions.ServiceFailure;
|
47
|
import org.dataone.service.types.v1.AccessPolicy;
|
48
|
import org.dataone.service.types.v1.AccessRule;
|
49
|
import org.dataone.service.types.v1.Checksum;
|
50
|
import org.dataone.service.types.v1.DescribeResponse;
|
51
|
import org.dataone.service.types.v1.Event;
|
52
|
import org.dataone.service.types.v1.Identifier;
|
53
|
import org.dataone.service.types.v1.NodeReference;
|
54
|
import org.dataone.service.types.v1.NodeType;
|
55
|
import org.dataone.service.types.v1.ObjectFormatIdentifier;
|
56
|
import org.dataone.service.types.v1.ObjectList;
|
57
|
import org.dataone.service.types.v1.Permission;
|
58
|
import org.dataone.service.types.v1.Replica;
|
59
|
import org.dataone.service.types.v1.ReplicationPolicy;
|
60
|
import org.dataone.service.types.v1.ReplicationStatus;
|
61
|
import org.dataone.service.types.v1.Session;
|
62
|
import org.dataone.service.types.v1.Subject;
|
63
|
import org.dataone.service.types.v1.Log;
|
64
|
import org.dataone.service.types.v1.Node;
|
65
|
import org.dataone.service.types.v1.NodeList;
|
66
|
import org.dataone.service.types.v1.ObjectFormat;
|
67
|
import org.dataone.service.types.v1.ObjectFormatList;
|
68
|
import org.dataone.service.types.v1.SystemMetadata;
|
69
|
import org.dataone.service.util.Constants;
|
70
|
|
71
|
import edu.ucsb.nceas.metacat.dataone.v1.CNodeService;
|
72
|
|
73
|
/**
|
74
|
* A JUnit test for testing the dataone CNCore implementation
|
75
|
*/
|
76
|
public class CNodeV1ServiceTest extends D1NodeV1ServiceTest {
|
77
|
|
78
|
/**
|
79
|
* constructor for the test
|
80
|
*/
|
81
|
public CNodeV1ServiceTest(String name)
|
82
|
{
|
83
|
super(name);
|
84
|
}
|
85
|
|
86
|
/**
|
87
|
* Create a suite of tests to be run together
|
88
|
*/
|
89
|
public static Test suite()
|
90
|
{
|
91
|
TestSuite suite = new TestSuite();
|
92
|
suite.addTest(new CNodeV1ServiceTest("initialize"));
|
93
|
|
94
|
/*suite.addTest(new CNodeV1ServiceTest("testChecksum"));
|
95
|
suite.addTest(new CNodeV1ServiceTest("testCreate"));
|
96
|
suite.addTest(new CNodeV1ServiceTest("testGet"));
|
97
|
suite.addTest(new CNodeV1ServiceTest("testGetFormat"));
|
98
|
suite.addTest(new CNodeV1ServiceTest("testGetLogRecords"));*/
|
99
|
suite.addTest(new CNodeV1ServiceTest("testGetSystemMetadata"));
|
100
|
suite.addTest(new CNodeV1ServiceTest("testGetFormat"));
|
101
|
/*suite.addTest(new CNodeV1ServiceTest("testIsAuthorized"));
|
102
|
suite.addTest(new CNodeV1ServiceTest("testListFormats"));
|
103
|
suite.addTest(new CNodeV1ServiceTest("testListNodes"));
|
104
|
suite.addTest(new CNodeV1ServiceTest("testObjectFormatNotFoundException"));
|
105
|
suite.addTest(new CNodeV1ServiceTest("testRegisterSystemMetadata"));
|
106
|
suite.addTest(new CNodeV1ServiceTest("testReplicationPolicy"));
|
107
|
suite.addTest(new CNodeV1ServiceTest("testReplicationStatus"));
|
108
|
suite.addTest(new CNodeV1ServiceTest("testReserveIdentifier"));
|
109
|
suite.addTest(new CNodeV1ServiceTest("testSearch"));
|
110
|
suite.addTest(new CNodeV1ServiceTest("testSetAccessPolicy"));
|
111
|
suite.addTest(new CNodeV1ServiceTest("testSetOwner"));
|
112
|
suite.addTest(new CNodeV1ServiceTest("readDeletedObject"));
|
113
|
suite.addTest(new CNodeV1ServiceTest("testGetSID"));*/
|
114
|
return suite;
|
115
|
}
|
116
|
|
117
|
|
118
|
|
119
|
|
120
|
/**
|
121
|
* test for getting system metadata
|
122
|
*/
|
123
|
public void testGetSystemMetadata() {
|
124
|
printTestHeader("testGetSystemMetadata");
|
125
|
|
126
|
try {
|
127
|
Session session = getTestSession();
|
128
|
Identifier guid = new Identifier();
|
129
|
guid.setValue("testGetSystemMetadata." + System.currentTimeMillis());
|
130
|
InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
131
|
SystemMetadata sysmeta = createV1SystemMetadata(guid, session.getSubject(), object);
|
132
|
Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
|
133
|
assertEquals(guid.getValue(), retGuid.getValue());
|
134
|
// get it
|
135
|
SystemMetadata retSysmeta = CNodeService.getInstance(request).getSystemMetadata(session, guid);
|
136
|
// check it
|
137
|
assertEquals(sysmeta.getIdentifier().getValue(), retSysmeta.getIdentifier().getValue());
|
138
|
assertTrue( retSysmeta instanceof org.dataone.service.types.v1.SystemMetadata);
|
139
|
assertFalse( retSysmeta instanceof org.dataone.service.types.v2.SystemMetadata);
|
140
|
System.out.println("=== the class name is "+retSysmeta.getClass().getName());
|
141
|
} catch(Exception e) {
|
142
|
fail("Unexpected error: " + e.getMessage());
|
143
|
}
|
144
|
}
|
145
|
|
146
|
public void testGetFormat() {
|
147
|
// make sure we are set up
|
148
|
setUpFormats();
|
149
|
|
150
|
String knownFormat = "text/plain";
|
151
|
ObjectFormatIdentifier fmtid = new ObjectFormatIdentifier();
|
152
|
fmtid.setValue(knownFormat);
|
153
|
try {
|
154
|
|
155
|
ObjectFormat format = CNodeService.getInstance(request).getFormat(fmtid);
|
156
|
assertTrue( format instanceof org.dataone.service.types.v1.ObjectFormat);
|
157
|
assertFalse( format instanceof org.dataone.service.types.v2.ObjectFormat);
|
158
|
System.out.println("=== the class name is "+format.getClass().getName());
|
159
|
String result = format.getFormatId().getValue();
|
160
|
System.out.println("Expected result: " + knownFormat);
|
161
|
System.out.println("Found result: " + result);
|
162
|
assertTrue(result.equals(knownFormat));
|
163
|
|
164
|
} catch (Exception npe) {
|
165
|
fail("Can't get the returned format : " + npe.getMessage());
|
166
|
|
167
|
}
|
168
|
}
|
169
|
|
170
|
|
171
|
|
172
|
}
|