From 04a0d1ba6e40d84234c1a8373fa0cb7f31ec529a Mon Sep 17 00:00:00 2001 From: "miriam.baglioni" Date: Fri, 9 Apr 2021 12:49:51 +0200 Subject: [PATCH] added test method to check the creation of relations between context and projects --- .../dump/complete/CreateRelationTest.java | 239 +++++++++--------- 1 file changed, 123 insertions(+), 116 deletions(-) diff --git a/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/dump/complete/CreateRelationTest.java b/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/dump/complete/CreateRelationTest.java index e7a6aa5db..572a51069 100644 --- a/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/dump/complete/CreateRelationTest.java +++ b/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/dump/complete/CreateRelationTest.java @@ -5,18 +5,18 @@ import java.util.*; import java.util.function.Consumer; import java.util.stream.Collectors; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import eu.dnetlib.dhp.schema.oaf.Project; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.Gson; import eu.dnetlib.dhp.schema.common.ModelSupport; import eu.dnetlib.dhp.schema.dump.oaf.graph.Relation; import eu.dnetlib.dhp.schema.oaf.Datasource; +import eu.dnetlib.dhp.schema.oaf.Project; import eu.dnetlib.dhp.utils.DHPUtils; public class CreateRelationTest { @@ -206,7 +206,7 @@ public class CreateRelationTest { " \n" + " oac_ni\n" + " 2018-03-01T12:00:00\n" + - " \n" + + " \n" + " \n" + " \n" + " re3data_____::5b9bf9171d92df854cf3c520692e9122\n" + @@ -442,55 +442,63 @@ public class CreateRelationTest { " oaa_elixir-gr\n" + " 2018-03-01T12:00:00\n" + " \n" + - " \n" + - " BIO-INFORMATICS RESEARCH NETWORK COORDINATING CENTER (BIRN-CC)\n" + - " \n" + - " 1U24RR025736-01\n" + - " NIH\n" + - " \n" + - " \n" + - " COLLABORATIVE RESEARCH: The Cognitive Neuroscience of Category Learning\n" + - " \n" + - " 0223843\n" + - " NSF\n" + - " \n" + - " \n" + - " The Cognitive Atlas: Developing an Interdisciplinary Knowledge Base Through Socia\n" + - " \n" + - " 5R01MH082795-05\n" + - " NIH\n" + - " \n" + - " \n" + - " Fragmented early life environmental and emotional / cognitive vulnerabilities\n" + - " \n" + - " 1P50MH096889-01A1\n" + - " NIH\n" + - " \n" + - " \n" + - " Enhancement of the 1000 Functional Connectome Project\n" + - " \n" + - " 1R03MH096321-01A1\n" + - " TUBITAK\n" + - " \n" + - " \n" + - " CRCNS Data Sharing: An open data repository for cognitive neuroscience: The OpenfMRI Project\n" + - " \n" + - " 1131441\n" + - " NSF\n" + - " \n" + - " \n" + - " Enhancing Human Cortical Plasticity: Visual Psychophysics and fMRI\n" + - " \n" + - " 0121950\n" + - " NSF\n" + - " \n" + - " \n" + - " Transforming statistical methodology for neuroimaging meta-analysis.\n" + - " \n" + - " 100309\n" + - " WT\n" + - " \n" + - " " + + " \n" + + " BIO-INFORMATICS RESEARCH NETWORK COORDINATING CENTER (BIRN-CC)\n" + + + " \n" + + " 1U24RR025736-01\n" + + " NIH\n" + + " \n" + + " \n" + + " COLLABORATIVE RESEARCH: The Cognitive Neuroscience of Category Learning\n" + + + " \n" + + " 0223843\n" + + " NSF\n" + + " \n" + + " \n" + + " The Cognitive Atlas: Developing an Interdisciplinary Knowledge Base Through Socia\n" + + + " \n" + + " 5R01MH082795-05\n" + + " NIH\n" + + " \n" + + " \n" + + " Fragmented early life environmental and emotional / cognitive vulnerabilities\n" + + + " \n" + + " 1P50MH096889-01A1\n" + + " NIH\n" + + " \n" + + " \n" + + " Enhancement of the 1000 Functional Connectome Project\n" + + + " \n" + + " 1R03MH096321-01A1\n" + + " TUBITAK\n" + + " \n" + + " \n" + + " CRCNS Data Sharing: An open data repository for cognitive neuroscience: The OpenfMRI Project\n" + + + " \n" + + " 1131441\n" + + " NSF\n" + + " \n" + + " \n" + + " Enhancing Human Cortical Plasticity: Visual Psychophysics and fMRI\n" + + + " \n" + + " 0121950\n" + + " NSF\n" + + " \n" + + " \n" + + " Transforming statistical methodology for neuroimaging meta-analysis.\n" + + + " \n" + + " 100309\n" + + " WT\n" + + " \n" + + " " + " \n" + @@ -627,88 +635,87 @@ public class CreateRelationTest { final Consumer consumer = ci -> cInfoList.add(ci); queryInformationSystem - .getContextRelation(consumer, "projects", ModelSupport.getIdPrefix(Project.class)); + .getContextRelation(consumer, "projects", ModelSupport.getIdPrefix(Project.class)); cInfoList.forEach(c -> System.out.println(new Gson().toJson(c))); - List rList = new ArrayList<>(); cInfoList.forEach(cInfo -> Process.getRelation(cInfo).forEach(rList::add)); - Assertions.assertEquals(44 , rList.size()); + Assertions.assertEquals(44, rList.size()); Assertions - .assertFalse( - rList - .stream() - .map(r -> r.getSource().getId()) - .collect(Collectors.toSet()) - .contains( - String - .format( - "%s|%s::%s", Constants.CONTEXT_ID, - Constants.CONTEXT_NS_PREFIX, - DHPUtils.md5("dh-ch")))); + .assertFalse( + rList + .stream() + .map(r -> r.getSource().getId()) + .collect(Collectors.toSet()) + .contains( + String + .format( + "%s|%s::%s", Constants.CONTEXT_ID, + Constants.CONTEXT_NS_PREFIX, + DHPUtils.md5("dh-ch")))); Assertions - .assertEquals( - 2, - rList - .stream() - .filter( - r -> r - .getSource() - .getId() - .equals( - String - .format( - "%s|%s::%s", Constants.CONTEXT_ID, - Constants.CONTEXT_NS_PREFIX, - DHPUtils.md5("clarin")))) - .collect(Collectors.toList()) - .size()); + .assertEquals( + 2, + rList + .stream() + .filter( + r -> r + .getSource() + .getId() + .equals( + String + .format( + "%s|%s::%s", Constants.CONTEXT_ID, + Constants.CONTEXT_NS_PREFIX, + DHPUtils.md5("clarin")))) + .collect(Collectors.toList()) + .size()); Assertions - .assertEquals( - 2, - rList - .stream() - .filter( - r -> r - .getTarget() - .getId() - .equals( - String - .format( - "%s|%s::%s", Constants.CONTEXT_ID, - Constants.CONTEXT_NS_PREFIX, - DHPUtils.md5("clarin")))) - .collect(Collectors.toList()) - .size()); + .assertEquals( + 2, + rList + .stream() + .filter( + r -> r + .getTarget() + .getId() + .equals( + String + .format( + "%s|%s::%s", Constants.CONTEXT_ID, + Constants.CONTEXT_NS_PREFIX, + DHPUtils.md5("clarin")))) + .collect(Collectors.toList()) + .size()); Set tmp = rList - .stream() - .filter( - r -> r - .getSource() - .getId() - .equals( - String - .format( - "%s|%s::%s", Constants.CONTEXT_ID, - Constants.CONTEXT_NS_PREFIX, - DHPUtils.md5("clarin")))) - .map(r -> r.getTarget().getId()) - .collect(Collectors.toSet()); + .stream() + .filter( + r -> r + .getSource() + .getId() + .equals( + String + .format( + "%s|%s::%s", Constants.CONTEXT_ID, + Constants.CONTEXT_NS_PREFIX, + DHPUtils.md5("clarin")))) + .map(r -> r.getTarget().getId()) + .collect(Collectors.toSet()); Assertions - .assertTrue( - tmp.contains("40|corda__h2020::b5a4eb56bf84bef2ebc193306b4d423f") && - tmp.contains("40|corda_______::ef782b2d85676aa3e5a907427feb18c4") ); + .assertTrue( + tmp.contains("40|corda__h2020::b5a4eb56bf84bef2ebc193306b4d423f") && + tmp.contains("40|corda_______::ef782b2d85676aa3e5a907427feb18c4")); rList.forEach(rel -> { - if (rel.getSource().getId().startsWith("40|")){ + if (rel.getSource().getId().startsWith("40|")) { String proj = rel.getSource().getId().substring(3); Assertions.assertTrue(proj.substring(0, proj.indexOf("::")).length() == 12); }