Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2010 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: cjones $'
8
 *     '$Date: 2011-11-02 20:08:27 -0700 (Wed, 02 Nov 2011) $'
9
 * '$Revision: 6594 $'
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.metacat.dataone;
27

    
28
import java.io.ByteArrayInputStream;
29
import java.io.InputStream;
30
import java.text.SimpleDateFormat;
31
import java.util.Date;
32

    
33
import javax.servlet.http.HttpServletRequest;
34

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

    
38
import org.apache.commons.io.IOUtils;
39
import org.apache.wicket.protocol.http.MockHttpServletRequest;
40
import org.dataone.service.util.Constants;
41
import org.dataone.service.exceptions.InsufficientResources;
42
import org.dataone.service.exceptions.InvalidRequest;
43
import org.dataone.service.exceptions.NotAuthorized;
44
import org.dataone.service.exceptions.NotFound;
45
import org.dataone.service.exceptions.NotImplemented;
46
import org.dataone.service.exceptions.ServiceFailure;
47
import org.dataone.service.types.v1.AccessPolicy;
48
import org.dataone.service.types.v1.AccessRule;
49
import org.dataone.service.types.v1.Checksum;
50
import org.dataone.service.types.v1.Event;
51
import org.dataone.service.types.v1.Identifier;
52
import org.dataone.service.types.v1.Log;
53
import org.dataone.service.types.v1.NodeReference;
54
import org.dataone.service.types.v1.ObjectFormat;
55
import org.dataone.service.types.v1.ObjectFormatIdentifier;
56
import org.dataone.service.types.v1.ObjectFormatList;
57
import org.dataone.service.types.v1.ObjectInfo;
58
import org.dataone.service.types.v1.ObjectList;
59
import org.dataone.service.types.v1.Permission;
60
import org.dataone.service.types.v1.Replica;
61
import org.dataone.service.types.v1.ReplicationPolicy;
62
import org.dataone.service.types.v1.ReplicationStatus;
63
import org.dataone.service.types.v1.Session;
64
import org.dataone.service.types.v1.Subject;
65
import org.dataone.service.types.v1.SystemMetadata;
66

    
67
/**
68
 * A JUnit test for testing the dataone CNCore implementation
69
 */
70
public class CNodeServiceTest extends D1NodeServiceTest {   
71
    
72
    /**
73
    * constructor for the test
74
    */
75
    public CNodeServiceTest(String name)
76
    {
77
        super(name);
78
    }
79

    
80
	/**
81
	 * Create a suite of tests to be run together
82
	 */
83
	public static Test suite() 
84
	{
85
		TestSuite suite = new TestSuite();
86
		suite.addTest(new CNodeServiceTest("initialize"));
87
		
88
		suite.addTest(new CNodeServiceTest("testAssertRelation"));
89
		suite.addTest(new CNodeServiceTest("testChecksum"));
90
		suite.addTest(new CNodeServiceTest("testCreate"));
91
		suite.addTest(new CNodeServiceTest("testGet"));
92
		suite.addTest(new CNodeServiceTest("testGetFormat"));
93
		suite.addTest(new CNodeServiceTest("testGetLogRecords"));
94
		suite.addTest(new CNodeServiceTest("testGetSystemMetadata"));
95
		suite.addTest(new CNodeServiceTest("testIsAuthorized"));
96
		suite.addTest(new CNodeServiceTest("testListFormats"));
97
		suite.addTest(new CNodeServiceTest("testListNodes"));
98
		suite.addTest(new CNodeServiceTest("testObjectFormatNotFoundException"));
99
		suite.addTest(new CNodeServiceTest("testRegisterSystemMetadata"));
100
		suite.addTest(new CNodeServiceTest("testReplicationPolicy"));
101
		suite.addTest(new CNodeServiceTest("testReplicationStatus"));
102
		suite.addTest(new CNodeServiceTest("testReserveIdentifier"));
103
		suite.addTest(new CNodeServiceTest("testSearch"));
104
		suite.addTest(new CNodeServiceTest("testSetAccessPolicy"));
105
		suite.addTest(new CNodeServiceTest("testSetOwner"));
106
	
107
		return suite;
108
	}
109
	
110
	
111
	/**
112
	 * test for registering standalone system metadata
113
	 */
114
	public Identifier testRegisterSystemMetadata() {
115
	    printTestHeader("testRegisterSystemMetadata");
116

    
117
	    try {
118
            Session session = getTestSession();
119
			Identifier guid = new Identifier();
120
			guid.setValue("testRegisterSystemMetadata." + System.currentTimeMillis());
121
			InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
122
			SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
123
			Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
124
			assertEquals(guid.getValue(), retGuid.getValue());
125
			return retGuid;
126
        } catch(Exception e) {
127
            fail("Unexpected error: " + e.getMessage());
128
        }
129
        return null;
130
	}
131
	
132
	/**
133
	 * test for getting system metadata
134
	 */
135
	public void testGetSystemMetadata() {
136
	    printTestHeader("testGetSystemMetadata");
137

    
138
	    try {
139
            Session session = getTestSession();
140
			Identifier guid = new Identifier();
141
			guid.setValue("testGetSystemMetadata." + System.currentTimeMillis());
142
			InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
143
			SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
144
			Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
145
			assertEquals(guid.getValue(), retGuid.getValue());
146
			// get it
147
			SystemMetadata retSysmeta = CNodeService.getInstance(request).getSystemMetadata(session, guid);
148
			// check it
149
			assertEquals(sysmeta.getIdentifier().getValue(), retSysmeta.getIdentifier().getValue());
150
        } catch(Exception e) {
151
            fail("Unexpected error: " + e.getMessage());
152
        }
153
	}
154
	
155
	public void testGetLogRecords() {
156
	    printTestHeader("testGetLogRecords");
157
	    try {
158

    
159
		    Session session = getTestSession();
160
		    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
161
		    Date fromDate = sdf.parse("2010-01-01");
162
		    Date toDate = new Date();
163
		    Event event = Event.CREATE;
164
		    int start = 0;
165
		    int count = 1;
166
	    
167
		    Log log = CNodeService.getInstance(request).getLogRecords(session, fromDate, toDate, 
168
		    	event, start, count);
169
		    assertNotNull(log);
170
		    assertTrue(log.getCount() == count);
171
		    assertTrue(log.getStart() == start);
172
		    assertTrue(log.getTotal() > 0);
173
	    } catch (Exception e) {
174
		    e.printStackTrace();
175
		    fail("Unexpected error: " + e.getMessage());
176
	    } 
177
	}
178
	
179
	public void testCreate() {
180
	    printTestHeader("testCreate");
181

    
182
	    try {
183
            Session session = getTestSession();
184
			Identifier guid = new Identifier();
185
			guid.setValue("testCreate." + System.currentTimeMillis());
186
			InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
187
			SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
188
			Identifier pid = CNodeService.getInstance(request).create(session, guid, object, sysmeta);
189
			assertEquals(guid, pid);
190
        } catch(Exception e) {
191
        	e.printStackTrace();
192
            fail("Unexpected error: " + e.getMessage());
193
        }
194
	}
195
	
196
	public void testGet() {
197
	    printTestHeader("testGet");
198

    
199
	    try {
200
            Session session = getTestSession();
201
			Identifier guid = new Identifier();
202
			guid.setValue("testGet." + System.currentTimeMillis());
203
			InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
204
			SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
205
			Identifier pid = CNodeService.getInstance(request).create(session, guid, object, sysmeta);
206
			assertEquals(guid.getValue(), pid.getValue());
207
			// get it
208
			InputStream retObject = CNodeService.getInstance(request).get(session, pid);
209
			// check it
210
			object.reset();
211
			assertTrue(IOUtils.contentEquals(object, retObject));
212
        } catch(Exception e) {
213
        	e.printStackTrace();
214
            fail("Unexpected error: " + e.getMessage());
215
        }
216
	}
217
	
218
	public void testAssertRelation() {
219
	    printTestHeader("testAssertRelation");
220

    
221
	    try {
222
            Session session = getTestSession();
223
			Identifier guid = new Identifier();
224
			guid.setValue("testAssertRelation." + System.currentTimeMillis());
225
			InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
226
			SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
227
			Identifier describePid = new Identifier();
228
			describePid.setValue("describePid." + System.currentTimeMillis());
229
			sysmeta.setObsoletes(describePid);
230
			// save it
231
			Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
232
			assertEquals(guid.getValue(), retGuid.getValue());
233
			// save the other
234
			InputStream object2 = new ByteArrayInputStream("test".getBytes("UTF-8"));
235
			SystemMetadata describeSysmeta = createSystemMetadata(describePid, session.getSubject(), object2);
236
			Identifier retDescribePid = CNodeService.getInstance(request).registerSystemMetadata(session, describePid, describeSysmeta);
237
			assertEquals(describePid.getValue(), retDescribePid.getValue());
238
			// check it
239
			boolean result = CNodeService.getInstance(request).assertRelation(session, guid, "obsoletes", describePid);
240
			assertTrue(result);
241
        } catch(Exception e) {
242
        	e.printStackTrace();
243
            fail("Unexpected error: " + e.getMessage());
244
        }
245
	}
246
	
247
	public void testChecksum() {
248
	    printTestHeader("testChecksum");
249

    
250
	    try {
251
            Session session = getTestSession();
252
			Identifier guid = new Identifier();
253
			guid.setValue("testChecksum." + System.currentTimeMillis());
254
			InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
255
			SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
256
			// save it
257
			Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
258
			assertEquals(guid.getValue(), retGuid.getValue());
259
			// check it
260
			Checksum checksum = CNodeService.getInstance(request).getChecksum(session, guid);
261
			assertEquals(sysmeta.getChecksum().getValue(), checksum.getValue());
262
        } catch(Exception e) {
263
            fail("Unexpected error: " + e.getMessage());
264
        }
265
	}
266
	
267
	public void testListNodes() {
268
	    printTestHeader("testListNodes");
269

    
270
	    try {
271
	    	CNodeService.getInstance(request).listNodes();
272
        } catch(NotImplemented e) {
273
        	// expecting not implemented
274
            assertTrue(true);
275
        } catch(Exception e) {
276
            fail("Unexpected error: " + e.getMessage());
277
        }
278
	}
279
	
280
	public void testReserveIdentifier() {
281
	    printTestHeader("testReserveIdentifier");
282

    
283
	    try {
284
            Session session = getTestSession();
285
			Identifier guid = new Identifier();
286
			guid.setValue("testReserveIdentifier." + System.currentTimeMillis());
287
			// reserve it
288
			boolean result = CNodeService.getInstance(request).reserveIdentifier(session, guid);
289
			assertTrue(result);
290
	    } catch(NotImplemented ni) {
291
        	// this is not implemented in Metacat
292
            assertTrue(true);	
293
        } catch(Exception e) {
294
        	e.printStackTrace();
295
            fail("Unexpected error: " + e.getMessage());
296
        }
297
	}
298
	
299
	public void testSearch() {
300
	    printTestHeader("testSearch");
301

    
302
	    try {
303
            Session session = getTestSession();
304
			Identifier guid = new Identifier();
305
			guid.setValue("testSearch." + System.currentTimeMillis());
306
			InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
307
			SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
308
			
309
			// save it
310
			Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
311
			assertEquals(guid.getValue(), retGuid.getValue());
312
			// search for it
313
			ObjectList objectList = CNodeService.getInstance(request).search(session, null, null);
314
			// check it
315
			assertNotNull(objectList);
316
			boolean result = false;
317
			for (ObjectInfo objectInfo: objectList.getObjectInfoList()) {
318
				Identifier pid = objectInfo.getIdentifier();
319
				if (pid.getValue().equals(guid.getValue())) {
320
					result = true;
321
					break;
322
				}
323
			}
324
			assertTrue(result);
325
        } catch(Exception e) {
326
            fail("Unexpected error: " + e.getMessage());
327
        }
328
	}
329
	
330
	public void testSetOwner() {
331
	    printTestHeader("testSetOwner");
332

    
333
	    try {
334
            Session session = getTestSession();
335
			Identifier guid = new Identifier();
336
			guid.setValue("testSetOwner." + System.currentTimeMillis());
337
			InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
338
			SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
339
			long serialVersion = 1L;
340
			// save it
341
			Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
342
			assertEquals(guid.getValue(), retGuid.getValue());
343
			Subject rightsHolder = new Subject();
344
			rightsHolder.setValue("newUser");
345
			// set it
346
			Identifier retPid = CNodeService.getInstance(request).setOwner(session, guid, rightsHolder, serialVersion);
347
			assertEquals(guid, retPid);
348
			// get it
349
			sysmeta = CNodeService.getInstance(request).getSystemMetadata(session, guid);
350
			assertNotNull(sysmeta);
351
			// check it
352
			assertEquals(rightsHolder.getValue(), sysmeta.getRightsHolder().getValue());
353
			
354
        } catch(Exception e) {
355
            fail("Unexpected error: " + e.getMessage());
356
        }
357
	}
358
	
359
	public void testSetAccessPolicy() {
360
	    printTestHeader("testSetAccessPolicy");
361

    
362
	    try {
363
            Session session = getTestSession();
364
			Identifier guid = new Identifier();
365
			guid.setValue("testSetAccessPolicy." + System.currentTimeMillis());
366
			InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
367
			SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
368
	    long serialVersion = 1L;
369

    
370
			// save it
371
			Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
372
			assertEquals(guid.getValue(), retGuid.getValue());
373
			AccessPolicy accessPolicy = new AccessPolicy();
374
			AccessRule accessRule = new AccessRule();
375
			accessRule.addPermission(Permission.WRITE);
376
			Subject publicSubject = new Subject();
377
			publicSubject.setValue(Constants.SUBJECT_PUBLIC);
378
			accessRule.addSubject(publicSubject);
379
			accessPolicy.addAllow(accessRule);
380
			// set it
381
			boolean result = CNodeService.getInstance(request).setAccessPolicy(session, guid, accessPolicy, serialVersion );
382
			assertTrue(result);
383
			// check it
384
			result = CNodeService.getInstance(request).isAuthorized(session, guid, Permission.WRITE);
385
			assertTrue(result);
386
        } catch(Exception e) {
387
            fail("Unexpected error: " + e.getMessage());
388
        }
389
	}
390
	
391
	public void testIsAuthorized() {
392
	    printTestHeader("testIsAuthorized");
393

    
394
	    try {
395
            Session session = getTestSession();
396
			Identifier guid = new Identifier();
397
			guid.setValue("testIsAuthorized." + System.currentTimeMillis());
398
			InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
399
			SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
400
			// save it
401
			Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
402
			assertEquals(guid.getValue(), retGuid.getValue());
403
			// check it
404
			Subject publicSubject = new Subject();
405
			publicSubject.setValue(Constants.SUBJECT_PUBLIC);
406
			session.setSubject(publicSubject);
407
			// public read
408
			boolean result = CNodeService.getInstance(request).isAuthorized(session, guid, Permission.READ);
409
			assertTrue(result);
410
			// not public write
411
			try {
412
				result = false;
413
				result = CNodeService.getInstance(request).isAuthorized(session, guid, Permission.WRITE);
414
				fail("Public WRITE should be denied");
415
			} catch (NotAuthorized nae) {
416
				result = true;
417
			}
418
			assertTrue(result);
419
        } catch(Exception e) {
420
            fail("Unexpected error: " + e.getMessage());
421
        }
422
	}
423
	
424
	public void testReplicationPolicy() {
425
	    printTestHeader("testReplicationPolicy");
426

    
427
	    try {
428
            Session session = getTestSession();
429
			Identifier guid = new Identifier();
430
			guid.setValue("testReplicationPolicy." + System.currentTimeMillis());
431
			InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
432
			SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
433
	    long serialVersion = 1L;
434

    
435
			// save it
436
			Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
437
			assertEquals(guid.getValue(), retGuid.getValue());
438
			
439
			ReplicationPolicy policy = new ReplicationPolicy();
440
			NodeReference node = new NodeReference();
441
			node.setValue("testNode");
442
			policy.addPreferredMemberNode(node );
443
			// set it
444
			boolean result = CNodeService.getInstance(request).setReplicationPolicy(session, guid, policy, serialVersion);
445
			assertTrue(result);
446
			// get it
447
			sysmeta = CNodeService.getInstance(request).getSystemMetadata(session, guid);
448
			assertNotNull(sysmeta);
449
			// check it
450
			assertEquals(policy.getPreferredMemberNode(0).getValue(), sysmeta.getReplicationPolicy().getPreferredMemberNode(0).getValue());
451
			
452
        } catch(Exception e) {
453
            fail("Unexpected error: " + e.getMessage());
454
        }
455
	}
456
	
457
	public void testReplicationStatus() {
458
	    printTestHeader("testReplicationStatus");
459

    
460
	    try {
461
            Session session = getTestSession();
462
			Identifier guid = new Identifier();
463
			guid.setValue("testReplicationStatus." + System.currentTimeMillis());
464
			InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
465
			SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
466
      long serialVersion = 1L;
467
			Replica replica = new Replica();
468
			NodeReference replicaMemberNode = new NodeReference();
469
			replicaMemberNode.setValue("testNode");
470
			replica.setReplicationStatus(ReplicationStatus.REQUESTED);
471
			replica.setReplicaMemberNode(replicaMemberNode);
472
			replica.setReplicaVerified(new Date());
473
			sysmeta.addReplica(replica );
474
			// save it
475
			Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
476
			assertEquals(guid.getValue(), retGuid.getValue());
477
			// set it
478
			ReplicationStatus status = ReplicationStatus.COMPLETED;
479
			boolean result = CNodeService.getInstance(request).setReplicationStatus(session, guid, replicaMemberNode, status, serialVersion);
480
			assertTrue(result);
481
			// get it
482
			sysmeta = CNodeService.getInstance(request).getSystemMetadata(session, guid);
483
			assertNotNull(sysmeta);
484
			// check it
485
			assertEquals(status, sysmeta.getReplica(0).getReplicationStatus());
486
			
487
        } catch(Exception e) {
488
            fail("Unexpected error: " + e.getMessage());
489
        }
490
	}
491
	
492
	/**
493
	 * Run an initial test that always passes to check that the test harness is
494
	 * working.
495
	 */
496
	public void initialize() 
497
	{
498
	    printTestHeader("initialize");
499
		assertTrue(1 == 1);
500
	}
501
	
502

    
503
	/**
504
	 * test to list the object formats registered in metacat
505
	 */
506
	public void testListFormats() {
507
		
508
    printTestHeader("testListFormats");
509
    
510
    // make sure we are set up
511
    setUpFormats();
512
    
513
    // there should be at least 59 formats in the list
514
  	int formatsCount = 59;
515
  	ObjectFormatList objectFormatList;
516
  	
517
  	try {
518
	    objectFormatList = CNodeService.getInstance(request).listFormats();
519
	  	assertTrue(objectFormatList.getTotal() >= formatsCount);
520
  	
521
  	} catch (InvalidRequest e) {
522
  		fail("Could not get the object format list: " + e.getMessage());
523
    
524
  	} catch (ServiceFailure e) {
525
  		fail("Could not get the object format list: " + e.getMessage());
526

    
527
    } catch (NotFound e) {
528
  		fail("Could not get the object format list: " + e.getMessage());
529

    
530
    } catch (InsufficientResources e) {
531
  		fail("Could not get the object format list: " + e.getMessage());
532

    
533
    } catch (NotImplemented e) {
534
  		fail("Could not get the object format list: " + e.getMessage());
535

    
536
    }
537
    
538
	}
539
	
540
  /**
541
   * Test getting a single object format from the registered list
542
   */
543
  public void testGetFormat() {
544
  	
545
    printTestHeader("testGetFormat");
546

    
547
    // make sure we are set up
548
    setUpFormats();
549
    
550
    String knownFormat = "text/plain";
551
    ObjectFormatIdentifier fmtid = new ObjectFormatIdentifier();
552
    fmtid.setValue(knownFormat);
553
  	
554
    try {
555
	    
556
			String result = 
557
				CNodeService.getInstance(request).getFormat(fmtid).getFormatId().getValue();
558
	  	System.out.println("Expected result: " + knownFormat);
559
	  	System.out.println("Found    result: " + result);
560
	  	assertTrue(result.equals(knownFormat));
561
  
562
    } catch (NullPointerException npe) {	  
563
	    fail("The returned format was null: " + npe.getMessage());
564
    
565
    } catch (NotFound nfe) {     
566
    	fail("The format " + knownFormat + " was not found: " + nfe.getMessage());
567
    	
568
    } catch (InvalidRequest ire) {
569
    	fail("The format " + knownFormat + " was not found: " + ire.getMessage());
570

    
571
    } catch (ServiceFailure sfe) {
572
    	fail("The format " + knownFormat + " was not found: " + sfe.getMessage());
573

    
574
    } catch (InsufficientResources ise) {
575
    	fail("The format " + knownFormat + " was not found: " + ise.getMessage());
576
 
577
    } catch (NotImplemented nie) {
578
    	fail("The getFormat() method has not been implemented: " + nie.getMessage());
579

    
580
    }
581
  	
582
  }
583
	
584
  /**
585
   * Test getting a non-existent object format, returning NotFound
586
   */
587
  public void testObjectFormatNotFoundException() {
588
  
589
    printTestHeader("testObjectFormatNotFoundException");
590

    
591
    ObjectFormatIdentifier fmtid = new ObjectFormatIdentifier();
592
  	String badFormat = "text/bad-format";
593
  	fmtid.setValue(badFormat);
594
  	
595
  	try {
596
  		
597
	    ObjectFormat objectFormat = 
598
	    	CNodeService.getInstance(request).getFormat(fmtid);
599
      
600
  	} catch (Exception e) {
601
	    
602
  		assertTrue(e instanceof NotFound);
603
  	}
604
  	
605
  }
606
 
607
}
(1-1/4)