Revision 7578
Added by Jing Tao over 11 years ago
metacat-index/src/test/java/edu/ucsb/nceas/metacat/index/SolrIndexTest.java | ||
---|---|---|
33 | 33 |
|
34 | 34 |
private static final String SYSTEMMETAFILEPATH = "src/test/resources/eml-system-meta-example.xml"; |
35 | 35 |
private static final String EMLFILEPATH = "src/test/resources/eml-example.xml"; |
36 |
private static final String SYSTEMMETAUPDATEFILEPATH = "src/test/resources/eml-updating-system-meta-example.xml"; |
|
37 |
private static final String EMLUPDATEFILEPATH = "src/test/resources/eml-updating-example.xml"; |
|
36 | 38 |
private static final String id = "urn:uuid:606a19dd-b531-4bf4-b5a5-6d06c3d39098"; |
39 |
private static final String newId = "urn:uuid:606a19dd-b531-4bf4-b5a5-6d06c3d39099"; |
|
37 | 40 |
private static final String SOLRHOME = "solr-home"; |
38 | 41 |
private static final String SOLRTESTHOMEPATH = "target/"+SOLRHOME; |
39 | 42 |
|
... | ... | |
48 | 51 |
SystemMetadata systemMetadata = TypeMarshaller.unmarshalTypeFromFile(SystemMetadata.class, SYSTEMMETAFILEPATH); |
49 | 52 |
InputStream emlInputStream = new FileInputStream(new File(EMLFILEPATH)); |
50 | 53 |
solrIndex.insert(id, systemMetadata, emlInputStream); |
51 |
doQuery(solrIndex.getSolrServer()); |
|
54 |
String result = doQuery(solrIndex.getSolrServer()); |
|
55 |
assertTrue(result.contains("version1")); |
|
52 | 56 |
} |
53 | 57 |
|
54 | 58 |
/** |
55 | 59 |
* Test building index for an insert. |
56 | 60 |
*/ |
57 | 61 |
@Test |
62 |
public void testUpdate() throws Exception { |
|
63 |
SolrIndex solrIndex = generateSolrIndex(); |
|
64 |
//InputStream systemInputStream = new FileInputStream(new File(SYSTEMMETAFILEPATH)); |
|
65 |
SystemMetadata systemMetadata = TypeMarshaller.unmarshalTypeFromFile(SystemMetadata.class, SYSTEMMETAUPDATEFILEPATH); |
|
66 |
InputStream emlInputStream = new FileInputStream(new File(EMLUPDATEFILEPATH)); |
|
67 |
solrIndex.update(newId, systemMetadata, emlInputStream); |
|
68 |
String result = doQuery(solrIndex.getSolrServer()); |
|
69 |
assertTrue(result.contains("version2")); |
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* Test building index for an insert. |
|
74 |
*/ |
|
75 |
@Test |
|
58 | 76 |
public void testDelete() throws Exception { |
59 | 77 |
SolrIndex solrIndex = generateSolrIndex(); |
60 |
solrIndex.remove(id); |
|
61 |
|
|
78 |
solrIndex.remove(newId); |
|
79 |
String result = doQuery(solrIndex.getSolrServer()); |
|
80 |
assertTrue(!result.contains("version1")); |
|
81 |
assertTrue(!result.contains("version2")); |
|
62 | 82 |
} |
63 | 83 |
|
64 | 84 |
|
... | ... | |
66 | 86 |
/* |
67 | 87 |
* Do query |
68 | 88 |
*/ |
69 |
private void doQuery(SolrServer server)
|
|
89 |
private String doQuery(SolrServer server)
|
|
70 | 90 |
throws SolrServerException { |
71 | 91 |
StringBuffer request = new StringBuffer(); |
72 | 92 |
request.append("q=" + "*:*"); |
... | ... | |
77 | 97 |
System.out.println("The query result:\n"); |
78 | 98 |
System.out.println(reponse.toString()); |
79 | 99 |
System.out.println("**************************************************************************"); |
100 |
return reponse.toString(); |
|
80 | 101 |
} |
81 | 102 |
|
82 | 103 |
|
Also available in: Unified diff
Add a test method to test the update method.