test
This commit is contained in:
parent
4ca5f77fa0
commit
4cfd49c4f0
|
@ -404,4 +404,36 @@ public class SolrRecordMapper {
|
|||
private String calculateOpenaireId(final String originalId, final DatasourceEntry collectedFromEntry) {
|
||||
return collectedFromEntry.getPrefix() + "::" + DigestUtils.md5Hex(originalId);
|
||||
}
|
||||
|
||||
public DatasourceManagerClient getDsmClient() {
|
||||
return dsmClient;
|
||||
}
|
||||
|
||||
public void setDsmClient(final DatasourceManagerClient dsmClient) {
|
||||
this.dsmClient = dsmClient;
|
||||
}
|
||||
|
||||
public VocabularyClient getVocClient() {
|
||||
return vocClient;
|
||||
}
|
||||
|
||||
public void setVocClient(final VocabularyClient vocClient) {
|
||||
this.vocClient = vocClient;
|
||||
}
|
||||
|
||||
public CommunityClient getCommunityClient() {
|
||||
return communityClient;
|
||||
}
|
||||
|
||||
public void setCommunityClient(final CommunityClient communityClient) {
|
||||
this.communityClient = communityClient;
|
||||
}
|
||||
|
||||
public ProjectClient getProjectClient() {
|
||||
return projectClient;
|
||||
}
|
||||
|
||||
public void setProjectClient(final ProjectClient projectClient) {
|
||||
this.projectClient = projectClient;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
package eu.dnetlib.app.directindex.mapping;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
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;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import eu.dnetlib.app.directindex.clients.CommunityClient;
|
||||
import eu.dnetlib.app.directindex.clients.DatasourceManagerClient;
|
||||
import eu.dnetlib.app.directindex.clients.ProjectClient;
|
||||
import eu.dnetlib.app.directindex.clients.VocabularyClient;
|
||||
import eu.dnetlib.app.directindex.errors.DirectIndexApiException;
|
||||
import eu.dnetlib.app.directindex.input.DatasourceEntry;
|
||||
import eu.dnetlib.app.directindex.input.ResultEntry;
|
||||
import eu.dnetlib.dhp.schema.solr.SolrRecord;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class SolrRecordMapperTest {
|
||||
|
||||
// Class under test
|
||||
private SolrRecordMapper solrRecordMapper;
|
||||
|
||||
@Mock
|
||||
private CommunityClient communityClient;
|
||||
@Mock
|
||||
private DatasourceManagerClient dsmClient;
|
||||
@Mock
|
||||
private ProjectClient projectClient;
|
||||
@Mock
|
||||
private VocabularyClient vocClient;
|
||||
|
||||
private static final String COLLECTED_FROM_ID = "test_aggr_00::12344567890";
|
||||
private static final String HOSTED_BY_ID = "test_repo_01::12344567890";
|
||||
|
||||
@BeforeEach
|
||||
public void initEach() throws DirectIndexApiException {
|
||||
solrRecordMapper = new SolrRecordMapper();
|
||||
solrRecordMapper.setCommunityClient(communityClient);
|
||||
solrRecordMapper.setDsmClient(dsmClient);
|
||||
solrRecordMapper.setProjectClient(projectClient);
|
||||
solrRecordMapper.setVocClient(vocClient);
|
||||
|
||||
lenient().when(dsmClient.findDatasource(COLLECTED_FROM_ID)).thenReturn(new DatasourceEntry(COLLECTED_FROM_ID, "TEST AGGREGATOR", "test________"));
|
||||
lenient().when(dsmClient.findDatasource(HOSTED_BY_ID)).thenReturn(new DatasourceEntry(HOSTED_BY_ID, "TEST AGGREGATOR", "test________"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToSolrRecord() throws Exception {
|
||||
|
||||
final ResultEntry result = new ObjectMapper().readValue(getClass().getResourceAsStream("sample-result-01.json"), ResultEntry.class);
|
||||
|
||||
final SolrRecord solrRecord = solrRecordMapper.toSolrRecord(result);
|
||||
|
||||
System.out.println(new ObjectMapper().writeValueAsString(solrRecord));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToResultEntry() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCalculateOpenaireId() throws DirectIndexApiException {
|
||||
|
||||
final String openaireId = solrRecordMapper.calculateOpenaireId("record-oai-12345", COLLECTED_FROM_ID);
|
||||
|
||||
verify(dsmClient, times(1)).findDatasource(COLLECTED_FROM_ID);
|
||||
|
||||
assertEquals("test________::1c733a354f58e08710edef8fde95d800", openaireId);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
"originalId" : "record-oai-12345",
|
||||
"title": "Simple test record",
|
||||
"authors": [
|
||||
"Michele Artini",
|
||||
"Claudio Atzori",
|
||||
"Alessia Bardi"
|
||||
],
|
||||
"publisher": "ISTI CNR PUBLISHER",
|
||||
"description" : "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
|
||||
"language" : "eng",
|
||||
"pids": [
|
||||
{"type":"doi", "value":"12345/test"},
|
||||
{"type":"doi", "value":"23456/test"},
|
||||
{"type":"doi", "value":"67890/test"}
|
||||
],
|
||||
"accessRightCode": "OPEN",
|
||||
"embargoEndDate" : null,
|
||||
"type": "publication",
|
||||
"resourceType": "001",
|
||||
"url" : "http//cnr.it/test/record01.pdf",
|
||||
"collectedFromId" : "test_aggr_00::12344567890",
|
||||
"hostedById" : "test_repo_01::12344567890",
|
||||
"contexts": [
|
||||
"egi::projects::EMI",
|
||||
"egi::classification::natsc::math::pure"
|
||||
],
|
||||
"linksToProjects": [
|
||||
"info:eu-repo/grantAgreement/EC/FP7/283595/EU//OpenAIREplus"
|
||||
]
|
||||
|
||||
}
|
Loading…
Reference in New Issue