@@ -324,6 +324,42 @@ public void testCreate() {
324
324
}
325
325
}
326
326
327
+ /**
328
+ * Test object creation without object format id in the system metadata
329
+ */
330
+ @ Test
331
+ public void testCreateWithoutObjectFormatId () throws Exception {
332
+ D1NodeServiceTest .printTestHeader ("testCreateWithoutObjectFormatId" );
333
+ Identifier guid = new Identifier ();
334
+ guid .setValue ("testCreate." + System .currentTimeMillis ());
335
+ Session session = null ;
336
+ session = d1NodeTest .getTestSession ();
337
+ try {
338
+ InputStream object =
339
+ new ByteArrayInputStream ("test" .getBytes (StandardCharsets .UTF_8 ));
340
+ SystemMetadata sysmeta =
341
+ D1NodeServiceTest .createSystemMetadata (guid , session .getSubject (), object );
342
+ sysmeta .setFormatId (null );
343
+ Identifier pid = d1NodeTest .mnCreate (session , guid , object , sysmeta );
344
+ fail ("It should fail since the format id is null." );
345
+ } catch (Exception e ) {
346
+ assertTrue (e instanceof InvalidSystemMetadata );
347
+ }
348
+ try {
349
+ InputStream object =
350
+ new ByteArrayInputStream ("test" .getBytes (StandardCharsets .UTF_8 ));
351
+ SystemMetadata sysmeta =
352
+ D1NodeServiceTest .createSystemMetadata (guid , session .getSubject (), object );
353
+ ObjectFormatIdentifier formatIdentifier = new ObjectFormatIdentifier ();
354
+ formatIdentifier .setValue ("" );
355
+ sysmeta .setFormatId (formatIdentifier );
356
+ Identifier pid = d1NodeTest .mnCreate (session , guid , object , sysmeta );
357
+ fail ("It should fail since the format id is blank." );
358
+ } catch (Exception e ) {
359
+ assertTrue (e instanceof InvalidSystemMetadata );
360
+ }
361
+ }
362
+
327
363
/**
328
364
* Test object creation
329
365
*/
@@ -786,6 +822,55 @@ public void testUpdate() {
786
822
}
787
823
}
788
824
825
+ /**
826
+ * Test to update objects with the system metadata without the format id
827
+ */
828
+ @ Test
829
+ public void testUpdateWithoutFormatId () {
830
+ D1NodeServiceTest .printTestHeader ("testUpdateWiouthFormatId" );
831
+ try {
832
+ Session session = d1NodeTest .getTestSession ();
833
+ Identifier guid = new Identifier ();
834
+ guid .setValue ("testUpdate." + System .currentTimeMillis ());
835
+ InputStream object =
836
+ new ByteArrayInputStream ("test" .getBytes (StandardCharsets .UTF_8 ));
837
+ SystemMetadata sysmeta =
838
+ D1NodeServiceTest .createSystemMetadata (guid , session .getSubject (), object );
839
+ // original
840
+ Identifier pid =
841
+ d1NodeTest .mnCreate (session , guid , object , sysmeta );
842
+
843
+ //Test the case that format id is null
844
+ Identifier newPid = new Identifier ();
845
+ newPid .setValue (
846
+ "testUpdate." + (System .currentTimeMillis () + 1 ));
847
+ object = new ByteArrayInputStream ("test" .getBytes (StandardCharsets .UTF_8 ));
848
+ SystemMetadata newMeta =
849
+ D1NodeServiceTest .createSystemMetadata (newPid , session .getSubject (), object );
850
+ newMeta .setFormatId (null );
851
+ object = new ByteArrayInputStream ("test" .getBytes (StandardCharsets .UTF_8 ));
852
+ try {
853
+ d1NodeTest .mnUpdate (session , pid , object , newPid , newMeta );
854
+ fail ("we shouldn't get here since the format id is null" );
855
+ } catch (Exception e ) {
856
+ assertTrue (e instanceof InvalidSystemMetadata );
857
+ }
858
+
859
+ object = new ByteArrayInputStream ("test" .getBytes (StandardCharsets .UTF_8 ));
860
+ ObjectFormatIdentifier formatIdentifier = new ObjectFormatIdentifier ();
861
+ formatIdentifier .setValue ("" );
862
+ newMeta .setFormatId (formatIdentifier );
863
+ try {
864
+ d1NodeTest .mnUpdate (session , pid , object , newPid , newMeta );
865
+ fail ("we shouldn't get here since the format id is blank" );
866
+ } catch (Exception e ) {
867
+ assertTrue (e instanceof InvalidSystemMetadata );
868
+ }
869
+ } catch (Exception e ) {
870
+ fail ("Unexpected error: " + e .getMessage ());
871
+ }
872
+ }
873
+
789
874
/**
790
875
* Test object updating
791
876
*/
0 commit comments