1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Copyright: 2004 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: 2013-09-12 13:45:05 -0700 (Thu, 12 Sep 2013) $'
|
9
|
* '$Revision: 8189 $'
|
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.admin.upgrade.dataone;
|
27
|
|
28
|
import java.util.ArrayList;
|
29
|
import java.util.HashMap;
|
30
|
import java.util.List;
|
31
|
import java.util.Map;
|
32
|
|
33
|
import org.dataone.ore.ResourceMapFactory;
|
34
|
import org.dataone.service.types.v1.Identifier;
|
35
|
import org.dspace.foresite.ResourceMap;
|
36
|
|
37
|
import junit.framework.Test;
|
38
|
import junit.framework.TestSuite;
|
39
|
import edu.ucsb.nceas.MCTestCase;
|
40
|
import edu.ucsb.nceas.metacat.admin.upgrade.dataone.GenerateSystemMetadata;
|
41
|
import edu.ucsb.nceas.metacat.dataone.SystemMetadataFactory;
|
42
|
|
43
|
/**
|
44
|
* A JUnit test for testing system metadata generation
|
45
|
*/
|
46
|
public class GenerateSystemMetadataTest
|
47
|
extends MCTestCase {
|
48
|
|
49
|
/**
|
50
|
* Constructor to build the test
|
51
|
*
|
52
|
* @param name the name of the test method
|
53
|
*/
|
54
|
public GenerateSystemMetadataTest(String name) {
|
55
|
super(name);
|
56
|
}
|
57
|
|
58
|
/**
|
59
|
* Establish a testing framework by initializing appropriate objects
|
60
|
*/
|
61
|
public void setUp() {
|
62
|
|
63
|
}
|
64
|
|
65
|
/**
|
66
|
* Release any objects after tests are complete
|
67
|
*/
|
68
|
public void tearDown() {
|
69
|
}
|
70
|
|
71
|
/**
|
72
|
* Create a suite of tests to be run together
|
73
|
*/
|
74
|
public static Test suite() {
|
75
|
TestSuite suite = new TestSuite();
|
76
|
suite.addTest(new GenerateSystemMetadataTest("initialize"));
|
77
|
// Test basic functions
|
78
|
//suite.addTest(new GenerateSystemMetadataTest("upgrade"));
|
79
|
// test ORE generation
|
80
|
suite.addTest(new GenerateSystemMetadataTest("testCreateResourceMap"));
|
81
|
|
82
|
// requires manual configuration to actually pass
|
83
|
//suite.addTest(new GenerateSystemMetadataTest("testOreExistsFor"));
|
84
|
|
85
|
return suite;
|
86
|
}
|
87
|
|
88
|
/**
|
89
|
* Run an initial test that always passes to check that the test
|
90
|
* harness is working.
|
91
|
*/
|
92
|
public void initialize() {
|
93
|
assertTrue(1 == 1);
|
94
|
}
|
95
|
|
96
|
public void upgrade() throws Exception {
|
97
|
GenerateSystemMetadata upgrader = new GenerateSystemMetadata();
|
98
|
upgrader.upgrade();
|
99
|
}
|
100
|
|
101
|
public void testCreateResourceMap() {
|
102
|
|
103
|
try {
|
104
|
Identifier resourceMapId = new Identifier();
|
105
|
resourceMapId.setValue("doi://1234/AA/map.1.1");
|
106
|
Identifier metadataId = new Identifier();
|
107
|
metadataId.setValue("doi://1234/AA/meta.1.1");
|
108
|
List<Identifier> dataIds = new ArrayList<Identifier>();
|
109
|
Identifier dataId = new Identifier();
|
110
|
dataId.setValue("doi://1234/AA/data.1.1");
|
111
|
Identifier dataId2 = new Identifier();
|
112
|
dataId2.setValue("doi://1234/AA/data.2.1");
|
113
|
dataIds.add(dataId);
|
114
|
dataIds.add(dataId2);
|
115
|
Map<Identifier, List<Identifier>> idMap = new HashMap<Identifier, List<Identifier>>();
|
116
|
idMap.put(metadataId, dataIds);
|
117
|
ResourceMapFactory rmf = ResourceMapFactory.getInstance();
|
118
|
ResourceMap resourceMap = rmf.createResourceMap(resourceMapId, idMap);
|
119
|
assertNotNull(resourceMap);
|
120
|
String rdfXml = ResourceMapFactory.getInstance().serializeResourceMap(resourceMap);
|
121
|
assertNotNull(rdfXml);
|
122
|
System.out.println(rdfXml);
|
123
|
|
124
|
// now put it back in an object
|
125
|
Map<Identifier, Map<Identifier, List<Identifier>>> retPackageMap = ResourceMapFactory.getInstance().parseResourceMap(rdfXml);
|
126
|
Identifier retPackageId = retPackageMap.keySet().iterator().next();
|
127
|
|
128
|
// Package Identifiers should match
|
129
|
assertEquals(resourceMapId.getValue(), retPackageId.getValue());
|
130
|
System.out.println("PACKAGEID IS: " + retPackageId.getValue());
|
131
|
|
132
|
// Get the Map of metadata/data identifiers
|
133
|
Map<Identifier, List<Identifier>> retIdMap = retPackageMap.get(retPackageId);
|
134
|
|
135
|
// same size
|
136
|
assertEquals(idMap.keySet().size(), retIdMap.keySet().size());
|
137
|
for (Identifier key : idMap.keySet()) {
|
138
|
System.out.println(" ORIGINAL: " + key.getValue());
|
139
|
List<Identifier> contained = idMap.get(key);
|
140
|
for (Identifier cKey : contained) {
|
141
|
System.out.println(" CONTAINS: " + cKey.getValue());
|
142
|
}
|
143
|
}
|
144
|
for (Identifier key : retIdMap.keySet()) {
|
145
|
System.out.println(" RETURNED: " + key.getValue());
|
146
|
List<Identifier> contained = idMap.get(key);
|
147
|
for (Identifier cKey : contained) {
|
148
|
System.out.println(" CONTAINS: " + cKey.getValue());
|
149
|
}
|
150
|
}
|
151
|
|
152
|
// same value
|
153
|
assertEquals(idMap.keySet().iterator().next().getValue(), retIdMap.keySet().iterator().next().getValue());
|
154
|
|
155
|
} catch (Exception e) {
|
156
|
e.printStackTrace();
|
157
|
fail();
|
158
|
}
|
159
|
}
|
160
|
|
161
|
/**
|
162
|
* Requires ORE to be present and parsed in the solr index to pass
|
163
|
*/
|
164
|
public void testOreExistsFor() {
|
165
|
String pid = "tao.1.1";
|
166
|
Identifier guid = new Identifier();
|
167
|
guid.setValue(pid);
|
168
|
boolean exists = SystemMetadataFactory.oreExistsFor(guid);
|
169
|
assertTrue(exists);
|
170
|
guid.setValue("BAD");
|
171
|
exists = SystemMetadataFactory.oreExistsFor(guid);
|
172
|
assertFalse(exists);
|
173
|
}
|
174
|
|
175
|
}
|
176
|
|