|
33 | 33 | import edu.ucsb.nceas.metacat.database.DBConnectionPool;
|
34 | 34 | import edu.ucsb.nceas.metacat.dataone.CNodeService;
|
35 | 35 | import edu.ucsb.nceas.metacat.dataone.MNodeService;
|
| 36 | +import edu.ucsb.nceas.metacat.doi.DOIServiceFactory; |
36 | 37 | import edu.ucsb.nceas.metacat.object.handler.JsonLDHandlerTest;
|
37 | 38 | import edu.ucsb.nceas.metacat.object.handler.NonXMLMetadataHandlers;
|
38 | 39 | import edu.ucsb.nceas.metacat.properties.PropertyService;
|
@@ -215,6 +216,7 @@ public static Test suite() {
|
215 | 216 | suite.addTest(new MNodeServiceTest("testInsertJson_LD"));
|
216 | 217 | suite.addTest(new MNodeServiceTest("testCreateAndUpdateEventLog"));
|
217 | 218 | suite.addTest(new MNodeServiceTest("testUpdateSystemMetadataPermission"));
|
| 219 | + suite.addTest(new MNodeServiceTest("testCreateAndUpdateWithDoiDisabled")); |
218 | 220 | return suite;
|
219 | 221 |
|
220 | 222 | }
|
@@ -1977,7 +1979,7 @@ else if (entry.getName().contains("data.2")) {
|
1977 | 1979 | // clean up
|
1978 | 1980 | bagFile.delete();
|
1979 | 1981 | Identifier doi = MNodeService.getInstance(request).publish(session, metadataId);
|
1980 |
| - Thread.sleep(60000); |
| 1982 | + Thread.sleep(80000); |
1981 | 1983 | System.out.println("+++++++++++++++++++ the metadataId on the ore package is "+metadataId.getValue());
|
1982 | 1984 | List<Identifier> oreIds = MNodeService.getInstance(request).lookupOreFor(session, doi, true);
|
1983 | 1985 | assertTrue(oreIds.size() == 1);
|
@@ -4068,5 +4070,62 @@ private ResultSet getEventLogs(Identifier guid) throws Exception {
|
4068 | 4070 | }
|
4069 | 4071 | return result;
|
4070 | 4072 | }
|
| 4073 | + |
| 4074 | + |
| 4075 | + /** |
| 4076 | + * Test to create and update object when DOI setting is disabled |
| 4077 | + */ |
| 4078 | + public void testCreateAndUpdateWithDoiDisabled() throws Exception { |
| 4079 | + printTestHeader("testCreateAndUpdateWithDoiDisabled"); |
| 4080 | + String originDOIstatusStr = PropertyService.getInstance().getProperty("guid.ezid.enabled"); |
| 4081 | + System.out.println("the dois status is ++++++++++++++ " + originDOIstatusStr); |
| 4082 | + try { |
| 4083 | + Session session = getTestSession(); |
| 4084 | + PropertyService.getInstance().setPropertyNoPersist("guid.ezid.enabled", "false");//disable doi |
| 4085 | + DOIServiceFactory.getDOIService().refreshStatus(); |
| 4086 | + try { |
| 4087 | + //make sure the service of doi is disabled |
| 4088 | + MNodeService.getInstance(request).generateIdentifier(session, "doi", null); |
| 4089 | + fail("we shouldn't get here since generating doi should fail when the feature is disabled"); |
| 4090 | + } catch (Exception e) { |
| 4091 | + assertTrue(e instanceof ServiceFailure); |
| 4092 | + assertTrue(e.getMessage().contains("DOI scheme is not enabled at this node")); |
| 4093 | + } |
| 4094 | + Identifier guid = new Identifier(); |
| 4095 | + guid.setValue("testCreateAndUpdateWithDoiDisabled." + System.currentTimeMillis()); |
| 4096 | + InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8")); |
| 4097 | + SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object); |
| 4098 | + Identifier newPid = new Identifier(); |
| 4099 | + newPid.setValue("testCreateAndUpdateWithDoiDisabled-2." + (System.currentTimeMillis() + 1)); // ensure it is different from original |
| 4100 | + Identifier pid = |
| 4101 | + MNodeService.getInstance(request).create(session, guid, object, sysmeta); |
| 4102 | + SystemMetadata getSysMeta = |
| 4103 | + MNodeService.getInstance(request).getSystemMetadata(session, pid); |
| 4104 | + assertEquals(pid.getValue(), getSysMeta.getIdentifier().getValue()); |
| 4105 | + |
| 4106 | + object = new ByteArrayInputStream("test".getBytes("UTF-8")); |
| 4107 | + SystemMetadata newSysMeta = createSystemMetadata(newPid, session.getSubject(), object); |
| 4108 | + // do the update |
| 4109 | + Identifier updatedPid = |
| 4110 | + MNodeService.getInstance(request).update(session, pid, object, newPid, newSysMeta); |
| 4111 | + |
| 4112 | + // get the updated system metadata |
| 4113 | + SystemMetadata updatedSysMeta = |
| 4114 | + MNodeService.getInstance(request).getSystemMetadata(session, updatedPid); |
| 4115 | + assertEquals(updatedPid.getValue(), updatedSysMeta.getIdentifier().getValue()); |
| 4116 | + |
| 4117 | + try { |
| 4118 | + //publish will fail too |
| 4119 | + MNodeService.getInstance(request).publish(session, updatedPid); |
| 4120 | + fail("we shouldn't get here since publishing should fail when the feature is disabled"); |
| 4121 | + } catch (Exception e) { |
| 4122 | + assertTrue(e instanceof ServiceFailure); |
| 4123 | + assertTrue(e.getMessage().contains("DOI scheme is not enabled at this node")); |
| 4124 | + } |
| 4125 | + } finally { |
| 4126 | + PropertyService.getInstance().setPropertyNoPersist("guid.ezid.enabled", originDOIstatusStr); |
| 4127 | + DOIServiceFactory.getDOIService().refreshStatus(); |
| 4128 | + } |
| 4129 | + } |
4071 | 4130 | }
|
4072 | 4131 |
|
0 commit comments