@@ -500,4 +500,49 @@ public void testLegacyConfig() throws IOException {
500500 assertEquals (pid1String , pid2 .asString ());
501501 assertEquals ("legacy" , pid2 .getProviderId ());
502502 }
503+
504+ //Tests support for legacy Perma provider - see #10516
505+ @ Test
506+ @ JvmSetting (key = JvmSettings .LEGACY_PERMALINK_BASEURL , value = "http://localhost:8080/" )
507+ public void testLegacyPermaConfig () throws IOException {
508+ MockitoAnnotations .openMocks (this );
509+ Mockito .when (settingsServiceBean .getValueForKey (SettingsServiceBean .Key .Shoulder )).thenReturn ("FK2" );
510+ Mockito .when (settingsServiceBean .getValueForKey (SettingsServiceBean .Key .Protocol )).thenReturn (PermaLinkPidProvider .PERMA_PROTOCOL );
511+ Mockito .when (settingsServiceBean .getValueForKey (SettingsServiceBean .Key .Authority )).thenReturn ("PermaTest" );
512+
513+ String protocol = settingsServiceBean .getValueForKey (SettingsServiceBean .Key .Protocol );
514+ String authority = settingsServiceBean .getValueForKey (SettingsServiceBean .Key .Authority );
515+ String shoulder = settingsServiceBean .getValueForKey (SettingsServiceBean .Key .Shoulder );
516+
517+ //Code mirrors the relevant part of PidProviderFactoryBean
518+ if (protocol != null && authority != null && shoulder != null ) {
519+ // This line is different than in PidProviderFactoryBean because here we've
520+ // already added the unmanaged providers, so we can't look for null
521+ if (!PidUtil .getPidProvider (protocol , authority , shoulder ).canManagePID ()) {
522+ PidProvider legacy = null ;
523+ // Try to add a legacy provider
524+ String identifierGenerationStyle = settingsServiceBean
525+ .getValueForKey (SettingsServiceBean .Key .IdentifierGenerationStyle , "random" );
526+ String dataFilePidFormat = settingsServiceBean .getValueForKey (SettingsServiceBean .Key .DataFilePIDFormat ,
527+ "DEPENDENT" );
528+ String baseUrl = JvmSettings .LEGACY_PERMALINK_BASEURL .lookupOptional ().orElse (SystemConfig .getDataverseSiteUrlStatic ());
529+ legacy = new PermaLinkPidProvider ("legacy" , "legacy" , authority , shoulder ,
530+ identifierGenerationStyle , dataFilePidFormat , "" , "" , baseUrl ,
531+ PermaLinkPidProvider .SEPARATOR );
532+ if (legacy != null ) {
533+ // Not testing parts that require this bean
534+ legacy .setPidProviderServiceBean (null );
535+ PidUtil .addToProviderList (legacy );
536+ }
537+ } else {
538+ System .out .println ("Legacy PID provider settings found - ignored since a provider for the same protocol, authority, shoulder has been registered" );
539+ }
540+
541+ }
542+ //Is a perma PID with the default "" separator recognized?
543+ String pid1String = "perma:PermaTestFK2ABCDEF" ;
544+ GlobalId pid2 = PidUtil .parseAsGlobalID (pid1String );
545+ assertEquals (pid1String , pid2 .asString ());
546+ assertEquals ("legacy" , pid2 .getProviderId ());
547+ }
503548}
0 commit comments