Project

General

Profile

« Previous | Next » 

Revision 6004

Added by Chris Jones over 13 years ago

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:

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