Refactor test to not use INSTANCE field of mappers

This commit is contained in:
Serafeim Chatzopoulos 2024-05-17 17:21:08 +03:00
parent e8e52684ad
commit 5e00c5668d
3 changed files with 6 additions and 12 deletions

View File

@ -1,13 +1,13 @@
package eu.openaire.api.mappers.response;
import eu.dnetlib.dhp.oa.model.Container;
import eu.dnetlib.dhp.oa.model.graph.*;
import eu.dnetlib.dhp.oa.model.graph.Datasource;
import eu.dnetlib.dhp.oa.model.graph.DatasourcePid;
import eu.dnetlib.dhp.oa.model.graph.DatasourceSchemeValue;
import eu.dnetlib.dhp.schema.solr.*;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;
import java.util.List;
import java.util.stream.Collectors;
@ -15,8 +15,6 @@ import java.util.stream.Collectors;
@Mapper(componentModel = "spring")
public interface DatasourceMapper {
DatasourceMapper INSTANCE = Mappers.getMapper( DatasourceMapper.class );
@Mapping(target = "journal", expression = "java( mapJournal(payload.getDatasource().getJournal()) )")
@Mapping(target = "policies", expression = "java( mapPolicies(payload.getDatasource().getPolicies()) )")
@Mapping(target = "subjects", expression = "java( mapSubjects(payload.getDatasource().getSubjects()) )")

View File

@ -1,12 +1,11 @@
package eu.openaire.api.mappers.response;
import eu.dnetlib.dhp.oa.model.*;
import eu.dnetlib.dhp.oa.model.APC;
import eu.dnetlib.dhp.oa.model.AccessRight;
import eu.dnetlib.dhp.oa.model.OpenAccessRoute;
import eu.dnetlib.dhp.oa.model.*;
import eu.dnetlib.dhp.oa.model.graph.GraphResult;
import eu.dnetlib.dhp.schema.common.ModelConstants;
import eu.dnetlib.dhp.schema.solr.*;
import eu.dnetlib.dhp.schema.solr.Author;
import eu.dnetlib.dhp.schema.solr.BestAccessRight;
import eu.dnetlib.dhp.schema.solr.Country;
@ -14,10 +13,10 @@ import eu.dnetlib.dhp.schema.solr.Instance;
import eu.dnetlib.dhp.schema.solr.Language;
import eu.dnetlib.dhp.schema.solr.OpenAccessColor;
import eu.dnetlib.dhp.schema.solr.Subject;
import eu.dnetlib.dhp.schema.solr.*;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;
import java.util.List;
import java.util.stream.Collectors;
@ -25,8 +24,6 @@ import java.util.stream.Collectors;
@Mapper(componentModel = "spring")
public interface ResultMapper {
ResultMapper INSTANCE = Mappers.getMapper( ResultMapper.class );
//@Mapping(target = "indicators", expression = "java (mapAuthor(payload.getResult().getIndicators()))") missing in the payload
@Mapping(target = "bestAccessRight", expression = "java(mapBestAccessRight(payload.getResult().getBestaccessright()))")
@Mapping(target = "instance", expression = "java(mapInstances(payload.getResult().getInstance()))")

View File

@ -4,7 +4,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.dhp.oa.model.Author;
import eu.dnetlib.dhp.oa.model.Instance;
import eu.dnetlib.dhp.oa.model.graph.GraphResult;
import eu.dnetlib.dhp.schema.solr.SolrRecord;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
@ -17,7 +16,6 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {ResultMapper.class})
@ -31,8 +29,9 @@ public class ResultMapperTest {
.getResourceAsStream(
"/eu/openaire/api/mappers/response/SolrResult.json"))), SolrRecord.class);
var resultMapper = new ResultMapperImpl();
GraphResult graphResult = ResultMapper.INSTANCE.toGraphResult(solrRecord);
GraphResult graphResult = resultMapper.toGraphResult(solrRecord);
Assertions.assertEquals("CSC_________::207f2db8a5174e57db3715909a2ffa76", graphResult.getId());
Assertions.assertEquals(2, graphResult.getOriginalId().size());