Project

General

Profile

« Previous | Next » 

Revision 9233

Added by Jing Tao over 9 years ago

Add a junit test case to test the write/read of new fields in the system metadata.

View differences:

test/edu/ucsb/nceas/metacattest/IdentifierManagerTest.java
37 37
import org.dataone.service.types.v1.NodeType;
38 38
import org.dataone.service.types.v1.Session;
39 39
import org.dataone.service.types.v1.Subject;
40
import org.dataone.service.types.v2.MediaType;
41
import org.dataone.service.types.v2.MediaTypeProperty;
40 42
import org.dataone.service.types.v2.Node;
41 43
import org.dataone.service.types.v2.NodeList;
42 44
import org.dataone.service.types.v2.SystemMetadata;
......
80 82
        suite.addTest(new IdentifierManagerTest("testCreateMapping"));
81 83
        suite.addTest(new IdentifierManagerTest("testGenerateLocalId"));
82 84
        suite.addTest(new IdentifierManagerTest("testGetHeadPID"));
83

  
85
        suite.addTest(new IdentifierManagerTest("testMediaType"));
84 86
        return suite;
85 87
    }
86 88
    /**
......
1394 1396
        return docid;
1395 1397
    }
1396 1398
    
1399
    /**
1400
     * Method to test new system metadata field such as media type and file name.
1401
     */
1402
    public void testMediaType() throws Exception {
1403
        String fileName = "new file name";
1404
        String name = "text/plain";
1405
        String p1Name = "charset";
1406
        String p1Value = "UTF8";
1407
        String p2Name = "n2";
1408
        String p2Value = "v2";
1409
        IdentifierManager im = IdentifierManager.getInstance();
1410
        
1411
        //test system metadata write/read without mediatype and file name.
1412
        String docid = "test." + new Date().getTime() + ".1";
1413
        String guid = "guid:" + docid;
1414
        //create a mapping (identifier-docid)
1415
        im.createMapping(guid, docid);
1416
        Session session = getTestSession();
1417
        Identifier id = new Identifier();
1418
        id.setValue(guid);
1419
        InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
1420
        SystemMetadata sysmeta = createSystemMetadata(id, session.getSubject(), object);
1421
        //sysmeta.setFileName(fileName);
1422
        im.insertOrUpdateSystemMetadata(sysmeta);
1423
        SystemMetadata read = im.getSystemMetadata(guid);
1424
        assertTrue(read.getIdentifier().equals(id));
1425
        assertTrue(read.getFileName() == null);
1426
        assertTrue(read.getMediaType() == null);
1427
        //remove the system metadata
1428
        im.deleteSystemMetadata(guid);
1429
        //remove the mapping
1430
        im.removeMapping(guid, docid);
1431
        
1432
        
1433
      //test system metadata write/read with mediatype and file name.
1434
        Thread.sleep(1000);
1435
        docid = "test." + new Date().getTime() + ".1";
1436
        guid = "guid:" + docid;
1437
        //create a mapping (identifier-docid)
1438
        im.createMapping(guid, docid);
1439
        id = new Identifier();
1440
        id.setValue(guid);
1441
        object = new ByteArrayInputStream("test".getBytes("UTF-8"));
1442
        sysmeta = createSystemMetadata(id, session.getSubject(), object);
1443
        sysmeta.setFileName(fileName);
1444
        MediaType media = new MediaType();
1445
        media.setName(name);
1446
        MediaTypeProperty p1 = new MediaTypeProperty();
1447
        p1.setName(p1Name);
1448
        p1.setValue(p1Value);
1449
        media.addProperty(p1);
1450
        MediaTypeProperty p2 = new MediaTypeProperty();
1451
        p2.setName(p2Name);
1452
        p2.setValue(p2Value);
1453
        media.addProperty(p2);
1454
        sysmeta.setMediaType(media);
1455
        im.insertOrUpdateSystemMetadata(sysmeta);
1456
        read = im.getSystemMetadata(guid);
1457
        assertTrue(read.getIdentifier().equals(id));
1458
        assertTrue(read.getFileName().equals(fileName));
1459
        MediaType type = read.getMediaType();
1460
        assertTrue(type.getName().equals(name));
1461
        List<MediaTypeProperty> list = type.getPropertyList();
1462
        assertTrue(list.size() == 2);
1463
        MediaTypeProperty item1 = list.get(0);
1464
        assertTrue(item1.getName().equals(p1Name));
1465
        assertTrue(item1.getValue().equals(p1Value));
1466
        MediaTypeProperty item2 = list.get(1);
1467
        assertTrue(item2.getName().equals(p2Name));
1468
        assertTrue(item2.getValue().equals(p2Value));
1469
        
1470
        //Thread.sleep(100000);
1471
        //remove the system metadata
1472
        im.deleteSystemMetadata(guid);
1473
        //remove the mapping
1474
        im.removeMapping(guid, docid);
1475
        
1476
        
1477
    }
1478
    
1397 1479
    private void ph(String s)
1398 1480
    {
1399 1481
        System.out.println("*********************** " + s + " ****************************");

Also available in: Unified diff