|
15 | 15 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
16 | 16 |
|
17 | 17 | import java.util.HashMap; |
| 18 | +import java.util.List; |
18 | 19 | import java.util.Map; |
19 | 20 |
|
20 | 21 | import org.dspace.app.rest.test.AbstractControllerIntegrationTest; |
| 22 | +import org.dspace.content.authority.service.ChoiceAuthorityService; |
| 23 | +import org.dspace.content.authority.service.MetadataAuthorityService; |
| 24 | +import org.dspace.core.service.PluginService; |
| 25 | +import org.dspace.importer.external.datamodel.ImportRecord; |
| 26 | +import org.dspace.importer.external.metadatamapping.MetadatumDTO; |
| 27 | +import org.dspace.importer.external.ror.service.RorImportMetadataSourceService; |
| 28 | +import org.dspace.importer.external.ror.service.RorServicesFactory; |
| 29 | +import org.dspace.importer.external.ror.service.RorServicesFactoryImpl; |
| 30 | +import org.dspace.services.ConfigurationService; |
| 31 | +import org.junit.AfterClass; |
| 32 | +import org.junit.Before; |
| 33 | +import org.junit.BeforeClass; |
21 | 34 | import org.junit.Test; |
| 35 | +import org.mockito.Mock; |
| 36 | +import org.mockito.MockedStatic; |
| 37 | +import org.mockito.Mockito; |
| 38 | +import org.springframework.beans.factory.annotation.Autowired; |
22 | 39 |
|
23 | 40 | public class RorOrgUnitAuthorityIT extends AbstractControllerIntegrationTest { |
24 | 41 |
|
| 42 | + public static final String ROR_ORGUNIT_AUTHORITY = |
| 43 | + "org.dspace.content.authority.RorOrgUnitAuthority = OrgUnitAuthority"; |
| 44 | + |
| 45 | + public static final String ROR_FILTER = "02z02cv32 OR 03vb2cr34"; |
| 46 | + |
| 47 | + private static MockedStatic<RorServicesFactory> mockRorServiceFactory; |
| 48 | + |
| 49 | + @Autowired |
| 50 | + protected ChoiceAuthorityService choiceAuthorityService; |
| 51 | + @Autowired |
| 52 | + protected PluginService pluginService; |
| 53 | + @Autowired |
| 54 | + protected MetadataAuthorityService metadataAuthorityService; |
| 55 | + @Autowired |
| 56 | + protected ConfigurationService configurationService; |
| 57 | + @Mock |
| 58 | + private RorImportMetadataSourceService metadataSourceService; |
| 59 | + |
| 60 | + @BeforeClass |
| 61 | + public static void init() { |
| 62 | + mockRorServiceFactory = Mockito.mockStatic(RorServicesFactory.class); |
| 63 | + } |
| 64 | + |
| 65 | + @AfterClass |
| 66 | + public static void close() { |
| 67 | + mockRorServiceFactory.close(); |
| 68 | + } |
| 69 | + |
| 70 | + @Before |
| 71 | + public void setup() throws Exception { |
| 72 | + |
| 73 | + RorServicesFactoryImpl rorServiceFactory = |
| 74 | + new RorServicesFactoryImpl(this.metadataSourceService); |
| 75 | + |
| 76 | + Mockito.when( |
| 77 | + metadataSourceService.getRecords( |
| 78 | + ROR_FILTER, 0, 0 |
| 79 | + ) |
| 80 | + ).thenReturn(List.of(getImportRecord1(), getImportRecord2())); |
| 81 | + |
| 82 | + mockRorServiceFactory.when(RorServicesFactory::getInstance).thenReturn(rorServiceFactory); |
| 83 | + } |
| 84 | + |
25 | 85 | @Test |
26 | 86 | public void testAuthority() throws Exception { |
27 | 87 |
|
28 | | - Map<String, String> expectedExtras = new HashMap<>(); |
29 | | - expectedExtras.put("data-ror_orgunit_id", "https://ror.org/02z02cv32"); |
30 | | - expectedExtras.put("ror_orgunit_id", "https://ror.org/02z02cv32"); |
31 | | - expectedExtras.put("data-ror_orgunit_type", "Nonprofit"); |
32 | | - expectedExtras.put("ror_orgunit_type", "Nonprofit"); |
33 | | - expectedExtras.put("data-ror_orgunit_acronym", "WEICan, IEEC"); |
34 | | - expectedExtras.put("ror_orgunit_acronym", "WEICan, IEEC"); |
35 | | - expectedExtras.put("data-ror_orgunit_country", "CA"); |
36 | | - expectedExtras.put("data-ror_orgunit_countryName", "CA"); |
37 | | - expectedExtras.put("ror_orgunit_countryName", "CA"); |
38 | | - |
39 | | - Map<String, String> expectedExtras2 = new HashMap<>(); |
40 | | - expectedExtras2.put("data-ror_orgunit_id", "https://ror.org/03vb2cr34"); |
41 | | - expectedExtras2.put("ror_orgunit_id", "https://ror.org/03vb2cr34"); |
42 | | - expectedExtras2.put("data-ror_orgunit_type", "Company"); |
43 | | - expectedExtras2.put("ror_orgunit_type", "Company"); |
44 | | - expectedExtras2.put("data-ror_orgunit_countryName", "Italia"); |
45 | | - expectedExtras2.put("ror_orgunit_countryName", "Italia"); |
46 | | - expectedExtras2.put("data-ror_orgunit_country", "IT"); |
47 | | - |
48 | 88 | String token = getAuthToken(eperson.getEmail(), password); |
49 | 89 | getClient(token).perform(get("/api/submission/vocabularies/OrgUnitAuthority/entries") |
50 | | - .param("filter", "02z02cv32 OR 03vb2cr34")) |
| 90 | + .param("filter", ROR_FILTER)) |
51 | 91 | .andExpect(status().isOk()) |
52 | 92 | .andExpect(jsonPath("$._embedded.entries", hasSize(2))) |
53 | 93 | .andExpect(jsonPath("$._embedded.entries", |
54 | 94 | hasItems( |
55 | 95 | matchItemAuthorityWithOtherInformations("will be referenced::ROR-ID::https://ror.org/02z02cv32", |
56 | 96 | "Wind Energy Institute of Canada", "Wind Energy Institute of Canada", "vocabularyEntry", |
57 | | - expectedExtras), |
| 97 | + getExtrasRecord1() |
| 98 | + ), |
58 | 99 | matchItemAuthorityWithOtherInformations("will be referenced::ROR-ID::https://ror.org/03vb2cr34", |
59 | 100 | "4Science", "4Science", "vocabularyEntry", |
60 | | - expectedExtras2)))); |
| 101 | + getExtrasRecord2() |
| 102 | + ) |
| 103 | + ) |
| 104 | + )); |
| 105 | + } |
| 106 | + |
| 107 | + private ImportRecord getImportRecord1() { |
| 108 | + return new ImportRecord( |
| 109 | + List.of( |
| 110 | + new RorMetadatum("dc.title", "Wind Energy Institute of Canada"), |
| 111 | + new RorMetadatum("organization.identifier.ror", "https://ror.org/02z02cv32"), |
| 112 | + new RorMetadatum("oairecerif.identifier.url", "http://www.weican.ca/"), |
| 113 | + new RorMetadatum("dc.type", "Nonprofit"), |
| 114 | + new RorMetadatum("oairecerif.acronym", "IEEC"), |
| 115 | + new RorMetadatum("oairecerif.acronym", "WEICan"), |
| 116 | + new RorMetadatum("organization.address.addressCountry", "CA"), |
| 117 | + new RorMetadatum("organization.foundingDate", "1981") |
| 118 | + |
| 119 | + ) |
| 120 | + ); |
| 121 | + } |
| 122 | + |
| 123 | + private Map<String, String> getExtrasRecord1() { |
| 124 | + Map<String, String> extras = new HashMap<>(); |
| 125 | + extras.put("data-ror_orgunit_id", "https://ror.org/02z02cv32"); |
| 126 | + extras.put("ror_orgunit_id", "https://ror.org/02z02cv32"); |
| 127 | + extras.put("data-ror_orgunit_type", "Nonprofit"); |
| 128 | + extras.put("ror_orgunit_type", "Nonprofit"); |
| 129 | + extras.put("data-ror_orgunit_acronym", "IEEC, WEICan"); |
| 130 | + extras.put("ror_orgunit_acronym", "IEEC, WEICan"); |
| 131 | + extras.put("data-ror_orgunit_country", "CA"); |
| 132 | + extras.put("data-ror_orgunit_countryName", "CA"); |
| 133 | + extras.put("ror_orgunit_countryName", "CA"); |
| 134 | + return extras; |
| 135 | + } |
| 136 | + |
| 137 | + private ImportRecord getImportRecord2() { |
| 138 | + return new ImportRecord( |
| 139 | + List.of( |
| 140 | + new RorMetadatum("dc.title", "4Science"), |
| 141 | + new RorMetadatum("organization.identifier.ror", "https://ror.org/03vb2cr34"), |
| 142 | + new RorMetadatum("oairecerif.identifier.url", "https://www.4science.it/"), |
| 143 | + new RorMetadatum("dc.type", "Company"), |
| 144 | + new RorMetadatum("organization.address.addressCountry", "IT"), |
| 145 | + new RorMetadatum("organization.foundingDate", "2015") |
| 146 | + ) |
| 147 | + ); |
| 148 | + } |
| 149 | + |
| 150 | + private Map<String, String> getExtrasRecord2() { |
| 151 | + Map<String, String> extras = new HashMap<>(); |
| 152 | + extras.put("data-ror_orgunit_id", "https://ror.org/03vb2cr34"); |
| 153 | + extras.put("ror_orgunit_id", "https://ror.org/03vb2cr34"); |
| 154 | + extras.put("data-ror_orgunit_type", "Company"); |
| 155 | + extras.put("ror_orgunit_type", "Company"); |
| 156 | + extras.put("data-ror_orgunit_countryName", "Italia"); |
| 157 | + extras.put("ror_orgunit_countryName", "Italia"); |
| 158 | + extras.put("data-ror_orgunit_country", "IT"); |
| 159 | + return extras; |
| 160 | + } |
| 161 | + |
| 162 | + private final class RorMetadatum extends MetadatumDTO { |
| 163 | + public RorMetadatum(String field, String value) { |
| 164 | + String[] split = field.split("\\."); |
| 165 | + setSchema(split[0]); |
| 166 | + setElement(split[1]); |
| 167 | + if (split.length > 2) { |
| 168 | + setQualifier(split[2]); |
| 169 | + } |
| 170 | + setValue(value); |
| 171 | + } |
61 | 172 | } |
62 | 173 |
|
63 | 174 | } |
0 commit comments