[BipFinderInstanceLevel] added tests in test class

This commit is contained in:
Miriam Baglioni 2022-01-12 17:25:04 +01:00
parent 4993666d73
commit e7d5a39c03
2 changed files with 66 additions and 6 deletions

View File

@ -11,7 +11,6 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import eu.dnetlib.dhp.schema.oaf.utils.CleaningFunctions;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.spark.SparkConf; import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD; import org.apache.spark.api.java.JavaRDD;
@ -34,6 +33,7 @@ import eu.dnetlib.dhp.schema.oaf.Instance;
import eu.dnetlib.dhp.schema.oaf.KeyValue; import eu.dnetlib.dhp.schema.oaf.KeyValue;
import eu.dnetlib.dhp.schema.oaf.Measure; import eu.dnetlib.dhp.schema.oaf.Measure;
import eu.dnetlib.dhp.schema.oaf.Result; import eu.dnetlib.dhp.schema.oaf.Result;
import eu.dnetlib.dhp.schema.oaf.utils.CleaningFunctions;
import eu.dnetlib.dhp.schema.oaf.utils.OafMapperUtils; import eu.dnetlib.dhp.schema.oaf.utils.OafMapperUtils;
import eu.dnetlib.dhp.utils.DHPUtils; import eu.dnetlib.dhp.utils.DHPUtils;
@ -102,12 +102,33 @@ public class PrepareBipFinder implements Serializable {
Instance inst = new Instance(); Instance inst = new Instance();
inst.setMeasures(getMeasure(v)); inst.setMeasures(getMeasure(v));
inst.setPid(Arrays.asList(OafMapperUtils.structuredProperty(cleanedPid, inst
OafMapperUtils.qualifier(DOI, DOI_CLASSNAME, .setPid(
Arrays
.asList(
OafMapperUtils
.structuredProperty(
cleanedPid,
OafMapperUtils
.qualifier(
DOI, DOI_CLASSNAME,
ModelConstants.DNET_PID_TYPES, ModelConstants.DNET_PID_TYPES,
ModelConstants.DNET_PID_TYPES), null))); ModelConstants.DNET_PID_TYPES),
null)));
r.setInstance(Arrays.asList(inst)); r.setInstance(Arrays.asList(inst));
r.setDataInfo(OafMapperUtils.dataInfo(false,null,null,false, OafMapperUtils.qualifier(ModelConstants.PROVENANCE_ENRICH, null,ModelConstants.DNET_PROVENANCE_ACTIONS, ModelConstants.DNET_PROVENANCE_ACTIONS))); r
.setDataInfo(
OafMapperUtils
.dataInfo(
false, null, true,
false,
OafMapperUtils
.qualifier(
ModelConstants.PROVENANCE_ENRICH,
null,
ModelConstants.DNET_PROVENANCE_ACTIONS,
ModelConstants.DNET_PROVENANCE_ACTIONS),
null));
return r; return r;
}, Encoders.bean(Result.class)) }, Encoders.bean(Result.class))
.write() .write()

View File

@ -245,6 +245,45 @@ public class ProduceTest {
.get(0) .get(0)
.getValue()); .getValue());
Assertions.assertEquals("10.3390/s18072310",
tmp.filter(row -> row.getId().equals(doi)).collect()
.get(0)
.getInstance().get(0)
.getPid().get(0)
.getValue().toLowerCase());
Assertions.assertEquals("doi",
tmp.filter(row -> row.getId().equals(doi)).collect()
.get(0)
.getInstance().get(0)
.getPid().get(0)
.getQualifier().getClassid());
Assertions.assertEquals("Digital Object Identifier",
tmp.filter(row -> row.getId().equals(doi)).collect()
.get(0)
.getInstance().get(0)
.getPid().get(0)
.getQualifier().getClassname());
}
@Test
void produceTestMeasures() throws Exception {
final String doi = "unresolved::10.3390/s18072310::doi";
JavaRDD<Result> tmp = getResultJavaRDD();
List<StructuredProperty> mes = tmp
.filter(row -> row.getInstance() != null && row.getInstance().size() > 0)
.flatMap(row -> row.getInstance().iterator())
.flatMap(i -> i.getPid().iterator())
.collect();
Assertions.assertEquals(86, mes.size());
tmp.filter(row -> row.getInstance() != null && row.getInstance().size() > 0)
.foreach(e -> Assertions.assertEquals("sysimport:enrich", e.getDataInfo().getProvenanceaction().getClassid()));
} }
@Test @Test