Project

General

Profile

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