Skip to content

Commit

Permalink
Add a junit test file for the changes on attributes. Now it can handl…
Browse files Browse the repository at this point in the history
…e the other entities.
  • Loading branch information
taojing2002 committed Aug 12, 2021
1 parent 4fa8f8c commit 0b09572
Show file tree
Hide file tree
Showing 3 changed files with 201 additions and 1 deletion.
190 changes: 190 additions & 0 deletions src/test/java/org/dataone/cn/index/SolrFieldXPathEmlAttributeTest.java
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.

Copy link
@amoeba

amoeba Aug 12, 2021

Contributor

I think something got mangled here:

This work was crfield name: eated" by participants

should probably read

This work was created by participants

* 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));
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<eml:eml xmlns:eml="https://eml.ecoinformatics.org/eml-2.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:stmml="http://www.xml-cml.org/schema/stmml-1.2" packageId="urn:uuid:4ad48407-8044-4f4a-9596-18e9cb221656" xsi:schemaLocation="https://eml.ecoinformatics.org/eml-2.2.0 https://eml.ecoinformatics.org/eml-2.2.0/eml.xsd" system="knb">
<eml:eml xmlns:eml="https://eml.ecoinformatics.org/eml-2.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:stmml="http://www.xml-cml.org/schema/stmml-1.2" packageId="urn:uuid:4ad48407-8044-4f4a-9596-18e9cb221658" xsi:schemaLocation="https://eml.ecoinformatics.org/eml-2.2.0 https://eml.ecoinformatics.org/eml-2.2.0/eml.xsd" system="knb">
<dataset>
<alternateIdentifier>https://doi.org/10.5061/dryad.0k6djh9z4</alternateIdentifier>
<title>Chum salmon escapement on Bonanza River in Norton Sound, Alaska</title>
Expand Down
10 changes: 10 additions & 0 deletions src/test/resources/org/dataone/cn/index/test-context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -497,4 +497,14 @@ xmlns:context="http://www.springframework.org/schema/context"
<constructor-arg type="java.lang.String"
value="org/dataone/cn/index/resources/d1_testdocs/json-ld/doi.org_10.5061_dryad.41sk145.jsonld"/>
</bean>

<bean id="emlWithDataTableTestDoc" class="org.springframework.core.io.ClassPathResource" >
<constructor-arg type="java.lang.String"
value="org/dataone/cn/index/resources/d1_testdocs/eml220/eml2.2.0testdatatable.xml"/>
</bean>

<bean id="emlWithOtherEntityTestDoc" class="org.springframework.core.io.ClassPathResource" >
<constructor-arg type="java.lang.String"
value="org/dataone/cn/index/resources/d1_testdocs/eml220/eml2.2.0testotherentity.xml"/>
</bean>
</beans>

0 comments on commit 0b09572

Please sign in to comment.