Revision 8620
Added by ben leinfelder almost 11 years ago
test/edu/ucsb/nceas/metacattest/DryadTest.java | ||
---|---|---|
1 |
/** |
|
2 |
* '$RCSfile$' |
|
3 |
* Copyright: 2004 Regents of the University of California and the |
|
4 |
* National Center for Ecological Analysis and Synthesis |
|
5 |
* Purpose: To test the Access Controls in metacat by JUnit |
|
6 |
* |
|
7 |
* '$Author$' |
|
8 |
* '$Date$' |
|
9 |
* '$Revision$' |
|
10 |
* |
|
11 |
* This program is free software; you can redistribute it and/or modify |
|
12 |
* it under the terms of the GNU General Public License as published by |
|
13 |
* the Free Software Foundation; either version 2 of the License, or |
|
14 |
* (at your option) any later version. |
|
15 |
* |
|
16 |
* This program is distributed in the hope that it will be useful, |
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19 |
* GNU General Public License for more details. |
|
20 |
* |
|
21 |
* You should have received a copy of the GNU General Public License |
|
22 |
* along with this program; if not, write to the Free Software |
|
23 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
*/ |
|
25 |
|
|
26 |
package edu.ucsb.nceas.metacattest; |
|
27 |
|
|
28 |
import java.io.IOException; |
|
29 |
import java.io.InputStream; |
|
30 |
import java.io.StringReader; |
|
31 |
|
|
32 |
import org.apache.commons.io.IOUtils; |
|
33 |
|
|
34 |
import junit.framework.Test; |
|
35 |
import junit.framework.TestSuite; |
|
36 |
import edu.ucsb.nceas.MCTestCase; |
|
37 |
import edu.ucsb.nceas.metacat.client.InsufficientKarmaException; |
|
38 |
import edu.ucsb.nceas.metacat.client.MetacatException; |
|
39 |
import edu.ucsb.nceas.metacat.client.MetacatFactory; |
|
40 |
import edu.ucsb.nceas.metacat.client.MetacatInaccessibleException; |
|
41 |
|
|
42 |
/** |
|
43 |
* A JUnit test for testing Metacat when Non Ascii Characters are inserted |
|
44 |
*/ |
|
45 |
public class DryadTest |
|
46 |
extends MCTestCase { |
|
47 |
|
|
48 |
private static final String DRYAD_TEST_DOC = "test/dryad-metadata-profile-sample.xml"; |
|
49 |
|
|
50 |
/** |
|
51 |
* Constructor to build the test |
|
52 |
* |
|
53 |
* @param name the name of the test method |
|
54 |
*/ |
|
55 |
public DryadTest(String name) { |
|
56 |
super(name); |
|
57 |
} |
|
58 |
|
|
59 |
/** |
|
60 |
* Establish a testing framework by initializing appropriate objects |
|
61 |
*/ |
|
62 |
public void setUp() { |
|
63 |
try { |
|
64 |
System.err.println("Test Metacat: " + metacatUrl); |
|
65 |
m = MetacatFactory.createMetacatConnection(metacatUrl); |
|
66 |
} |
|
67 |
catch (MetacatInaccessibleException mie) { |
|
68 |
System.err.println("Metacat is: " + metacatUrl); |
|
69 |
fail("Metacat connection failed." + mie.getMessage()); |
|
70 |
} |
|
71 |
} |
|
72 |
|
|
73 |
/** |
|
74 |
* Release any objects after tests are complete |
|
75 |
*/ |
|
76 |
public void tearDown() { |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* Create a suite of tests to be run together |
|
81 |
*/ |
|
82 |
public static Test suite() { |
|
83 |
TestSuite suite = new TestSuite(); |
|
84 |
suite.addTest(new DryadTest("initialize")); |
|
85 |
// Test basic functions |
|
86 |
suite.addTest(new DryadTest("insertDoc")); |
|
87 |
return suite; |
|
88 |
} |
|
89 |
|
|
90 |
/** |
|
91 |
* Run an initial test that always passes to check that the test |
|
92 |
* harness is working. |
|
93 |
*/ |
|
94 |
public void initialize() { |
|
95 |
assertTrue(1 == 1); |
|
96 |
} |
|
97 |
|
|
98 |
/** |
|
99 |
* Test insert of Dryad document |
|
100 |
* @throws InsufficientKarmaException |
|
101 |
* @throws MetacatException |
|
102 |
* @throws IOException |
|
103 |
* @throws MetacatInaccessibleException |
|
104 |
*/ |
|
105 |
public void insertDoc() { |
|
106 |
try { |
|
107 |
m.login(username, password); |
|
108 |
String docid = this.generateDocumentId(); |
|
109 |
docid += ".1"; |
|
110 |
String documentContents = this.getTestDocFromFile(DRYAD_TEST_DOC); |
|
111 |
m.insert(docid, new StringReader(documentContents), null); |
|
112 |
InputStream results = m.read(docid); |
|
113 |
String resultString = IOUtils.toString(results); |
|
114 |
assertEquals(documentContents, resultString); |
|
115 |
m.logout(); |
|
116 |
} catch (Exception e) { |
|
117 |
e.printStackTrace(); |
|
118 |
fail(e.getMessage()); |
|
119 |
} |
|
120 |
|
|
121 |
} |
|
122 |
|
|
123 |
|
|
124 |
} |
|
0 | 125 |
Also available in: Unified diff
initial basic test of inserting dryad metadata. NOTE: uses metacat api, not dataone api. https://projects.ecoinformatics.org/ecoinfo/issues/6419