Revision 8624
Added by ben leinfelder almost 11 years ago
test/edu/ucsb/nceas/metacattest/DryadTest.java | ||
---|---|---|
26 | 26 |
package edu.ucsb.nceas.metacattest; |
27 | 27 |
|
28 | 28 |
import java.io.InputStream; |
29 |
import java.io.StringReader; |
|
30 | 29 |
import java.math.BigInteger; |
31 | 30 |
|
31 |
import junit.framework.Test; |
|
32 |
import junit.framework.TestSuite; |
|
33 |
|
|
32 | 34 |
import org.apache.commons.io.IOUtils; |
33 | 35 |
import org.dataone.service.types.v1.Identifier; |
34 | 36 |
import org.dataone.service.types.v1.ObjectFormatIdentifier; |
35 | 37 |
import org.dataone.service.types.v1.Session; |
36 | 38 |
import org.dataone.service.types.v1.SystemMetadata; |
37 | 39 |
|
38 |
import junit.framework.Test; |
|
39 |
import junit.framework.TestSuite; |
|
40 |
import edu.ucsb.nceas.metacat.client.MetacatFactory; |
|
41 |
import edu.ucsb.nceas.metacat.client.MetacatInaccessibleException; |
|
42 | 40 |
import edu.ucsb.nceas.metacat.dataone.D1NodeServiceTest; |
43 | 41 |
import edu.ucsb.nceas.metacat.dataone.MNodeService; |
44 | 42 |
|
... | ... | |
60 | 58 |
} |
61 | 59 |
|
62 | 60 |
/** |
63 |
* Establish a testing framework by initializing appropriate objects |
|
64 |
*/ |
|
65 |
public void setUp() { |
|
66 |
try { |
|
67 |
System.err.println("Test Metacat: " + metacatUrl); |
|
68 |
m = MetacatFactory.createMetacatConnection(metacatUrl); |
|
69 |
} |
|
70 |
catch (MetacatInaccessibleException mie) { |
|
71 |
System.err.println("Metacat is: " + metacatUrl); |
|
72 |
fail("Metacat connection failed." + mie.getMessage()); |
|
73 |
} |
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* Release any objects after tests are complete |
|
78 |
*/ |
|
79 |
public void tearDown() { |
|
80 |
} |
|
81 |
|
|
82 |
/** |
|
83 | 61 |
* Create a suite of tests to be run together |
84 | 62 |
*/ |
85 | 63 |
public static Test suite() { |
86 | 64 |
TestSuite suite = new TestSuite(); |
87 | 65 |
suite.addTest(new DryadTest("initialize")); |
88 | 66 |
// Test basic functions |
89 |
//suite.addTest(new DryadTest("insertDoc")); |
|
90 | 67 |
suite.addTest(new DryadTest("d1InsertDoc")); |
91 | 68 |
|
92 | 69 |
return suite; |
... | ... | |
101 | 78 |
} |
102 | 79 |
|
103 | 80 |
/** |
104 |
* Test insert of Dryad document via Metacat |
|
105 |
* Note: formatId will be generic |
|
106 |
*/ |
|
107 |
public void insertDoc() { |
|
108 |
try { |
|
109 |
m.login(username, password); |
|
110 |
String docid = this.generateDocumentId(); |
|
111 |
docid += ".1"; |
|
112 |
String documentContents = this.getTestDocFromFile(DRYAD_TEST_DOC); |
|
113 |
m.insert(docid, new StringReader(documentContents), null); |
|
114 |
InputStream results = m.read(docid); |
|
115 |
String resultString = IOUtils.toString(results); |
|
116 |
assertEquals(documentContents, resultString); |
|
117 |
m.logout(); |
|
118 |
} catch (Exception e) { |
|
119 |
e.printStackTrace(); |
|
120 |
fail(e.getMessage()); |
|
121 |
} |
|
122 |
|
|
123 |
} |
|
124 |
|
|
125 |
/** |
|
126 | 81 |
* Insert test doc using D1 API |
127 | 82 |
*/ |
128 | 83 |
public void d1InsertDoc() { |
129 | 84 |
try { |
130 | 85 |
String docid = this.generateDocumentId(); |
131 |
docid += ".1"; |
|
132 | 86 |
String documentContents = this.getTestDocFromFile(DRYAD_TEST_DOC); |
133 | 87 |
Session session = getTestSession(); |
134 | 88 |
Identifier pid = new Identifier(); |
... | ... | |
142 | 96 |
InputStream results = MNodeService.getInstance(request).get(session, pid); |
143 | 97 |
String resultString = IOUtils.toString(results); |
144 | 98 |
assertEquals(documentContents, resultString); |
145 |
m.logout(); |
|
146 | 99 |
} catch (Exception e) { |
147 | 100 |
e.printStackTrace(); |
148 | 101 |
fail(e.getMessage()); |
149 | 102 |
} |
150 | 103 |
|
151 | 104 |
} |
152 |
|
|
153 | 105 |
|
154 | 106 |
} |
Also available in: Unified diff
clean up dryad test doc - only use D1 api. https://projects.ecoinformatics.org/ecoinfo/issues/6419