Revision 9160
Added by ben leinfelder over 9 years ago
test/edu/ucsb/nceas/metacat/annotation/store/AnnotatorStoreTest.java | ||
---|---|---|
1 |
/** '$RCSfile$' |
|
2 |
* Copyright: 2010 Regents of the University of California and the |
|
3 |
* National Center for Ecological Analysis and Synthesis |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; either version 2 of the License, or |
|
8 |
* (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 |
*/ |
|
19 |
package edu.ucsb.nceas.metacat.annotation.store; |
|
20 |
|
|
21 |
import java.io.ByteArrayInputStream; |
|
22 |
import java.io.InputStream; |
|
23 |
|
|
24 |
import org.dataone.portal.TokenGenerator; |
|
25 |
|
|
26 |
import junit.framework.Test; |
|
27 |
import junit.framework.TestSuite; |
|
28 |
import net.minidev.json.JSONObject; |
|
29 |
import net.minidev.json.JSONValue; |
|
30 |
import edu.ucsb.nceas.metacat.dataone.D1NodeServiceTest; |
|
31 |
|
|
32 |
public class AnnotatorStoreTest extends D1NodeServiceTest { |
|
33 |
|
|
34 |
private static String ANNOTATION_TEST_DOC = "test/annotator-sample.json"; |
|
35 |
|
|
36 |
/** |
|
37 |
* constructor for the test |
|
38 |
*/ |
|
39 |
public AnnotatorStoreTest(String name) { |
|
40 |
super(name); |
|
41 |
|
|
42 |
} |
|
43 |
|
|
44 |
/** |
|
45 |
* Establish a testing framework by initializing appropriate objects |
|
46 |
*/ |
|
47 |
public void setUp() throws Exception { |
|
48 |
super.setUp(); |
|
49 |
String testToken = TokenGenerator.getJWT("uid=kepler,o=unaffiliated,dc=ecoinformatics,dc=org", "Kepler"); |
|
50 |
request.addHeader("x-annotator-auth-token", testToken); |
|
51 |
|
|
52 |
} |
|
53 |
|
|
54 |
/** |
|
55 |
* Release any objects after tests are complete |
|
56 |
*/ |
|
57 |
public void tearDown() { |
|
58 |
} |
|
59 |
|
|
60 |
/** |
|
61 |
* Create a suite of tests to be run together |
|
62 |
*/ |
|
63 |
public static Test suite() { |
|
64 |
TestSuite suite = new TestSuite(); |
|
65 |
suite.addTest(new AnnotatorStoreTest("testRoundTrip")); |
|
66 |
|
|
67 |
return suite; |
|
68 |
} |
|
69 |
|
|
70 |
public void testRoundTrip() { |
|
71 |
try { |
|
72 |
|
|
73 |
|
|
74 |
// read the test annotation for CRUD operations |
|
75 |
AnnotatorStore as = new AnnotatorStore(request); |
|
76 |
InputStream is = new ByteArrayInputStream(this.getTestDocFromFile(ANNOTATION_TEST_DOC).getBytes("UTF-8")); |
|
77 |
JSONObject annotation = (JSONObject) JSONValue.parse(is); |
|
78 |
String id = as.create(annotation); |
|
79 |
|
|
80 |
// check the created |
|
81 |
JSONObject originalAnnotation = as.read(id); |
|
82 |
String text = "Original annotation content"; |
|
83 |
String originalText = originalAnnotation.get("text").toString(); |
|
84 |
assertEquals(text, originalText); |
|
85 |
|
|
86 |
// test the update |
|
87 |
// text = "updated content"; |
|
88 |
// JSONObject partialAnnotation = (JSONObject) JSONValue.parse("{'text' : '" + text + "' }"); |
|
89 |
// as.update(id, partialAnnotation); |
|
90 |
// JSONObject updatedAnnotation = as.read(id); |
|
91 |
// String updatedText = updatedAnnotation.get("text").toString(); |
|
92 |
// assertEquals(text, updatedText); |
|
93 |
|
|
94 |
// TODO: check delete |
|
95 |
as.delete(id); |
|
96 |
|
|
97 |
} catch (Exception e) { |
|
98 |
e.printStackTrace(); |
|
99 |
fail(e.getMessage()); |
|
100 |
|
|
101 |
} |
|
102 |
} |
|
103 |
|
|
104 |
|
|
105 |
} |
|
106 | 0 |
pom.xml | ||
---|---|---|
12 | 12 |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
13 | 13 |
<d1_libclient_version>2.0.0-SNAPSHOT</d1_libclient_version> |
14 | 14 |
<d1_portal_version>2.0.0-SNAPSHOT</d1_portal_version> |
15 |
<d1_annotator_version>0.1-SNAPSHOT</d1_annotator_version> |
|
16 | 15 |
<metacat_common_version>2.5.0-SNAPSHOT</metacat_common_version> |
17 | 16 |
</properties> |
18 | 17 |
<repositories> |
... | ... | |
71 | 70 |
</exclusions> |
72 | 71 |
</dependency> |
73 | 72 |
<dependency> |
74 |
<artifactId>d1_annotator</artifactId> |
|
75 |
<groupId>org.dataone</groupId> |
|
76 |
<version>${d1_annotator_version}</version> |
|
77 |
<type>jar</type> |
|
78 |
<!-- exclude extraneous artifacts (jars) --> |
|
79 |
<exclusions> |
|
80 |
<exclusion> |
|
81 |
<groupId>org.jibx</groupId> |
|
82 |
<artifactId>jibx-tools</artifactId> |
|
83 |
</exclusion> |
|
84 |
<exclusion> |
|
85 |
<groupId>org.jibx</groupId> |
|
86 |
<artifactId>jibx-schema</artifactId> |
|
87 |
</exclusion> |
|
88 |
<exclusion> |
|
89 |
<groupId>org.jibx</groupId> |
|
90 |
<artifactId>jibx-extras</artifactId> |
|
91 |
</exclusion> |
|
92 |
<exclusion> |
|
93 |
<groupId>org.jibx</groupId> |
|
94 |
<artifactId>jibx-bind</artifactId> |
|
95 |
</exclusion> |
|
96 |
<exclusion> |
|
97 |
<groupId>org.apache.maven.plugins</groupId> |
|
98 |
<artifactId>maven-compiler-plugin</artifactId> |
|
99 |
</exclusion> |
|
100 |
<exclusion> |
|
101 |
<groupId>org.apache.maven.plugins</groupId> |
|
102 |
<artifactId>maven-jar-plugin</artifactId> |
|
103 |
</exclusion> |
|
104 |
<exclusion> |
|
105 |
<groupId>org.apache.maven.plugins</groupId> |
|
106 |
<artifactId>maven-clean-plugin</artifactId> |
|
107 |
</exclusion> |
|
108 |
<exclusion> |
|
109 |
<groupId>org.jibx</groupId> |
|
110 |
<artifactId>maven-jibx-plugin</artifactId> |
|
111 |
</exclusion> |
|
112 |
</exclusions> |
|
113 |
</dependency> |
|
114 |
<dependency> |
|
115 | 73 |
<artifactId>d1_portal</artifactId> |
116 | 74 |
<groupId>org.dataone</groupId> |
117 | 75 |
<version>${d1_portal_version}</version> |
Also available in: Unified diff
remove d1_annotator and tests from project -- should be used elsewhere.