Project

General

Profile

« Previous | Next » 

Revision 6716

Added by Jing Tao over 12 years ago

Add new test method to test getAccessControl.

View differences:

MetacatClientTest.java
82 82
    private String failpass = "uidfnkj43987yfdn";
83 83
    private String newdocid = null;
84 84
    private String testfile = "test/jones.204.22.xml";
85
    private String testEMLWithAccess = "test/tao.14563.1.xml";
85 86
    private String onlinetestdatafile = "test/onlineDataFile1";
86 87
    private String queryFile = "test/query.xml";
87 88
    private String testdocument = "";
......
162 163
      suite.addTest(new MetacatClientTest("reuseSession"));
163 164
      suite.addTest(new MetacatClientTest("reuseInvalidSession"));
164 165
      suite.addTest(new MetacatClientTest("insertSpatialDocs"));
166
      suite.addTest(new MetacatClientTest("getAccessControl"));
167
      suite.addTest(new MetacatClientTest("getAccessControlFromDocWithoutAccess"));
165 168
      return suite;
166 169
  }
167 170

  
......
382 385
            fail("General exception:\n" + e.getMessage());
383 386
        }
384 387
    }
388
    
389
    /**
390
     * Test to get access control part of a document
391
     */
392
    public void getAccessControl() {
393
      try {
394
        FileInputStream fis = new FileInputStream(testEMLWithAccess);
395
        String document = IOUtils.toString(fis);
396
        String identifier = newdocid + ".1";
397
        m.login(username, password);
398
        String response = m.insert(identifier,
399
                new StringReader(document), null);
400
        assertTrue(response.indexOf("<success>") != -1);
401
        assertTrue(response.indexOf(identifier) != -1);
402
        response = m.getAccessControl(identifier);
403
        //System.out.println("reponse is "+reponse);
404
        assertTrue(response.indexOf("<permission>read</permission>") != -1);
405
        assertTrue(response.indexOf("<principal>public</principal>") != -1);
406
    } catch (MetacatAuthException mae) {
407
        fail("Authorization failed:\n" + mae.getMessage());
408
    } catch (MetacatInaccessibleException mie) {
409
        fail("Metacat Inaccessible:\n" + mie.getMessage());
410
    } catch (InsufficientKarmaException ike) {
411
        assertTrue(1 == 1);
412
        fail("Insufficient karma:\n" + ike.getMessage());
413
    } catch (MetacatException me) {
414
        fail("Metacat Error:\n" + me.getMessage());
415
    } catch (Exception e) {
416
        fail("General exception:\n" + e.getMessage());
417
    }
418
     
419
  }
420
    
421
    /**
422
     * Test to get access control part of a document
423
     */
424
    public void getAccessControlFromDocWithoutAccess() {
425
      try {
426
        String identifier = newdocid + ".1";
427
        m.login(username, password);
428
        String response = m.insert(identifier,
429
                new StringReader(testdocument), null);
430
        assertTrue(response.indexOf("<success>") != -1);
431
        assertTrue(response.indexOf(identifier) != -1);
432
        response = m.getAccessControl(identifier);
433
        //System.out.println("the identifier is "+identifier);
434
        //System.out.println("reponse is "+response);
435
        assertTrue(response.indexOf("<permission>read</permission>") == -1);
436
        assertTrue(response.indexOf("<principal>public</principal>") == -1);
437
        assertTrue(response.indexOf("<access authSystem=") != -1);
438
    } catch (MetacatAuthException mae) {
439
        fail("Authorization failed:\n" + mae.getMessage());
440
    } catch (MetacatInaccessibleException mie) {
441
        fail("Metacat Inaccessible:\n" + mie.getMessage());
442
    } catch (InsufficientKarmaException ike) {
443
        assertTrue(1 == 1);
444
        fail("Insufficient karma:\n" + ike.getMessage());
445
    } catch (MetacatException me) {
446
        fail("Metacat Error:\n" + me.getMessage());
447
    } catch (Exception e) {
448
        fail("General exception:\n" + e.getMessage());
449
    }
450
     
451
  }
385 452

  
386 453
    /**
387 454
     * Test the upload() function with a data file.

Also available in: Unified diff