Project

General

Profile

« Previous | Next » 

Revision 4477

Added by daigle about 16 years ago

Add test cases for EML 2.1.0 documents. Add some generics typing.

View differences:

test/edu/ucsb/nceas/metacattest/InlineDataAccessTest.java
45 45
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
46 46
import junit.framework.Test;
47 47
import junit.framework.TestSuite;
48
import java.io.File;
49 48

  
50 49
/**
51 50
 * A JUnit test for testing Access Control for Inline data in Metacat
......
77 76

  
78 77
    private Metacat m;
79 78

  
80
    /**
81
     * These variables are for eml-2.0.1 only. For other eml versions,
82
     * this function might have to modified
83
     */
84

  
85
    private String testEmlHeader =
79
    private String testEml_200_Header =
86 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" +
87 89
        " xmlns:eml=\"eml://ecoinformatics.org/eml-2.0.1\"" +
88 90
        " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
89 91
        " packageId=\"eml.1.1\" system=\"knb\"" +
90 92
        " xsi:schemaLocation=\"eml://ecoinformatics.org/eml-2.0.1 eml.xsd\"" +
91 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\">";
92 102

  
93 103
    private String testEmlCreatorBlock =
94 104
        "<creator scope=\"document\">                                       " +
......
119 129
        "    <detector type=\"EM\"></detector>                              " +
120 130
        "  </instrument>                                                    ";
121 131

  
122
    private String testdoc = testEmlHeader +
123
        "<dataset scope=\"document\"><title>the title</title>"
124
        +  testEmlCreatorBlock
125
        + "<distribution scope=\"document\" id=\"inlineEntity1\">"
126
        + "<inline>" + testEmlInlineBlock1 + "</inline></distribution>"
127
        + "<distribution scope=\"document\" id=\"inlineEntity2\">"
128
        + "<inline>" + testEmlInlineBlock2 + "</inline></distribution>"
129
        + testEmlContactBlock
130
        + getAccessBlock(anotheruser, true, false, false, false, true)
131
        + "</dataset><additionalMetadata><describes>inlineEntity2"
132
        + "</describes></additionalMetadata>"
133
        + "<additionalMetadata>"
134
        + "<describes>inlineEntity1</describes>"
135
        + "<describes>inlineEntity2</describes>"
136
        + getAccessBlock(anotheruser, false, false, false, false, true)
137
        + "</additionalMetadata></eml:eml>";
138 132

  
139

  
140 133
    /**
141 134
     * This function returns an access block based on the params passed
142 135
     */
......
184 177
    }
185 178

  
186 179
    /**
187
     * This function returns a valid eml document with no access rules
188
     * This function is for eml-2.0.1 only. For other eml versions,
189
     * this function might have to modified
190
     */
191
    private String getTestEmlDoc(String title, String inlineData1,
192
                                 String inlineData2, String OnlineUrl1,
193
                                 String OnlineUrl2, String docAccessBlock,
194
                                 String inlineAccessBlock1,
195
                                 String inlineAccessBlock2,
196
                                 String OnlineAccessBlock1,
197
                                 String OnlineAccessBlock2) {
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) {
198 186

  
199
        String testDocument = "";
200
        testDocument = testDocument + testEmlHeader +
201
            "<dataset scope=\"document\"><title>" + title + "</title>" +
202
            testEmlCreatorBlock;
187
		String testDocument = testEml_201_Header;
203 188

  
204
        if (inlineData1 != null) {
205
            testDocument = testDocument
206
                + "<distribution scope=\"document\" id=\"inlineEntity1\">"
207
                + "<inline>" + inlineData1 + "</inline></distribution>";
208
        }
209
        if (inlineData2 != null) {
210
            testDocument = testDocument
211
                + "<distribution scope=\"document\" id=\"inlineEntity2\">"
212
                + "<inline>" + inlineData2 + "</inline></distribution>";
213
        }
214
        if (OnlineUrl1 != null) {
215
            testDocument = testDocument
216
                + "<distribution scope=\"document\" id=\"InlineEntity1\">"
217
                + "<Inline><url function=\"download\">"
218
                + OnlineUrl1 + "</url></Inline></distribution>";
219
        }
220
        if (OnlineUrl2 != null) {
221
            testDocument = testDocument +
222
                "<distribution scope=\"document\" id=\"InlineEntity2\">"
223
                + "<Inline><url function=\"download\">"
224
                + OnlineUrl2 + "</url></Inline></distribution>";
225
        }
226
        testDocument += testEmlContactBlock;
189
		testDocument += "<dataset scope=\"document\"><title>" + title + "</title>"
190
				+ testEmlCreatorBlock;
227 191

  
228
        if (docAccessBlock != null) {
229
            testDocument += docAccessBlock;
230
        }
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
		}
231 221

  
232
        testDocument += "</dataset>";
222
		testDocument += "</dataset>";
233 223

  
234
        if (inlineAccessBlock1 != null) {
235
            testDocument += "<additionalMetadata>";
236
            testDocument += "<describes>inlineEntity1</describes>";
237
            testDocument += inlineAccessBlock1;
238
            testDocument += "</additionalMetadata>";
239
        }
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
		}
240 232

  
241
        if (inlineAccessBlock2 != null) {
242
            testDocument += "<additionalMetadata>";
243
            testDocument += "<describes>inlineEntity2</describes>";
244
            testDocument += inlineAccessBlock2;
245
            testDocument += "</additionalMetadata>";
246
        }
233
		if (inlineAccessBlock2 != null) {
234
			testDocument += "<additionalMetadata>";
235
			testDocument += "<describes>inlineEntity2</describes>";
236
			testDocument += inlineAccessBlock2;
237
			testDocument += "</additionalMetadata>";
238
		}
247 239

  
248
        if (OnlineAccessBlock1 != null) {
249
            testDocument += "<additionalMetadata>";
250
            testDocument += "<describes>InlineEntity1</describes>";
251
            testDocument += OnlineAccessBlock1;
252
            testDocument += "</additionalMetadata>";
253
        }
240
		if (onlineAccessBlock1 != null) {
241
			testDocument += "<additionalMetadata>";
242
			testDocument += "<describes>InlineEntity1</describes>";
243
			testDocument += onlineAccessBlock1;
244
			testDocument += "</additionalMetadata>";
245
		}
254 246

  
255
        if (OnlineAccessBlock2 != null) {
256
            testDocument += "<additionalMetadata>";
257
            testDocument += "<describes>InlineEntity2</describes>";
258
            testDocument += OnlineAccessBlock2;
259
            testDocument += "</additionalMetadata>";
260
        }
247
		if (onlineAccessBlock2 != null) {
248
			testDocument += "<additionalMetadata>";
249
			testDocument += "<describes>InlineEntity2</describes>";
250
			testDocument += onlineAccessBlock2;
251
			testDocument += "</additionalMetadata>";
252
		}
261 253

  
262
        testDocument += "</eml:eml>";
254
		testDocument += "</eml:eml>";
263 255

  
264
        //System.out.println("Returning following document" + testDocument);
265
        return testDocument;
266
    }
256
		debug("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) {
267 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>\t</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("Returning following document" + testDocument);
358
		return testDocument;
359
	}
360

  
268 361
    /**
269
     * Constructor to build the test
270
     *
271
     * @param name the name of the test method
272
     */
362
	 * Constructor to build the test
363
	 * 
364
	 * @param name
365
	 *            the name of the test method
366
	 */
273 367
    public InlineDataAccessTest(String name) {
274 368
        super(name);
275 369
        newdocid = generateDocid();
......
302 396
        TestSuite suite = new TestSuite();
303 397
        suite.addTest(new InlineDataAccessTest("initialize"));
304 398

  
305
        suite.addTest(new InlineDataAccessTest("inlineDataCasesTest_1"));
306
        suite.addTest(new InlineDataAccessTest("inlineDataCasesTest_2"));
307
        suite.addTest(new InlineDataAccessTest("inlineDataCasesTest_3"));
308
        suite.addTest(new InlineDataAccessTest("inlineDataCasesTest_4"));
309
        suite.addTest(new InlineDataAccessTest("inlineDataCasesTest_5"));
310
        suite.addTest(new InlineDataAccessTest("inlineDataCasesTest_6"));
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"));
311 411

  
312 412
        return suite;
313 413
    }
......
321 421
        assertTrue(1 == 1);
322 422
    }
323 423

  
324
    /** *********
325
     * Checking the following cases:
424
    /**
425
     * For EML 2.0.1, checking the following cases:
326 426
     * when only Inline data is uploaded by a user and
327 427
     * -> he tries to read it  - success
328 428
     * -> he tries to add same docid again  - failure
......
331 431
     * -> he tries to delete it  - success
332 432
     * -> he tries to read it after deleteing - failure
333 433
     */
334
    public void inlineDataCasesTest_1() {
335
		debug("\nRunning: inlineDataCasesTest_1()");
336
        try {
337
            newdocid = generateDocid();
338
            m.login(username, password);
434
    public void inlineData201CasesTest_1() {
435
		debug("\nRunning: inlineData201CasesTest_1()");
436
		try {
437
			newdocid = generateDocid();
438
			m.login(username, password);
339 439

  
340
            // insert a document
341
            testdocument = getTestEmlDoc("Testing insert", testEmlInlineBlock1,
342
                                         null, null, null, null,
343
                                         null, null, null, null);
440
			// insert a document
441
			testdocument = get201TestEmlDoc("Testing insert", testEmlInlineBlock1,
442
					null, null, null, null, null, null, null, null);
344 443

  
345
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
346
            readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, true);
444
			insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
445
			readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, true);
347 446

  
348
            // insert same document again
349
            insertDocid(newdocid + ".1", testdocument, FAILURE, false);
447
			// insert same document again
448
			insertDocid(newdocid + ".1", testdocument, FAILURE, false);
350 449

  
351
            // update by changing inline data
352
            testdocument = getTestEmlDoc("Testing update inline",
353
                                         testEmlInlineBlock2,
354
                                         null, null, null, null,
355
                                         null, null, null, null);
356
            updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
357
            readDocidWhichEqualsDoc(newdocid + ".2", testdocument, SUCCESS, true);
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);
358 456

  
359
            // update by removing inline data
360
            testdocument = getTestEmlDoc("Testing update inline",
361
                                         null,
362
                                         null, null, null, null,
363
                                         null, null, null, null);
364
            updateDocid(newdocid + ".3", testdocument, SUCCESS, false);
365
            readDocidWhichEqualsDoc(newdocid + ".3", testdocument, SUCCESS, true);
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);
366 463

  
367
            // update by introducing inline data
368
            testdocument = getTestEmlDoc("Testing update inline",
369
                                         testEmlInlineBlock1,
370
                                         null, null, null, null,
371
                                         null, null, null, null);
372
            updateDocid(newdocid + ".4", testdocument, SUCCESS, false);
373
            readDocidWhichEqualsDoc(newdocid + ".4", testdocument, SUCCESS, true);
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);
374 470

  
375
            // read inline data only
376
            readInlineDataWhichEqualsDoc(newdocid + ".1.1",
377
                                         testEmlInlineBlock1, SUCCESS, false);
471
			// read inline data only
472
			readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, SUCCESS,
473
					false);
378 474

  
379
            // delete the inline data
380
            // sleep needed only in case of inline data - jing said that
381
            // somehow the thread writing data to xml_index takes too much time
382
            // when used with inline data. hence if delete is requested too soon
383
            // database gives an error of xml_index records left with FK to
384
            // xml_document record which is going to be deleted.
385
            Thread.sleep(10000);
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);
386 482

  
387
            deleteDocid(newdocid + ".4", SUCCESS, false);
388
            readDocidWhichEqualsDoc(newdocid + ".4", testdocument, FAILURE, false);
389
            m.logout();
390
        }
391
        catch (MetacatAuthException mae) {
392
            fail("Authorization failed:\n" + mae.getMessage());
393
        }
394
        catch (MetacatInaccessibleException mie) {
395
            fail("Metacat Inaccessible:\n" + mie.getMessage());
396
        }
397
        catch (Exception e) {
398
            fail("General exception:\n" + e.getMessage());
399
        }
400
    }
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);
401 507

  
402
    /** *********
403
     * Checking the following cases:
404
     * when only inline data is uploaded by a user and another user
405
     * -> tries to read it  - failure
406
     * -> tries to read inline data only - failure
407
     * -> tries to update - failure
408
     * -> tries to delete it  - failure
409
     */
410
    public void inlineDataCasesTest_2() {
411
		debug("\nRunning: inlineDataCasesTest_2()");
412
        try {
413
            newdocid = generateDocid();
414
            m.login(username, password);
508
			// insert a document
509
			testdocument = get210TestEmlDoc("Testing insert", testEmlInlineBlock1,
510
					null, null, null, null, null, null, null, null);
415 511

  
416
            // insert a document
417
            testdocument = getTestEmlDoc("Testing insert", testEmlInlineBlock1,
418
                                         null, null, null, null,
419
                                         null, null, null, null);
512
			insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
513
			readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, true);
420 514

  
421
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
422
            readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, true);
515
			// insert same document again
516
			insertDocid(newdocid + ".1", testdocument, FAILURE, false);
423 517

  
424
            // login as another user
425
            m.logout();
426
            m.login(anotheruser, anotherpassword);
518
			// update by changing inline data
519
			testdocument = get210TestEmlDoc("Testing update inline",
520
					testEmlInlineBlock2, null, null, null, null, null, null, null, null);
521
			Thread.sleep(2000);
522
			updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
523
			readDocidWhichEqualsDoc(newdocid + ".2", testdocument, SUCCESS, true);
427 524

  
428
            // try to read document or data only
429
            readDocidWhichEqualsDoc(newdocid, testdocument, FAILURE, true);
430
            readInlineDataWhichEqualsDoc(newdocid + ".1.1",
431
                                         testEmlInlineBlock1, FAILURE, true);
525
			// update by removing inline data
526
			testdocument = get210TestEmlDoc("Testing update inline", null, null,
527
					null, null, null, null, null, null, null);
528
			Thread.sleep(2000);
529
			updateDocid(newdocid + ".3", testdocument, SUCCESS, false);
530
			readDocidWhichEqualsDoc(newdocid + ".3", testdocument, SUCCESS, true);
432 531

  
433
            // try to update the document
434
            testdocument = getTestEmlDoc("Testing insert", testEmlInlineBlock1,
435
                                         null, null, null, null,
436
                                         null, null, null, null);
437
            updateDocid(newdocid + ".2", testdocument, FAILURE, true);
532
			// update by introducing inline data
533
			testdocument = get210TestEmlDoc("Testing update inline",
534
					testEmlInlineBlock1, null, null, null, null, null, null, null, null);
535
			Thread.sleep(2000);
536
			updateDocid(newdocid + ".4", testdocument, SUCCESS, false);
537
			readDocidWhichEqualsDoc(newdocid + ".4", testdocument, SUCCESS, true);
438 538

  
439
            // try to delete the document
440
            deleteDocid(newdocid + ".1", FAILURE, true);
441
            m.logout();
539
			// read inline data only
540
			readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, SUCCESS,
541
					false);
442 542

  
443
            // delete the document
444
            m.login(username, password);
445
            deleteDocid(newdocid + ".1", SUCCESS, false);
446
            m.logout();
543
			// delete the inline data
544
			// sleep needed only in case of inline data - jing said that
545
			// somehow the thread writing data to xml_index takes too much time
546
			// when used with inline data. hence if delete is requested too soon
547
			// database gives an error of xml_index records left with FK to
548
			// xml_document record which is going to be deleted.
549
			Thread.sleep(10000);
447 550

  
448
        }
449
        catch (MetacatAuthException mae) {
450
            fail("Authorization failed:\n" + mae.getMessage());
451
        }
452
        catch (MetacatInaccessibleException mie) {
453
            fail("Metacat Inaccessible:\n" + mie.getMessage());
454
        }
455
        catch (Exception e) {
456
            fail("General exception:\n" + e.getMessage());
457
        }
458
    }
551
			deleteDocid(newdocid + ".4", SUCCESS, false);
552
			readDocidWhichEqualsDoc(newdocid + ".4", testdocument, FAILURE, false);
553
			m.logout();
554
		} catch (MetacatAuthException mae) {
555
			fail("Authorization failed:\n" + mae.getMessage());
556
		} catch (MetacatInaccessibleException mie) {
557
			fail("Metacat Inaccessible:\n" + mie.getMessage());
558
		} catch (Exception e) {
559
			fail("General exception:\n" + e.getMessage());
560
		}
561
	}
459 562

  
460
    /** *********
461
     * Checking the following cases:
462
     * when only inline data is uploaded by a user with the following different
463
     * access controls in another document
464
     *   1.read
465
     *   2.write
466
     *   3.change permission
467
     *   4.all
468
     * And another user tries to do the following:
469
     * -> tries to read it
470
     * -> tries to update it
471
     * -> tries to set permissions on it
472
     * -> tries to delete it
473
     */
474
    public void inlineDataCasesTest_3() {
475
		debug("\nRunning: inlineDataCasesTest_3()");
476
        try {
563
    /***************************************************************************
564
	 * For EML 2.0.1, checking the following cases: when only inline data is 
565
	 * uploaded by a user and another user -> tries to read it - failure -> 
566
	 * tries to read inline data only - failure -> tries to update - failure -> 
567
	 * tries to delete it - failure
568
	 */
569
    public void inlineData201CasesTest_2() {
570
		debug("\nRunning: inlineData201CasesTest_2()");
571
		try {
572
			newdocid = generateDocid();
573
			m.login(username, password);
477 574

  
478
            /////////Case 1./////////////////////
479
            // insert an inline document - read only
480
            m.login(username, password);
481
            newdocid = generateDocid();
575
			// insert a document
576
			testdocument = get201TestEmlDoc("Testing insert", testEmlInlineBlock1,
577
					null, null, null, null, null, null, null, null);
482 578

  
483
            // insert a document which gives read access to the inline document
484
            testdocument = getTestEmlDoc("InlineDataAccessTest: Doing insert",
485
                                         testEmlInlineBlock1, null, null,
486
                                         null, getAccessBlock(anotheruser, true,
487
                true, false, false, false),
488
                                         null, null, null, null);
489
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
490
            m.logout();
579
			insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
580
			readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, true);
491 581

  
492
            // login as another user
493
            m.login(anotheruser, anotherpassword);
582
			// login as another user
583
			m.logout();
584
			m.login(anotheruser, anotherpassword);
494 585

  
495
            // try to read the document and the inline data
496
            readDocid(newdocid + ".1", SUCCESS, false);
497
            readInlineDataWhichEqualsDoc(newdocid + ".1.1",
498
                                         testEmlInlineBlock1, SUCCESS, false);
586
			// try to read document or data only
587
			readDocidWhichEqualsDoc(newdocid, testdocument, FAILURE, true);
588
			readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE,
589
					true);
499 590

  
500
            // try to update the inline data
501
            testdocument = getTestEmlDoc("InlineDataAccessTest: Doing update",
502
                                         testEmlInlineBlock2, null, null,
503
                                         null, getAccessBlock(anotheruser, true,
504
                true, false, false, false),
505
                                         null, null, null, null);
506
            updateDocid(newdocid + ".2", testdocument, FAILURE, true);
591
			// try to update the document
592
			testdocument = get201TestEmlDoc("Testing insert", testEmlInlineBlock1,
593
					null, null, null, null, null, null, null, null);
594
			Thread.sleep(2000);
595
			updateDocid(newdocid + ".2", testdocument, FAILURE, true);
507 596

  
508
            // try to set the permissions for the inline data
509
            testdocument = getTestEmlDoc("InlineDataAccessTest: Doing insert",
510
                                         testEmlInlineBlock1, null, null,
511
                                         null, getAccessBlock(anotheruser, true,
512
                false, false, false, true),
513
                                         null, null, null, null);
514
            updateDocid(newdocid + ".2", testdocument, FAILURE, true);
597
			// try to delete the document
598
			deleteDocid(newdocid + ".1", FAILURE, true);
599
			m.logout();
515 600

  
516
            // try to delete the document
517
            deleteDocid(newdocid + ".1", FAILURE, true);
518
            m.logout();
601
			// delete the document
602
			m.login(username, password);
603
			deleteDocid(newdocid + ".1", SUCCESS, false);
604
			m.logout();
519 605

  
520
            // delete the document
521
            m.login(username, password);
522
            deleteDocid(newdocid + ".1", SUCCESS, false);
523
            m.logout();
606
		} catch (MetacatAuthException mae) {
607
			fail("Authorization failed:\n" + mae.getMessage());
608
		} catch (MetacatInaccessibleException mie) {
609
			fail("Metacat Inaccessible:\n" + mie.getMessage());
610
		} catch (Exception e) {
611
			fail("General exception:\n" + e.getMessage());
612
		}
613
	}
614
    
615
    /***************************************************************************
616
	 * For EML 2.1.0, checking the following cases: when only inline data is 
617
	 * uploaded by a user and another user -> tries to read it - failure -> 
618
	 * tries to read inline data only - failure -> tries to update - failure -> 
619
	 * tries to delete it - failure
620
	 */
621
    public void inlineData210CasesTest_2() {
622
		debug("\nRunning: inlineData210CasesTest_2()");
623
		try {
624
			newdocid = generateDocid();
625
			m.login(username, password);
524 626

  
525
            /////////Case 2./////////////////////
526
            // insert an inline document - write only
527
            m.login(username, password);
528
            newdocid = generateDocid();
627
			// insert a document
628
			testdocument = get210TestEmlDoc("Testing insert", testEmlInlineBlock1,
629
					null, null, null, null, null, null, null, null);
529 630

  
530
            // insert a document which gives read access to the inline document
531
            testdocument = getTestEmlDoc("InlineDataAccessTest: Doing insert",
532
                                         testEmlInlineBlock1, null, null,
533
                                         null, getAccessBlock(anotheruser, true,
534
                                         false, true, false, false),
535
                                         null, null, null, null);
536
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
537
            m.logout();
631
			insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
632
			readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, true);
538 633

  
539
            // login as another user
540
            m.login(anotheruser, anotherpassword);
634
			// login as another user
635
			m.logout();
636
			m.login(anotheruser, anotherpassword);
541 637

  
542
            // try to read the document and the inline data
543
            readDocid(newdocid + ".1", FAILURE, true);
544
            readInlineDataWhichEqualsDoc(newdocid + ".1.1",
545
                                         testEmlInlineBlock1, FAILURE, true);
638
			// try to read document or data only
639
			readDocidWhichEqualsDoc(newdocid, testdocument, FAILURE, true);
640
			readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE,
641
					true);
546 642

  
547
            // try to update the inline data
548
            testdocument = getTestEmlDoc("InlineDataAccessTest: Doing update",
549
                                         testEmlInlineBlock2, null, null,
550
                                         null, getAccessBlock(anotheruser, true,
551
                                         false, true, false, false),
552
                                         null, null, null, null);
553
            updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
643
			// try to update the document
644
			testdocument = get210TestEmlDoc("Testing insert", testEmlInlineBlock1,
645
					null, null, null, null, null, null, null, null);
646
			Thread.sleep(2000);
647
			updateDocid(newdocid + ".2", testdocument, FAILURE, true);
554 648

  
555
            // try to set the permissions for the inline data
556
            testdocument = getTestEmlDoc("InlineDataAccessTest: Doing insert",
557
                                         testEmlInlineBlock1, null, null,
558
                                         null, getAccessBlock(anotheruser, true,
559
                false, false, false, true),
560
                                         null, null, null, null);
561
            updateDocid(newdocid + ".3", testdocument, FAILURE, true);
649
			// try to delete the document
650
			deleteDocid(newdocid + ".1", FAILURE, true);
651
			m.logout();
562 652

  
563
            // try to delete the document
564
            deleteDocid(newdocid + ".2", FAILURE, true);
565
            m.logout();
653
			// delete the document
654
			m.login(username, password);
655
			deleteDocid(newdocid + ".1", SUCCESS, false);
656
			m.logout();
566 657

  
567
            // delete the document
568
            m.login(username, password);
569
            deleteDocid(newdocid + ".2", SUCCESS, false);
570
            m.logout();
658
		} catch (MetacatAuthException mae) {
659
			fail("Authorization failed:\n" + mae.getMessage());
660
		} catch (MetacatInaccessibleException mie) {
661
			fail("Metacat Inaccessible:\n" + mie.getMessage());
662
		} catch (Exception e) {
663
			fail("General exception:\n" + e.getMessage());
664
		}
665
	}
571 666

  
572
            /////////Case 3./////////////////////
573
            // insert an inline document - change permission only
574
            m.login(username, password);
575
            newdocid = generateDocid();
667
    /***************************************************************************
668
	 * For EML 2.0.1, checking the following cases: 
669
	 * when only inline data is uploaded by a user with the following different 
670
	 * access controls in another document 1.read 2.write 3.change permission 
671
	 * 4.all And another user tries to do the following: -> tries to read it -> 
672
	 * tries to update it -> tries to set permissions on it -> tries to delete it
673
	 */
674
    public void inlineData201CasesTest_3() {
675
		debug("\nRunning: inlineData201CasesTest_3()");
676
		try {
576 677

  
577
            // insert a document which gives read access to the inline document
578
            testdocument = getTestEmlDoc("InlineDataAccessTest: Doing insert",
579
                                         testEmlInlineBlock1, null, null,
580
                                         null, getAccessBlock(anotheruser, true,
581
                false, false, true, false),
582
                                         null, null, null, null);
583
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
584
            m.logout();
678
			// ///////Case 1./////////////////////
679
			// insert an inline document - read only
680
			m.login(username, password);
681
			newdocid = generateDocid();
585 682

  
586
            // login as another user
587
            m.login(anotheruser, anotherpassword);
683
			// insert a document which gives read access to the inline document
684
			testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
685
					testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
686
							true, true, false, false, false), null, null, null, null);
687
			
688
			insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
689
			m.logout();
588 690

  
589
            // try to read the document and the inline data
590
            readDocid(newdocid + ".1", FAILURE, true);
591
            readInlineDataWhichEqualsDoc(newdocid + ".1.1",
592
                                         testEmlInlineBlock1, FAILURE, true);
691
			// login as another user
692
			m.login(anotheruser, anotherpassword);
593 693

  
594
            // try to update the inline data
595
            testdocument = getTestEmlDoc("InlineDataAccessTest: Doing update",
596
                                         testEmlInlineBlock2, null, null,
597
                                         null, getAccessBlock(anotheruser, true,
598
                false, false, true, false),
599
                                         null, null, null, null);
600
            updateDocid(newdocid + ".2", testdocument, FAILURE, true);
694
			// try to read the document and the inline data
695
			readDocid(newdocid + ".1", SUCCESS, false);
696
			readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, SUCCESS,
697
					false);
601 698

  
602
            // try to set the permissions for the inline data
603
            testdocument = getTestEmlDoc("InlineDataAccessTest: Doing insert",
604
                                         testEmlInlineBlock1, null, null,
605
                                         null, getAccessBlock(anotheruser, true,
606
                false, false, false, true),
607
                                         null, null, null, null);
608
            // ERRRRRRRRRRRR
609
            //updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
699
			// try to update the inline data
700
			testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing update",
701
					testEmlInlineBlock2, null, null, null, getAccessBlock(anotheruser,
702
							true, true, false, false, false), null, null, null, null);
703
			Thread.sleep(2000);
704
			updateDocid(newdocid + ".2", testdocument, FAILURE, true);
610 705

  
611
            // try to delete the document
612
            deleteDocid(newdocid + ".1", FAILURE, true);
613
            m.logout();
706
			// try to set the permissions for the inline data
707
			testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
708
					testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
709
							true, false, false, false, true), null, null, null, null);
710
			Thread.sleep(2000);
711
			updateDocid(newdocid + ".2", testdocument, FAILURE, true);
614 712

  
615
            // delete the document
616
            m.login(username, password);
617
            deleteDocid(newdocid + ".1", SUCCESS, false);
618
            m.logout();
713
			// try to delete the document
714
			deleteDocid(newdocid + ".1", FAILURE, true);
715
			m.logout();
619 716

  
717
			// delete the document
718
			m.login(username, password);
719
			deleteDocid(newdocid + ".1", SUCCESS, false);
720
			m.logout();
620 721

  
621
            /////////Case 4./////////////////////
622
            // insert an inline document - change permission only
623
            m.login(username, password);
624
            newdocid = generateDocid();
722
			// ///////Case 2./////////////////////
723
			// insert an inline document - write only
724
			m.login(username, password);
725
			newdocid = generateDocid();
625 726

  
626
            // insert a document which gives read access to the inline document
627
            testdocument = getTestEmlDoc("InlineDataAccessTest: Doing insert",
628
                                         testEmlInlineBlock1, null, null,
629
                                         null, getAccessBlock(anotheruser, true,
630
                                         false, false, false, true),
631
                                         null, null, null, null);
632
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
633
            m.logout();
727
			// insert a document which gives read access to the inline document
728
			testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
729
					testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
730
							true, false, true, false, false), null, null, null, null);
731
			insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
732
			m.logout();
634 733

  
635
            // login as another user
636
            m.login(anotheruser, anotherpassword);
734
			// login as another user
735
			m.login(anotheruser, anotherpassword);
637 736

  
638
            // try to read the document and the inline data
639
            readDocid(newdocid + ".1", SUCCESS, false);
640
            readInlineDataWhichEqualsDoc(newdocid + ".1.1",
641
                                         testEmlInlineBlock1, SUCCESS, false);
737
			// try to read the document and the inline data
738
			readDocid(newdocid + ".1", FAILURE, true);
739
			readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE,
740
					true);
642 741

  
643
            // try to update the inline data
644
            testdocument = getTestEmlDoc("InlineDataAccessTest: Doing update",
645
                                         testEmlInlineBlock2, null, null,
646
                                         null, getAccessBlock(anotheruser, true,
647
                                         false, false, false, true),
648
                                         null, null, null, null);
649
            updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
742
			// try to update the inline data
743
			testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing update",
744
					testEmlInlineBlock2, null, null, null, getAccessBlock(anotheruser,
745
							true, false, true, false, false), null, null, null, null);
746
			Thread.sleep(2000);
747
			updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
650 748

  
651
            // try to set the permissions for the inline data
652
            testdocument = getTestEmlDoc("InlineDataAccessTest: Doing insert",
653
                                         testEmlInlineBlock1, null, null,
654
                                         null, getAccessBlock(anotheruser, true,
655
                                         true, true, true, false),
656
                                         null, null, null, null);
657
            updateDocid(newdocid + ".3", testdocument, SUCCESS, false);
749
			// try to set the permissions for the inline data
750
			testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
751
					testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
752
							true, false, false, false, true), null, null, null, null);
753
			Thread.sleep(2000);
754
			updateDocid(newdocid + ".3", testdocument, FAILURE, true);
658 755

  
659
            // try to delete the document
660
            // sleep needed only in case of inline data - jing said that
661
            // somehow the thread writing data to xml_index takes too much time
662
            // when used with inline data. hence if delete is requested too soon
663
            // database gives an error of xml_index records left with FK to
664
            // xml_document record which is going to be deleted.
665
            Thread.sleep(10000);
756
			// try to delete the document
757
			deleteDocid(newdocid + ".2", FAILURE, true);
758
			m.logout();
666 759

  
667
            deleteDocid(newdocid + ".3", SUCCESS, false);
668
            m.logout();
760
			// delete the document
761
			m.login(username, password);
762
			deleteDocid(newdocid + ".2", SUCCESS, false);
763
			m.logout();
669 764

  
670
        }
671
        catch (MetacatAuthException mae) {
672
            fail("Authorization failed:\n" + mae.getMessage());
673
        }
674
        catch (MetacatInaccessibleException mie) {
675
            fail("Metacat Inaccessible:\n" + mie.getMessage());
676
        }
677
        catch (Exception e) {
678
            fail("General exception:\n" + e.getMessage());
679
        }
680
    }
765
			// ///////Case 3./////////////////////
766
			// insert an inline document - change permission only
767
			m.login(username, password);
768
			newdocid = generateDocid();
681 769

  
682
    /** *********
683
     * Checking the following cases:
684
     * when only Inline data is uploaded by a user with the following different
685
     * access controls specified in addiotnal metadata in another document
686
     *   1.read
687
     *   2.write
688
     *   3.change permission
689
     *   4.all
690
     * And another user tries to do the following:
691
     * -> tries to read it
692
     * -> tries to update it
693
     * -> tries to set permissions on it
694
     * -> tries to delete it
695
     */
696
    public void inlineDataCasesTest_4() {
697
		debug("\nRunning: inlineDataCasesTest_4()");
698
        try {
699
            /////////Case 1./////////////////////
700
            // insert an inline document - read only
701
            m.login(username, password);
702
            newdocid = generateDocid();
770
			// insert a document which gives read access to the inline document
771
			testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
772
					testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
773
							true, false, false, true, false), null, null, null, null);
774
			insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
775
			m.logout();
703 776

  
704
            // insert a document which gives read access to the inline document
705
            testdocument = getTestEmlDoc("InlineDataAccessTest: Doing insert",
706
                                         testEmlInlineBlock1, null, null, null,
707
                                         null, getAccessBlock(anotheruser, true,
708
                                         true, false, false, false),
709
                                         null, null, null);
710
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
711
            m.logout();
777
			// login as another user
778
			m.login(anotheruser, anotherpassword);
712 779

  
713
            // login as another user
714
            m.login(anotheruser, anotherpassword);
780
			// try to read the document and the inline data
781
			readDocid(newdocid + ".1", FAILURE, true);
782
			readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE,
783
					true);
715 784

  
716
            // try to read the document and the inline data
717
            readDocid(newdocid + ".1", FAILURE, true);
718
            // ERRRRRRRRRRRRRRR
719
            readInlineDataWhichEqualsDoc(newdocid + ".1.1",
720
                                         testEmlInlineBlock1, FAILURE, true);
785
			// try to update the inline data
786
			testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing update",
787
					testEmlInlineBlock2, null, null, null, getAccessBlock(anotheruser,
788
							true, false, false, true, false), null, null, null, null);
789
			Thread.sleep(2000);
790
			updateDocid(newdocid + ".2", testdocument, FAILURE, true);
721 791

  
722
            // try to update the inline data
723
            testdocument = getTestEmlDoc("InlineDataAccessTest: Doing update",
724
                                         testEmlInlineBlock2, null, null,null,
725
                                         null, getAccessBlock(anotheruser, true,
726
                                         true, false, false, false),
727
                                         null, null, null);
728
            updateDocid(newdocid + ".2", testdocument, FAILURE, true);
792
			// try to set the permissions for the inline data
793
			testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
794
					testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
795
							true, false, false, false, true), null, null, null, null);
796
			// ERRRRRRRRRRRR
797
			// updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
729 798

  
730
            // try to set the permissions for the inline data
731
            testdocument = getTestEmlDoc("InlineDataAccessTest: Doing insert",
732
                                         testEmlInlineBlock1, null, null,null,
733
                                         null, getAccessBlock(anotheruser, true,
734
                                         false, false, false, true),
735
                                         null, null, null);
736
            updateDocid(newdocid + ".2", testdocument, FAILURE, true);
799
			// try to delete the document
800
			deleteDocid(newdocid + ".1", FAILURE, true);
801
			m.logout();
737 802

  
738
            // try to delete the document
739
            deleteDocid(newdocid + ".1", FAILURE, true);
740
            m.logout();
803
			// delete the document
804
			m.login(username, password);
805
			deleteDocid(newdocid + ".1", SUCCESS, false);
806
			m.logout();
741 807

  
742
            // delete the document
743
            m.login(username, password);
744
            deleteDocid(newdocid + ".1", SUCCESS, false);
745
            m.logout();
808
			// ///////Case 4./////////////////////
809
			// insert an inline document - change permission only
810
			m.login(username, password);
811
			newdocid = generateDocid();
746 812

  
747
            /////////Case 2./////////////////////
748
            // insert an inline document - write only
749
            m.login(username, password);
750
            newdocid = generateDocid();
813
			// insert a document which gives read access to the inline document
814
			testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
815
					testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
816
							true, false, false, false, true), null, null, null, null);
817
			insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
818
			m.logout();
751 819

  
752
            // insert a document which gives read access to the inline document
753
            testdocument = getTestEmlDoc("InlineDataAccessTest: Doing insert",
754
                                         testEmlInlineBlock1, null, null, null,
755
                                         null, getAccessBlock(anotheruser, true,
756
                                         false, true, false, false),
757
                                         null, null, null);
758
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
759
            m.logout();
820
			// login as another user
821
			m.login(anotheruser, anotherpassword);
760 822

  
761
            // login as another user
762
            m.login(anotheruser, anotherpassword);
823
			// try to read the document and the inline data
824
			readDocid(newdocid + ".1", SUCCESS, false);
825
			readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, SUCCESS,
826
					false);
763 827

  
764
            // try to read the document and the inline data
765
            readDocid(newdocid + ".1", FAILURE, true);
766
            readInlineDataWhichEqualsDoc(newdocid + ".1.1",
767
                                         testEmlInlineBlock1, FAILURE, true);
828
			// try to update the inline data
829
			testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing update",
830
					testEmlInlineBlock2, null, null, null, getAccessBlock(anotheruser,
831
							true, false, false, false, true), null, null, null, null);
832
			Thread.sleep(2000);
833
			updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
768 834

  
769
            // try to update the inline data
770
            testdocument = getTestEmlDoc("InlineDataAccessTest: Doing update",
771
                                         testEmlInlineBlock2, null, null, null,
772
                                         null, getAccessBlock(anotheruser, true,
773
                                         false, true, false, false),
774
                                         null, null, null);
775
            //ERRRRRRRRRRRRRRRRRRRRRRRR
776
            // updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
835
			// try to set the permissions for the inline data
836
			testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert",
837
					testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
838
							true, true, true, true, false), null, null, null, null);
839
			Thread.sleep(2000);
840
			updateDocid(newdocid + ".3", testdocument, SUCCESS, false);
777 841

  
778
            // try to set the permissions for the inline data
779
            testdocument = getTestEmlDoc("InlineDataAccessTest: Doing insert",
780
                                         testEmlInlineBlock1, null, null, null,
781
                                         null, getAccessBlock(anotheruser, true,
782
                                         false, false, false, true),
783
                                         null, null, null);
784
            updateDocid(newdocid + ".2", testdocument, FAILURE, true);
842
			// try to delete the document
843
			// sleep needed only in case of inline data - jing said that
844
			// somehow the thread writing data to xml_index takes too much time
845
			// when used with inline data. hence if delete is requested too soon
846
			// database gives an error of xml_index records left with FK to
847
			// xml_document record which is going to be deleted.
848
			Thread.sleep(10000);
785 849

  
786
            // try to delete the document
787
            deleteDocid(newdocid + ".1", FAILURE, true);
788
            m.logout();
850
			deleteDocid(newdocid + ".3", SUCCESS, false);
851
			m.logout();
789 852

  
790
            // delete the document
791
            m.login(username, password);
792
            deleteDocid(newdocid + ".1", SUCCESS, false);
793
            m.logout();
853
		} catch (MetacatAuthException mae) {
854
			fail("Authorization failed:\n" + mae.getMessage());
855
		} catch (MetacatInaccessibleException mie) {
856
			fail("Metacat Inaccessible:\n" + mie.getMessage());
857
		} catch (Exception e) {
858
			fail("General exception:\n" + e.getMessage());
859
		}
860
	}
861
    
862
    /***************************************************************************
863
	 * For EML 2.1.0, checking the following cases: 
864
	 * when only inline data is uploaded by a user with the following different 
865
	 * access controls in another document 1.read 2.write 3.change permission 
866
	 * 4.all And another user tries to do the following: -> tries to read it -> 
867
	 * tries to update it -> tries to set permissions on it -> tries to delete it
868
	 */
869
    public void inlineData210CasesTest_3() {
870
		debug("\nRunning: inlineData210CasesTest_3()");
871
		try {
794 872

  
795
            /////////Case 3./////////////////////
796
            // insert an inline document - change permission only
797
            m.login(username, password);
798
            newdocid = generateDocid();
873
			// ///////Case 1./////////////////////
874
			// insert an inline document - read only
875
			m.login(username, password);
876
			newdocid = generateDocid();
799 877

  
800
            // insert a document which gives read access to the inline document
801
            testdocument = getTestEmlDoc("InlineDataAccessTest: Doing insert",
802
                                         testEmlInlineBlock1, null, null, null,
803
                                         null, getAccessBlock(anotheruser, true,
804
                                         false, false, true, false),
805
                                         null, null, null);
806
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
807
            m.logout();
878
			// insert a document which gives read access to the inline document
879
			testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
880
					testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
881
							true, true, false, false, false), null, null, null, null);
882
			insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
883
			m.logout();
808 884

  
809
            // login as another user
810
            m.login(anotheruser, anotherpassword);
885
			// login as another user
886
			m.login(anotheruser, anotherpassword);
811 887

  
812
            // try to read the document and the inline data
813
            readDocid(newdocid + ".1", FAILURE, true);
814
            readInlineDataWhichEqualsDoc(newdocid + ".1.1",
815
                                         testEmlInlineBlock1, FAILURE, true);
888
			// try to read the document and the inline data
889
			readDocid(newdocid + ".1", SUCCESS, false);
890
			readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, SUCCESS,
891
					false);
816 892

  
817
            // try to update the inline data
818
            testdocument = getTestEmlDoc("InlineDataAccessTest: Doing update",
819
                                         testEmlInlineBlock2, null, null, null,
820
                                         null, getAccessBlock(anotheruser, true,
821
                                         false, false, true, false),
822
                                         null, null, null);
823
            updateDocid(newdocid + ".2", testdocument, FAILURE, true);
893
			// try to update the inline data
894
			testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing update",
895
					testEmlInlineBlock2, null, null, null, getAccessBlock(anotheruser,
896
							true, true, false, false, false), null, null, null, null);
897
			Thread.sleep(2000);
898
			updateDocid(newdocid + ".2", testdocument, FAILURE, true);
824 899

  
825
            // try to set the permissions for the inline data
826
            testdocument = getTestEmlDoc("InlineDataAccessTest: Doing insert",
827
                                         testEmlInlineBlock1, null, null, null,
828
                                         null, getAccessBlock(anotheruser, true,
829
                                         false, false, false, true),
830
                                         null, null, null);
831
            // ERRRRRRRRRRRR
832
            //updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
900
			// try to set the permissions for the inline data
901
			testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
902
					testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
903
							true, false, false, false, true), null, null, null, null);
904
			Thread.sleep(2000);
905
			updateDocid(newdocid + ".2", testdocument, FAILURE, true);
833 906

  
834
            // try to delete the document
835
            deleteDocid(newdocid + ".1", FAILURE, true);
836
            m.logout();
907
			// try to delete the document
908
			deleteDocid(newdocid + ".1", FAILURE, true);
909
			m.logout();
837 910

  
838
            // delete the document
839
            m.login(username, password);
840
            deleteDocid(newdocid + ".1", SUCCESS, false);
841
            m.logout();
911
			// delete the document
912
			m.login(username, password);
913
			deleteDocid(newdocid + ".1", SUCCESS, false);
914
			m.logout();
842 915

  
916
			// ///////Case 2./////////////////////
917
			// insert an inline document - write only
918
			m.login(username, password);
919
			newdocid = generateDocid();
843 920

  
844
            /////////Case 4./////////////////////
845
            // insert an inline document - change permission only
846
            m.login(username, password);
847
            newdocid = generateDocid();
921
			// insert a document which gives read access to the inline document
922
			testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
923
					testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
924
							true, false, true, false, false), null, null, null, null);
925
			insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
926
			m.logout();
848 927

  
849
            // insert a document which gives read access to the inline document
850
            testdocument = getTestEmlDoc("InlineDataAccessTest: Doing insert",
851
                                         testEmlInlineBlock1, null, null, null,
852
                                         null, getAccessBlock(anotheruser, true,
853
                                         false, false, false, true),
854
                                         null, null, null);
855
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
856
            m.logout();
928
			// login as another user
929
			m.login(anotheruser, anotherpassword);
857 930

  
858
            // login as another user
859
            m.login(anotheruser, anotherpassword);
931
			// try to read the document and the inline data
932
			readDocid(newdocid + ".1", FAILURE, true);
933
			readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE,
934
					true);
860 935

  
861
            // try to read the document and the inline data
862
            readDocid(newdocid + ".1", FAILURE, true);
863
            // ERRRRRRRRRRRRRRR
864
            //readInlineDataWhichEqualsDoc(newdocid + ".1.1",
865
            //                             testEmlInlineBlock1, SUCCESS, false);
936
			// try to update the inline data
937
			testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing update",
938
					testEmlInlineBlock2, null, null, null, getAccessBlock(anotheruser,
939
							true, false, true, false, false), null, null, null, null);
940
			Thread.sleep(2000);
941
			updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
866 942

  
867
            // try to update the inline data
868
            testdocument = getTestEmlDoc("InlineDataAccessTest: Doing update",
869
                                         testEmlInlineBlock2, null, null, null,
870
                                         null, getAccessBlock(anotheruser, true,
871
                                         false, false, false, true),
872
                                         null, null, null);
873
            // ERRRRRR
874
            // updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
943
			// try to set the permissions for the inline data
944
			testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
945
					testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
946
							true, false, false, false, true), null, null, null, null);
947
			Thread.sleep(2000);
948
			updateDocid(newdocid + ".3", testdocument, FAILURE, true);
875 949

  
876
            // try to set the permissions for the inline data
877
            testdocument = getTestEmlDoc("InlineDataAccessTest: Doing insert",
878
                                         testEmlInlineBlock1, null, null, null,
879
                                         null, getAccessBlock(anotheruser, true,
880
                                         true, true, true, false),
881
                                         null, null, null);
882
            // ERRRRRRRRRR
883
            // updateDocid(newdocid + ".3", testdocument, SUCCESS, false);
950
			// try to delete the document
951
			deleteDocid(newdocid + ".2", FAILURE, true);
952
			m.logout();
884 953

  
885
            // try to delete the document
886
            deleteDocid(newdocid + ".3", FAILURE, true);
887
            m.logout();
954
			// delete the document
955
			m.login(username, password);
956
			deleteDocid(newdocid + ".2", SUCCESS, false);
957
			m.logout();
888 958

  
889
            // delete the document
890
            m.login(username, password);
891
            deleteDocid(newdocid + ".1", SUCCESS, false);
892
            m.logout();
959
//			// ///////Case 3./////////////////////
960
//			// insert an inline document - change permission only
961
//			m.login(username, password);
962
//			newdocid = generateDocid();
963
//
964
//			// insert a document which gives read access to the inline document
965
//			testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
966
//					testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
967
//							true, false, false, true, false), null, null, null, null);
968
//			insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
969
//			m.logout();
970
//
971
//			// login as another user
972
//			m.login(anotheruser, anotherpassword);
973
//
974
//			// try to read the document and the inline data
975
//			readDocid(newdocid + ".1", FAILURE, true);
976
//			readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE,
977
//					true);
978
//
979
//			// try to update the inline data
980
//			testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing update",
981
//					testEmlInlineBlock2, null, null, null, getAccessBlock(anotheruser,
982
//							true, false, false, true, false), null, null, null, null);
983
//			Thread.sleep(2000);
984
//			updateDocid(newdocid + ".2", testdocument, FAILURE, true);
985
//
986
//			// try to set the permissions for the inline data
987
//			testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
988
//					testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
989
//							true, false, false, false, true), null, null, null, null);
990
//			// ERRRRRRRRRRRR
991
//			// updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
992
//
993
//			// try to delete the document
994
//			deleteDocid(newdocid + ".1", FAILURE, true);
995
//			m.logout();
996
//
997
//			// delete the document
998
//			m.login(username, password);
999
//			deleteDocid(newdocid + ".1", SUCCESS, false);
1000
//			m.logout();
1001
//
1002
//			// ///////Case 4./////////////////////
1003
//			// insert an inline document - change permission only
1004
//			m.login(username, password);
1005
//			newdocid = generateDocid();
1006
//
1007
//			// insert a document which gives read access to the inline document
1008
//			testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
1009
//					testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
1010
//							true, false, false, false, true), null, null, null, null);
1011
//			insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
1012
//			m.logout();
1013
//
1014
//			// login as another user
1015
//			m.login(anotheruser, anotherpassword);
1016
//
1017
//			// try to read the document and the inline data
1018
//			readDocid(newdocid + ".1", SUCCESS, false);
1019
//			readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, SUCCESS,
1020
//					false);
1021
//
1022
//			// try to update the inline data
1023
//			testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing update",
1024
//					testEmlInlineBlock2, null, null, null, getAccessBlock(anotheruser,
1025
//							true, false, false, false, true), null, null, null, null);
1026
//			Thread.sleep(2000);
1027
//			updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
1028
//
1029
//			// try to set the permissions for the inline data
1030
//			testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert",
1031
//					testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser,
1032
//							true, true, true, true, false), null, null, null, null);
1033
//			Thread.sleep(2000);
1034
//			updateDocid(newdocid + ".3", testdocument, SUCCESS, false);
1035
//
1036
//			// try to delete the document
1037
//			// sleep needed only in case of inline data - jing said that
1038
//			// somehow the thread writing data to xml_index takes too much time
1039
//			// when used with inline data. hence if delete is requested too soon
1040
//			// database gives an error of xml_index records left with FK to
1041
//			// xml_document record which is going to be deleted.
1042
//			Thread.sleep(10000);
1043
//
1044
//			deleteDocid(newdocid + ".3", SUCCESS, false);
1045
//			m.logout();
893 1046

  
894
        }
895
        catch (MetacatAuthException mae) {
896
            fail("Authorization failed:\n" + mae.getMessage());
897
        }
898
        catch (MetacatInaccessibleException mie) {
899
            fail("Metacat Inaccessible:\n" + mie.getMessage());
900
        }
901
        catch (Exception e) {
902
            fail("General exception:\n" + e.getMessage());
903
        }
904
    }
1047
		} catch (MetacatAuthException mae) {
1048
			fail("Authorization failed:\n" + mae.getMessage());
1049
		} catch (MetacatInaccessibleException mie) {
1050
			fail("Metacat Inaccessible:\n" + mie.getMessage());
1051
		} catch (Exception e) {
1052
			fail("General exception:\n" + e.getMessage());
1053
		}
1054
	}
905 1055

  
906
    /** *********
907
     * Checking the following cases:
908
     * -> when no inline data is specified in the document but
909
     *    rules are specified in additional metadata
910
     * -> when a user has RW permission for inline data, can he delete it
911
     * -> when inline data with document refering to it is uploaded with read
912
     *    access for metadata and no access for data
913
     */
914
    public void inlineDataCasesTest_5() {
1056
    /***************************************************************************
1057
	 * For EML 2.0.1, checking the following cases: when only Inline data is 
1058
	 * uploaded by a user with the following different access controls specified 
1059
	 * in addiotnal metadata in another document 1.read 2.write 3.change permission 
1060
	 * 4.all And another user tries to do the following: -> tries to read it -> 
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff