Project

General

Profile

Revision 6004

Added a new test method testDeleteDocumentByGUID() to ensure MetacatHandler can delete based on GUID, but fall back to docid if the GUID isn't present. Modified CrudServiceTest and made some private methods public to leverage the D1 REST calls in that library (i.e. create() a doc with a GUID).

View differences:

test/edu/ucsb/nceas/metacat/dataone/CrudServiceTest.java
718 718
	
719 719
	/**
720 720
	 * create(AuthToken token, Identifier guid, InputStream object, SystemMetadata sysmeta) 
721
     *   throws InvalidToken, ServiceFailure, NotAuthorized, IdentifierNotUnique, UnsupportedType, 
722
     *       InsufficientResources, InvalidSystemMetadata, NotImplemented
723
     *
724
     * public InputStream get(AuthToken token, Identifier guid)
725
     *       throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, 
726
     *       NotImplemented
721
   *   throws InvalidToken, ServiceFailure, NotAuthorized, IdentifierNotUnique, UnsupportedType, 
722
   *       InsufficientResources, InvalidSystemMetadata, NotImplemented
723
   *
724
   * public InputStream get(AuthToken token, Identifier guid)
725
   *       throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, 
726
   *       NotImplemented
727 727
	 */
728 728
	public void testCreateAndGet()
729 729
	{
......
758 758
            fail("Error in testCreate: " + e.getMessage());
759 759
        }
760 760
	}
761

  
761
	
762 762
	/**
763 763
	 * getInstance()
764 764
	 */
......
800 800
        return IOUtils.toString(gotDocStream);
801 801
	}
802 802
	
803
	private String getTestDoc()
803
	public String getTestDoc()
804 804
	{
805 805
	    return getTestDoc(null);
806 806
	}
......
808 808
	/**
809 809
	 * return a test document.  objectFormat should come from MCTestCase
810 810
	 */
811
	private String getTestDoc(String objectFormat)
811
	public String getTestDoc(String objectFormat)
812 812
	{
813 813
	    if(objectFormat == null)
814 814
	    {
......
829 829
	 * authenticate and return a token
830 830
	 * use the test.mcUser and test.mcPassword username/password combo
831 831
	 */
832
	private AuthToken getToken()
832
	public AuthToken getToken()
833 833
	  throws Exception
834 834
	{
835 835
        String username = PropertyService.getProperty("test.mcUser");
......
840 840
	/**
841 841
	 * authenticate and return a token using the given credentials
842 842
	 */
843
	private AuthToken getToken(String username, String password)
843
	public AuthToken getToken(String username, String password)
844 844
	  throws Exception
845 845
	{
846 846
	    CrudService cs = CrudService.getInstance();
......
857 857
	/**
858 858
	 * create a doc using CrudService.create() and return its id
859 859
	 */
860
	private Identifier createDoc(AuthToken token, String testDoc) throws Exception
860
	public Identifier createDoc(AuthToken token, String testDoc) throws Exception
861 861
	{
862 862
	    return createDoc(token, testDoc, ObjectFormat.convert("eml://ecoinformatics.org/eml-2.1.0"));
863 863
	}
......
865 865
	/**
866 866
	 * create a doc using CrudService.create() and return its id
867 867
	 */
868
	private Identifier createDoc(AuthToken token, String testDoc, ObjectFormat format) throws Exception
868
	public Identifier createDoc(AuthToken token, String testDoc, ObjectFormat format) throws Exception
869 869
	{
870 870
	    Identifier id;
871 871
        CrudService cs = CrudService.getInstance();
......
986 986
             .append(HEXES.charAt((b & 0x0F)));
987 987
        }
988 988
        return hex.toString();
989
    }
989
  }
990 990
}
test/edu/ucsb/nceas/metacattest/MetaCatServletTest.java
27 27
package edu.ucsb.nceas.metacattest;
28 28

  
29 29
import edu.ucsb.nceas.MCTestCase;
30
import edu.ucsb.nceas.metacat.dataone.CrudServiceTest;
30 31
import edu.ucsb.nceas.metacat.properties.PropertyService;
31 32
import edu.ucsb.nceas.utilities.HttpMessage;
32 33
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
34

  
33 35
import junit.framework.Test;
34 36
import junit.framework.TestSuite;
35 37

  
......
37 39
import java.net.*;
38 40
import java.util.*;
39 41

  
42
import org.dataone.service.types.AuthToken;
43
import org.dataone.service.types.Identifier;
44

  
40 45
/**
41 46
 * A JUnit test for testing Step class processing
42 47
 */
......
113 118
		suite.addTest(new MetaCatServletTest("testInsertXMLDocument", serial));
114 119
		suite.addTest(new MetaCatServletTest("testReadXMLDocumentXMLFormat", serial));
115 120
		suite.addTest(new MetaCatServletTest("testUpdateXMLDocument", serial));
116

  
121
    
117 122
		suite.addTest(new MetaCatServletTest("testReadXMLDocumentHTMLFormat", serial));
118 123
		suite.addTest(new MetaCatServletTest("testReadXMLDocumentZipFormat", serial));
119

  
124
    
120 125
		suite.addTest(new MetaCatServletTest("testDeleteXMLDocument", serial));
126
		
127
		// test delete using GUID
128
		number = Math.random() * 100000;
129
		serial = Integer.toString(((new Double(number)).intValue()));
130
		suite.addTest(new MetaCatServletTest("testDeleteDocumentByGUID", serial));
121 131

  
122 132
		// insert invalid xml document
123 133
		number = Math.random() * 100000;
......
129 139
		suite
130 140
				.addTest(new MetaCatServletTest("testInsertNonWellFormedXMLDocument",
131 141
						serial));
132

  
142
    
133 143
		suite.addTest(new MetaCatServletTest("testLogOut"));
134 144

  
135 145
		return suite;
......
149 159
	public void testNCEASLogin() {
150 160
		debug("\nRunning: testNCEASLogin test");
151 161
		String user = "uid=john,o=NCEAS,dc=ecoinformatics,dc=org";
152
		String passwd = "123456";
162
		String passwd = "12345678";
153 163
		assertTrue(logIn(user, passwd));
154 164
		// assertTrue( withProtocol.getProtocol().equals("http"));
155 165
	}
......
404 414

  
405 415
	}
406 416

  
417
  /**
418
   * Test to delete a document by GUID (not docid).  This exercises 
419
   * MetacatServlet.handleDeleteAction()'s handling of GUIDs.
420
   */
421
  public void testDeleteDocumentByGUID() {
422
    debug("\nRunning: testDeleteDocumentByGUID test");
423
    
424
    CrudServiceTest crudServiceTest = new CrudServiceTest("testDeleteDocumentByGUID");
425
    String guid = "";
426
    String user = "uid=john,o=NCEAS,dc=ecoinformatics,dc=org";
427
		String passwd = "123456";
428
		AuthToken token = null;
429
		String result = "";
430
    // create a document via the CRUD service to get a GUID
431
    try {
432
      token = crudServiceTest.getToken(user, passwd);
433
      String testDocument = crudServiceTest.getTestDoc();
434
      Identifier identifier = crudServiceTest.createDoc(token, testDocument);
435
      guid = identifier.getValue();
436
      
437
    } catch (Exception e) {
438
      fail("Could not create test document to delete: " + e.getMessage());
439
      
440
    }
441
    
442
    // delete the document via the Metacat servlet with the GUID
443
    try {
444
      Properties props = new Properties();
445
      props.put("action", "delete");
446
      props.put("docid", guid);
447
      props.put("sessionid", token.getToken());
448
      debug("Trying to delete by GUID: " + guid);
449
      result = getMetacatString(props);
450
        
451
    } catch ( Exception e ) {
452
      fail("Couldn't delete GUID: " + guid);
453
        
454
    }
455
    
456
    assertTrue(result.indexOf("<success>") > 0);
457
    
458
  }
407 459
	/**
408 460
	 * Test logout action
409 461
	 */

Also available in: Unified diff