Revision 5350
Added by berkley almost 14 years ago
CrudServiceTest.java | ||
---|---|---|
80 | 80 |
public static Test suite() |
81 | 81 |
{ |
82 | 82 |
TestSuite suite = new TestSuite(); |
83 |
suite.addTest(new CrudServiceTest("initialize")); |
|
83 |
/*suite.addTest(new CrudServiceTest("initialize"));
|
|
84 | 84 |
suite.addTest(new CrudServiceTest("testSingletonAccessor")); |
85 | 85 |
suite.addTest(new CrudServiceTest("testCreateAndGet")); |
86 |
suite.addTest(new CrudServiceTest("testGetSystemMetadata")); |
|
86 |
suite.addTest(new CrudServiceTest("testGetSystemMetadata"));*/ |
|
87 |
suite.addTest(new CrudServiceTest("testUpdate")); |
|
87 | 88 |
//suite.addTest(new CrudServiceTest("")); |
88 | 89 |
//suite.addTest(new CrudServiceTest("")); |
89 |
//suite.addTest(new CrudServiceTest("")); |
|
90 | 90 |
return suite; |
91 | 91 |
} |
92 | 92 |
|
93 | 93 |
/** |
94 |
* public Identifier update(AuthToken token, Identifier guid, |
|
95 |
* InputStream object, Identifier obsoletedGuid, SystemMetadata sysmeta) |
|
96 |
* throws InvalidToken, ServiceFailure, NotAuthorized, IdentifierNotUnique, |
|
97 |
* UnsupportedType, InsufficientResources, NotFound, InvalidSystemMetadata, |
|
98 |
* NotImplemented |
|
99 |
*/ |
|
100 |
public void testUpdate() |
|
101 |
{ |
|
102 |
printTestHeader("testUpdate"); |
|
103 |
try |
|
104 |
{ |
|
105 |
CrudService cs = CrudService.getInstance(); |
|
106 |
AuthToken token = getToken(); |
|
107 |
//create a doc |
|
108 |
System.out.println("CST: creating document"); |
|
109 |
Identifier id = createDoc(token, getTestDoc()); |
|
110 |
System.out.println("CST: document created. Id: " + id.getValue()); |
|
111 |
//get the doc and sysmetadata |
|
112 |
System.out.println("CST: getting document with id " + id.getValue()); |
|
113 |
String gotDoc = getDoc(token, id); |
|
114 |
System.out.println("CST: getting sysmeta for doc with id " + id.getValue()); |
|
115 |
SystemMetadata sm = getSystemMetadata(token, id); |
|
116 |
//update the doc |
|
117 |
System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ doing the update now $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"); |
|
118 |
gotDoc = gotDoc.replaceAll("XXX", "YYY"); |
|
119 |
System.out.println("CST: Changed test doc to " + gotDoc); |
|
120 |
Identifier newid = new Identifier(); |
|
121 |
newid.setValue(generateDocumentId()); |
|
122 |
System.out.println("CST: Generated newid " + newid); |
|
123 |
StringBufferInputStream sbis = new StringBufferInputStream(gotDoc); |
|
124 |
SystemMetadata newsm = createSystemMetadata(newid, gotDoc); |
|
125 |
System.out.println("CST: Created system metadata for new doc...updating."); |
|
126 |
Identifier updatedid = cs.update(token, newid, sbis, id, newsm); |
|
127 |
System.out.println("CST: Called update. Returned id " + id); |
|
128 |
//get doc - check that it matches update |
|
129 |
String newdoc = getDoc(token, newid); |
|
130 |
assertTrue(gotDoc.equals(newdoc)); |
|
131 |
//get sysmeta - check that ids and other fields are updated |
|
132 |
SystemMetadata newnewsm = getSystemMetadata(token, id); |
|
133 |
List obsoletedByList = newnewsm.getObsoletedByList(); |
|
134 |
assertTrue(obsoletedByList.size() == 1); |
|
135 |
String obsBy = ((Identifier)obsoletedByList.get(0)).getValue(); |
|
136 |
assertTrue(obsBy.equals(id.getValue())); |
|
137 |
} |
|
138 |
catch(Exception e) |
|
139 |
{ |
|
140 |
e.printStackTrace(); |
|
141 |
fail("Error in testUpdate: " + e.getMessage()); |
|
142 |
} |
|
143 |
} |
|
144 |
|
|
145 |
/** |
|
94 | 146 |
* public SystemMetadata getSystemMetadata(AuthToken token, Identifier guid) |
95 | 147 |
* throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, |
96 | 148 |
* InvalidRequest, NotImplemented |
... | ... | |
229 | 281 |
*/ |
230 | 282 |
private String getTestDoc() |
231 | 283 |
{ |
232 |
return "<?xml version=\"1.0\"?><test></test>\n"; |
|
284 |
return "<?xml version=\"1.0\"?><test><somecontent>This is some content XXX</somecontent></test>\n";
|
|
233 | 285 |
} |
234 | 286 |
|
235 | 287 |
/** |
... | ... | |
270 | 322 |
|
271 | 323 |
//create the system metadata then run the create method |
272 | 324 |
StringBufferInputStream sbis = new StringBufferInputStream(testDoc); |
273 |
SystemMetadata sm = new SystemMetadata(); |
|
325 |
SystemMetadata sm = createSystemMetadata(id, testDoc); |
|
326 |
//create the doc |
|
327 |
cs.create(token, id, sbis, sm); |
|
328 |
System.out.println("document with id " + id.getValue() + " created."); |
|
329 |
return id; |
|
330 |
} |
|
331 |
|
|
332 |
/** |
|
333 |
* create a generic SystemMetadata object for testing |
|
334 |
*/ |
|
335 |
private SystemMetadata createSystemMetadata(Identifier id, String testDoc) |
|
336 |
throws Exception |
|
337 |
{ |
|
338 |
SystemMetadata sm = new SystemMetadata(); |
|
274 | 339 |
//set the id |
275 | 340 |
System.out.println("creating system metadata object for document with id " + id.getValue()); |
276 | 341 |
sm.setIdentifier(id); |
... | ... | |
299 | 364 |
nr.setValue("metacat"); |
300 | 365 |
sm.setOriginMemberNode(nr); |
301 | 366 |
sm.setAuthoritativeMemberNode(nr); |
302 |
//create the doc |
|
303 |
cs.create(token, id, sbis, sm); |
|
304 |
System.out.println("document with id " + id.getValue() + " created."); |
|
305 |
return id; |
|
367 |
return sm; |
|
306 | 368 |
} |
307 | 369 |
|
308 | 370 |
/** |
Also available in: Unified diff
amost have update working. still need to get unit test squared away.