-
Notifications
You must be signed in to change notification settings - Fork 1
/
SolrFieldXPathEmlAttributeTest.java
190 lines (168 loc) · 9.33 KB
/
SolrFieldXPathEmlAttributeTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/**
* This work was crfield name: eated" by participants in the DataONE project, and is
* jointly copyrighted by participating institutions in DataONE. For
* more information on DataONE, see our web site at http://dataone.org.
*
* Copyright 2021
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Id$
*/
package org.dataone.cn.index;
import java.io.File;
import java.util.HashMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dataone.cn.index.processor.IndexTaskProcessor;
import org.dataone.cn.indexer.parser.JsonLdSubprocessor;
import org.dataone.cn.indexer.parser.ScienceMetadataDocumentSubprocessor;
import org.dataone.cn.indexer.resourcemap.RdfXmlProcessorTest;
import org.dataone.service.types.v1.NodeReference;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.io.Resource;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
/**
* A junit test to test the xpath of attributes of EML for dataTables or otherEntities
* @author tao
*
*/
@ThreadLeakScope(ThreadLeakScope.Scope.NONE)
public class SolrFieldXPathEmlAttributeTest extends JsonLdSubprocessorTest {
/* Log it */
private static Log log = LogFactory.getLog( SolrFieldXPathEmlAttributeTest.class);
/* The EML objects */
private Resource emlWithDataTable;
private Resource emlWithOtherEntity;
/* An instance of the EML220 Subprocessor */
private ScienceMetadataDocumentSubprocessor eml220Subprocessor;
/* Store a map of expected Solr fields and their values for testing */
private HashMap<String, String> expectedFields = new HashMap<String, String>();
private static final int SLEEPTIME = 5000;
/**
* For each test, set up the Solr service and test data
*
* @throws Exception
*/
@Before
public void setUp() throws Exception {
// Start up the embedded Jetty server and Solr service
super.setUp();
emlWithDataTable = (Resource) context.getBean("emlWithDataTableTestDoc");
emlWithOtherEntity = (Resource) context.getBean("emlWithOtherEntityTestDoc");
eml220Subprocessor = (ScienceMetadataDocumentSubprocessor) context.getBean("eml220Subprocessor");
}
/**
* For each test, clean up, bring down the Solr service
*/
@After
public void tearDown() throws Exception {
super.tearDown();
}
/**
* Test the end to end index processing an EML document with a data table
*
* @throws Exception
*/
//@Ignore
@Test
public void testInsertEmlWithDataTable() throws Exception {
/* variables used to populate system metadata for each resource */
File object = null;
String formatId = null;
NodeReference nodeid = new NodeReference();
nodeid.setValue("urn:node:mnTestXXXX");
String userDN = "uid=tester,o=testers,dc=dataone,dc=org";
// Insert the schema.org file into the task queue
String id = "urn:uuid:4ad48407-8044-4f4a-9596-18e9cb221656";
formatId = "https://eml.ecoinformatics.org/eml-2.2.0";
insertResource(id, formatId, emlWithDataTable, nodeid, userDN);
Thread.sleep(SLEEPTIME);
// now process the tasks
processor.processIndexTaskQueue();
Thread.sleep(SLEEPTIME);
Thread.sleep(SLEEPTIME);
Thread.sleep(SLEEPTIME);
Thread.sleep(SLEEPTIME);
assertPresentInSolrIndex(id);
assertTrue(compareFieldValue(id, "title", "Chum salmon escapement on Bonanza River in Norton Sound, Alaska"));
String[] projects = {"Chum salmon escapement on Bonanza River in Norton Sound, Alaska"};
assertTrue(compareFieldValue(id, "project", projects));
String[] attributeNames = {"Species","Sp code","Sample Date","GumCard #","Fish #","External Sex","METF Length", "Comments",
"ageFresh", "ageSalt", "ageErrorID"};
assertTrue(compareFieldValue(id, "attributeName", attributeNames));
String[] attributeDescriptions = {"Species of salmon sampled","ADF&G species codes","Date that a salmon was collected",
"Scale gum card identifier","Fish identifier/number",
"Code which represents the sex of a sampled salmon. Sex was determined using external features.",
"Mid-eye to fork of tail fish length measurement","comments about sample",
"Freshwater age of fish in years","Saltwater age of fish in years","Source of error in age estimate"};
assertTrue(compareFieldValue(id, "attributeDescription", attributeDescriptions));
String[] attributeUnits = {"millimeter","dimensionless","dimensionless"};
assertTrue(compareFieldValue(id, "attributeUnit", attributeUnits));
String[] attributes = {"Species Species of salmon sampled","Sp code ADF&G species codes","Sample Date Date that a salmon was collected",
"GumCard # Scale gum card identifier","Fish # Fish identifier/number",
"External Sex Code which represents the sex of a sampled salmon. Sex was determined using external features.",
"METF Length Mid-eye to fork of tail fish length measurement millimeter","Comments comments about sample",
"ageFresh Freshwater age of fish in years dimensionless","ageSalt Saltwater age of fish in years dimensionless",
"ageErrorID Source of error in age estimate"};
assertTrue(compareFieldValue(id, "attribute", attributes));
}
/**
* Test the end to end index processing an EML document with other entities
*
* @throws Exception
*/
@Test
public void testInsertEmlWithOtherEntity() throws Exception {
File object = null;
String formatId = null;
NodeReference nodeid = new NodeReference();
nodeid.setValue("urn:node:mnTestXXXX");
String userDN = "uid=tester,o=testers,dc=dataone,dc=org";
// Insert the schema.org file into the task queue
String id = "urn:uuid:4ad48407-8044-4f4a-9596-18e9cb221658";
formatId = "https://eml.ecoinformatics.org/eml-2.2.0";
insertResource(id, formatId, emlWithOtherEntity, nodeid, userDN);
Thread.sleep(SLEEPTIME);
// now process the tasks
processor.processIndexTaskQueue();
Thread.sleep(SLEEPTIME);
Thread.sleep(SLEEPTIME);
Thread.sleep(SLEEPTIME);
Thread.sleep(SLEEPTIME);
assertPresentInSolrIndex(id);
assertTrue(compareFieldValue(id, "title", "Chum salmon escapement on Bonanza River in Norton Sound, Alaska"));
String[] projects = {"Chum salmon escapement on Bonanza River in Norton Sound, Alaska"};
assertTrue(compareFieldValue(id, "project", projects));
String[] attributeNames = {"Species","Sp code","Sample Date","GumCard #","Fish #","External Sex","METF Length", "Comments",
"ageFresh", "ageSalt", "ageErrorID"};
assertTrue(compareFieldValue(id, "attributeName", attributeNames));
String[] attributeDescriptions = {"Species of salmon sampled","ADF&G species codes","Date that a salmon was collected",
"Scale gum card identifier","Fish identifier/number",
"Code which represents the sex of a sampled salmon. Sex was determined using external features.",
"Mid-eye to fork of tail fish length measurement","comments about sample",
"Freshwater age of fish in years","Saltwater age of fish in years","Source of error in age estimate"};
assertTrue(compareFieldValue(id, "attributeDescription", attributeDescriptions));
String[] attributeUnits = {"millimeter","dimensionless", "dimensionless"};
assertTrue(compareFieldValue(id, "attributeUnit", attributeUnits));
String[] attributes = {"Species Species of salmon sampled","Sp code ADF&G species codes","Sample Date Date that a salmon was collected",
"GumCard # Scale gum card identifier","Fish # Fish identifier/number",
"External Sex Code which represents the sex of a sampled salmon. Sex was determined using external features.",
"METF Length Mid-eye to fork of tail fish length measurement millimeter","Comments comments about sample",
"ageFresh Freshwater age of fish in years dimensionless","ageSalt Saltwater age of fish in years dimensionless",
"ageErrorID Source of error in age estimate"};
assertTrue(compareFieldValue(id, "attribute", attributes));
}
}