Project

General

Profile

« Previous | Next » 

Revision 8135

Added by Jing Tao over 11 years ago

Add a junit test to test resourcemap subprocessor.

View differences:

metacat-index/src/test/java/edu/ucsb/nceas/metacat/index/resourcemap/ResourceMapSubprocessorIT.java
1
package edu.ucsb.nceas.metacat.index.resourcemap;
2

  
3
import static org.junit.Assert.*;
4

  
5
import java.io.File;
6
import java.io.FileInputStream;
7
import java.util.ArrayList;
8
import java.util.HashMap;
9
import java.util.List;
10
import java.util.Map;
11

  
12
import javax.xml.parsers.DocumentBuilder;
13
import javax.xml.parsers.DocumentBuilderFactory;
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.dataone.configuration.Settings;
19
import org.junit.Test;
20
import org.w3c.dom.Document;
21
import org.w3c.dom.Node;
22

  
23
import edu.ucsb.nceas.metacat.index.SolrIndex;
24
import edu.ucsb.nceas.metacat.index.SolrIndexIT;
25

  
26
public class ResourceMapSubprocessorIT {
27
    
28
    /**
29
     * Test the case that the resource map contains a component which is not int the solr index server.
30
     * @throws Exception
31
     */
32
    @Test
33
    public void testProcessDocument() throws Exception {
34
        //Settings.getConfiguration().setProperty("dataone.hazelcast.configFilePath", "../lib/hazelcast.xml");
35
        String id = "resourceMap_urn:uuid:04780847-6082-455b-9831-22269c9ec0a5";
36
        Document doc = getResourceMapDoc();
37
        System.out.println("the lenght of child is "+doc.getChildNodes().getLength());
38
        System.out.println("the name of the childs is "+doc.getChildNodes().item(0).getLocalName());
39
        Node child = doc.getChildNodes().item(0);
40
        List<SolrElementField> sysSolrFields = new ArrayList<SolrElementField>();
41
        SolrDoc indexDocument = new SolrDoc(sysSolrFields);
42
        Map<String, SolrDoc> docs = new HashMap<String, SolrDoc>();
43
        docs.put(id, indexDocument);
44
        ResourceMapSubprocessor processor = getResourceMapSubprocessor();
45
        try {
46
            processor.processDocument(id, docs, doc);
47
            assertTrue("ResourceMapProcessor should throw an exception because the resource map has a component which doesn't exist.", false);
48
        } catch (Exception e) {
49
            assertTrue("ResourceMapProcessor should throw a ResourceMapException because the resource map has a component which doesn't exist.", e instanceof ResourceMapException);
50
            //System.out.println("the message is "+e.getMessage());
51
        }
52
    }
53
    
54
    /*
55
     * Get the document format of the test resource map file 
56
     */
57
    private Document getResourceMapDoc() throws Exception{
58
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
59
        documentBuilderFactory.setNamespaceAware(true);
60
        DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
61
        File file = new File("src/test/resources/resorcemap-example");
62
        Document doc = builder.parse(new FileInputStream(file));
63
        return doc;
64
    }
65
    
66
    /*
67
     * Get the ResourceMapSubprocessor
68
     */
69
    private ResourceMapSubprocessor getResourceMapSubprocessor() throws Exception {
70
        ResourceMapSubprocessor resorceMapprocessor = null;
71
        SolrIndex solrIndex = SolrIndexIT.generateSolrIndex();
72
        List<IDocumentSubprocessor> processors = solrIndex.getSubprocessors();
73
        for(IDocumentSubprocessor processor : processors) {
74
            if(processor instanceof ResourceMapSubprocessor) {
75
                resorceMapprocessor = (ResourceMapSubprocessor) processor;
76
            }
77
        }
78
        return resorceMapprocessor;
79
    }
80
}
metacat-index/src/test/resources/resorcemap-example
1
<rdf:RDF
2
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
3
    xmlns:foaf="http://xmlns.com/foaf/0.1/"
4
    xmlns:owl="http://www.w3.org/2002/07/owl#"
5
    xmlns:dc="http://purl.org/dc/elements/1.1/"
6
    xmlns:ore="http://www.openarchives.org/ore/terms/"
7
    xmlns:dcterms="http://purl.org/dc/terms/"
8
    xmlns:j.0="http://purl.org/spar/cito/" > 
9
  <rdf:Description rdf:about="https://cn.dataone.org/cn/v1/resolve/urn:uuid:79ed958f-e5e3-438e-b5e0-c347abbe448c">
10
    <ore:isAggregatedBy>https://cn.dataone.org/cn/v1/resolve/resourceMap_urn:uuid:04780847-6082-455b-9831-22269c9ec0a5#aggregation</ore:isAggregatedBy>
11
    <dcterms:identifier rdf:datatype="http://www.w3.org/2001/XMLSchema#string">urn:uuid:79ed958f-e5e3-438e-b5e0-c347abbe448c</dcterms:identifier>
12
    <j.0:isDocumentedBy rdf:resource="https://cn.dataone.org/cn/v1/resolve/liu.100111.1"/>
13
  </rdf:Description>
14
  <rdf:Description rdf:nodeID="A0">
15
    <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Java libclient</foaf:name>
16
    <rdf:type rdf:resource="http://purl.org/dc/terms/Agent"/>
17
  </rdf:Description>
18
  <rdf:Description rdf:about="https://cn.dataone.org/cn/v1/resolve/resourceMap_urn:uuid:04780847-6082-455b-9831-22269c9ec0a5">
19
    <dcterms:modified rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2013-06-03T17:00:17.612-07:00</dcterms:modified>
20
    <ore:describes rdf:resource="https://cn.dataone.org/cn/v1/resolve/resourceMap_urn:uuid:04780847-6082-455b-9831-22269c9ec0a5#aggregation"/>
21
    <rdf:type rdf:resource="http://www.openarchives.org/ore/terms/ResourceMap"/>
22
    <dc:creator rdf:nodeID="A0"/>
23
    <dcterms:identifier rdf:datatype="http://www.w3.org/2001/XMLSchema#string">resourceMap_urn:uuid:04780847-6082-455b-9831-22269c9ec0a5</dcterms:identifier>
24
  </rdf:Description>
25
  <rdf:Description rdf:about="https://cn.dataone.org/cn/v1/resolve/resourceMap_urn:uuid:04780847-6082-455b-9831-22269c9ec0a5#aggregation">
26
    <rdf:type rdf:resource="http://www.openarchives.org/ore/terms/Aggregation"/>
27
    <ore:isDescribedBy rdf:resource="https://cn.dataone.org/cn/v1/resolve/resourceMap_urn:uuid:04780847-6082-455b-9831-22269c9ec0a5"/>
28
    <dc:title>DataONE Aggregation</dc:title>
29
    <ore:aggregates rdf:resource="https://cn.dataone.org/cn/v1/resolve/liu.100111.1"/>
30
    <ore:aggregates rdf:resource="https://cn.dataone.org/cn/v1/resolve/urn:uuid:79ed958f-e5e3-438e-b5e0-c347abbe448c"/>
31
  </rdf:Description>
32
  <rdf:Description rdf:about="https://cn.dataone.org/cn/v1/resolve/liu.100111.1">
33
    <ore:isAggregatedBy>https://cn.dataone.org/cn/v1/resolve/resourceMap_urn:uuid:04780847-6082-455b-9831-22269c9ec0a5#aggregation</ore:isAggregatedBy>
34
    <dcterms:identifier rdf:datatype="http://www.w3.org/2001/XMLSchema#string">liu.100111.1</dcterms:identifier>
35
    <j.0:documents rdf:resource="https://cn.dataone.org/cn/v1/resolve/urn:uuid:79ed958f-e5e3-438e-b5e0-c347abbe448c"/>
36
  </rdf:Description>
37
</rdf:RDF>

Also available in: Unified diff