Project

General

Profile

« Previous | Next » 

Revision 9020

use input stream instead of Document for resource map processing test

View differences:

ResourceMapSubprocessorIT.java
4 4

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

  
12
import javax.xml.parsers.DocumentBuilder;
13
import javax.xml.parsers.DocumentBuilderFactory;
14

  
15 13
import org.dataone.cn.indexer.parser.IDocumentSubprocessor;
16 14
import org.dataone.cn.indexer.solrhttp.SolrDoc;
17 15
import org.dataone.cn.indexer.solrhttp.SolrElementField;
18 16
import org.junit.Test;
19
import org.w3c.dom.Document;
20
import org.w3c.dom.Node;
21 17

  
22 18
import edu.ucsb.nceas.metacat.index.SolrIndex;
23 19
import edu.ucsb.nceas.metacat.index.SolrIndexIT;
......
32 28
    public void testProcessDocument() throws Exception {
33 29
        //Settings.getConfiguration().setProperty("dataone.hazelcast.configFilePath", "../lib/hazelcast.xml");
34 30
        String id = "resourceMap_urn:uuid:04780847-6082-455b-9831-22269c9ec0a5";
35
        Document doc = getResourceMapDoc();
36
        System.out.println("the lenght of child is "+doc.getChildNodes().getLength());
37
        System.out.println("the name of the childs is "+doc.getChildNodes().item(0).getLocalName());
38
        Node child = doc.getChildNodes().item(0);
31
        InputStream is = getResourceMapDoc();
39 32
        List<SolrElementField> sysSolrFields = new ArrayList<SolrElementField>();
40 33
        SolrDoc indexDocument = new SolrDoc(sysSolrFields);
41 34
        Map<String, SolrDoc> docs = new HashMap<String, SolrDoc>();
42 35
        docs.put(id, indexDocument);
43 36
        ResourceMapSubprocessor processor = getResourceMapSubprocessor();
44 37
        try {
45
            processor.processDocument(id, docs, doc);
38
            processor.processDocument(id, docs, is);
46 39
            assertTrue("ResourceMapProcessor should throw an exception because the resource map has a component which doesn't exist.", false);
47 40
        } catch (Exception e) {
48 41
            assertTrue("ResourceMapProcessor should throw a ResourceMapException because the resource map has a component which doesn't exist.", e instanceof ResourceMapException);
......
53 46
    /*
54 47
     * Get the document format of the test resource map file 
55 48
     */
56
    private Document getResourceMapDoc() throws Exception{
57
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
58
        documentBuilderFactory.setNamespaceAware(true);
59
        DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
60
        File file = new File("src/test/resources/resorcemap-example");
61
        Document doc = builder.parse(new FileInputStream(file));
62
        return doc;
49
    private InputStream getResourceMapDoc() throws Exception{
50
    	File file = new File("src/test/resources/resorcemap-example");
51
        InputStream is = new FileInputStream(file);
52
        return is;
63 53
    }
64 54
    
65 55
    /*

Also available in: Unified diff