2023-06-28 15:24:18 +02:00
|
|
|
package eu.dnetlib.openaire.community.importer;
|
|
|
|
|
2023-06-28 15:37:01 +02:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
2023-06-28 15:24:18 +02:00
|
|
|
import static org.junit.jupiter.api.Assertions.fail;
|
|
|
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.junit.jupiter.api.extension.ExtendWith;
|
|
|
|
import org.mockito.Mock;
|
|
|
|
import org.mockito.junit.jupiter.MockitoExtension;
|
|
|
|
|
2023-06-28 15:28:12 +02:00
|
|
|
import eu.dnetlib.openaire.community.CommunityService;
|
|
|
|
import eu.dnetlib.openaire.community.model.DbOrganization;
|
|
|
|
import eu.dnetlib.openaire.community.repository.DbOrganizationRepository;
|
2023-06-28 15:24:18 +02:00
|
|
|
|
|
|
|
@ExtendWith(MockitoExtension.class)
|
|
|
|
class CommunityImporterServiceTest {
|
|
|
|
|
|
|
|
// Class under test
|
|
|
|
private CommunityImporterService importer;
|
|
|
|
|
|
|
|
@Mock
|
|
|
|
private DbOrganizationRepository dbOrganizationRepository;
|
|
|
|
|
|
|
|
@Mock
|
|
|
|
private CommunityService service;
|
|
|
|
|
|
|
|
@BeforeEach
|
|
|
|
public void setUp() {
|
|
|
|
importer = new CommunityImporterService();
|
|
|
|
importer.setDbOrganizationRepository(dbOrganizationRepository);
|
|
|
|
importer.setService(service);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testImportPropagationOrganizationsFromProfile() throws Exception {
|
|
|
|
final String profile = IOUtils.toString(getClass().getResourceAsStream("old_provision_wf.xml"), StandardCharsets.UTF_8.toString());
|
|
|
|
final List<DbOrganization> list = importer.importPropagationOrganizationsFromProfile(profile, true);
|
2023-06-28 15:37:01 +02:00
|
|
|
// list.forEach(System.out::println);
|
|
|
|
|
|
|
|
assertEquals(245, list.size());
|
|
|
|
assertEquals(1, list.stream().filter(o -> o.getOrgId().equals("20|openorgs____::9dd5545aacd3d8019e00c3f837269746")).count());
|
|
|
|
assertEquals(2, list.stream().filter(o -> o.getOrgId().equals("20|openorgs____::d11f981828c485cd23d93f7f24f24db1")).count());
|
|
|
|
assertEquals(14, list.stream().filter(o -> o.getCommunity().equals("beopen")).count());
|
2023-06-28 15:24:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testImportCommunity() {
|
|
|
|
fail("Not yet implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|