Project

General

Profile

« Previous | Next » 

Revision 6094

Added by Matt Jones over 13 years ago

Fixed MetaCatServletTest test failures by removing the hardcoded username/passwords used in the tests and replacing those with data from metacat.properties.

View differences:

test/edu/ucsb/nceas/metacattest/MetaCatServletTest.java
157 157
	/**
158 158
	 * Test the login to neceas succesfully
159 159
	 */
160
	public void testNCEASLogin() {
161
		debug("\nRunning: testNCEASLogin test");
162
		String user = "uid=john,o=NCEAS,dc=ecoinformatics,dc=org";
163
		String passwd = "123456";
164
		assertTrue(logIn(user, passwd));
165
		// assertTrue( withProtocol.getProtocol().equals("http"));
166
	}
160
    public void testNCEASLogin() {
161
        debug("\nRunning: testNCEASLogin test");
162
        try {
163
            String user = PropertyService.getProperty("test.mcUser");
164
            String passwd = PropertyService.getProperty("test.mcPassword");
165
            assertTrue(logIn(user, passwd));
166
        } catch (PropertyNotFoundException pnfe) {
167
            fail("Could not find property: " + pnfe.getMessage());
168
        }
169
    }
167 170

  
168 171
	/**
169 172
	 * Test the login to neceas failed
170 173
	 */
171 174
	public void testNCEASLoginFail() {
172 175
		debug("\nRunning: testNCEASLoginFail test");
173
		String user = "uid=john,o=NCEAS,dc=ecoinformatics,dc=org";
174
		String passwd = "12345678";
175
		assertTrue(!logIn(user, passwd));
176

  
176
        try {
177
            String user = PropertyService.getProperty("test.mcUser");
178
            String passwd = "BogusPasswordShouldFail";
179
            assertTrue(!logIn(user, passwd));
180
        } catch (PropertyNotFoundException pnfe) {
181
            fail("Could not find property: " + pnfe.getMessage());
182
        }
177 183
	}
178 184

  
179 185
	/**
......
238 244
	/**
239 245
	 * Test insert a xml document successfully
240 246
	 */
241
	public void testInsertXMLDocument() {
242
		debug("\nRunning: testInsertXMLDocument test");
243
		String name = null;
244
		try {
245
			name = "john" + PropertyService.getProperty("document.accNumSeparator")
246
					+ serialNumber
247
					+ PropertyService.getProperty("document.accNumSeparator") + "1";
248
		} catch (PropertyNotFoundException pnfe) {
249
			fail("Could not find property: " + pnfe.getMessage());
250
		}
251
		debug("insert docid: " + name);
252
		String content = "<?xml version=\"1.0\"?>"
253
				+ "<!DOCTYPE acl PUBLIC \"-//ecoinformatics.org//"
254
				+ "eml-access-2.0.0beta6//EN\" \"http://pine.nceas.ucsb."
255
				+ "edu:8080/tao/dtd/eml-access-2.0.0beta6.dtd\">"
256
				+ "<acl authSystem=\"knb\" order=\"allowFirst\">" + "<identifier>" + name
257
				+ "</identifier>" + "<allow>"
258
				+ "<principal>uid=john,o=NCEAS,dc=ecoinformatics,dc=org</principal>"
259
				+ "<permission>all</permission>" + "</allow>" + "<allow>"
260
				+ "<principal>public</principal>" + "<permission>read</permission>"
261
				+ "</allow>" + "</acl>";
262
		debug("xml document: " + content);
263
		assertTrue(handleXMLDocument(content, name, "insert"));
247
    public void testInsertXMLDocument() {
248
        debug("\nRunning: testInsertXMLDocument test");
249
        String name = null;
250
        try {
251
            String user = PropertyService.getProperty("test.mcUser");
252
            String passwd = PropertyService.getProperty("test.mcPassword");
264 253

  
265
	}
254
            name = "john" + PropertyService.getProperty("document.accNumSeparator") + serialNumber + PropertyService.getProperty("document.accNumSeparator")
255
                    + "1";
256
            debug("insert docid: " + name);
257
            String content = "<?xml version=\"1.0\"?>" + "<!DOCTYPE acl PUBLIC \"-//ecoinformatics.org//"
258
                    + "eml-access-2.0.0beta6//EN\" \"http://pine.nceas.ucsb.edu:8080/tao/dtd/eml-access-2.0.0beta6.dtd\">"
259
                    + "<acl authSystem=\"knb\" order=\"allowFirst\">" + "<identifier>" + name + "</identifier>" + "<allow>" + "<principal>" + user
260
                    + "</principal>" + "<permission>all</permission>" + "</allow>" + "<allow>" + "<principal>public</principal>"
261
                    + "<permission>read</permission>" + "</allow>" + "</acl>";
262
            debug("xml document: " + content);
263
            assertTrue(handleXMLDocument(content, name, "insert"));
264
        } catch (PropertyNotFoundException pnfe) {
265
            fail("Could not find property: " + pnfe.getMessage());
266
        }
267
    }
266 268

  
267 269
	/**
268 270
	 * Test insert a invalidate xml document successfully In the String, there
269 271
	 * is no <!Doctype ... Public/System/>
270 272
	 */
271
	public void testInsertInvalidateXMLDocument() {
272
		debug("\nRunning: testInsertInvalidateXMLDocument test");
273
		String name = null;
274
		try {
275
			name = "john" + PropertyService.getProperty("document.accNumSeparator")
276
					+ serialNumber
277
					+ PropertyService.getProperty("document.accNumSeparator") + "1";
278
		} catch (PropertyNotFoundException pnfe) {
279
			fail("Could not find property: " + pnfe.getMessage());
280
		}
281
		debug("insert docid: " + name);
282
		String content = "<?xml version=\"1.0\"?>"
283
				+ "<acl authSystem=\"knb\" order=\"allowFirst\">" + "<identifier>" + name
284
				+ "</identifier>" + "<allow>"
285
				+ "<principal>uid=john,o=NCEAS,dc=ecoinformatics,dc=org</principal>"
286
				+ "<permission>all</permission>" + "</allow>" + "<allow>"
287
				+ "<principal>public</principal>" + "<permission>read</permission>"
288
				+ "</allow>" + "</acl>";
289
		debug("xml document: " + content);
290
		assertTrue(handleXMLDocument(content, name, "insert"));
291
	}
273
    public void testInsertInvalidateXMLDocument() {
274
        debug("\nRunning: testInsertInvalidateXMLDocument test");
275
        String name = null;
276
        try {
277
            String user = PropertyService.getProperty("test.mcUser");
278
            String passwd = PropertyService.getProperty("test.mcPassword");
292 279

  
280
            name = "john" + PropertyService.getProperty("document.accNumSeparator") + serialNumber + PropertyService.getProperty("document.accNumSeparator")
281
                    + "1";
282
            debug("insert docid: " + name);
283
            String content = "<?xml version=\"1.0\"?>" + "<acl authSystem=\"knb\" order=\"allowFirst\">" + "<identifier>" + name + "</identifier>" + "<allow>"
284
                    + "<principal>" + user + "</principal>" + "<permission>all</permission>" + "</allow>" + "<allow>" + "<principal>public</principal>"
285
                    + "<permission>read</permission>" + "</allow>" + "</acl>";
286
            debug("xml document: " + content);
287
            assertTrue(handleXMLDocument(content, name, "insert"));
288
        } catch (PropertyNotFoundException pnfe) {
289
            fail("Could not find property: " + pnfe.getMessage());
290
        }
291
    }
292

  
293 293
	/**
294 294
	 * Test insert a non well-formed xml document successfully There is no
295 295
	 * </acl> in this string
296 296
	 */
297
	public void testInsertNonWellFormedXMLDocument() {
298
		debug("\nRunning: testInsertNonWellFormedXMLDocument test");
299
		String name = null;
300
		try {
301
			name = "john" + PropertyService.getProperty("document.accNumSeparator")
302
					+ serialNumber
303
					+ PropertyService.getProperty("document.accNumSeparator") + "1";
304
		} catch (PropertyNotFoundException pnfe) {
305
			fail("Could not find property: " + pnfe.getMessage());
306
		}
307
		debug("insert non well-formed docid: " + name);
308
		String content = "<?xml version=\"1.0\"?>"
309
				+ "<acl authSystem=\"knb\" order=\"allowFirst\">" + "<identifier>" + name
310
				+ "</identifier>" + "<allow>"
311
				+ "<principal>uid=john,o=NCEAS,dc=ecoinformatics,dc=org</principal>"
312
				+ "<permission>all</permission>" + "</allow>" + "<allow>"
313
				+ "<principal>public</principal>" + "<permission>read</permission>"
314
				+ "</allow>";
297
    public void testInsertNonWellFormedXMLDocument() {
298
        debug("\nRunning: testInsertNonWellFormedXMLDocument test");
299
        String name = null;
300
        try {
301
            String user = PropertyService.getProperty("test.mcUser");
302
            String passwd = PropertyService.getProperty("test.mcPassword");
315 303

  
316
		debug("xml document: " + content);
317
		assertTrue(!handleXMLDocument(content, name, "insert"));
318
	}
304
            name = "john" + PropertyService.getProperty("document.accNumSeparator") + serialNumber + PropertyService.getProperty("document.accNumSeparator")
305
                    + "1";
306
            debug("insert non well-formed docid: " + name);
307
            String content = "<?xml version=\"1.0\"?>" + "<acl authSystem=\"knb\" order=\"allowFirst\">" + "<identifier>" + name + "</identifier>" + "<allow>"
308
                    + "<principal>" + user + "</principal>" + "<permission>all</permission>" + "</allow>" + "<allow>" + "<principal>public</principal>"
309
                    + "<permission>read</permission>" + "</allow>";
319 310

  
311
            debug("xml document: " + content);
312
            assertTrue(!handleXMLDocument(content, name, "insert"));
313
        } catch (PropertyNotFoundException pnfe) {
314
            fail("Could not find property: " + pnfe.getMessage());
315
        }
316
    }
317

  
320 318
	/**
321 319
	 * Test read a xml document in xml format successfully
322 320
	 */
......
371 369
	/**
372 370
	 * Test insert a xml document successfully
373 371
	 */
374
	public void testUpdateXMLDocument() {
375
		debug("\nRunning: testUpdateXMLDocument test");
376
		String name = null;
377
		try {
378
			name = "john" + PropertyService.getProperty("document.accNumSeparator")
379
					+ serialNumber
380
					+ PropertyService.getProperty("document.accNumSeparator") + "2";
381
		} catch (PropertyNotFoundException pnfe) {
382
			fail("Could not find property: " + pnfe.getMessage());
383
		}
384
		debug("update docid: " + name);
385
		String content = "<?xml version=\"1.0\"?>"
386
				+ "<!DOCTYPE acl PUBLIC \"-//ecoinformatics.org//"
387
				+ "eml-access-2.0.0beta6//EN\" \"http://pine.nceas.ucsb."
388
				+ "edu:8080/tao/dtd/eml-access-2.0.0beta6.dtd\">"
389
				+ "<acl authSystem=\"knb\" order=\"allowFirst\">" + "<identifier>" + name
390
				+ "</identifier>" + "<allow>"
391
				+ "<principal>uid=john,o=NCEAS,dc=ecoinformatics,dc=org</principal>"
392
				+ "<permission>all</permission>" + "</allow>" + "<allow>"
393
				+ "<principal>public</principal>" + "<permission>read</permission>"
394
				+ "</allow>" + "</acl>";
395
		debug("xml document: " + content);
396
		assertTrue(handleXMLDocument(content, name, "update"));
372
    public void testUpdateXMLDocument() {
373
        debug("\nRunning: testUpdateXMLDocument test");
374
        String name = null;
375
        try {
376
            String user = PropertyService.getProperty("test.mcUser");
377
            String passwd = PropertyService.getProperty("test.mcPassword");
397 378

  
398
	}
379
            name = "john" + PropertyService.getProperty("document.accNumSeparator") + serialNumber + PropertyService.getProperty("document.accNumSeparator")
380
                    + "2";
381
            debug("update docid: " + name);
382
            String content = "<?xml version=\"1.0\"?>" + "<!DOCTYPE acl PUBLIC \"-//ecoinformatics.org//"
383
                    + "eml-access-2.0.0beta6//EN\" \"http://pine.nceas.ucsb." + "edu:8080/tao/dtd/eml-access-2.0.0beta6.dtd\">"
384
                    + "<acl authSystem=\"knb\" order=\"allowFirst\">" + "<identifier>" + name + "</identifier>" + "<allow>" + "<principal>" + user
385
                    + "</principal>" + "<permission>all</permission>" + "</allow>" + "<allow>" + "<principal>public</principal>"
386
                    + "<permission>read</permission>" + "</allow>" + "</acl>";
387
            debug("xml document: " + content);
388
            assertTrue(handleXMLDocument(content, name, "update"));
389
        } catch (PropertyNotFoundException pnfe) {
390
            fail("Could not find property: " + pnfe.getMessage());
391
        }
392
    }
399 393

  
400 394
	/**
401 395
	 * Test delete a xml document successfully
......
415 409

  
416 410
	}
417 411

  
418
  /**
419
   * Test to delete a document by GUID (not docid).  This exercises 
420
   * MetacatServlet.handleDeleteAction()'s handling of GUIDs.
421
   */
422
  public void testDeleteDocumentByGUID() {
423
    debug("\nRunning: testDeleteDocumentByGUID test");
424
    
425
    CrudServiceTest crudServiceTest = new CrudServiceTest("testDeleteDocumentByGUID");
426
    String guid = "";
427
    String user = "uid=john,o=NCEAS,dc=ecoinformatics,dc=org";
428
		String passwd = "123456";
429
		AuthToken token = null;
430
		String result = "";
431
    // create a document via the CRUD service to get a GUID
432
    try {
433
      token = crudServiceTest.getToken(user, passwd);
434
      String testDocument = crudServiceTest.getTestDoc();
435
      Identifier identifier = crudServiceTest.createDoc(token, testDocument);
436
      guid = identifier.getValue();
437
      
438
    } catch (Exception e) {
439
      fail("Could not create test document to delete: " + e.getMessage());
440
      
412
    /**
413
     * Test to delete a document by GUID (not docid).  This exercises 
414
     * MetacatServlet.handleDeleteAction()'s handling of GUIDs.
415
     */
416
    public void testDeleteDocumentByGUID() {
417
        debug("\nRunning: testDeleteDocumentByGUID test");
418

  
419
        try {
420
            String user = PropertyService.getProperty("test.mcUser");
421
            String passwd = PropertyService.getProperty("test.mcPassword");
422
            
423
            CrudServiceTest crudServiceTest = new CrudServiceTest("testDeleteDocumentByGUID");
424
            String guid = "";
425
            AuthToken token = null;
426
            String result = "";
427
            // create a document via the CRUD service to get a GUID
428
            try {
429
                token = crudServiceTest.getToken(user, passwd);
430
                String testDocument = crudServiceTest.getTestDoc();
431
                Identifier identifier = crudServiceTest.createDoc(token, testDocument);
432
                guid = identifier.getValue();
433
            } catch (Exception e) {
434
                fail("Could not create test document to delete: " + e.getMessage());
435
            }
436

  
437
            // delete the document via the Metacat servlet with the GUID
438
            try {
439
                Properties props = new Properties();
440
                props.put("action", "delete");
441
                props.put("docid", guid);
442
                props.put("sessionid", token.getToken());
443
                debug("Trying to delete by GUID: " + guid);
444
                result = getMetacatString(props);
445
            } catch (Exception e) {
446
                fail("Couldn't delete GUID: " + guid);
447
            }
448
            assertTrue(result.indexOf("<success>") > 0);
449
        } catch (PropertyNotFoundException pnfe) {
450
            fail("Could not find property: " + pnfe.getMessage());
451
        }
441 452
    }
442 453
    
443
    // delete the document via the Metacat servlet with the GUID
444
    try {
445
      Properties props = new Properties();
446
      props.put("action", "delete");
447
      props.put("docid", guid);
448
      props.put("sessionid", token.getToken());
449
      debug("Trying to delete by GUID: " + guid);
450
      result = getMetacatString(props);
451
        
452
    } catch ( Exception e ) {
453
      fail("Couldn't delete GUID: " + guid);
454
        
455
    }
456
    
457
    assertTrue(result.indexOf("<success>") > 0);
458
    
459
  }
460 454
	/**
461 455
	 * Test logout action
462 456
	 */

Also available in: Unified diff