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