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: daigle $'
|
8
|
* '$Date: 2008-12-17 14:17:55 -0800 (Wed, 17 Dec 2008) $'
|
9
|
* '$Revision: 4679 $'
|
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.Reader;
|
29
|
import java.io.StringReader;
|
30
|
import java.util.Calendar;
|
31
|
import java.util.Date;
|
32
|
import java.util.GregorianCalendar;
|
33
|
import java.util.SimpleTimeZone;
|
34
|
import java.util.TimeZone;
|
35
|
|
36
|
import edu.ucsb.nceas.MCTestCase;
|
37
|
import edu.ucsb.nceas.metacat.client.InsufficientKarmaException;
|
38
|
import edu.ucsb.nceas.metacat.client.Metacat;
|
39
|
import edu.ucsb.nceas.metacat.client.MetacatAuthException;
|
40
|
import edu.ucsb.nceas.metacat.client.MetacatException;
|
41
|
import edu.ucsb.nceas.metacat.client.MetacatFactory;
|
42
|
import edu.ucsb.nceas.metacat.client.MetacatInaccessibleException;
|
43
|
import edu.ucsb.nceas.metacat.service.PropertyService;
|
44
|
import edu.ucsb.nceas.utilities.IOUtil;
|
45
|
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
|
46
|
import junit.framework.Test;
|
47
|
import junit.framework.TestSuite;
|
48
|
|
49
|
/**
|
50
|
* A JUnit test for testing Access Control for Inline data in Metacat
|
51
|
*/
|
52
|
public class InlineDataAccessTest
|
53
|
extends MCTestCase {
|
54
|
|
55
|
private static String metacatUrl;
|
56
|
private static String username;
|
57
|
private static String password;
|
58
|
private static String anotheruser;
|
59
|
private static String anotherpassword;
|
60
|
static {
|
61
|
try {
|
62
|
metacatUrl = PropertyService.getProperty("test.metacatUrl");
|
63
|
username = PropertyService.getProperty("test.mcUser");
|
64
|
password = PropertyService.getProperty("test.mcPassword");
|
65
|
anotheruser = PropertyService.getProperty("test.mcAnotherUser");
|
66
|
anotherpassword = PropertyService.getProperty("test.mcAnotherPassword");
|
67
|
} catch (PropertyNotFoundException pnfe) {
|
68
|
System.err.println("Could not get property in static block: "
|
69
|
+ pnfe.getMessage());
|
70
|
}
|
71
|
}
|
72
|
|
73
|
private String prefix = "test";
|
74
|
private String newdocid = null;
|
75
|
private String testdocument = "";
|
76
|
|
77
|
private Metacat m;
|
78
|
|
79
|
private String testEml_200_Header =
|
80
|
"<?xml version=\"1.0\"?><eml:eml" +
|
81
|
" xmlns:eml=\"eml://ecoinformatics.org/eml-2.0.0\"" +
|
82
|
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
|
83
|
" packageId=\"eml.1.1\" system=\"knb\"" +
|
84
|
" xsi:schemaLocation=\"eml://ecoinformatics.org/eml-2.0.0 eml.xsd\"" +
|
85
|
" scope=\"system\">";
|
86
|
|
87
|
private String testEml_201_Header =
|
88
|
"<?xml version=\"1.0\"?><eml:eml" +
|
89
|
" xmlns:eml=\"eml://ecoinformatics.org/eml-2.0.1\"" +
|
90
|
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
|
91
|
" packageId=\"eml.1.1\" system=\"knb\"" +
|
92
|
" xsi:schemaLocation=\"eml://ecoinformatics.org/eml-2.0.1 eml.xsd\"" +
|
93
|
" scope=\"system\">";
|
94
|
|
95
|
private String testEml_210_Header =
|
96
|
"<?xml version=\"1.0\"?><eml:eml" +
|
97
|
" xmlns:eml=\"eml://ecoinformatics.org/eml-2.1.0\"" +
|
98
|
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
|
99
|
" packageId=\"eml.1.1\" system=\"knb\"" +
|
100
|
" xsi:schemaLocation=\"eml://ecoinformatics.org/eml-2.1.0 eml.xsd\"" +
|
101
|
" scope=\"system\">";
|
102
|
|
103
|
private String testEmlCreatorBlock =
|
104
|
"<creator scope=\"document\"> " +
|
105
|
" <individualName> " +
|
106
|
" <surName>Smith</surName> " +
|
107
|
" </individualName> " +
|
108
|
"</creator> ";
|
109
|
|
110
|
private String testEmlContactBlock =
|
111
|
"<contact scope=\"document\"> " +
|
112
|
" <individualName> " +
|
113
|
" <surName>Jackson</surName> " +
|
114
|
" </individualName> " +
|
115
|
"</contact> ";
|
116
|
|
117
|
private String testEmlInlineBlock1 =
|
118
|
" <admin> " +
|
119
|
" <contact> " +
|
120
|
" <name>Operator</name> " +
|
121
|
" <institution>PSI</institution> " +
|
122
|
" </contact> " +
|
123
|
" </admin> ";
|
124
|
|
125
|
private String testEmlInlineBlock2 =
|
126
|
" <instrument> " +
|
127
|
" <instName>LCQ</instName> " +
|
128
|
" <source type=\"ESI\"></source> " +
|
129
|
" <detector type=\"EM\"></detector> " +
|
130
|
" </instrument> ";
|
131
|
|
132
|
|
133
|
/**
|
134
|
* This function returns an access block based on the params passed
|
135
|
*/
|
136
|
protected String getAccessBlock(String principal, boolean grantAccess,
|
137
|
boolean read, boolean write,
|
138
|
boolean changePermission, boolean all) {
|
139
|
String accessBlock = "<access " +
|
140
|
"authSystem=\"ldap://ldap.ecoinformatics.org:389/dc=ecoinformatics,dc=org\"" +
|
141
|
" order=\"allowFirst\" scope=\"document\">";
|
142
|
|
143
|
if (grantAccess) {
|
144
|
accessBlock += "<allow>";
|
145
|
}
|
146
|
else {
|
147
|
accessBlock += "<deny>";
|
148
|
}
|
149
|
|
150
|
accessBlock = accessBlock + "<principal>" + principal + "</principal>";
|
151
|
|
152
|
if (all) {
|
153
|
accessBlock += "<permission>all</permission>";
|
154
|
}
|
155
|
else {
|
156
|
if (read) {
|
157
|
accessBlock += "<permission>read</permission>";
|
158
|
}
|
159
|
if (write) {
|
160
|
accessBlock += "<permission>write</permission>";
|
161
|
}
|
162
|
if (changePermission) {
|
163
|
accessBlock += "<permission>changePermission</permission>";
|
164
|
}
|
165
|
}
|
166
|
|
167
|
if (grantAccess) {
|
168
|
accessBlock += "</allow>";
|
169
|
}
|
170
|
else {
|
171
|
accessBlock += "</deny>";
|
172
|
}
|
173
|
accessBlock += "</access>";
|
174
|
|
175
|
return accessBlock;
|
176
|
|
177
|
}
|
178
|
|
179
|
/**
|
180
|
* This function returns a valid eml 2.0 1 document
|
181
|
*/
|
182
|
private String get201TestEmlDoc(String title, String inlineData1, String inlineData2,
|
183
|
String onlineUrl1, String onlineUrl2, String docAccessBlock,
|
184
|
String inlineAccessBlock1, String inlineAccessBlock2,
|
185
|
String onlineAccessBlock1, String onlineAccessBlock2) {
|
186
|
|
187
|
String testDocument = testEml_201_Header;
|
188
|
|
189
|
testDocument += "<dataset scope=\"document\"><title>" + title + "</title>"
|
190
|
+ testEmlCreatorBlock;
|
191
|
|
192
|
// The inline/online level access block sits at the same level as the
|
193
|
// inline element.
|
194
|
if (inlineData1 != null) {
|
195
|
testDocument += "<distribution scope=\"document\" id=\"inlineEntity1\">"
|
196
|
+ "<inline>" + inlineData1 + "</inline></distribution>";
|
197
|
}
|
198
|
if (inlineData2 != null) {
|
199
|
testDocument = testDocument
|
200
|
+ "<distribution scope=\"document\" id=\"inlineEntity2\">"
|
201
|
+ "<inline>" + inlineData2 + "</inline></distribution>";
|
202
|
}
|
203
|
if (onlineUrl1 != null) {
|
204
|
testDocument = testDocument
|
205
|
+ "<distribution scope=\"document\" id=\"InlineEntity1\">"
|
206
|
+ "<inline><url function=\"download\">" + onlineUrl1
|
207
|
+ "</url></inline></distribution>";
|
208
|
}
|
209
|
if (onlineUrl2 != null) {
|
210
|
testDocument = testDocument
|
211
|
+ "<distribution scope=\"document\" id=\"InlineEntity2\">"
|
212
|
+ "<inline><url function=\"download\">" + onlineUrl2
|
213
|
+ "</url></inline></distribution>";
|
214
|
}
|
215
|
testDocument += testEmlContactBlock;
|
216
|
|
217
|
// The document level access block sits inside the dataset element.
|
218
|
if (docAccessBlock != null) {
|
219
|
testDocument += docAccessBlock;
|
220
|
}
|
221
|
|
222
|
testDocument += "</dataset>";
|
223
|
|
224
|
// The inline access blocks live in additionalMetadata elements at
|
225
|
// the same level as the dataset.
|
226
|
if (inlineAccessBlock1 != null) {
|
227
|
testDocument += "<additionalMetadata>";
|
228
|
testDocument += "<describes>inlineEntity1</describes>";
|
229
|
testDocument += inlineAccessBlock1;
|
230
|
testDocument += "</additionalMetadata>";
|
231
|
}
|
232
|
|
233
|
if (inlineAccessBlock2 != null) {
|
234
|
testDocument += "<additionalMetadata>";
|
235
|
testDocument += "<describes>inlineEntity2</describes>";
|
236
|
testDocument += inlineAccessBlock2;
|
237
|
testDocument += "</additionalMetadata>";
|
238
|
}
|
239
|
|
240
|
if (onlineAccessBlock1 != null) {
|
241
|
testDocument += "<additionalMetadata>";
|
242
|
testDocument += "<describes>InlineEntity1</describes>";
|
243
|
testDocument += onlineAccessBlock1;
|
244
|
testDocument += "</additionalMetadata>";
|
245
|
}
|
246
|
|
247
|
if (onlineAccessBlock2 != null) {
|
248
|
testDocument += "<additionalMetadata>";
|
249
|
testDocument += "<describes>InlineEntity2</describes>";
|
250
|
testDocument += onlineAccessBlock2;
|
251
|
testDocument += "</additionalMetadata>";
|
252
|
}
|
253
|
|
254
|
testDocument += "</eml:eml>";
|
255
|
|
256
|
debug("get201TestEmlDoc returning following document: " + testDocument);
|
257
|
return testDocument;
|
258
|
}
|
259
|
|
260
|
/**
|
261
|
* This function returns a valid eml document
|
262
|
*/
|
263
|
private String get210TestEmlDoc(String title, String inlineData1,
|
264
|
String inlineData2, String onlineUrl1,
|
265
|
String onlineUrl2, String docAccessBlock,
|
266
|
String inlineAccessBlock1,
|
267
|
String inlineAccessBlock2,
|
268
|
String onlineAccessBlock1,
|
269
|
String onlineAccessBlock2) {
|
270
|
|
271
|
String testDocument = testEml_210_Header;
|
272
|
|
273
|
// the document level access block sits at the same level and
|
274
|
// before the dataset element.
|
275
|
if (docAccessBlock != null) {
|
276
|
testDocument += docAccessBlock;
|
277
|
}
|
278
|
|
279
|
testDocument += "<dataset scope=\"document\"><title>" + title + "</title>"
|
280
|
+ testEmlCreatorBlock + testEmlContactBlock
|
281
|
+ "<dataTable>"
|
282
|
+ " <entityName>Test Data</entityName>"
|
283
|
+ " <physical>"
|
284
|
+ " <objectName>2.1.0 test physical</objectName>"
|
285
|
+ " <size unit=\"bytes\">1</size>"
|
286
|
+ " <characterEncoding>ASCII</characterEncoding>"
|
287
|
+ " <dataFormat>"
|
288
|
+ " <textFormat>"
|
289
|
+ " <numHeaderLines>1</numHeaderLines>"
|
290
|
+ " <attributeOrientation>column</attributeOrientation>"
|
291
|
+ " <simpleDelimited>"
|
292
|
+ " <fieldDelimiter>,</fieldDelimiter>"
|
293
|
+ " </simpleDelimited>"
|
294
|
+ " </textFormat>"
|
295
|
+ " </dataFormat>";
|
296
|
|
297
|
// The inline/online level access block sits at the same level as the
|
298
|
// inline element.
|
299
|
if (inlineData1 != null) {
|
300
|
testDocument += "<distribution><inline>" + inlineData1 + "</inline>";
|
301
|
if (inlineAccessBlock1 != null) {
|
302
|
testDocument += inlineAccessBlock1;
|
303
|
}
|
304
|
testDocument += "</distribution>";
|
305
|
}
|
306
|
if (inlineData2 != null) {
|
307
|
testDocument += "<distribution><inline>" + inlineData2 + "</inline>";
|
308
|
if (inlineAccessBlock2 != null) {
|
309
|
testDocument += inlineAccessBlock2;
|
310
|
}
|
311
|
testDocument += "</distribution>";
|
312
|
}
|
313
|
if (onlineUrl1 != null) {
|
314
|
testDocument = testDocument
|
315
|
+ "<distribution><inline><url function=\"download\">" + onlineUrl1
|
316
|
+ "</url></inline>";
|
317
|
if (onlineAccessBlock1 != null) {
|
318
|
testDocument += onlineAccessBlock1;
|
319
|
}
|
320
|
testDocument += "</distribution>";
|
321
|
}
|
322
|
if (onlineUrl2 != null) {
|
323
|
testDocument = testDocument
|
324
|
+ "<distribution><inline><url function=\"download\">" + onlineUrl2
|
325
|
+ "</url></inline>";
|
326
|
if (onlineAccessBlock2 != null) {
|
327
|
testDocument += onlineAccessBlock2;
|
328
|
}
|
329
|
testDocument += "</distribution>";
|
330
|
}
|
331
|
testDocument +=
|
332
|
" </physical>"
|
333
|
+ " <attributeList>"
|
334
|
+ " <attribute>"
|
335
|
+ " <attributeName>rain</attributeName>"
|
336
|
+ " <attributeLabel>Surface Rainfall</attributeLabel>"
|
337
|
+ " <attributeDefinition>The amount of rainfall on the sampling unit."
|
338
|
+ " </attributeDefinition>"
|
339
|
+ " <storageType>float</storageType>"
|
340
|
+ " <storageType typeSystem=\"http://java.sun.com/docs/books/jls/second_edition/html\">double</storageType>"
|
341
|
+ " <measurementScale>"
|
342
|
+ " <interval>"
|
343
|
+ " <unit><standardUnit>millimeter</standardUnit></unit>"
|
344
|
+ " <precision>0.5</precision>"
|
345
|
+ " <numericDomain id=\"nd.1\">"
|
346
|
+ " <numberType>real</numberType>"
|
347
|
+ " <bounds>"
|
348
|
+ " <minimum exclusive=\"false\">0</minimum>"
|
349
|
+ " </bounds>"
|
350
|
+ " </numericDomain>"
|
351
|
+ " </interval>"
|
352
|
+ " </measurementScale>"
|
353
|
+ " </attribute>"
|
354
|
+ " </attributeList>"
|
355
|
+ "</dataTable></dataset></eml:eml>";
|
356
|
|
357
|
debug("get210TestEmlDoc returning following document: " + testDocument);
|
358
|
return testDocument;
|
359
|
}
|
360
|
|
361
|
/**
|
362
|
* Constructor to build the test
|
363
|
*
|
364
|
* @param name
|
365
|
* the name of the test method
|
366
|
*/
|
367
|
public InlineDataAccessTest(String name) {
|
368
|
super(name);
|
369
|
newdocid = generateDocid();
|
370
|
}
|
371
|
|
372
|
/**
|
373
|
* Establish a testing framework by initializing appropriate objects
|
374
|
*/
|
375
|
public void setUp() {
|
376
|
try {
|
377
|
System.err.println("Test Metacat: " + metacatUrl);
|
378
|
m = MetacatFactory.createMetacatConnection(metacatUrl);
|
379
|
}
|
380
|
catch (MetacatInaccessibleException mie) {
|
381
|
System.err.println("Metacat is: " + metacatUrl);
|
382
|
fail("Metacat connection failed." + mie.getMessage());
|
383
|
}
|
384
|
}
|
385
|
|
386
|
/**
|
387
|
* Release any objects after tests are complete
|
388
|
*/
|
389
|
public void tearDown() {
|
390
|
}
|
391
|
|
392
|
/**
|
393
|
* Create a suite of tests to be run together
|
394
|
*/
|
395
|
public static Test suite() {
|
396
|
TestSuite suite = new TestSuite();
|
397
|
suite.addTest(new InlineDataAccessTest("initialize"));
|
398
|
|
399
|
suite.addTest(new InlineDataAccessTest("inlineData201CasesTest_1"));
|
400
|
suite.addTest(new InlineDataAccessTest("inlineData210CasesTest_1"));
|
401
|
suite.addTest(new InlineDataAccessTest("inlineData201CasesTest_2"));
|
402
|
suite.addTest(new InlineDataAccessTest("inlineData210CasesTest_2"));
|
403
|
suite.addTest(new InlineDataAccessTest("inlineData201CasesTest_3"));
|
404
|
suite.addTest(new InlineDataAccessTest("inlineData210CasesTest_3"));
|
405
|
suite.addTest(new InlineDataAccessTest("inlineData201CasesTest_4"));
|
406
|
suite.addTest(new InlineDataAccessTest("inlineData210CasesTest_4"));
|
407
|
suite.addTest(new InlineDataAccessTest("inlineData201CasesTest_5"));
|
408
|
suite.addTest(new InlineDataAccessTest("inlineData210CasesTest_5"));
|
409
|
suite.addTest(new InlineDataAccessTest("inlineData201CasesTest_6"));
|
410
|
suite.addTest(new InlineDataAccessTest("inlineData210CasesTest_6"));
|
411
|
|
412
|
return suite;
|
413
|
}
|
414
|
|
415
|
|
416
|
/**
|
417
|
* Run an initial test that always passes to check that the test
|
418
|
* harness is working.
|
419
|
*/
|
420
|
public void initialize() {
|
421
|
assertTrue(1 == 1);
|
422
|
}
|
423
|
|
424
|
/**
|
425
|
* For EML 2.0.1, checking the following cases:
|
426
|
* when only Inline data is uploaded by a user and
|
427
|
* -> he tries to read it - success
|
428
|
* -> he tries to add same docid again - failure
|
429
|
* -> he tries to update it - success
|
430
|
* -> he removes it and adds it again - success
|
431
|
* -> he tries to delete it - success
|
432
|
* -> he tries to read it after deleteing - failure
|
433
|
*/
|
434
|
public void inlineData201CasesTest_1() {
|
435
|
debug("\nRunning: inlineData201CasesTest_1()");
|
436
|
try {
|
437
|
newdocid = generateDocid();
|
438
|
m.login(username, password);
|
439
|
|
440
|
// insert a document
|
441
|
testdocument = get201TestEmlDoc("Testing insert", testEmlInlineBlock1,
|
442
|
null, null, null, null, null, null, null, null);
|
443
|
|
444
|
insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
|
445
|
readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, true);
|
446
|
|
447
|
// insert same document again
|
448
|
insertDocid(newdocid + ".1", testdocument, FAILURE, false);
|
449
|
|
450
|
// update by changing inline data
|
451
|
testdocument = get201TestEmlDoc("Testing update inline",
|
452
|
testEmlInlineBlock2, null, null, null, null, null, null, null, null);
|
453
|
Thread.sleep(2000);
|
454
|
updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
|
455
|
readDocidWhichEqualsDoc(newdocid + ".2", testdocument, SUCCESS, true);
|
456
|
|
457
|
// update by removing inline data
|
458
|
testdocument = get201TestEmlDoc("Testing update inline", null, null,
|
459
|
null, null, null, null, null, null, null);
|
460
|
Thread.sleep(2000);
|
461
|
updateDocid(newdocid + ".3", testdocument, SUCCESS, false);
|
462
|
readDocidWhichEqualsDoc(newdocid + ".3", testdocument, SUCCESS, true);
|
463
|
|
464
|
// update by introducing inline data
|
465
|
testdocument = get201TestEmlDoc("Testing update inline",
|
466
|
testEmlInlineBlock1, null, null, null, null, null, null, null, null);
|
467
|
Thread.sleep(2000);
|
468
|
updateDocid(newdocid + ".4", testdocument, SUCCESS, false);
|
469
|
readDocidWhichEqualsDoc(newdocid + ".4", testdocument, SUCCESS, true);
|
470
|
|
471
|
// read inline data only
|
472
|
readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, SUCCESS,
|
473
|
false);
|
474
|
|
475
|
// delete the inline data
|
476
|
// sleep needed only in case of inline data - jing said that
|
477
|
// somehow the thread writing data to xml_index takes too much time
|
478
|
// when used with inline data. hence if delete is requested too soon
|
479
|
// database gives an error of xml_index records left with FK to
|
480
|
// xml_document record which is going to be deleted.
|
481
|
Thread.sleep(10000);
|
482
|
|
483
|
deleteDocid(newdocid + ".4", SUCCESS, false);
|
484
|
readDocidWhichEqualsDoc(newdocid + ".4", testdocument, FAILURE, false);
|
485
|
m.logout();
|
486
|
} catch (MetacatAuthException mae) {
|
487
|
fail("Authorization failed:\n" + mae.getMessage());
|
488
|
} catch (MetacatInaccessibleException mie) {
|
489
|
fail("Metacat Inaccessible:\n" + mie.getMessage());
|
490
|
} catch (Exception e) {
|
491
|
fail("General exception:\n" + e.getMessage());
|
492
|
}
|
493
|
}
|
494
|
|
495
|
/**
|
496
|
* For EML 2.1.0, checking the following cases: when only Inline data is
|
497
|
* uploaded by a user and -> he tries to read it - success -> he tries to
|
498
|
* add same docid again - failure -> he tries to update it - success -> he
|
499
|
* removes it and adds it again - success -> he tries to delete it - success ->
|
500
|
* he tries to read it after deleteing - failure
|
501
|
*/
|
502
|
public void inlineData210CasesTest_1() {
|
503
|
debug("\nRunning: inlineData210CasesTest_1()");
|
504
|
try {
|
505
|
newdocid = generateDocid();
|
506
|
m.login(username, password);
|
507
|
|
508
|
// insert a document
|
509
|
testdocument = get210TestEmlDoc("Testing insert", testEmlInlineBlock1,
|
510
|
null, null, null, null, null, null, null, null);
|
511
|
|
512
|
debug("testdocument: " + testdocument);
|
513
|
|
514
|
insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
|
515
|
readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, true);
|
516
|
|
517
|
// insert same document again
|
518
|
insertDocid(newdocid + ".1", testdocument, FAILURE, false);
|
519
|
|
520
|
// update by changing inline data
|
521
|
testdocument = get210TestEmlDoc("Testing update inline",
|
522
|
testEmlInlineBlock2, null, null, null, null, null, null, null, null);
|
523
|
Thread.sleep(2000);
|
524
|
updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
|
525
|
readDocidWhichEqualsDoc(newdocid + ".2", testdocument, SUCCESS, true);
|
526
|
|
527
|
// update by removing inline data
|
528
|
testdocument = get210TestEmlDoc("Testing update inline", null, null,
|
529
|
null, null, null, null, null, null, null);
|
530
|
Thread.sleep(2000);
|
531
|
updateDocid(newdocid + ".3", testdocument, SUCCESS, false);
|
532
|
readDocidWhichEqualsDoc(newdocid + ".3", testdocument, SUCCESS, true);
|
533
|
|
534
|
// update by introducing inline data
|
535
|
testdocument = get210TestEmlDoc("Testing update inline",
|
536
|
testEmlInlineBlock1, null, null, null, null, null, null, null, null);
|
537
|
Thread.sleep(2000);
|
538
|
updateDocid(newdocid + ".4", testdocument, SUCCESS, false);
|
539
|
readDocidWhichEqualsDoc(newdocid + ".4", testdocument, SUCCESS, true);
|
540
|
|
541
|
// read inline data only
|
542
|
readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, SUCCESS,
|
543
|
false);
|
544
|
|
545
|
// delete the inline data
|
546
|
// sleep needed only in case of inline data - jing said that
|
547
|
// somehow the thread writing data to xml_index takes too much time
|
548
|
// when used with inline data. hence if delete is requested too soon
|
549
|
// database gives an error of xml_index records left with FK to
|
550
|
// xml_document record which is going to be deleted.
|
551
|
Thread.sleep(10000);
|
552
|
|
553
|
deleteDocid(newdocid + ".4", SUCCESS, false);
|
554
|
readDocidWhichEqualsDoc(newdocid + ".4", testdocument, FAILURE, false);
|
555
|
m.logout();
|
556
|
} catch (MetacatAuthException mae) {
|
557
|
fail("Authorization failed:\n" + mae.getMessage());
|
558
|
} catch (MetacatInaccessibleException mie) {
|
559
|
fail("Metacat Inaccessible:\n" + mie.getMessage());
|
560
|
} catch (Exception e) {
|
561
|
fail("General exception:\n" + e.getMessage());
|
562
|
}
|
563
|
}
|
564
|
|
565
|
/***************************************************************************
|
566
|
* For EML 2.0.1, checking the following cases: when only inline data is
|
567
|
* uploaded by a user and another user -> tries to read it - failure ->
|
568
|
* tries to read inline data only - failure -> tries to update - failure ->
|
569
|
* tries to delete it - failure
|
570
|
*/
|
571
|
public void inlineData201CasesTest_2() {
|
572
|
debug("\nRunning: inlineData201CasesTest_2()");
|
573
|
try {
|
574
|
newdocid = generateDocid();
|
575
|
m.login(username, password);
|
576
|
|
577
|
// insert a document
|
578
|
testdocument = get201TestEmlDoc("Testing insert", testEmlInlineBlock1,
|
579
|
null, null, null, null, null, null, null, null);
|
580
|
|
581
|
insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
|
582
|
readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, true);
|
583
|
|
584
|
// login as another user
|
585
|
m.logout();
|
586
|
m.login(anotheruser, anotherpassword);
|
587
|
|
588
|
// try to read document or data only
|
589
|
readDocidWhichEqualsDoc(newdocid, testdocument, FAILURE, true);
|
590
|
readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE,
|
591
|
true);
|
592
|
|
593
|
// try to update the document
|
594
|
testdocument = get201TestEmlDoc("Testing insert", testEmlInlineBlock1,
|
595
|
null, null, null, null, null, null, null, null);
|
596
|
Thread.sleep(2000);
|
597
|
updateDocid(newdocid + ".2", testdocument, FAILURE, true);
|
598
|
|
599
|
// try to delete the document
|
600
|
deleteDocid(newdocid + ".1", FAILURE, true);
|
601
|
m.logout();
|
602
|
|
603
|
// delete the document
|
604
|
m.login(username, password);
|
605
|
deleteDocid(newdocid + ".1", SUCCESS, false);
|
606
|
m.logout();
|
607
|
|
608
|
} catch (MetacatAuthException mae) {
|
609
|
fail("Authorization failed:\n" + mae.getMessage());
|
610
|
} catch (MetacatInaccessibleException mie) {
|
611
|
fail("Metacat Inaccessible:\n" + mie.getMessage());
|
612
|
} catch (Exception e) {
|
613
|
fail("General exception:\n" + e.getMessage());
|
614
|
}
|
615
|
}
|
616
|
|
617
|
/***************************************************************************
|
618
|
* For EML 2.1.0, checking the following cases: when only inline data is
|
619
|
* uploaded by a user and another user -> tries to read it - failure ->
|
620
|
* tries to read inline data only - failure -> tries to update - failure ->
|
621
|
* tries to delete it - failure
|
622
|
*/
|
623
|
public void inlineData210CasesTest_2() {
|
624
|
debug("\nRunning: inlineData210CasesTest_2()");
|
625
|
try {
|
626
|
newdocid = generateDocid();
|
627
|
m.login(username, password);
|
628
|
|
629
|
// insert a document
|
630
|
testdocument = get210TestEmlDoc("Testing insert", testEmlInlineBlock1,
|
631
|
null, null, null, null, null, null, null, null);
|
632
|
|
633
|
insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
|
634
|
readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, true);
|
635
|
|
636
|
// login as another user
|
637
|
m.logout();
|
638
|
m.login(anotheruser, anotherpassword);
|
639
|
|
640
|
// try to read document or data only
|
641
|
readDocidWhichEqualsDoc(newdocid, testdocument, FAILURE, true);
|
642
|
readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE,
|
643
|
true);
|
644
|
|
645
|
// try to update the document
|
646
|
testdocument = get210TestEmlDoc("Testing insert", testEmlInlineBlock1,
|
647
|
null, null, null, null, null, null, null, null);
|
648
|
Thread.sleep(2000);
|
649
|
updateDocid(newdocid + ".2", testdocument, FAILURE, true);
|
650
|
|
651
|
// try to delete the document
|
652
|
deleteDocid(newdocid + ".1", FAILURE, true);
|
653
|
m.logout();
|
654
|
|
655
|
// delete the document
|
656
|
m.login(username, password);
|
657
|
deleteDocid(newdocid + ".1", SUCCESS, false);
|
658
|
m.logout();
|
659
|
|
660
|
} catch (MetacatAuthException mae) {
|
661
|
fail("Authorization failed:\n" + mae.getMessage());
|
662
|
} catch (MetacatInaccessibleException mie) {
|
663
|
fail("Metacat Inaccessible:\n" + mie.getMessage());
|
664
|
} catch (Exception e) {
|
665
|
fail("General exception:\n" + e.getMessage());
|
666
|
}
|
667
|
}
|
668
|
|
669
|
/***************************************************************************
|
670
|
* For EML 2.0.1, checking the following cases:
|
671
|
* when only inline data is uploaded by a user with the following different
|
672
|
* access controls in another document 1.read 2.write 3.change permission
|
673
|
* 4.all And another user tries to do the following: -> tries to read it ->
|
674
|
* tries to update it -> tries to set permissions on it -> tries to delete it
|
675
|
*/
|
676
|
public void inlineData201CasesTest_3() {
|
677
|
debug("\nRunning: inlineData201CasesTest_3()");
|
678
|
try {
|
679
|
|
680
|
// ///////Case 1./////////////////////
|
681
|
// insert an inline document - read only
|
682
|
m.login(username, password);
|
683
|
newdocid = generateDocid();
|
684
|
|
685
|
// insert a document which gives read access to the inline document
|
686
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
|
687
|
testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
|
688
|
true, true, false, false, false), null, null, null, null);
|
689
|
|
690
|
insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
|
691
|
m.logout();
|
692
|
|
693
|
// login as another user
|
694
|
m.login(anotheruser, anotherpassword);
|
695
|
|
696
|
// try to read the document and the inline data
|
697
|
readDocid(newdocid + ".1", SUCCESS, false);
|
698
|
readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, SUCCESS,
|
699
|
false);
|
700
|
|
701
|
// try to update the inline data
|
702
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing update",
|
703
|
testEmlInlineBlock2, null, null, null, getAccessBlock(anotheruser,
|
704
|
true, true, false, false, false), null, null, null, null);
|
705
|
Thread.sleep(2000);
|
706
|
updateDocid(newdocid + ".2", testdocument, FAILURE, true);
|
707
|
|
708
|
// try to set the permissions for the inline data
|
709
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
|
710
|
testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
|
711
|
true, false, false, false, true), null, null, null, null);
|
712
|
Thread.sleep(2000);
|
713
|
updateDocid(newdocid + ".2", testdocument, FAILURE, true);
|
714
|
|
715
|
// try to delete the document
|
716
|
deleteDocid(newdocid + ".1", FAILURE, true);
|
717
|
m.logout();
|
718
|
|
719
|
// delete the document
|
720
|
m.login(username, password);
|
721
|
deleteDocid(newdocid + ".1", SUCCESS, false);
|
722
|
m.logout();
|
723
|
|
724
|
// ///////Case 2./////////////////////
|
725
|
// insert an inline document - write only
|
726
|
m.login(username, password);
|
727
|
newdocid = generateDocid();
|
728
|
|
729
|
// insert a document which gives read access to the inline document
|
730
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
|
731
|
testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
|
732
|
true, false, true, false, false), null, null, null, null);
|
733
|
insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
|
734
|
m.logout();
|
735
|
|
736
|
// login as another user
|
737
|
m.login(anotheruser, anotherpassword);
|
738
|
|
739
|
// try to read the document and the inline data
|
740
|
readDocid(newdocid + ".1", FAILURE, true);
|
741
|
readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE,
|
742
|
true);
|
743
|
|
744
|
// try to update the inline data
|
745
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing update",
|
746
|
testEmlInlineBlock2, null, null, null, getAccessBlock(anotheruser,
|
747
|
true, false, true, false, false), null, null, null, null);
|
748
|
Thread.sleep(2000);
|
749
|
updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
|
750
|
|
751
|
// try to set the permissions for the inline data
|
752
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
|
753
|
testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
|
754
|
true, false, false, false, true), null, null, null, null);
|
755
|
Thread.sleep(2000);
|
756
|
updateDocid(newdocid + ".3", testdocument, FAILURE, true);
|
757
|
|
758
|
// try to delete the document
|
759
|
deleteDocid(newdocid + ".2", FAILURE, true);
|
760
|
m.logout();
|
761
|
|
762
|
// delete the document
|
763
|
m.login(username, password);
|
764
|
deleteDocid(newdocid + ".2", SUCCESS, false);
|
765
|
m.logout();
|
766
|
|
767
|
// ///////Case 3./////////////////////
|
768
|
// insert an inline document - change permission only
|
769
|
m.login(username, password);
|
770
|
newdocid = generateDocid();
|
771
|
|
772
|
// insert a document which gives read access to the inline document
|
773
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
|
774
|
testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
|
775
|
true, false, false, true, false), null, null, null, null);
|
776
|
insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
|
777
|
m.logout();
|
778
|
|
779
|
// login as another user
|
780
|
m.login(anotheruser, anotherpassword);
|
781
|
|
782
|
// try to read the document and the inline data
|
783
|
readDocid(newdocid + ".1", FAILURE, true);
|
784
|
readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE,
|
785
|
true);
|
786
|
|
787
|
// try to update the inline data
|
788
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing update",
|
789
|
testEmlInlineBlock2, null, null, null, getAccessBlock(anotheruser,
|
790
|
true, false, false, true, false), null, null, null, null);
|
791
|
Thread.sleep(2000);
|
792
|
updateDocid(newdocid + ".2", testdocument, FAILURE, true);
|
793
|
|
794
|
// try to set the permissions for the inline data
|
795
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
|
796
|
testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
|
797
|
true, false, false, false, true), null, null, null, null);
|
798
|
// ERRRRRRRRRRRR
|
799
|
// updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
|
800
|
|
801
|
// try to delete the document
|
802
|
deleteDocid(newdocid + ".1", FAILURE, true);
|
803
|
m.logout();
|
804
|
|
805
|
// delete the document
|
806
|
m.login(username, password);
|
807
|
deleteDocid(newdocid + ".1", SUCCESS, false);
|
808
|
m.logout();
|
809
|
|
810
|
// ///////Case 4./////////////////////
|
811
|
// insert an inline document - change permission only
|
812
|
m.login(username, password);
|
813
|
newdocid = generateDocid();
|
814
|
|
815
|
// insert a document which gives read access to the inline document
|
816
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
|
817
|
testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
|
818
|
true, false, false, false, true), null, null, null, null);
|
819
|
insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
|
820
|
m.logout();
|
821
|
|
822
|
// login as another user
|
823
|
m.login(anotheruser, anotherpassword);
|
824
|
|
825
|
// try to read the document and the inline data
|
826
|
readDocid(newdocid + ".1", SUCCESS, false);
|
827
|
readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, SUCCESS,
|
828
|
false);
|
829
|
|
830
|
// try to update the inline data
|
831
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing update",
|
832
|
testEmlInlineBlock2, null, null, null, getAccessBlock(anotheruser,
|
833
|
true, false, false, false, true), null, null, null, null);
|
834
|
Thread.sleep(2000);
|
835
|
updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
|
836
|
|
837
|
// try to set the permissions for the inline data
|
838
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
|
839
|
testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
|
840
|
true, true, true, true, false), null, null, null, null);
|
841
|
Thread.sleep(2000);
|
842
|
updateDocid(newdocid + ".3", testdocument, SUCCESS, false);
|
843
|
|
844
|
// try to delete the document
|
845
|
// sleep needed only in case of inline data - jing said that
|
846
|
// somehow the thread writing data to xml_index takes too much time
|
847
|
// when used with inline data. hence if delete is requested too soon
|
848
|
// database gives an error of xml_index records left with FK to
|
849
|
// xml_document record which is going to be deleted.
|
850
|
Thread.sleep(10000);
|
851
|
|
852
|
deleteDocid(newdocid + ".3", SUCCESS, false);
|
853
|
m.logout();
|
854
|
|
855
|
} catch (MetacatAuthException mae) {
|
856
|
fail("Authorization failed:\n" + mae.getMessage());
|
857
|
} catch (MetacatInaccessibleException mie) {
|
858
|
fail("Metacat Inaccessible:\n" + mie.getMessage());
|
859
|
} catch (Exception e) {
|
860
|
fail("General exception:\n" + e.getMessage());
|
861
|
}
|
862
|
}
|
863
|
|
864
|
/***************************************************************************
|
865
|
* For EML 2.1.0, checking the following cases:
|
866
|
* when only inline data is uploaded by a user with the following different
|
867
|
* access controls in another document 1.read 2.write 3.change permission
|
868
|
* 4.all And another user tries to do the following: -> tries to read it ->
|
869
|
* tries to update it -> tries to set permissions on it -> tries to delete it
|
870
|
*/
|
871
|
public void inlineData210CasesTest_3() {
|
872
|
debug("\nRunning: inlineData210CasesTest_3()");
|
873
|
try {
|
874
|
|
875
|
// ///////Case 1./////////////////////
|
876
|
// insert an inline document - read only
|
877
|
debug("Case 1:");
|
878
|
m.login(username, password);
|
879
|
newdocid = generateDocid();
|
880
|
|
881
|
// insert a document which gives read access to the inline document
|
882
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
|
883
|
testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
|
884
|
true, true, false, false, false), null, null, null, null);
|
885
|
insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
|
886
|
m.logout();
|
887
|
|
888
|
// login as another user
|
889
|
m.login(anotheruser, anotherpassword);
|
890
|
|
891
|
// try to read the document and the inline data
|
892
|
readDocid(newdocid + ".1", SUCCESS, false);
|
893
|
readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, SUCCESS,
|
894
|
false);
|
895
|
|
896
|
// try to update the inline data
|
897
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing update",
|
898
|
testEmlInlineBlock2, null, null, null, getAccessBlock(anotheruser,
|
899
|
true, true, false, false, false), null, null, null, null);
|
900
|
Thread.sleep(2000);
|
901
|
updateDocid(newdocid + ".2", testdocument, FAILURE, true);
|
902
|
|
903
|
// try to set the permissions for the inline data
|
904
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
|
905
|
testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
|
906
|
true, false, false, false, true), null, null, null, null);
|
907
|
Thread.sleep(2000);
|
908
|
updateDocid(newdocid + ".2", testdocument, FAILURE, true);
|
909
|
|
910
|
// try to delete the document
|
911
|
deleteDocid(newdocid + ".1", FAILURE, true);
|
912
|
m.logout();
|
913
|
|
914
|
// delete the document
|
915
|
m.login(username, password);
|
916
|
deleteDocid(newdocid + ".1", SUCCESS, false);
|
917
|
m.logout();
|
918
|
|
919
|
// ///////Case 2./////////////////////
|
920
|
// insert an inline document - write only
|
921
|
debug("Case 2:");
|
922
|
m.login(username, password);
|
923
|
newdocid = generateDocid();
|
924
|
|
925
|
// insert a document which gives read access to the inline document
|
926
|
debug("Inserting doc: " + newdocid + ".1, which allows document level"
|
927
|
+ " write access for " + anotheruser + " and expect SUCCESS");
|
928
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
|
929
|
testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
|
930
|
true, false, true, false, false), null, null, null, null);
|
931
|
insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
|
932
|
m.logout();
|
933
|
|
934
|
// login as another user
|
935
|
m.login(anotheruser, anotherpassword);
|
936
|
|
937
|
// try to read the document and the inline data
|
938
|
debug("Try to read:" + newdocid + ".1 as user: " + anotheruser
|
939
|
+ " and expect FAILURE since write access does not imply read access");
|
940
|
readDocid(newdocid + ".1", FAILURE, true);
|
941
|
readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE,
|
942
|
true);
|
943
|
|
944
|
// try to update the inline data
|
945
|
debug("Updating doc: " + newdocid + ".2, with new inline data."
|
946
|
+ " as: " + anotheruser + " and expect SUCCESS");
|
947
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing update",
|
948
|
testEmlInlineBlock2, null, null, null, getAccessBlock(anotheruser,
|
949
|
true, false, true, false, false), null, null, null, null);
|
950
|
Thread.sleep(2000);
|
951
|
updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
|
952
|
|
953
|
// try to set the permissions for the inline data
|
954
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
|
955
|
testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
|
956
|
true, false, false, false, true), null, null, null, null);
|
957
|
Thread.sleep(2000);
|
958
|
updateDocid(newdocid + ".3", testdocument, FAILURE, true);
|
959
|
|
960
|
// try to delete the document
|
961
|
deleteDocid(newdocid + ".2", FAILURE, true);
|
962
|
m.logout();
|
963
|
|
964
|
// delete the document
|
965
|
m.login(username, password);
|
966
|
deleteDocid(newdocid + ".2", SUCCESS, false);
|
967
|
m.logout();
|
968
|
|
969
|
// ///////Case 3./////////////////////
|
970
|
// insert an inline document - change permission only
|
971
|
debug("Case 3:");
|
972
|
m.login(username, password);
|
973
|
newdocid = generateDocid();
|
974
|
|
975
|
// insert a document which gives read access to the inline document
|
976
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
|
977
|
testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
|
978
|
true, false, false, true, false), null, null, null, null);
|
979
|
insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
|
980
|
m.logout();
|
981
|
|
982
|
// login as another user
|
983
|
m.login(anotheruser, anotherpassword);
|
984
|
|
985
|
// try to read the document and the inline data
|
986
|
readDocid(newdocid + ".1", FAILURE, true);
|
987
|
readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE,
|
988
|
true);
|
989
|
|
990
|
// try to update the inline data
|
991
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing update",
|
992
|
testEmlInlineBlock2, null, null, null, getAccessBlock(anotheruser,
|
993
|
true, false, false, true, false), null, null, null, null);
|
994
|
Thread.sleep(2000);
|
995
|
updateDocid(newdocid + ".2", testdocument, FAILURE, true);
|
996
|
|
997
|
// try to set the permissions for the inline data
|
998
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
|
999
|
testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
|
1000
|
true, false, false, false, true), null, null, null, null);
|
1001
|
// ERRRRRRRRRRRR
|
1002
|
// updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
|
1003
|
|
1004
|
// try to delete the document
|
1005
|
deleteDocid(newdocid + ".1", FAILURE, true);
|
1006
|
m.logout();
|
1007
|
|
1008
|
// delete the document
|
1009
|
m.login(username, password);
|
1010
|
deleteDocid(newdocid + ".1", SUCCESS, false);
|
1011
|
m.logout();
|
1012
|
|
1013
|
// ///////Case 4./////////////////////
|
1014
|
// insert an inline document - change permission only
|
1015
|
debug("Case 4:");
|
1016
|
m.login(username, password);
|
1017
|
newdocid = generateDocid();
|
1018
|
|
1019
|
// insert a document which gives read access to the inline document
|
1020
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1021
|
testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
|
1022
|
true, false, false, false, true), null, null, null, null);
|
1023
|
insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
|
1024
|
m.logout();
|
1025
|
|
1026
|
// login as another user
|
1027
|
m.login(anotheruser, anotherpassword);
|
1028
|
|
1029
|
// try to read the document and the inline data
|
1030
|
readDocid(newdocid + ".1", SUCCESS, false);
|
1031
|
readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, SUCCESS,
|
1032
|
false);
|
1033
|
|
1034
|
// try to update the inline data
|
1035
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing update",
|
1036
|
testEmlInlineBlock2, null, null, null, getAccessBlock(anotheruser,
|
1037
|
true, false, false, false, true), null, null, null, null);
|
1038
|
Thread.sleep(2000);
|
1039
|
updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
|
1040
|
|
1041
|
// try to set the permissions for the inline data
|
1042
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1043
|
testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
|
1044
|
true, true, true, true, false), null, null, null, null);
|
1045
|
Thread.sleep(2000);
|
1046
|
updateDocid(newdocid + ".3", testdocument, SUCCESS, false);
|
1047
|
|
1048
|
// try to delete the document
|
1049
|
// sleep needed only in case of inline data - jing said that
|
1050
|
// somehow the thread writing data to xml_index takes too much time
|
1051
|
// when used with inline data. hence if delete is requested too soon
|
1052
|
// database gives an error of xml_index records left with FK to
|
1053
|
// xml_document record which is going to be deleted.
|
1054
|
Thread.sleep(10000);
|
1055
|
|
1056
|
deleteDocid(newdocid + ".3", SUCCESS, false);
|
1057
|
m.logout();
|
1058
|
|
1059
|
} catch (MetacatAuthException mae) {
|
1060
|
fail("Authorization failed:\n" + mae.getMessage());
|
1061
|
} catch (MetacatInaccessibleException mie) {
|
1062
|
fail("Metacat Inaccessible:\n" + mie.getMessage());
|
1063
|
} catch (Exception e) {
|
1064
|
fail("General exception:\n" + e.getMessage());
|
1065
|
}
|
1066
|
}
|
1067
|
|
1068
|
/***************************************************************************
|
1069
|
* For EML 2.0.1, checking the following cases: when only Inline data is
|
1070
|
* uploaded by a user with the following different access controls specified
|
1071
|
* in addiotnal metadata in another document 1.read 2.write 3.change permission
|
1072
|
* 4.all And another user tries to do the following: -> tries to read it ->
|
1073
|
* tries to update it -> tries to set permissions on it -> tries to delete it
|
1074
|
*/
|
1075
|
public void inlineData201CasesTest_4() {
|
1076
|
debug("\nRunning: inlineData201CasesTest_4()");
|
1077
|
try {
|
1078
|
// ///////Case 1./////////////////////
|
1079
|
// insert an inline document - read only
|
1080
|
m.login(username, password);
|
1081
|
newdocid = generateDocid();
|
1082
|
|
1083
|
// insert a document which gives read access to the inline document
|
1084
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1085
|
testEmlInlineBlock1, null, null, null, null, getAccessBlock(
|
1086
|
anotheruser, true, true, false, false, false), null, null,
|
1087
|
null);
|
1088
|
insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
|
1089
|
m.logout();
|
1090
|
|
1091
|
// login as another user
|
1092
|
m.login(anotheruser, anotherpassword);
|
1093
|
|
1094
|
// try to read the document and the inline data
|
1095
|
readDocid(newdocid + ".1", FAILURE, true);
|
1096
|
// ERRRRRRRRRRRRRRR
|
1097
|
readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE,
|
1098
|
true);
|
1099
|
|
1100
|
// try to update the inline data
|
1101
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing update",
|
1102
|
testEmlInlineBlock2, null, null, null, null, getAccessBlock(
|
1103
|
anotheruser, true, true, false, false, false), null, null,
|
1104
|
null);
|
1105
|
updateDocid(newdocid + ".2", testdocument, FAILURE, true);
|
1106
|
|
1107
|
// try to set the permissions for the inline data
|
1108
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1109
|
testEmlInlineBlock1, null, null, null, null, getAccessBlock(
|
1110
|
anotheruser, true, false, false, false, true), null, null,
|
1111
|
null);
|
1112
|
updateDocid(newdocid + ".2", testdocument, FAILURE, true);
|
1113
|
|
1114
|
// try to delete the document
|
1115
|
deleteDocid(newdocid + ".1", FAILURE, true);
|
1116
|
m.logout();
|
1117
|
|
1118
|
// delete the document
|
1119
|
m.login(username, password);
|
1120
|
deleteDocid(newdocid + ".1", SUCCESS, false);
|
1121
|
m.logout();
|
1122
|
|
1123
|
// ///////Case 2./////////////////////
|
1124
|
// insert an inline document - write only
|
1125
|
m.login(username, password);
|
1126
|
newdocid = generateDocid();
|
1127
|
|
1128
|
// insert a document which gives read access to the inline document
|
1129
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1130
|
testEmlInlineBlock1, null, null, null, null, getAccessBlock(
|
1131
|
anotheruser, true, false, true, false, false), null, null,
|
1132
|
null);
|
1133
|
insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
|
1134
|
m.logout();
|
1135
|
|
1136
|
// login as another user
|
1137
|
m.login(anotheruser, anotherpassword);
|
1138
|
|
1139
|
// try to read the document and the inline data
|
1140
|
readDocid(newdocid + ".1", FAILURE, true);
|
1141
|
readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE,
|
1142
|
true);
|
1143
|
|
1144
|
// try to update the inline data
|
1145
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing update",
|
1146
|
testEmlInlineBlock2, null, null, null, null, getAccessBlock(
|
1147
|
anotheruser, true, false, true, false, false), null, null,
|
1148
|
null);
|
1149
|
// ERRRRRRRRRRRRRRRRRRRRRRRR
|
1150
|
// updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
|
1151
|
|
1152
|
// try to set the permissions for the inline data
|
1153
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1154
|
testEmlInlineBlock1, null, null, null, null, getAccessBlock(
|
1155
|
anotheruser, true, false, false, false, true), null, null,
|
1156
|
null);
|
1157
|
updateDocid(newdocid + ".2", testdocument, FAILURE, true);
|
1158
|
|
1159
|
// try to delete the document
|
1160
|
deleteDocid(newdocid + ".1", FAILURE, true);
|
1161
|
m.logout();
|
1162
|
|
1163
|
// delete the document
|
1164
|
m.login(username, password);
|
1165
|
deleteDocid(newdocid + ".1", SUCCESS, false);
|
1166
|
m.logout();
|
1167
|
|
1168
|
// ///////Case 3./////////////////////
|
1169
|
// insert an inline document - change permission only
|
1170
|
m.login(username, password);
|
1171
|
newdocid = generateDocid();
|
1172
|
|
1173
|
// insert a document which gives read access to the inline document
|
1174
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1175
|
testEmlInlineBlock1, null, null, null, null, getAccessBlock(
|
1176
|
anotheruser, true, false, false, true, false), null, null,
|
1177
|
null);
|
1178
|
insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
|
1179
|
m.logout();
|
1180
|
|
1181
|
// login as another user
|
1182
|
m.login(anotheruser, anotherpassword);
|
1183
|
|
1184
|
// try to read the document and the inline data
|
1185
|
readDocid(newdocid + ".1", FAILURE, true);
|
1186
|
readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE,
|
1187
|
true);
|
1188
|
|
1189
|
// try to update the inline data
|
1190
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing update",
|
1191
|
testEmlInlineBlock2, null, null, null, null, getAccessBlock(
|
1192
|
anotheruser, true, false, false, true, false), null, null,
|
1193
|
null);
|
1194
|
updateDocid(newdocid + ".2", testdocument, FAILURE, true);
|
1195
|
|
1196
|
// try to set the permissions for the inline data
|
1197
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1198
|
testEmlInlineBlock1, null, null, null, null, getAccessBlock(
|
1199
|
anotheruser, true, false, false, false, true), null, null,
|
1200
|
null);
|
1201
|
// ERRRRRRRRRRRR
|
1202
|
// updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
|
1203
|
|
1204
|
// try to delete the document
|
1205
|
deleteDocid(newdocid + ".1", FAILURE, true);
|
1206
|
m.logout();
|
1207
|
|
1208
|
// delete the document
|
1209
|
m.login(username, password);
|
1210
|
deleteDocid(newdocid + ".1", SUCCESS, false);
|
1211
|
m.logout();
|
1212
|
|
1213
|
// ///////Case 4./////////////////////
|
1214
|
// insert an inline document - change permission only
|
1215
|
m.login(username, password);
|
1216
|
newdocid = generateDocid();
|
1217
|
|
1218
|
// insert a document which gives read access to the inline document
|
1219
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1220
|
testEmlInlineBlock1, null, null, null, null, getAccessBlock(
|
1221
|
anotheruser, true, false, false, false, true), null, null,
|
1222
|
null);
|
1223
|
insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
|
1224
|
m.logout();
|
1225
|
|
1226
|
// login as another user
|
1227
|
m.login(anotheruser, anotherpassword);
|
1228
|
|
1229
|
// try to read the document and the inline data
|
1230
|
readDocid(newdocid + ".1", FAILURE, true);
|
1231
|
// ERRRRRRRRRRRRRRR
|
1232
|
// readInlineDataWhichEqualsDoc(newdocid + ".1.1",
|
1233
|
// testEmlInlineBlock1, SUCCESS, false);
|
1234
|
|
1235
|
// try to update the inline data
|
1236
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing update",
|
1237
|
testEmlInlineBlock2, null, null, null, null, getAccessBlock(
|
1238
|
anotheruser, true, false, false, false, true), null, null,
|
1239
|
null);
|
1240
|
// ERRRRRR
|
1241
|
// updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
|
1242
|
|
1243
|
// try to set the permissions for the inline data
|
1244
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1245
|
testEmlInlineBlock1, null, null, null, null, getAccessBlock(
|
1246
|
anotheruser, true, true, true, true, false), null, null, null);
|
1247
|
// ERRRRRRRRRR
|
1248
|
// updateDocid(newdocid + ".3", testdocument, SUCCESS, false);
|
1249
|
|
1250
|
// try to delete the document
|
1251
|
deleteDocid(newdocid + ".3", FAILURE, true);
|
1252
|
m.logout();
|
1253
|
|
1254
|
// delete the document
|
1255
|
m.login(username, password);
|
1256
|
deleteDocid(newdocid + ".1", SUCCESS, false);
|
1257
|
m.logout();
|
1258
|
|
1259
|
} catch (MetacatAuthException mae) {
|
1260
|
fail("Authorization failed:\n" + mae.getMessage());
|
1261
|
} catch (MetacatInaccessibleException mie) {
|
1262
|
fail("Metacat Inaccessible:\n" + mie.getMessage());
|
1263
|
} catch (Exception e) {
|
1264
|
fail("General exception:\n" + e.getMessage());
|
1265
|
}
|
1266
|
}
|
1267
|
|
1268
|
/***************************************************************************
|
1269
|
* For EML 2.1.0, checking the following cases: when only Inline data is
|
1270
|
* uploaded by a user with the following different access controls specified
|
1271
|
* in addiotnal metadata in another document 1.read 2.write 3.change permission
|
1272
|
* 4.all And another user tries to do the following: -> tries to read it ->
|
1273
|
* tries to update it -> tries to set permissions on it -> tries to delete it
|
1274
|
*/
|
1275
|
public void inlineData210CasesTest_4() {
|
1276
|
debug("\nRunning: inlineData210CasesTest_4()");
|
1277
|
try {
|
1278
|
// ///////Case 1./////////////////////
|
1279
|
// insert an inline document - read only
|
1280
|
m.login(username, password);
|
1281
|
newdocid = generateDocid();
|
1282
|
|
1283
|
// insert a document which gives read access to the inline document
|
1284
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1285
|
testEmlInlineBlock1, null, null, null, null, getAccessBlock(
|
1286
|
anotheruser, true, true, false, false, false), null, null,
|
1287
|
null);
|
1288
|
debug("testdocument: " + testdocument);
|
1289
|
insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
|
1290
|
m.logout();
|
1291
|
|
1292
|
// login as another user
|
1293
|
m.login(anotheruser, anotherpassword);
|
1294
|
|
1295
|
// try to read the document and the inline data
|
1296
|
readDocid(newdocid + ".1", FAILURE, true);
|
1297
|
// ERRRRRRRRRRRRRRR
|
1298
|
readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE,
|
1299
|
true);
|
1300
|
|
1301
|
// try to update the inline data
|
1302
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing update",
|
1303
|
testEmlInlineBlock2, null, null, null, null, getAccessBlock(
|
1304
|
anotheruser, true, true, false, false, false), null, null,
|
1305
|
null);
|
1306
|
Thread.sleep(2000);
|
1307
|
updateDocid(newdocid + ".2", testdocument, FAILURE, true);
|
1308
|
|
1309
|
// try to set the permissions for the inline data
|
1310
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1311
|
testEmlInlineBlock1, null, null, null, null, getAccessBlock(
|
1312
|
anotheruser, true, false, false, false, true), null, null,
|
1313
|
null);
|
1314
|
Thread.sleep(2000);
|
1315
|
updateDocid(newdocid + ".2", testdocument, FAILURE, true);
|
1316
|
|
1317
|
// try to delete the document
|
1318
|
deleteDocid(newdocid + ".1", FAILURE, true);
|
1319
|
m.logout();
|
1320
|
|
1321
|
// delete the document
|
1322
|
m.login(username, password);
|
1323
|
deleteDocid(newdocid + ".1", SUCCESS, false);
|
1324
|
m.logout();
|
1325
|
|
1326
|
// ///////Case 2./////////////////////
|
1327
|
// insert an inline document - write only
|
1328
|
m.login(username, password);
|
1329
|
newdocid = generateDocid();
|
1330
|
|
1331
|
// insert a document which gives read access to the inline document
|
1332
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1333
|
testEmlInlineBlock1, null, null, null, null, getAccessBlock(
|
1334
|
anotheruser, true, false, true, false, false), null, null,
|
1335
|
null);
|
1336
|
insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
|
1337
|
m.logout();
|
1338
|
|
1339
|
// login as another user
|
1340
|
m.login(anotheruser, anotherpassword);
|
1341
|
|
1342
|
// try to read the document and the inline data
|
1343
|
readDocid(newdocid + ".1", FAILURE, true);
|
1344
|
readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE,
|
1345
|
true);
|
1346
|
|
1347
|
// try to update the inline data
|
1348
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing update",
|
1349
|
testEmlInlineBlock2, null, null, null, null, getAccessBlock(
|
1350
|
anotheruser, true, false, true, false, false), null, null,
|
1351
|
null);
|
1352
|
// ERRRRRRRRRRRRRRRRRRRRRRRR
|
1353
|
// updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
|
1354
|
|
1355
|
// try to set the permissions for the inline data
|
1356
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1357
|
testEmlInlineBlock1, null, null, null, null, getAccessBlock(
|
1358
|
anotheruser, true, false, false, false, true), null, null,
|
1359
|
null);
|
1360
|
Thread.sleep(2000);
|
1361
|
updateDocid(newdocid + ".2", testdocument, FAILURE, true);
|
1362
|
|
1363
|
// try to delete the document
|
1364
|
deleteDocid(newdocid + ".1", FAILURE, true);
|
1365
|
m.logout();
|
1366
|
|
1367
|
// delete the document
|
1368
|
m.login(username, password);
|
1369
|
deleteDocid(newdocid + ".1", SUCCESS, false);
|
1370
|
m.logout();
|
1371
|
|
1372
|
// ///////Case 3./////////////////////
|
1373
|
// insert an inline document - change permission only
|
1374
|
m.login(username, password);
|
1375
|
newdocid = generateDocid();
|
1376
|
|
1377
|
// insert a document which gives read access to the inline document
|
1378
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1379
|
testEmlInlineBlock1, null, null, null, null, getAccessBlock(
|
1380
|
anotheruser, true, false, false, true, false), null, null,
|
1381
|
null);
|
1382
|
insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
|
1383
|
m.logout();
|
1384
|
|
1385
|
// login as another user
|
1386
|
m.login(anotheruser, anotherpassword);
|
1387
|
|
1388
|
// try to read the document and the inline data
|
1389
|
readDocid(newdocid + ".1", FAILURE, true);
|
1390
|
readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE,
|
1391
|
true);
|
1392
|
|
1393
|
// try to update the inline data
|
1394
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing update",
|
1395
|
testEmlInlineBlock2, null, null, null, null, getAccessBlock(
|
1396
|
anotheruser, true, false, false, true, false), null, null,
|
1397
|
null);
|
1398
|
Thread.sleep(2000);
|
1399
|
updateDocid(newdocid + ".2", testdocument, FAILURE, true);
|
1400
|
|
1401
|
// try to set the permissions for the inline data
|
1402
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1403
|
testEmlInlineBlock1, null, null, null, null, getAccessBlock(
|
1404
|
anotheruser, true, false, false, false, true), null, null,
|
1405
|
null);
|
1406
|
// ERRRRRRRRRRRR
|
1407
|
// updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
|
1408
|
|
1409
|
// try to delete the document
|
1410
|
deleteDocid(newdocid + ".1", FAILURE, true);
|
1411
|
m.logout();
|
1412
|
|
1413
|
// delete the document
|
1414
|
m.login(username, password);
|
1415
|
deleteDocid(newdocid + ".1", SUCCESS, false);
|
1416
|
m.logout();
|
1417
|
|
1418
|
// ///////Case 4./////////////////////
|
1419
|
// insert an inline document - change permission only
|
1420
|
m.login(username, password);
|
1421
|
newdocid = generateDocid();
|
1422
|
|
1423
|
// insert a document which gives read access to the inline document
|
1424
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1425
|
testEmlInlineBlock1, null, null, null, null, getAccessBlock(
|
1426
|
anotheruser, true, false, false, false, true), null, null,
|
1427
|
null);
|
1428
|
insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
|
1429
|
m.logout();
|
1430
|
|
1431
|
// login as another user
|
1432
|
m.login(anotheruser, anotherpassword);
|
1433
|
|
1434
|
// try to read the document and the inline data
|
1435
|
readDocid(newdocid + ".1", FAILURE, true);
|
1436
|
// ERRRRRRRRRRRRRRR
|
1437
|
// readInlineDataWhichEqualsDoc(newdocid + ".1.1",
|
1438
|
// testEmlInlineBlock1, SUCCESS, false);
|
1439
|
|
1440
|
// try to update the inline data
|
1441
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing update",
|
1442
|
testEmlInlineBlock2, null, null, null, null, getAccessBlock(
|
1443
|
anotheruser, true, false, false, false, true), null, null,
|
1444
|
null);
|
1445
|
// ERRRRRR
|
1446
|
// updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
|
1447
|
|
1448
|
// try to set the permissions for the inline data
|
1449
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1450
|
testEmlInlineBlock1, null, null, null, null, getAccessBlock(
|
1451
|
anotheruser, true, true, true, true, false), null, null, null);
|
1452
|
// ERRRRRRRRRR
|
1453
|
// updateDocid(newdocid + ".3", testdocument, SUCCESS, false);
|
1454
|
|
1455
|
// try to delete the document
|
1456
|
deleteDocid(newdocid + ".3", FAILURE, true);
|
1457
|
m.logout();
|
1458
|
|
1459
|
// delete the document
|
1460
|
m.login(username, password);
|
1461
|
deleteDocid(newdocid + ".1", SUCCESS, false);
|
1462
|
m.logout();
|
1463
|
|
1464
|
} catch (MetacatAuthException mae) {
|
1465
|
fail("Authorization failed:\n" + mae.getMessage());
|
1466
|
} catch (MetacatInaccessibleException mie) {
|
1467
|
fail("Metacat Inaccessible:\n" + mie.getMessage());
|
1468
|
} catch (Exception e) {
|
1469
|
fail("General exception:\n" + e.getMessage());
|
1470
|
}
|
1471
|
}
|
1472
|
|
1473
|
/***************************************************************************
|
1474
|
* For EML 2.0.1, checking the following cases: -> when no inline data is
|
1475
|
* specified in the document but rules are specified in additional metadata ->
|
1476
|
* when a user has RW permission for inline data, can he delete it -> when
|
1477
|
* inline data with document refering to it is uploaded with read access for
|
1478
|
* metadata and no access for data
|
1479
|
*/
|
1480
|
public void inlineData201CasesTest_5() {
|
1481
|
debug("\nRunning: inlineData201CasesTest_5()");
|
1482
|
try {
|
1483
|
|
1484
|
m.login(username, password);
|
1485
|
|
1486
|
/////////Case 1
|
1487
|
debug("Case 1:");
|
1488
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1489
|
null, null, null, null, null, getAccessBlock(anotheruser, true, true,
|
1490
|
false, false, false), null, null, null);
|
1491
|
newdocid = generateDocid();
|
1492
|
|
1493
|
// try to insert the wrong document. This document is wrong because
|
1494
|
// it has an access block but no distribution.
|
1495
|
insertDocid(newdocid + ".1", testdocument, FAILURE, false);
|
1496
|
m.logout();
|
1497
|
|
1498
|
/////////Case 2
|
1499
|
debug("Case 2:");
|
1500
|
m.login(username, password);
|
1501
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1502
|
testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
|
1503
|
true, true, true, false, false), null, null, null, null);
|
1504
|
newdocid = generateDocid();
|
1505
|
insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
|
1506
|
m.logout();
|
1507
|
|
1508
|
m.login(anotheruser, anotherpassword);
|
1509
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1510
|
null, null, null, null, getAccessBlock(anotheruser, true, true, true,
|
1511
|
false, false), null, null, null, null);
|
1512
|
/// ERRRRRRRRRRRR
|
1513
|
Thread.sleep(2000);
|
1514
|
updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
|
1515
|
|
1516
|
/////////Case 3
|
1517
|
debug("Case 3:");
|
1518
|
// insert a document
|
1519
|
m.login(username, password);
|
1520
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1521
|
testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
|
1522
|
true, false, false, false, true), getAccessBlock(anotheruser,
|
1523
|
false, false, false, false, true), null, null, null);
|
1524
|
newdocid = generateDocid();
|
1525
|
insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
|
1526
|
m.logout();
|
1527
|
|
1528
|
// try to read the Inline data
|
1529
|
m.login(anotheruser, anotherpassword);
|
1530
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1531
|
"", null, null, null, getAccessBlock(anotheruser, true, false, false,
|
1532
|
false, true), getAccessBlock(anotheruser, false, false,
|
1533
|
false, false, true), null, null, null);
|
1534
|
readDocidWhichEqualsDoc(newdocid + ".1", testdocument, SUCCESS, false);
|
1535
|
|
1536
|
// try to update the rules for inline data
|
1537
|
// / ERRRRRRRRRRRR it lets you do that
|
1538
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1539
|
testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
|
1540
|
true, false, false, false, true), getAccessBlock(anotheruser,
|
1541
|
true, false, false, false, true), null, null, null);
|
1542
|
Thread.sleep(2000);
|
1543
|
updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
|
1544
|
readDocidWhichEqualsDoc(newdocid + ".2", testdocument, SUCCESS, false);
|
1545
|
|
1546
|
m.logout();
|
1547
|
} catch (MetacatAuthException mae) {
|
1548
|
fail("Authorization failed:\n" + mae.getMessage());
|
1549
|
} catch (MetacatInaccessibleException mie) {
|
1550
|
fail("Metacat Inaccessible:\n" + mie.getMessage());
|
1551
|
} catch (Exception e) {
|
1552
|
fail("General exception:\n" + e.getMessage());
|
1553
|
}
|
1554
|
}
|
1555
|
|
1556
|
/***************************************************************************
|
1557
|
* For EML 2.1.0, checking the following cases: -> when no inline data is
|
1558
|
* specified in the document but rules are specified in additional metadata ->
|
1559
|
* when a user has RW permission for inline data, can he delete it -> when
|
1560
|
* inline data with document refering to it is uploaded with read access for
|
1561
|
* metadata and no access for data
|
1562
|
*/
|
1563
|
public void inlineData210CasesTest_5() {
|
1564
|
debug("\nRunning: inlineData210CasesTest_5()");
|
1565
|
try {
|
1566
|
|
1567
|
/////////Case 2
|
1568
|
debug("Case 2:");
|
1569
|
m.login(username, password);
|
1570
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1571
|
testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
|
1572
|
true, true, true, false, false), null, null, null, null);
|
1573
|
newdocid = generateDocid();
|
1574
|
insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
|
1575
|
m.logout();
|
1576
|
|
1577
|
m.login(anotheruser, anotherpassword);
|
1578
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1579
|
null, null, null, null, getAccessBlock(anotheruser, true, true, true,
|
1580
|
false, false), null, null, null, null);
|
1581
|
/// ERRRRRRRRRRRR
|
1582
|
Thread.sleep(2000);
|
1583
|
updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
|
1584
|
|
1585
|
/////////Case 3
|
1586
|
debug("Case 3:");
|
1587
|
// insert a document
|
1588
|
m.login(username, password);
|
1589
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1590
|
testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
|
1591
|
true, false, false, false, true), getAccessBlock(anotheruser,
|
1592
|
false, false, false, false, true), null, null, null);
|
1593
|
newdocid = generateDocid();
|
1594
|
insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
|
1595
|
m.logout();
|
1596
|
|
1597
|
// try to read the Inline data
|
1598
|
m.login(anotheruser, anotherpassword);
|
1599
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1600
|
"", null, null, null, getAccessBlock(anotheruser, true, false, false,
|
1601
|
false, true), getAccessBlock(anotheruser, false, false,
|
1602
|
false, false, true), null, null, null);
|
1603
|
readDocidWhichEqualsDoc(newdocid + ".1", testdocument, SUCCESS, false);
|
1604
|
|
1605
|
// try to update the rules for inline data
|
1606
|
// shouldn't succeed
|
1607
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1608
|
testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
|
1609
|
true, false, false, false, true), getAccessBlock(anotheruser,
|
1610
|
true, false, false, false, true), null, null, null);
|
1611
|
debug("inserting this: " + testdocument);
|
1612
|
Thread.sleep(2000);
|
1613
|
updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
|
1614
|
readDocidWhichEqualsDoc(newdocid + ".2", testdocument, SUCCESS, false);
|
1615
|
|
1616
|
m.logout();
|
1617
|
} catch (MetacatAuthException mae) {
|
1618
|
fail("Authorization failed:\n" + mae.getMessage());
|
1619
|
} catch (MetacatInaccessibleException mie) {
|
1620
|
fail("Metacat Inaccessible:\n" + mie.getMessage());
|
1621
|
} catch (Exception e) {
|
1622
|
fail("General exception:\n" + e.getMessage());
|
1623
|
}
|
1624
|
}
|
1625
|
|
1626
|
/***************************************************************************
|
1627
|
* for EML 2.0.1, checking the following cases: -> when inline data is
|
1628
|
* inserted and updated, do access rules apply to the old document
|
1629
|
*/
|
1630
|
public void inlineData201CasesTest_6() {
|
1631
|
debug("\nRunning: inlineData201CasesTest_6()");
|
1632
|
try {
|
1633
|
|
1634
|
// insert the document
|
1635
|
m.login(username, password);
|
1636
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1637
|
testEmlInlineBlock1, testEmlInlineBlock2, null, null, getAccessBlock(
|
1638
|
anotheruser, true, true, true, false, false), getAccessBlock(
|
1639
|
anotheruser, false, false, false, false, true),
|
1640
|
getAccessBlock(anotheruser, false, false, false, false, true), null,
|
1641
|
null);
|
1642
|
newdocid = generateDocid();
|
1643
|
insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
|
1644
|
|
1645
|
m.logout();
|
1646
|
|
1647
|
// update the document
|
1648
|
m.login(anotheruser, anotherpassword);
|
1649
|
testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing update",
|
1650
|
testEmlInlineBlock2, testEmlInlineBlock1, null, null, getAccessBlock(
|
1651
|
anotheruser, true, true, true, false, false), getAccessBlock(
|
1652
|
anotheruser, false, false, false, false, true),
|
1653
|
getAccessBlock(anotheruser, false, false, false, false, true), null,
|
1654
|
null);
|
1655
|
Thread.sleep(2000);
|
1656
|
updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
|
1657
|
|
1658
|
// try reading the inline document
|
1659
|
readInlineDataWhichEqualsDoc(newdocid + ".2.1", testEmlInlineBlock1, FAILURE,
|
1660
|
true);
|
1661
|
|
1662
|
System.out.print("Trying to read " + newdocid + ".1.1");
|
1663
|
readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE,
|
1664
|
true);
|
1665
|
|
1666
|
m.logout();
|
1667
|
} catch (MetacatAuthException mae) {
|
1668
|
fail("Authorization failed:\n" + mae.getMessage());
|
1669
|
} catch (MetacatInaccessibleException mie) {
|
1670
|
fail("Metacat Inaccessible:\n" + mie.getMessage());
|
1671
|
} catch (Exception e) {
|
1672
|
fail("General exception:\n" + e.getMessage());
|
1673
|
}
|
1674
|
}
|
1675
|
|
1676
|
/***************************************************************************
|
1677
|
* for EML 2.1.0, checking the following cases: -> when inline data is
|
1678
|
* inserted and updated, do access rules apply to the old document
|
1679
|
*/
|
1680
|
public void inlineData210CasesTest_6() {
|
1681
|
debug("\nRunning: inlineData210CasesTest_6()");
|
1682
|
try {
|
1683
|
|
1684
|
// insert the document
|
1685
|
m.login(username, password);
|
1686
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
|
1687
|
testEmlInlineBlock1, testEmlInlineBlock2, null, null, getAccessBlock(
|
1688
|
anotheruser, true, true, true, false, false), getAccessBlock(
|
1689
|
anotheruser, false, false, false, false, true),
|
1690
|
getAccessBlock(anotheruser, false, false, false, false, true), null,
|
1691
|
null);
|
1692
|
newdocid = generateDocid();
|
1693
|
insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
|
1694
|
|
1695
|
m.logout();
|
1696
|
|
1697
|
// update the document
|
1698
|
m.login(anotheruser, anotherpassword);
|
1699
|
testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing update",
|
1700
|
testEmlInlineBlock2, testEmlInlineBlock1, null, null, getAccessBlock(
|
1701
|
anotheruser, true, true, true, false, false), getAccessBlock(
|
1702
|
anotheruser, false, false, false, false, true),
|
1703
|
getAccessBlock(anotheruser, false, false, false, false, true), null,
|
1704
|
null);
|
1705
|
Thread.sleep(2000);
|
1706
|
updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
|
1707
|
|
1708
|
// try reading the inline document
|
1709
|
readInlineDataWhichEqualsDoc(newdocid + ".2.1", testEmlInlineBlock1, FAILURE,
|
1710
|
true);
|
1711
|
|
1712
|
System.out.print("Trying to read " + newdocid + ".1.1");
|
1713
|
readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE,
|
1714
|
true);
|
1715
|
|
1716
|
m.logout();
|
1717
|
} catch (MetacatAuthException mae) {
|
1718
|
fail("Authorization failed:\n" + mae.getMessage());
|
1719
|
} catch (MetacatInaccessibleException mie) {
|
1720
|
fail("Metacat Inaccessible:\n" + mie.getMessage());
|
1721
|
} catch (Exception e) {
|
1722
|
fail("General exception:\n" + e.getMessage());
|
1723
|
}
|
1724
|
}
|
1725
|
|
1726
|
|
1727
|
/**
|
1728
|
* Insert a document into metacat. The expected result is passed as result
|
1729
|
*/
|
1730
|
|
1731
|
private String insertDocid(String docid, String docText, boolean result,
|
1732
|
boolean expectKarmaException) {
|
1733
|
String response = null;
|
1734
|
try {
|
1735
|
response = m.insert(docid,
|
1736
|
new StringReader(testdocument), null);
|
1737
|
if (result) {
|
1738
|
assertTrue( (response.indexOf("<success>") != -1));
|
1739
|
assertTrue(response.indexOf(docid) != -1);
|
1740
|
}
|
1741
|
else {
|
1742
|
assertTrue( (response.indexOf("<success>") == -1));
|
1743
|
}
|
1744
|
System.err.println(response);
|
1745
|
}
|
1746
|
catch (MetacatInaccessibleException mie) {
|
1747
|
fail("Metacat Inaccessible:\n" + mie.getMessage());
|
1748
|
}
|
1749
|
catch (InsufficientKarmaException ike) {
|
1750
|
if (!expectKarmaException) {
|
1751
|
fail("Insufficient karma:\n" + ike.getMessage());
|
1752
|
}
|
1753
|
}
|
1754
|
catch (MetacatException me) {
|
1755
|
if (result) {
|
1756
|
fail("Metacat Error:\n" + me.getMessage());
|
1757
|
}
|
1758
|
else {
|
1759
|
System.err.println("Metacat Error: " + me.getMessage());
|
1760
|
}
|
1761
|
}
|
1762
|
catch (Exception e) {
|
1763
|
fail("General exception:\n" + e.getMessage());
|
1764
|
}
|
1765
|
return response;
|
1766
|
}
|
1767
|
|
1768
|
/**
|
1769
|
* Insert a document into metacat. The expected result is passed as result
|
1770
|
*/
|
1771
|
|
1772
|
// private String uploadDocid(String docid, String filePath, boolean result,
|
1773
|
// boolean expectedKarmaException) {
|
1774
|
// String response = null;
|
1775
|
// try {
|
1776
|
// response = m.upload(docid, new File(filePath));
|
1777
|
// if (result) {
|
1778
|
// assertTrue( (response.indexOf("<success>") != -1));
|
1779
|
// assertTrue(response.indexOf(docid) != -1);
|
1780
|
// }
|
1781
|
// else {
|
1782
|
// assertTrue( (response.indexOf("<success>") == -1));
|
1783
|
// }
|
1784
|
// System.err.println("respose from metacat: " + response);
|
1785
|
// }
|
1786
|
// catch (MetacatInaccessibleException mie) {
|
1787
|
// fail("Metacat Inaccessible:\n" + mie.getMessage());
|
1788
|
// }
|
1789
|
// catch (InsufficientKarmaException ike) {
|
1790
|
// if (!expectedKarmaException) {
|
1791
|
// fail("Insufficient karma:\n" + ike.getMessage());
|
1792
|
// }
|
1793
|
// }
|
1794
|
// catch (MetacatException me) {
|
1795
|
// if (result) {
|
1796
|
// fail("Metacat Error:\n" + me.getMessage());
|
1797
|
// }
|
1798
|
// else {
|
1799
|
// System.err.println("Metacat Error: " + me.getMessage());
|
1800
|
// }
|
1801
|
// }
|
1802
|
// catch (Exception e) {
|
1803
|
// fail("General exception:\n" + e.getMessage());
|
1804
|
// }
|
1805
|
// return response;
|
1806
|
// }
|
1807
|
|
1808
|
/**
|
1809
|
* Update a document in metacat. The expected result is passed as result
|
1810
|
*/
|
1811
|
private String updateDocid(String docid, String docText, boolean result,
|
1812
|
boolean expectedKarmaFailure) {
|
1813
|
String response = null;
|
1814
|
try {
|
1815
|
response = m.update(docid,
|
1816
|
new StringReader(testdocument), null);
|
1817
|
|
1818
|
if (result) {
|
1819
|
assertTrue( (response.indexOf("<success>") != -1));
|
1820
|
assertTrue(response.indexOf(docid) != -1);
|
1821
|
}
|
1822
|
else {
|
1823
|
assertTrue( (response.indexOf("<success>") == -1));
|
1824
|
}
|
1825
|
System.err.println(response);
|
1826
|
}
|
1827
|
catch (MetacatInaccessibleException mie) {
|
1828
|
fail("Metacat Inaccessible:\n" + mie.getMessage());
|
1829
|
}
|
1830
|
catch (InsufficientKarmaException ike) {
|
1831
|
if (!expectedKarmaFailure) {
|
1832
|
fail("Insufficient karma:\n" + ike.getMessage());
|
1833
|
}
|
1834
|
}
|
1835
|
catch (MetacatException me) {
|
1836
|
if (! (expectedKarmaFailure &&
|
1837
|
(me.getMessage().indexOf(
|
1838
|
"User tried to update an access module when they don't have \"ALL\" permission") !=
|
1839
|
-1))) {
|
1840
|
fail("Metacat Error:\n" + me.getMessage());
|
1841
|
}
|
1842
|
}
|
1843
|
catch (Exception e) {
|
1844
|
fail("General exception:\n" + e.getMessage());
|
1845
|
}
|
1846
|
|
1847
|
return response;
|
1848
|
}
|
1849
|
|
1850
|
/**
|
1851
|
* Delete a document into metacat. The expected result is passed as result
|
1852
|
*/
|
1853
|
private void deleteDocid(String docid, boolean result,
|
1854
|
boolean expectedKarmaFailure) {
|
1855
|
try {
|
1856
|
String response = m.delete(docid);
|
1857
|
if (result) {
|
1858
|
assertTrue(response.indexOf("<success>") != -1);
|
1859
|
}
|
1860
|
else {
|
1861
|
assertTrue(response.indexOf("<success>") == -1);
|
1862
|
}
|
1863
|
System.err.println(response);
|
1864
|
}
|
1865
|
catch (MetacatInaccessibleException mie) {
|
1866
|
fail("Metacat Inaccessible:\n" + mie.getMessage());
|
1867
|
}
|
1868
|
catch (InsufficientKarmaException ike) {
|
1869
|
if (!expectedKarmaFailure) {
|
1870
|
fail("Insufficient karma:\n" + ike.getMessage());
|
1871
|
}
|
1872
|
|
1873
|
}
|
1874
|
catch (MetacatException me) {
|
1875
|
if (result) {
|
1876
|
fail("Metacat Error:\n" + me.getMessage());
|
1877
|
}
|
1878
|
else {
|
1879
|
System.err.println("Metacat Error:\n" + me.getMessage());
|
1880
|
}
|
1881
|
}
|
1882
|
catch (Exception e) {
|
1883
|
fail("General exception:\n" + e.getMessage());
|
1884
|
}
|
1885
|
}
|
1886
|
|
1887
|
/**
|
1888
|
* Read inline data from metacat. The expected result is passed as result
|
1889
|
*/
|
1890
|
private void readInlineDataWhichEqualsDoc(String docid, String testDoc,
|
1891
|
boolean result,
|
1892
|
boolean expextedKarmaFailure) {
|
1893
|
try {
|
1894
|
debug("before read, docid: " + docid);
|
1895
|
Reader r = m.readInlineData(docid);
|
1896
|
debug("after read, docid: " + docid);
|
1897
|
String doc = IOUtil.getAsString(r, true);
|
1898
|
debug("after get as string, doc: " + doc);
|
1899
|
|
1900
|
if (result) {
|
1901
|
if (!testDoc.equals(doc)) {
|
1902
|
System.out.println("doc :" + doc);
|
1903
|
System.out.println("testDoc:" + testDoc);
|
1904
|
}
|
1905
|
|
1906
|
assertTrue(testDoc.equals(doc));
|
1907
|
}
|
1908
|
else {
|
1909
|
System.out.println("doc :" + doc);
|
1910
|
System.out.println("testDoc:" + testDoc);
|
1911
|
assertTrue(doc.indexOf("<error>") != -1);
|
1912
|
}
|
1913
|
}
|
1914
|
catch (MetacatInaccessibleException mie) {
|
1915
|
fail("Metacat Inaccessible:\n" + mie.getMessage());
|
1916
|
}
|
1917
|
catch (InsufficientKarmaException ike) {
|
1918
|
if (!expextedKarmaFailure) {
|
1919
|
fail("Insufficient karma:\n" + ike.getMessage());
|
1920
|
}
|
1921
|
}
|
1922
|
catch (MetacatException me) {
|
1923
|
if (result) {
|
1924
|
fail("Metacat Error:\n" + me.getMessage());
|
1925
|
}
|
1926
|
else {
|
1927
|
System.err.println("Metacat Error:\n" + me.getMessage());
|
1928
|
}
|
1929
|
}
|
1930
|
catch (Exception e) {
|
1931
|
fail("General exception:\n" + e.getMessage());
|
1932
|
}
|
1933
|
}
|
1934
|
|
1935
|
/**
|
1936
|
* Read a document from metacat. The expected result is passed as result
|
1937
|
*/
|
1938
|
private void readDocid(String docid, boolean result,
|
1939
|
boolean expextedKarmaFailure) {
|
1940
|
try {
|
1941
|
Reader r = m.read(docid);
|
1942
|
String response = IOUtil.getAsString(r, true);
|
1943
|
|
1944
|
if (!result) {
|
1945
|
assertTrue(response.indexOf("<success>") == -1);
|
1946
|
}
|
1947
|
System.err.println(response);
|
1948
|
}
|
1949
|
catch (MetacatInaccessibleException mie) {
|
1950
|
fail("Metacat Inaccessible:\n" + mie.getMessage());
|
1951
|
}
|
1952
|
catch (InsufficientKarmaException ike) {
|
1953
|
if (!expextedKarmaFailure) {
|
1954
|
fail("Insufficient karma:\n" + ike.getMessage());
|
1955
|
}
|
1956
|
}
|
1957
|
catch (MetacatException me) {
|
1958
|
if (result) {
|
1959
|
fail("Metacat Error:\n" + me.getMessage());
|
1960
|
}
|
1961
|
else {
|
1962
|
System.err.println("Metacat Error:\n" + me.getMessage());
|
1963
|
}
|
1964
|
}
|
1965
|
catch (Exception e) {
|
1966
|
fail("General exception:\n" + e.getMessage());
|
1967
|
}
|
1968
|
}
|
1969
|
|
1970
|
/**
|
1971
|
* Read a document from metacat and check if it is equal to a given string.
|
1972
|
* The expected result is passed as result
|
1973
|
*/
|
1974
|
|
1975
|
private void readDocidWhichEqualsDoc(String docid, String testDoc,
|
1976
|
boolean result,
|
1977
|
boolean expextedKarmaFailure) {
|
1978
|
try {
|
1979
|
Reader r = m.read(docid);
|
1980
|
String doc = IOUtil.getAsString(r, true);
|
1981
|
if (result) {
|
1982
|
|
1983
|
if (!testDoc.equals(doc)) {
|
1984
|
System.out.println("doc ***********************");
|
1985
|
System.out.println(doc);
|
1986
|
System.out.println("end doc ***********************");
|
1987
|
System.out.println("testDoc ***********************");
|
1988
|
System.out.println(testDoc);
|
1989
|
System.out.println("end testDoc ***********************");
|
1990
|
}
|
1991
|
|
1992
|
assertTrue(testDoc.equals(doc));
|
1993
|
}
|
1994
|
else {
|
1995
|
assertTrue(doc.indexOf("<error>") != -1);
|
1996
|
}
|
1997
|
}
|
1998
|
catch (MetacatInaccessibleException mie) {
|
1999
|
fail("Metacat Inaccessible:\n" + mie.getMessage());
|
2000
|
}
|
2001
|
catch (InsufficientKarmaException ike) {
|
2002
|
if (result) {
|
2003
|
fail("Metacat Error:\n" + ike.getMessage());
|
2004
|
}
|
2005
|
else {
|
2006
|
System.out.println("Metacat Error:\n" + ike.getMessage());
|
2007
|
}
|
2008
|
}
|
2009
|
catch (MetacatException me) {
|
2010
|
if (result) {
|
2011
|
fail("Metacat Error:\n" + me.getMessage());
|
2012
|
}
|
2013
|
else {
|
2014
|
System.out.println("Metacat Error:\n" + me.getMessage());
|
2015
|
}
|
2016
|
}
|
2017
|
catch (Exception e) {
|
2018
|
fail("General exception:\n" + e.getMessage());
|
2019
|
}
|
2020
|
|
2021
|
}
|
2022
|
|
2023
|
/**
|
2024
|
* Create a hopefully unique docid for testing insert and update. Does
|
2025
|
* not include the 'revision' part of the id.
|
2026
|
*
|
2027
|
* @return a String docid based on the current date and time
|
2028
|
*/
|
2029
|
private String generateDocid() {
|
2030
|
StringBuffer docid = new StringBuffer(prefix);
|
2031
|
docid.append(".");
|
2032
|
|
2033
|
try {
|
2034
|
Thread.sleep(1100);
|
2035
|
} catch (InterruptedException ie) {
|
2036
|
System.out.println("Warning: generateDocid() could not sleep 1100 ms");
|
2037
|
}
|
2038
|
// Create a calendar to get the date formatted properly
|
2039
|
String[] ids = TimeZone.getAvailableIDs( -8 * 60 * 60 * 1000);
|
2040
|
SimpleTimeZone pdt = new SimpleTimeZone( -8 * 60 * 60 * 1000, ids[0]);
|
2041
|
pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
|
2042
|
pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY,
|
2043
|
2 * 60 * 60 * 1000);
|
2044
|
Calendar calendar = new GregorianCalendar(pdt);
|
2045
|
Date trialTime = new Date();
|
2046
|
calendar.setTime(trialTime);
|
2047
|
docid.append(calendar.get(Calendar.YEAR));
|
2048
|
docid.append(calendar.get(Calendar.DAY_OF_YEAR));
|
2049
|
docid.append(calendar.get(Calendar.HOUR_OF_DAY));
|
2050
|
docid.append(calendar.get(Calendar.MINUTE));
|
2051
|
docid.append(calendar.get(Calendar.SECOND));
|
2052
|
|
2053
|
return docid.toString();
|
2054
|
}
|
2055
|
}
|