Project

General

Profile

1
package edu.ucsb.nceas.metacat.index.resourcemap;
2

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

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

    
13
import org.dataone.cn.indexer.parser.IDocumentSubprocessor;
14
import org.dataone.cn.indexer.solrhttp.SolrDoc;
15
import org.dataone.cn.indexer.solrhttp.SolrElementField;
16
import org.junit.Test;
17

    
18
import edu.ucsb.nceas.metacat.index.SolrIndex;
19
import edu.ucsb.nceas.metacat.index.SolrIndexIT;
20

    
21
public class ResourceMapSubprocessorIT {
22
    
23
    /**
24
     * Test the case that the resource map contains a component which is not int the solr index server.
25
     * @throws Exception
26
     */
27
    @Test
28
    public void testProcessDocument() throws Exception {
29
        //Settings.getConfiguration().setProperty("dataone.hazelcast.configFilePath", "../lib/hazelcast.xml");
30
        String id = "resourceMap_urn:uuid:04780847-6082-455b-9831-22269c9ec0a5";
31
        InputStream is = getResourceMapDoc();
32
        List<SolrElementField> sysSolrFields = new ArrayList<SolrElementField>();
33
        SolrDoc indexDocument = new SolrDoc(sysSolrFields);
34
        Map<String, SolrDoc> docs = new HashMap<String, SolrDoc>();
35
        docs.put(id, indexDocument);
36
        ResourceMapSubprocessor processor = getResourceMapSubprocessor();
37
        try {
38
            processor.processDocument(id, docs, is);
39
            assertTrue("ResourceMapProcessor should throw an exception because the resource map has a component which doesn't exist.", false);
40
        } catch (Exception e) {
41
            assertTrue("ResourceMapProcessor should throw a ResourceMapException because the resource map has a component which doesn't exist.", e instanceof ResourceMapException);
42
            //System.out.println("the message is "+e.getMessage());
43
        }
44
    }
45
    
46
    /*
47
     * Get the document format of the test resource map file 
48
     */
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;
53
    }
54
    
55
    /*
56
     * Get the ResourceMapSubprocessor
57
     */
58
    private ResourceMapSubprocessor getResourceMapSubprocessor() throws Exception {
59
        ResourceMapSubprocessor resorceMapprocessor = null;
60
        SolrIndex solrIndex = SolrIndexIT.generateSolrIndex();
61
        List<IDocumentSubprocessor> processors = solrIndex.getSubprocessors();
62
        for(IDocumentSubprocessor processor : processors) {
63
            if(processor instanceof ResourceMapSubprocessor) {
64
                resorceMapprocessor = (ResourceMapSubprocessor) processor;
65
            }
66
        }
67
        return resorceMapprocessor;
68
    }
69
}
    (1-1/1)