Revision 7492
Added by ben leinfelder almost 12 years ago
test/edu/ucsb/nceas/metacat/admin/upgrade/dataone/GenerateSystemMetadataTest.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
package edu.ucsb.nceas.metacat.admin.upgrade.dataone; |
27 | 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 |
|
|
28 | 37 |
import junit.framework.Test; |
29 | 38 |
import junit.framework.TestSuite; |
30 | 39 |
import edu.ucsb.nceas.MCTestCase; |
... | ... | |
65 | 74 |
TestSuite suite = new TestSuite(); |
66 | 75 |
suite.addTest(new GenerateSystemMetadataTest("initialize")); |
67 | 76 |
// Test basic functions |
68 |
suite.addTest(new GenerateSystemMetadataTest("upgrade")); |
|
69 |
|
|
77 |
//suite.addTest(new GenerateSystemMetadataTest("upgrade")); |
|
78 |
// test ORE generation |
|
79 |
suite.addTest(new GenerateSystemMetadataTest("testCreateResourceMap")); |
|
80 |
|
|
70 | 81 |
return suite; |
71 | 82 |
} |
72 | 83 |
|
... | ... | |
83 | 94 |
upgrader.upgrade(); |
84 | 95 |
} |
85 | 96 |
|
97 |
public void testCreateResourceMap() { |
|
98 |
|
|
99 |
try { |
|
100 |
Identifier resourceMapId = new Identifier(); |
|
101 |
resourceMapId.setValue("doi://1234/AA/map.1.1"); |
|
102 |
Identifier metadataId = new Identifier(); |
|
103 |
metadataId.setValue("doi://1234/AA/meta.1.1"); |
|
104 |
List<Identifier> dataIds = new ArrayList<Identifier>(); |
|
105 |
Identifier dataId = new Identifier(); |
|
106 |
dataId.setValue("doi://1234/AA/data.1.1"); |
|
107 |
Identifier dataId2 = new Identifier(); |
|
108 |
dataId2.setValue("doi://1234/AA/data.2.1"); |
|
109 |
dataIds.add(dataId); |
|
110 |
dataIds.add(dataId2); |
|
111 |
Map<Identifier, List<Identifier>> idMap = new HashMap<Identifier, List<Identifier>>(); |
|
112 |
idMap.put(metadataId, dataIds); |
|
113 |
ResourceMapFactory rmf = ResourceMapFactory.getInstance(); |
|
114 |
ResourceMap resourceMap = rmf.createResourceMap(resourceMapId, idMap); |
|
115 |
assertNotNull(resourceMap); |
|
116 |
String rdfXml = ResourceMapFactory.getInstance().serializeResourceMap(resourceMap); |
|
117 |
assertNotNull(rdfXml); |
|
118 |
System.out.println(rdfXml); |
|
119 |
|
|
120 |
// now put it back in an object |
|
121 |
Map<Identifier, Map<Identifier, List<Identifier>>> retPackageMap = ResourceMapFactory.getInstance().parseResourceMap(rdfXml); |
|
122 |
Identifier retPackageId = retPackageMap.keySet().iterator().next(); |
|
123 |
|
|
124 |
// Package Identifiers should match |
|
125 |
assertEquals(resourceMapId.getValue(), retPackageId.getValue()); |
|
126 |
System.out.println("PACKAGEID IS: " + retPackageId.getValue()); |
|
127 |
|
|
128 |
// Get the Map of metadata/data identifiers |
|
129 |
Map<Identifier, List<Identifier>> retIdMap = retPackageMap.get(retPackageId); |
|
130 |
|
|
131 |
// same size |
|
132 |
assertEquals(idMap.keySet().size(), retIdMap.keySet().size()); |
|
133 |
for (Identifier key : idMap.keySet()) { |
|
134 |
System.out.println(" ORIGINAL: " + key.getValue()); |
|
135 |
List<Identifier> contained = idMap.get(key); |
|
136 |
for (Identifier cKey : contained) { |
|
137 |
System.out.println(" CONTAINS: " + cKey.getValue()); |
|
138 |
} |
|
139 |
} |
|
140 |
for (Identifier key : retIdMap.keySet()) { |
|
141 |
System.out.println(" RETURNED: " + key.getValue()); |
|
142 |
List<Identifier> contained = idMap.get(key); |
|
143 |
for (Identifier cKey : contained) { |
|
144 |
System.out.println(" CONTAINS: " + cKey.getValue()); |
|
145 |
} |
|
146 |
} |
|
147 |
|
|
148 |
// same value |
|
149 |
assertEquals(idMap.keySet().iterator().next().getValue(), retIdMap.keySet().iterator().next().getValue()); |
|
150 |
|
|
151 |
} catch (Exception e) { |
|
152 |
e.printStackTrace(); |
|
153 |
fail(); |
|
154 |
} |
|
155 |
} |
|
156 |
|
|
86 | 157 |
} |
87 | 158 |
|
Also available in: Unified diff
remove older lucene library and include ORE test to make sure that change does not prevent us from generating OREs. http://bugzilla.ecoinformatics.org/show_bug.cgi?id=5874