Project

General

Profile

« Previous | Next » 

Revision 9052

Added by Jing Tao over 9 years ago

Add the code to test series id in the archive, delete, isAuthorized and systemMetadataChanged method.

View differences:

test/edu/ucsb/nceas/metacat/dataone/MNodeServiceTest.java
815 815
          // create the object
816 816
          Identifier pid = new Identifier();
817 817
          pid.setValue("testSystemMetadataChanged." + System.currentTimeMillis());
818
          Identifier sid = new Identifier();
819
          sid.setValue("testSystemMetadataChangedSid."+System.currentTimeMillis());
818 820
          InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
819 821
          SystemMetadata sysmeta = createSystemMetadata(pid, session.getSubject(), object);
822
          sysmeta.setSeriesId(sid);
820 823
          Identifier retPid = MNodeService.getInstance(request).create(session, pid, object, sysmeta);
821 824
          assertEquals(retPid.getValue(), pid.getValue());
822 825
          
823 826
          // pretend the system metadata changed on the CN
824 827
          MNodeService.getInstance(request).systemMetadataChanged(session, 
825 828
                  retPid, 5000L, Calendar.getInstance().getTime());
829
          MNodeService.getInstance(request).systemMetadataChanged(session, 
830
                  sid, 5000L, Calendar.getInstance().getTime());
831
          edu.ucsb.nceas.metacat.dataone.v1.MNodeService.getInstance(request).systemMetadataChanged(session, 
832
                  retPid, 5000L, Calendar.getInstance().getTime());
833
          edu.ucsb.nceas.metacat.dataone.v1.MNodeService.getInstance(request).systemMetadataChanged(session, 
834
                  sid, 5000L, Calendar.getInstance().getTime());
826 835
          
827 836
      } catch (Exception e) {
828 837
          if (e instanceof NotAuthorized) {
......
1515 1524
                
1516 1525
            }
1517 1526
            
1527
            boolean isAuthorized = 
1528
                    MNodeService.getInstance(request).isAuthorized(session, guid, Permission.READ);
1529
            assertEquals(isAuthorized, true);
1518 1530
            
1531
            isAuthorized = 
1532
                    MNodeService.getInstance(request).isAuthorized(session, seriesId, Permission.READ);
1533
            assertEquals(isAuthorized, true);
1519 1534
            
1535
            isAuthorized = 
1536
                    edu.ucsb.nceas.metacat.dataone.v1.MNodeService.getInstance(request).isAuthorized(session, guid, Permission.READ);
1537
            assertEquals(isAuthorized, true);
1538
            
1539
            try {
1540
                isAuthorized = 
1541
                        edu.ucsb.nceas.metacat.dataone.v1.MNodeService.getInstance(request).isAuthorized(session, seriesId, Permission.READ);
1542
                fail("we can't reach here since the v1 isAuthorized method doesn't suppport series id");
1543
            } catch (NotFound e) {
1544
                
1545
            }
1546

  
1520 1547
            //do a update with the same series id
1521 1548
            Thread.sleep(1000);
1522 1549
            Identifier newPid = new Identifier();
......
1780 1807
                
1781 1808
            } 
1782 1809
            
1810
            //test archive a series id by v1
1811
            try {
1812
                edu.ucsb.nceas.metacat.dataone.v1.MNodeService.getInstance(request).archive(session, seriesId2);
1813
                fail("we can't reach here since the v1 archive method doesn't support the sid ");
1814
            } catch (NotFound nf2) {
1815
                
1816
            }
1817
            
1818
            // test delete a series id by v1
1819
            Session mnSession = getMNSession();
1820
            try {
1821
                edu.ucsb.nceas.metacat.dataone.v1.MNodeService.getInstance(request).delete(mnSession, seriesId2);
1822
                fail("we can't reach here since the v1 delete method doesn't support the sid ");
1823
            } catch (NotFound nf2) {
1824
                
1825
            }
1826
            
1827
            // test archive a series id by v2
1828
            MNodeService.getInstance(request).archive(session, seriesId2);
1829
            SystemMetadata archived = MNodeService.getInstance(request).getSystemMetadata(session, seriesId2);
1830
            assertTrue(archived.getArchived());
1831
            archived = MNodeService.getInstance(request).getSystemMetadata(session, newPid2);
1832
            assertTrue(archived.getArchived());
1833
            
1834
            // test delete a series id by v2
1835
            MNodeService.getInstance(request).delete(mnSession, seriesId2);
1836
            try {
1837
                MNodeService.getInstance(request).get(session, seriesId2);
1838
                fail("we can't reach here since the series id was deleted ");
1839
            } catch (NotFound nf3) {
1840
                System.out.println("the message is ============="+nf3.getMessage());
1841
                //assertTrue(nf3.getMessage().indexOf("delete") >0);
1842
            }
1843
            
1844
            try {
1845
                MNodeService.getInstance(request).get(session, newPid2);
1846
                fail("we can't reach here since the series id was deleted ");
1847
            } catch (NotFound nf3) {
1848
                //System.out.println("the message is ============="+nf3.getMessage());
1849
                assertTrue(nf3.getMessage().indexOf("delete") >0);
1850
            }
1851
            
1852
            try {
1853
                edu.ucsb.nceas.metacat.dataone.v1.MNodeService.getInstance(request).get(session, newPid2);
1854
                fail("we can't reach here since the series id was deleted ");
1855
            } catch (NotFound nf3) {
1856
                System.out.println("the message is ============="+nf3.getMessage());
1857
                assertTrue(nf3.getMessage().indexOf("delete") >0);
1858
            }
1859
            
1860
            //archive seriesId
1861
            MNodeService.getInstance(request).archive(mnSession, seriesId);
1862
            archived = MNodeService.getInstance(request).getSystemMetadata(session, seriesId);
1863
            assertTrue(archived.getArchived());
1864
            archived = MNodeService.getInstance(request).getSystemMetadata(session, newPid);
1865
            assertTrue(archived.getArchived());
1866
            
1867
            
1868
            //delete seriesId
1869
            MNodeService.getInstance(request).delete(mnSession, seriesId);
1870
            try {
1871
                MNodeService.getInstance(request).get(session, newPid);
1872
                fail("we can't reach here since the series id was deleted ");
1873
            } catch (NotFound nf3) {
1874
                //System.out.println("the message is ============="+nf3.getMessage());
1875
                assertTrue(nf3.getMessage().indexOf("delete") >0);
1876
            }
1877
            SystemMetadata meta = MNodeService.getInstance(request).getSystemMetadata(session, seriesId);
1878
            assertTrue(meta.getIdentifier().getValue().equals(guid.getValue()));
1879
            
1783 1880
        } catch (Exception e) {
1784 1881
            fail(e.getMessage());
1785 1882
        }

Also available in: Unified diff