1
|
package edu.ucsb.nceas.metacat.index.annotation;
|
2
|
|
3
|
import static org.junit.Assert.assertTrue;
|
4
|
|
5
|
import java.io.ByteArrayOutputStream;
|
6
|
import java.io.File;
|
7
|
import java.io.FileInputStream;
|
8
|
import java.io.InputStream;
|
9
|
import java.util.ArrayList;
|
10
|
import java.util.HashMap;
|
11
|
import java.util.List;
|
12
|
import java.util.Map;
|
13
|
import java.util.Set;
|
14
|
|
15
|
import org.dataone.cn.indexer.parser.IDocumentSubprocessor;
|
16
|
import org.dataone.cn.indexer.solrhttp.SolrDoc;
|
17
|
import org.dataone.cn.indexer.solrhttp.SolrElementField;
|
18
|
import org.junit.Test;
|
19
|
import org.dataone.cn.indexer.annotation.RdfXmlSubprocessor;
|
20
|
|
21
|
import edu.ucsb.nceas.metacat.index.SolrIndex;
|
22
|
import edu.ucsb.nceas.metacat.index.SolrIndexIT;
|
23
|
|
24
|
public class MetacatRdfXmlSubprocessorTest {
|
25
|
|
26
|
/**
|
27
|
* Test the case that the resource map contains a component which is not int the solr index server.
|
28
|
* @throws Exception
|
29
|
*/
|
30
|
@Test
|
31
|
public void testProcessDocument() throws Exception {
|
32
|
//Settings.getConfiguration().setProperty("dataone.hazelcast.configFilePath", "../lib/hazelcast.xml");
|
33
|
String id = "resourceMap_urn:uuid:04780847-6082-455b-9831-22269c9ec0a6";
|
34
|
InputStream is = getResourceMapDoc();
|
35
|
List<SolrElementField> sysSolrFields = new ArrayList<SolrElementField>();
|
36
|
SolrElementField idField = new SolrElementField();
|
37
|
idField.setName("id");
|
38
|
idField.setValue(id);
|
39
|
sysSolrFields.add(idField);
|
40
|
SolrDoc indexDocument = new SolrDoc(sysSolrFields);
|
41
|
Map<String, SolrDoc> docs = new HashMap<String, SolrDoc>();
|
42
|
docs.put(id, indexDocument);
|
43
|
MetacatRdfXmlSubprocessor processor = getMetacatRdfXmlSubprocessor();
|
44
|
|
45
|
try {
|
46
|
Map<String, SolrDoc> result = processor.processDocument(id, docs, is);
|
47
|
Set<String> ids = result.keySet();
|
48
|
for(String newId: ids) {
|
49
|
SolrDoc resultSolrDoc = result.get(newId);
|
50
|
if(newId.equals("urn:uuid:2c20432e-116a-4085-b8d6-abfc4b2dada2")){
|
51
|
SolrElementField field1 = resultSolrDoc.getField("prov_wasDerivedFrom");
|
52
|
assertTrue(" the wasDerivedFrom value should be urn:uuid:621a115f-f1ed-4bef-bca5-f8741793a540. But the real value is "+field1.getValue(), field1.getValue().equals("urn:uuid:621a115f-f1ed-4bef-bca5-f8741793a540"));
|
53
|
SolrElementField field2 = resultSolrDoc.getField("prov_generatedByExecution");
|
54
|
assertTrue("the wasGeneratedBy value should be urn:uuid:9ceeaeb3-6ef3-4b1e-bc4d-96e299fab3a4. But the real value is"+field2.getValue(), field2.getValue().equals("urn:uuid:9ceeaeb3-6ef3-4b1e-bc4d-96e299fab3a4"));
|
55
|
} else if (newId.equals("urn:uuid:9ceeaeb3-6ef3-4b1e-bc4d-96e299fab3a4")) {
|
56
|
SolrElementField field1 = resultSolrDoc.getField("prov_used");
|
57
|
//assertTrue(" the used value should be urn:uuid:621a115f-f1ed-4bef-bca5-f8741793a540. But the real value is "+field1.getValue(), field1.getValue().equals("urn:uuid:621a115f-f1ed-4bef-bca5-f8741793a540"));
|
58
|
|
59
|
} else if (newId.equals("urn:uuid:621a115f-f1ed-4bef-bca5-f8741793a540")) {
|
60
|
List<String>list = resultSolrDoc.getAllFieldValues("prov_wasDerivedFrom");
|
61
|
assertTrue("The list must contain urn:uuid:ee635a61-c930-444d-8214-db65178a1a47", list.contains("urn:uuid:ee635a61-c930-444d-8214-db65178a1a47"));
|
62
|
assertTrue("The list must contain urn:uuid:23495598-d50b-4317-b0e1-05a9d9e52632", list.contains("urn:uuid:23495598-d50b-4317-b0e1-05a9d9e52632"));
|
63
|
assertTrue("The list must contain urn:uuid:urn:uuid:672ba6c5-8812-4c05-a324-246af172c67a", list.contains("urn:uuid:672ba6c5-8812-4c05-a324-246af172c67a"));
|
64
|
assertTrue("The list must contain urn:uuid:e534b2ab-3a1b-44ed-8a99-ce54a0487aea", list.contains("urn:uuid:e534b2ab-3a1b-44ed-8a99-ce54a0487aea"));
|
65
|
list = resultSolrDoc.getAllFieldValues("prov_generatedByExecution");
|
66
|
assertTrue("The list must contain urn:uuid:d8e46217-2650-42b2-896f-0f006b1a2d3b", list.contains("urn:uuid:d8e46217-2650-42b2-896f-0f006b1a2d3b"));
|
67
|
list = resultSolrDoc.getAllFieldValues("prov_hasDerivations");
|
68
|
assertTrue("The output must contain prov_hasDerivations urn:uuid:2c20432e-116a-4085-b8d6-abfc4b2dada2", list.contains("urn:uuid:2c20432e-116a-4085-b8d6-abfc4b2dada2"));
|
69
|
} else if (newId.equals("urn:uuid:a0e104da-c925-4765-af60-29310de1b99a")) {
|
70
|
List<String>list = resultSolrDoc.getAllFieldValues("prov_generatedByExecution");
|
71
|
assertTrue("The list must contain urn:uuid:9ceeaeb3-6ef3-4b1e-bc4d-96e299fab3a4", list.contains("urn:uuid:9ceeaeb3-6ef3-4b1e-bc4d-96e299fab3a4"));
|
72
|
} else if (newId.equals("urn:uuid:d8e46217-2650-42b2-896f-0f006b1a2d3b")) {
|
73
|
List<String>list = resultSolrDoc.getAllFieldValues("prov_used");
|
74
|
/*assertTrue("The list must contain urn:uuid:ee635a61-c930-444d-8214-db65178a1a47", list.contains("urn:uuid:ee635a61-c930-444d-8214-db65178a1a47"));
|
75
|
assertTrue("The list must contain urn:uuid:23495598-d50b-4317-b0e1-05a9d9e52632", list.contains("urn:uuid:23495598-d50b-4317-b0e1-05a9d9e52632"));
|
76
|
assertTrue("The list must contain urn:uuid:672ba6c5-8812-4c05-a324-246af172c67a", list.contains("urn:uuid:672ba6c5-8812-4c05-a324-246af172c67a"));
|
77
|
assertTrue("The list must contain urn:uuid:e534b2ab-3a1b-44ed-8a99-ce54a0487aea", list.contains("urn:uuid:e534b2ab-3a1b-44ed-8a99-ce54a0487aea"));*/
|
78
|
}
|
79
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
80
|
resultSolrDoc.serialize(baos, "UTF-8");
|
81
|
System.out.println("after process, the solr doc is \n"+baos.toString());
|
82
|
}
|
83
|
|
84
|
} catch (Exception e) {
|
85
|
e.printStackTrace();
|
86
|
assertTrue("It shouldn't throw an exception.", false);
|
87
|
}
|
88
|
}
|
89
|
|
90
|
/*
|
91
|
* Get the document format of the test resource map file
|
92
|
*/
|
93
|
private InputStream getResourceMapDoc() throws Exception{
|
94
|
File file = new File("src/test/resources/rdfxml-example.xml");
|
95
|
InputStream is = new FileInputStream(file);
|
96
|
return is;
|
97
|
}
|
98
|
|
99
|
/*
|
100
|
* Get the ResourceMapSubprocessor
|
101
|
*/
|
102
|
private MetacatRdfXmlSubprocessor getMetacatRdfXmlSubprocessor() throws Exception {
|
103
|
MetacatRdfXmlSubprocessor resorceMapprocessor = null;
|
104
|
SolrIndex solrIndex = SolrIndexIT.generateSolrIndex();
|
105
|
List<IDocumentSubprocessor> processors = solrIndex.getSubprocessors();
|
106
|
for(IDocumentSubprocessor processor : processors) {
|
107
|
if(processor instanceof MetacatRdfXmlSubprocessor) {
|
108
|
resorceMapprocessor = (MetacatRdfXmlSubprocessor) processor;
|
109
|
}
|
110
|
}
|
111
|
return resorceMapprocessor;
|
112
|
}
|
113
|
|
114
|
|
115
|
}
|