Project

General

Profile

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