@@ -218,13 +218,18 @@ public ResourceManagerImpl getResourceManagerImpl() throws IOException, SAXExcep
218
218
InputStream eventCoreIs = ResourceManagerImplTest .class .getResourceAsStream ("/extensions/dwc_event_2015-04-24.xml" );
219
219
Extension eventCore = extensionFactory .build (eventCoreIs );
220
220
221
+ // construct simple images extension
222
+ InputStream simpleImageIs = ResourceManagerImplTest .class .getResourceAsStream ("/extensions/simple_image.xml" );
223
+ Extension simpleImage = extensionFactory .build (simpleImageIs );
224
+
221
225
ExtensionManager extensionManager = mock (ExtensionManager .class );
222
226
223
227
// mock ExtensionManager returning different Extensions
224
228
when (extensionManager .get ("http://rs.tdwg.org/dwc/terms/Occurrence" )).thenReturn (occurrenceCore );
225
229
when (extensionManager .get ("http://rs.tdwg.org/dwc/terms/Event" )).thenReturn (eventCore );
226
230
when (extensionManager .get ("http://rs.tdwg.org/dwc/xsd/simpledarwincore/SimpleDarwinRecord" ))
227
231
.thenReturn (occurrenceCore );
232
+ when (extensionManager .get ("http://rs.gbif.org/terms/1.0/Image" )).thenReturn (simpleImage );
228
233
229
234
ExtensionRowTypeConverter extensionRowTypeConverter = new ExtensionRowTypeConverter (extensionManager );
230
235
ConceptTermConverter conceptTermConverter = new ConceptTermConverter (extensionRowTypeConverter );
@@ -490,6 +495,93 @@ public void testCreateFromSingleGzipFile()
490
495
assertTrue (res .getEml ().getDescription ().isEmpty ());
491
496
}
492
497
498
+ /**
499
+ * test resource (with extension) creation from zipped resource folder.
500
+ */
501
+ @ Test
502
+ public void testCreateWithExtensionFromZippedFile ()
503
+ throws AlreadyExistingException , ImportException , SAXException , ParserConfigurationException , IOException ,
504
+ InvalidFilenameException {
505
+ // retrieve sample zipped resource folder
506
+ File resourceXML = FileUtils .getClasspathFile ("resources/amphibians/resource.xml" );
507
+ // mock finding resource.xml file
508
+ when (mockedDataDir .resourceFile (anyString (), anyString ())).thenReturn (resourceXML );
509
+
510
+ // retrieve sample zipped resource folder
511
+ File emlXML = FileUtils .getClasspathFile ("resources/amphibians/eml.xml" );
512
+ // mock finding eml.xml file
513
+ when (mockedDataDir .resourceEmlFile (anyString (), any (BigDecimal .class ))).thenReturn (emlXML );
514
+
515
+ // create instance of manager
516
+ ResourceManager resourceManager = getResourceManagerImpl ();
517
+
518
+ // retrieve sample zipped resource folder
519
+ File zippedResourceFolder = FileUtils .getClasspathFile ("resources/amphibians.zip" );
520
+
521
+ // create a new resource.
522
+ resourceManager .create ("amphibians" , null , zippedResourceFolder , creator , baseAction );
523
+
524
+ // test if new resource was added to the resources list.
525
+ assertEquals (1 , resourceManager .list ().size ());
526
+
527
+ // get added resource.
528
+ Resource res = resourceManager .get ("amphibians" );
529
+
530
+ // test if resource was added correctly.
531
+ assertEquals ("amphibians" , res .getShortname ());
532
+ assertEquals (creator , res .getCreator ());
533
+ assertEquals (creator , res .getModifier ());
534
+
535
+ // test if resource.xml was created.
536
+ assertTrue (mockedDataDir .resourceFile ("amphibians" , ResourceManagerImpl .PERSISTENCE_FILE ).exists ());
537
+
538
+ // properties that get preserved
539
+ // there are 2 source files
540
+ assertEquals (2 , res .getSources ().size ());
541
+ assertEquals ("danbifdb" , res .getSources ().get (0 ).getName ());
542
+ assertEquals (65 , res .getSource ("danbifdb" ).getColumns ());
543
+
544
+ // there is 1 mapping
545
+ assertEquals (2 , res .getMappings ().size ());
546
+ assertEquals ("danbifdb" , res .getMappings ().get (0 ).getSource ().getName ());
547
+ assertEquals (Constants .DWC_ROWTYPE_OCCURRENCE , res .getMappings ().get (0 ).getExtension ().getRowType ());
548
+ assertEquals ("http://rs.gbif.org/terms/1.0/Image" , res .getMappings ().get (1 ).getExtension ().getRowType ());
549
+
550
+ // properties that get reset
551
+ assertEquals (Constants .INITIAL_RESOURCE_VERSION , res .getEmlVersion ());
552
+ // the resource shouldn't be registered
553
+ assertFalse (res .isRegistered ());
554
+ // the resource shouldn't have any managers
555
+ assertEquals (0 , res .getManagers ().size ());
556
+ // the resource shouldn't have a last published date
557
+ assertNull (res .getLastPublished ());
558
+ // the resource shouldn't be registered (no org, no key)
559
+ assertNull (res .getKey ());
560
+ assertNull (res .getOrganisation ());
561
+ // the status should be private
562
+ assertEquals (PublicationStatus .PRIVATE , res .getStatus ());
563
+ // the resource should have a created date
564
+ assertNotNull (res .getCreated ());
565
+ // the record count is 0
566
+ assertEquals (0 , res .getRecordsPublished ());
567
+ // the DOI was reset
568
+ assertNull (res .getDoi ());
569
+ assertEquals (IdentifierStatus .UNRESERVED , res .getIdentifierStatus ());
570
+ assertNull (res .getDoiOrganisationKey ());
571
+ // the change summary was reset
572
+ assertNull (res .getChangeSummary ());
573
+ // the VersionHistory was cleared
574
+ assertEquals (0 , res .getVersionHistory ().size ());
575
+ // the auto-publication was reset
576
+ assertEquals (PublicationMode .AUTO_PUBLISH_OFF , res .getPublicationMode ());
577
+ assertNull (res .getUpdateFrequency ());
578
+ assertNull (res .getNextPublished ());
579
+ // the other last modified dates were also reset
580
+ assertNull (res .getMetadataModified ());
581
+ assertNull (res .getMappingsModified ());
582
+ assertNull (res .getSourcesModified ());
583
+ }
584
+
493
585
/**
494
586
* test resource creation from zipped file, but resource.xml references non-existent extension.
495
587
*/
0 commit comments