-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a junit test file for the changes on attributes. Now it can handl…
…e the other entities.
- Loading branch information
1 parent
4fa8f8c
commit 0b09572
Showing
3 changed files
with
201 additions
and
1 deletion.
There are no files selected for viewing
190 changes: 190 additions & 0 deletions
190
src/test/java/org/dataone/cn/index/SolrFieldXPathEmlAttributeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
/** | ||
* This work was crfield name: eated" by participants in the DataONE project, and is | ||
This comment has been minimized.
Sorry, something went wrong. |
||
* 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)); | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...t/resources/org/dataone/cn/index/resources/d1_testdocs/eml220/eml2.2.0testotherentity.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I think something got mangled here:
should probably read