Project

General

Profile

« Previous | Next » 

Revision 52537

Creating branch for production mapping-utils: we need to exclude version from 6.2.4 until we want to apply the specific mapping by specific types

View differences:

modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/deploy.info
1
{"type_source": "SVN", "goal": "package -U source:jar", 
2
"url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet45/modules/dnet-openaireplus-mapping-utils/trunk/", "deploy_repository": "dnet45-snapshots", "version": "4", "mail": "sandro.labruzzo@isti.cnr.it,michele.artini@isti.cnr.it, claudio.atzori@isti.cnr.it, alessia.bardi@isti.cnr.it", "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-snapshots", "name": "dnet-openaireplus-mapping-utils"}
modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/src/test/java/eu/dnetlib/openaire/exporter/model/ProjectTest.java
1
package eu.dnetlib.openaire.exporter.model;
2

  
3
import org.junit.Before;
4
import org.junit.Test;
5

  
6
import static org.junit.Assert.assertEquals;
7

  
8
public class ProjectTest {
9

  
10
	Project pMZOS;
11
	Project pFP7;
12

  
13
	@Before
14
	public void setUp() throws Exception {
15
		pMZOS = new Project()
16
				.setFunder("MZOS")
17
				.setJurisdiction("HR")
18
				.setFundingpathid("irb_hr______::MZOS")
19
				.setAcronym("")
20
				.setTitle("Project Title")
21
				.setCode("115-1152437-2500")
22
				.setStartdate("2007-01-01")
23
				.setEnddate("2009-01-01");
24

  
25
		pFP7 = new Project()
26
				.setFunder("EC")
27
				.setJurisdiction("EU")
28
				.setFundingpathid("ec__________::EC::FP7::SP1::NMP")
29
				.setAcronym("REFFIBRE")
30
				.setTitle("Project Title")
31
				.setCode("604187")
32
				.setStartdate("2013-11-01")
33
				.setEnddate("20015-01-01");
34
	}
35

  
36
	@Test
37
	public void testIdNamespaceMZOS(){
38
		String ns = pMZOS.getIdnamespace();
39
		assertEquals("info:eu-repo/grantAgreement/MZOS//115-1152437-2500/HR", ns);
40
	}
41

  
42
	@Test
43
	public void testIdNamespaceFP7(){
44
		String ns = pFP7.getIdnamespace();
45
		assertEquals("info:eu-repo/grantAgreement/EC/FP7/604187/EU", ns);
46
	}
47

  
48

  
49

  
50
}
modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/src/test/java/eu/dnetlib/openaire/exporter/model/ProjectDetailTest.java
1
package eu.dnetlib.openaire.exporter.model;
2

  
3
import java.io.IOException;
4
import java.io.StringReader;
5

  
6
import com.google.common.collect.Lists;
7
import org.apache.commons.io.IOUtils;
8
import org.springframework.core.io.ClassPathResource;
9
import org.springframework.core.io.Resource;
10

  
11
import static org.junit.Assert.assertEquals;
12

  
13
/**
14
 * Created by claudio on 22/09/16.
15
 */
16
public class ProjectDetailTest {
17

  
18
	private Resource projectsCsv = new ClassPathResource("/eu/dnetlib/openaire/exporter/model/projectDetails.csv");
19
	private Resource projectsJson = new ClassPathResource("/eu/dnetlib/openaire/exporter/model/projectDetails.json");
20

  
21
	//@Test
22
	public void testSerialisationCSV() throws IOException {
23
		final String csv = IOUtils.toString(projectsCsv.getInputStream());
24
		doTest(csv, "csv");
25
	}
26

  
27
	//@Test
28
	public void testSerialisationCSV2() throws IOException {
29
		final ProjectDetail p = new ProjectDetail()
30
				.setAcronym("acro")
31
				.setCode("01")
32
				.setOptional1("op1")
33
				.setOptional2("op2")
34
				.setProjectId("project_01")
35
				.setJsonextrainfo("extraInfo")
36
				.setFundingPath(Lists.newArrayList("fundingpath1", "fundingpath2"));
37

  
38
		doTest(p.asCSV(), "csv");
39
	}
40

  
41
	//@Test
42
	public void testSerialisationJSON() throws IOException {
43
		final String json = IOUtils.toString(projectsJson.getInputStream());
44
		doTest(json, "json");
45
	}
46

  
47
	private void doTest(final String data, final String format) throws IOException {
48
		final StringReader reader = new StringReader(data);
49
		for(String line : IOUtils.readLines(reader)) {
50
			System.out.println("line:          " + line);
51
			ProjectDetail p;
52
			String s = "";
53
			switch (format) {
54
			case "csv":
55
				p = ProjectDetail.fromCSV(line);
56
				s = p.asCSV();
57
				break;
58
			case "json":
59
				p = ProjectDetail.fromJson(line);
60
				s = p.asJson();
61
				break;
62
			default: throw new IllegalArgumentException("invalid format: " + format);
63
			}
64
			System.out.println("serialisation: " + s);
65
			assertEquals(s, line);
66
		}
67
	}
68

  
69
}
modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/src/test/java/eu/dnetlib/pace/clustering/BlacklistAwareClusteringCombinerTest.java
1
package eu.dnetlib.pace.clustering;
2

  
3
import org.junit.Before;
4
import org.junit.Test;
5

  
6
import eu.dnetlib.pace.AbstractProtoPaceTest;
7
import eu.dnetlib.pace.config.Config;
8
import eu.dnetlib.pace.config.Type;
9
import eu.dnetlib.pace.model.FieldListImpl;
10
import eu.dnetlib.pace.model.FieldValueImpl;
11
import eu.dnetlib.pace.model.MapDocument;
12

  
13
public class BlacklistAwareClusteringCombinerTest extends AbstractProtoPaceTest {
14

  
15
	private Config config;
16

  
17
	@Before
18
	public void setUp() {
19
		config = getResultFullConf();
20
	}
21

  
22
	@Test
23
	public void testCombine() {
24
		final MapDocument result =
25
				result(config, "A", "Dipping in Cygnus X-2 in a multi-wavelength campaign due to absorption of extended ADC emission", "2013");
26
		final FieldListImpl fl = new FieldListImpl();
27
		fl.add(new FieldValueImpl(Type.String, "desc", "hello world description pipeline"));
28

  
29
		result.getFieldMap().put("desc", fl);
30

  
31
		fl.clear();
32
		fl.add(new FieldValueImpl(Type.String, "title", "lorem ipsum cabalie qwerty"));
33
		final FieldListImpl field = (FieldListImpl) result.getFieldMap().get("title");
34
		field.add(fl);
35

  
36
		System.out.println(BlacklistAwareClusteringCombiner.filterAndCombine(result, config, config.blacklists()));
37
	}
38
}
modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/src/test/java/eu/dnetlib/pace/clustering/ClusteringCombinerTest.java
1
package eu.dnetlib.pace.clustering;
2

  
3
import org.junit.Before;
4
import org.junit.Test;
5

  
6
import eu.dnetlib.pace.AbstractProtoPaceTest;
7
import eu.dnetlib.pace.config.Config;
8
import eu.dnetlib.pace.config.Type;
9
import eu.dnetlib.pace.model.FieldListImpl;
10
import eu.dnetlib.pace.model.FieldValueImpl;
11
import eu.dnetlib.pace.model.MapDocument;
12

  
13
public class ClusteringCombinerTest extends AbstractProtoPaceTest {
14

  
15
	private Config config;
16

  
17
	@Before
18
	public void setUp() {
19
		config = getResultFullConf();
20
	}
21

  
22
	@Test
23
	public void testCombine() {
24
		String title = "Dipping in Cygnus X-2 in a multi-wavelength campaign due to absorption of extended ADC emission";
25
		MapDocument result = result(config, "A", title, "2013");
26

  
27
		FieldListImpl fl = new FieldListImpl();
28
		fl.add(new FieldValueImpl(Type.String, "desc", "lorem ipsum cabalie qwerty"));
29

  
30
		result.getFieldMap().put("desc", fl);
31
		System.out.println(title);
32
		System.out.println(ClusteringCombiner.combine(result, config));
33
	}
34

  
35
}
modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/src/test/java/eu/dnetlib/pace/AbstractProtoPaceTest.java
1
package eu.dnetlib.pace;
2

  
3
import java.io.IOException;
4
import java.io.StringWriter;
5
import java.util.ArrayList;
6
import java.util.LinkedList;
7
import java.util.List;
8
import java.util.stream.Collectors;
9
import java.util.stream.IntStream;
10

  
11
import com.google.common.collect.Lists;
12
import com.google.gson.Gson;
13
import eu.dnetlib.data.mapreduce.util.OafTest;
14
import eu.dnetlib.data.proto.FieldTypeProtos.Author;
15
import eu.dnetlib.data.proto.FieldTypeProtos.Qualifier;
16
import eu.dnetlib.data.proto.FieldTypeProtos.StructuredProperty;
17
import eu.dnetlib.data.proto.FieldTypeProtos.StructuredProperty.Builder;
18
import eu.dnetlib.data.proto.OafProtos.Oaf;
19
import eu.dnetlib.data.proto.OafProtos.OafEntity;
20
import eu.dnetlib.data.proto.OrganizationProtos.Organization;
21
import eu.dnetlib.data.proto.ResultProtos.Result;
22
import eu.dnetlib.pace.config.Config;
23
import eu.dnetlib.pace.config.DedupConfig;
24
import eu.dnetlib.pace.config.Type;
25
import eu.dnetlib.pace.model.Field;
26
import eu.dnetlib.pace.model.FieldValueImpl;
27
import eu.dnetlib.pace.model.MapDocument;
28
import eu.dnetlib.pace.model.ProtoDocumentBuilder;
29
import eu.dnetlib.pace.model.gt.GTAuthor;
30

  
31
import org.apache.commons.io.IOUtils;
32
import org.apache.commons.lang.RandomStringUtils;
33
import org.apache.commons.lang.StringUtils;
34

  
35
public abstract class AbstractProtoPaceTest extends OafTest {
36

  
37
	protected DedupConfig getResultFullConf() {
38
		return DedupConfig.load(readFromClasspath("/eu/dnetlib/pace/result.full.pace.conf"));
39
	}
40

  
41
	protected DedupConfig getResultSimpleConf() {
42
		return DedupConfig.load(readFromClasspath("/eu/dnetlib/pace/result.simple.pace.conf"));
43
	}
44

  
45
	protected DedupConfig getResultConf() {
46
		return DedupConfig.load(readFromClasspath("/eu/dnetlib/pace/result.pace.conf"));
47
	}
48

  
49
	protected DedupConfig getOrganizationSimpleConf() {
50
		return DedupConfig.load(readFromClasspath("/eu/dnetlib/pace/organization.pace.conf"));
51
	}
52

  
53
	protected DedupConfig getResultAuthorsConf() {
54
		return DedupConfig.load(readFromClasspath("/eu/dnetlib/pace/result.authors.pace.conf"));
55
	}
56

  
57
	protected DedupConfig getResultProdConf() {
58
		return DedupConfig.load(readFromClasspath("/eu/dnetlib/pace/result.prod.pace.conf"));
59
	}
60

  
61
	protected MapDocument author(final Config conf, final String id, final Oaf oaf) {
62
		return ProtoDocumentBuilder.newInstance(id, oaf.getEntity(), conf.model());
63
	}
64

  
65
	protected GTAuthor getGTAuthor(final String path) {
66

  
67
		final Gson gson = new Gson();
68

  
69
		final String json = readFromClasspath(path);
70

  
71
		final GTAuthor gta = gson.fromJson(json, GTAuthor.class);
72

  
73
		return gta;
74
	}
75

  
76
	private String readFromClasspath(final String filename) {
77
		final StringWriter sw = new StringWriter();
78
		try {
79
			IOUtils.copy(getClass().getResourceAsStream(filename), sw);
80
			return sw.toString();
81
		} catch (final IOException e) {
82
			throw new RuntimeException("cannot load resource from classpath: " + filename);
83
		}
84
	}
85

  
86
	protected MapDocument result(final Config config, final String id, final String title) {
87
		return result(config, id, title, null, new ArrayList<>(), null);
88
	}
89

  
90
	protected MapDocument result(final Config config, final String id, final String title, final String date) {
91
		return result(config, id, title, date, new ArrayList<>(), null);
92
	}
93

  
94
	protected MapDocument result(final Config config, final String id, final String title, final String date, final List<String> pid) {
95
		return result(config, id, title, date, pid, null);
96
	}
97

  
98
	protected MapDocument result(final Config config, final String id, final String title, final String date, final String pid) {
99
		return result(config, id, title, date, pid, null);
100
	}
101

  
102
	protected MapDocument result(final Config config, final String id, final String title, final String date, final String pid, final List<String> authors) {
103
		return result(config, id, title, date, Lists.newArrayList(pid), authors);
104
	}
105

  
106
	protected MapDocument result(final Config config, final String id, final String title, final String date, final List<String> pid, final List<String> authors) {
107
		final Result.Metadata.Builder metadata = Result.Metadata.newBuilder();
108
		if (!StringUtils.isBlank(title)) {
109
			metadata.addTitle(getStruct(title, getQualifier("main title", "dnet:titles")));
110
			metadata.addTitle(getStruct(RandomStringUtils.randomAlphabetic(10), getQualifier("alternative title", "dnet:titles")));
111
		}
112
		if (!StringUtils.isBlank(date)) {
113
			metadata.setDateofacceptance(sf(date));
114
		}
115

  
116
		final OafEntity.Builder entity = oafEntity(id, eu.dnetlib.data.proto.TypeProtos.Type.result);
117
		final Result.Builder result = Result.newBuilder().setMetadata(metadata);
118

  
119
		if (authors != null) {
120
			result.getMetadataBuilder().addAllAuthor(
121
					IntStream.range(0, authors.size())
122
							.mapToObj(i -> author(authors.get(i), i))
123
							.collect(Collectors.toCollection(LinkedList::new)));
124
		}
125

  
126
		entity.setResult(result);
127

  
128
		if (pid != null) {
129
			for(String p : pid) {
130
				if (!StringUtils.isBlank(p)) {
131
					entity.addPid(sp(p, "doi"));
132
					//entity.addPid(sp(RandomStringUtils.randomAlphabetic(10), "oai"));
133
				}
134
			}
135
		}
136

  
137
		final OafEntity build = entity.build();
138
		return ProtoDocumentBuilder.newInstance(id, build, config.model());
139
	}
140

  
141
	private Author author(final String s, int rank) {
142
		final eu.dnetlib.pace.model.Person p = new eu.dnetlib.pace.model.Person(s, false);
143
		final Author.Builder author = Author.newBuilder();
144
		if (p.isAccurate()) {
145
			author.setName(p.getNormalisedFirstName());
146
			author.setSurname(p.getNormalisedSurname());
147
		}
148
		author.setFullname(p.getNormalisedFullname());
149
		author.setRank(rank);
150

  
151
		return author.build();
152
	}
153

  
154
	private OafEntity.Builder oafEntity(final String id, final eu.dnetlib.data.proto.TypeProtos.Type type) {
155
		final OafEntity.Builder entity = OafEntity.newBuilder().setId(id).setType(type);
156
		return entity;
157
	}
158

  
159
	protected MapDocument organization(final Config config, final String id, final String legalName) {
160
		return organization(config, id, legalName, null);
161
	}
162

  
163
	protected MapDocument organization(final Config config, final String id, final String legalName, final String legalShortName) {
164
		final Organization.Metadata.Builder metadata = Organization.Metadata.newBuilder();
165
		if (legalName != null) {
166
			metadata.setLegalname(sf(legalName));
167
		}
168
		if (legalShortName != null) {
169
			metadata.setLegalshortname(sf(legalShortName));
170
		}
171

  
172
		final OafEntity.Builder entity = oafEntity(id, eu.dnetlib.data.proto.TypeProtos.Type.result);
173
		entity.setOrganization(Organization.newBuilder().setMetadata(metadata));
174

  
175
		return ProtoDocumentBuilder.newInstance(id, entity.build(), config.model());
176
	}
177

  
178
	private StructuredProperty sp(final String pid, final String type) {
179
		final Builder pidSp =
180
				StructuredProperty.newBuilder().setValue(pid)
181
						.setQualifier(Qualifier.newBuilder().setClassid(type).setClassname(type).setSchemeid("dnet:pid_types").setSchemename("dnet:pid_types"));
182
		return pidSp.build();
183
	}
184

  
185
	protected Field title(final String s) {
186
		return new FieldValueImpl(Type.String, "title", s);
187
	}
188

  
189
	protected static StructuredProperty.Builder getStruct(final String value, final Qualifier.Builder qualifier) {
190
		return StructuredProperty.newBuilder().setValue(value).setQualifier(qualifier);
191
	}
192

  
193
	/*
194
	 * protected static StringField.Builder sf(final String s) { return StringField.newBuilder().setValue(s); }
195
	 * 
196
	 * protected static Qualifier.Builder getQualifier(final String classname, final String schemename) { return
197
	 * Qualifier.newBuilder().setClassid(classname).setClassname(classname).setSchemeid(schemename).setSchemename(schemename); }
198
	 */
199

  
200
}
modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/src/test/java/eu/dnetlib/pace/model/ProtoDocumentBuilderTest.java
1
package eu.dnetlib.pace.model;
2

  
3
import com.google.common.collect.Iterables;
4
import com.google.common.collect.Sets;
5
import com.google.common.collect.Sets.SetView;
6
import eu.dnetlib.pace.AbstractProtoPaceTest;
7
import eu.dnetlib.pace.config.Config;
8
import org.junit.Test;
9

  
10
import static org.junit.Assert.assertFalse;
11
import static org.junit.Assert.assertTrue;
12

  
13
public class ProtoDocumentBuilderTest extends AbstractProtoPaceTest {
14

  
15
	@Test
16
	public void test_serialise1() {
17

  
18
		final String id = "12345";
19

  
20
		final Config config = getResultFullConf();
21

  
22
		final MapDocument document = ProtoDocumentBuilder.newInstance(id, getResult(id), config.model());
23

  
24
		assertFalse(document.fieldNames().isEmpty());
25
		assertFalse(Iterables.isEmpty(document.fields()));
26

  
27
		System.out.println("original:\n" + document);
28

  
29
		final String stringDoc = MapDocumentSerializer.toString(document);
30

  
31
		System.out.println("srialization:\n" + stringDoc);
32

  
33
		final MapDocument decoded = MapDocumentSerializer.decode(stringDoc.getBytes());
34

  
35
		final SetView<String> diff = Sets.difference(document.fieldNames(), decoded.fieldNames());
36

  
37
		assertTrue(diff.isEmpty());
38

  
39
		System.out.println("decoded:\n" + decoded);
40
	}
41

  
42
}
modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/src/test/java/eu/dnetlib/pace/model/gt/AuthorTest.java
1
package eu.dnetlib.pace.model.gt;
2

  
3
import static org.junit.Assert.assertTrue;
4

  
5
import java.util.Set;
6

  
7
import org.junit.Test;
8

  
9
import com.google.common.collect.Sets;
10

  
11
import eu.dnetlib.pace.model.gt.Author;
12
import eu.dnetlib.pace.model.gt.Authors;
13

  
14
public class AuthorTest {
15

  
16
	@Test
17
	public void test() {
18
		final Set<Author> s1 = getAuthors(3);
19
		final Set<Author> s2 = getAuthors(3);
20

  
21
		final Set<Author> i = Sets.intersection(s1, s2);
22

  
23
		System.out.println(i);
24

  
25
		assertTrue(i.size() == 3);
26

  
27
	}
28

  
29
	@Test
30
	public void test1() {
31
		final Authors a1 = new Authors(a("1", "Wang, M."));
32
		final Authors a2 = new Authors(a("1", "Wang, M."));
33

  
34
		final Set<Author> i = Sets.intersection(a1, a2);
35

  
36
		assertTrue(i.size() == 1);
37

  
38
	}
39

  
40
	private Set<Author> getAuthors(final int n) {
41
		final Set<Author> s = Sets.newHashSet();
42

  
43
		for (int i = 0; i < n; i++) {
44
			s.add(a(i + "", "name" + i));
45
		}
46
		return s;
47
	}
48

  
49
	private Author a(final String id, final String fullname) {
50
		final Author a = new Author();
51
		a.setId(id);
52
		a.setFullname(fullname);
53
		return a;
54
	}
55

  
56
}
modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/src/test/java/eu/dnetlib/pace/distance/DetectorTest.java
1
package eu.dnetlib.pace.distance;
2

  
3
import java.util.List;
4

  
5
import com.google.common.collect.Lists;
6
import eu.dnetlib.pace.AbstractProtoPaceTest;
7
import eu.dnetlib.pace.config.Config;
8
import eu.dnetlib.pace.distance.eval.ScoreResult;
9
import eu.dnetlib.pace.model.MapDocument;
10
import org.junit.Test;
11

  
12
import static org.junit.Assert.assertTrue;
13

  
14
public class DetectorTest extends AbstractProtoPaceTest {
15

  
16
	@Test
17
	public void testDistanceResultSimple() {
18
		final Config config = getResultSimpleConf();
19

  
20
		final MapDocument resA = result(config, "A", "Recent results from CDF");
21
		final MapDocument resB = result(config, "B", "Recent results from CDF");
22

  
23
		final ScoreResult sr = new PaceDocumentDistance().between(resA, resB, config);
24
		final double d = sr.getScore();
25
		System.out.println(String.format(" d ---> %s", d));
26

  
27
		assertTrue(d == 1.0);
28
	}
29

  
30
	@Test
31
	public void testDistanceResultSimpleMissingDates() {
32
		final Config config = getResultSimpleConf();
33

  
34
		final MapDocument resA = result(config, "A", "Recent results from BES");
35
		final MapDocument resB = result(config, "A", "Recent results from CES");
36

  
37
		final ScoreResult sr = new PaceDocumentDistance().between(resA, resB, config);
38
		final double d = sr.getScore();
39
		System.out.println(String.format(" d ---> %s", d));
40

  
41
		assertTrue(d > 0.97);
42
	}
43

  
44
	@Test
45
	public void testDistanceResultInvalidDate() {
46
		final Config config = getResultConf();
47

  
48
		final MapDocument resA = result(config, "A", "title title title 6BESR", "2013-01-05");
49
		final MapDocument resB = result(config, "B", "title title title 6BESR", "qwerty");
50

  
51
		final ScoreResult sr = new PaceDocumentDistance().between(resA, resB, config);
52
		final double d = sr.getScore();
53
		System.out.println(String.format(" d ---> %s", d));
54

  
55
		assertTrue(d == 1.0);
56
	}
57

  
58
	@Test
59
	public void testDistanceResultMissingOneDate() {
60
		final Config config = getResultConf();
61

  
62
		final MapDocument resA = result(config, "A", "title title title 6BESR", null);
63
		final MapDocument resB = result(config, "B", "title title title 6CLER", "2012-02");
64

  
65
		final ScoreResult sr = new PaceDocumentDistance().between(resA, resB, config);
66
		double d = sr.getScore();
67
		System.out.println(String.format(" d ---> %s", d));
68

  
69
		assertTrue((d > 0.9) && (d < 1.0));
70
	}
71

  
72
	@Test
73
	public void testDistanceResult() {
74
		final Config config = getResultConf();
75

  
76
		final MapDocument resA = result(config, "A", "title title title BES", "");
77
		final MapDocument resB = result(config, "B", "title title title CLEO");
78

  
79
		final ScoreResult sr = new PaceDocumentDistance().between(resA, resB, config);
80
		double d = sr.getScore();
81
		System.out.println(String.format(" d ---> %s", d));
82

  
83
		assertTrue((d > 0.9) && (d < 1.0));
84
	}
85

  
86
	@Test
87
	public void testDistanceResultMissingTwoDate() {
88
		final Config config = getResultConf();
89

  
90
		final MapDocument resA = result(config, "A", "title title title 6BESR");
91
		final MapDocument resB = result(config, "B", "title title title 6CLER");
92

  
93
		final ScoreResult sr = new PaceDocumentDistance().between(resA, resB, config);
94
		double d = sr.getScore();
95
		System.out.println(String.format(" d ---> %s", d));
96

  
97
		assertTrue((d > 0.9) && (d < 1.0));
98
	}
99

  
100
	@Test
101
	public void testDistanceOrganizationIgnoreMissing() {
102

  
103
		final Config config = getOrganizationSimpleConf();
104

  
105
		final MapDocument orgA = organization(config, "A", "CONSIGLIO NAZIONALE DELLE RICERCHE");
106
		final MapDocument orgB = organization(config, "B", "CONSIGLIO NAZIONALE DELLE RICERCHE", "CNR");
107

  
108
		final ScoreResult sr = new PaceDocumentDistance().between(orgA, orgB, config);
109
		final double d = sr.getScore();
110
		System.out.println(String.format(" d ---> %s", d));
111

  
112
		assertTrue(d == 1.0);
113
	}
114

  
115
	@Test
116
	public void testDistanceResultCase1() {
117

  
118
		final Config config = getResultConf();
119

  
120
		final MapDocument resA = result(config, "A", "Search the Standard Model Higgs boson", "2003");
121
		final MapDocument resB = result(config, "B", "Search for the Standard Model Higgs Boson", "2003");
122

  
123
		final ScoreResult sr = new PaceDocumentDistance().between(resA, resB, config);
124
		double d = sr.getScore();
125
		System.out.println(String.format(" d ---> %s", d));
126

  
127
		assertTrue((d > 0.9) && (d < 1.0));
128
	}
129

  
130
	@Test
131
	public void testDistanceResultCaseDoiMatch1() {
132
		final Config config = getResultConf();
133

  
134
		final MapDocument resA = result(config, "A", "Search the Standard Model Higgs boson", "2003", "10.1594/PANGAEA.726855");
135
		final MapDocument resB = result(config, "B", "Search the Standard Model Higgs Boson", "2003", "10.1594/PANGAEA.726855");
136

  
137
		final ScoreResult sr = new PaceDocumentDistance().between(resA, resB, config);
138
		double d = sr.getScore();
139
		System.out.println(String.format(" d ---> %s", d));
140

  
141
		assertTrue("exact DOIs will produce an exact match", d == 1.0);
142
	}
143

  
144
	@Test
145
	public void testDistanceResultCaseDoiMatch2() {
146
		final Config config = getResultConf();
147

  
148
		final MapDocument resA = result(config, "A", "Conference proceedings on X. Appendix", "2003", "10.1594/PANGAEA.726855");
149
		final MapDocument resB = result(config, "B", "Search the Standard Model Higgs Boson", "2005", "10.1594/PANGAEA.726855");
150

  
151
		final ScoreResult sr = new PaceDocumentDistance().between(resA, resB, config);
152
		double d = sr.getScore();
153
		System.out.println(String.format(" d ---> %s", d));
154

  
155
		assertTrue("exact DOIs will produce an exact match, regardless of different titles or publication years", d == 1.0);
156
	}
157

  
158
	@Test
159
	public void testDistanceResultCaseDoiMatch3() {
160
		final Config config = getResultConf();
161

  
162
		final MapDocument resA = result(config, "A", "Conference proceedings on X. Appendix", "2003", "10.1016/j.jmb.2010.12.024");
163
		final MapDocument resB = result(config, "B", "Conference proceedings on X. Appendix", "2003");
164

  
165
		final ScoreResult sr = new PaceDocumentDistance().between(resA, resB, config);
166
		double d = sr.getScore();
167
		System.out.println(String.format(" d ---> %s", d));
168

  
169
		assertTrue("a missing DOI will casue the comparsion to continue with the following conditions", d == 1.0);
170
	}
171

  
172
	@Test
173
	public void testDistanceResultCaseDoiMatch4() {
174
		final Config config = getResultConf();
175

  
176
		final MapDocument resA = result(config, "A", "Conference proceedings on X. Appendix", "2003", "10.1016/j.jmb.2010.12.024");
177
		final MapDocument resB = result(config, "B", "Conference proceedings on X. Appendix", "2005");
178

  
179
		final ScoreResult sr = new PaceDocumentDistance().between(resA, resB, config);
180
		double d = sr.getScore();
181
		System.out.println(String.format(" d ---> %s", d));
182

  
183
		assertTrue("a missing DOI, comparsion continues with the following conditions, different publication years will drop the score to 0", d == 0.0);
184
	}
185

  
186
	@Test
187
	public void testDistanceResultCaseDoiMatch5() {
188

  
189
		final Config config = getResultConf();
190

  
191
		final MapDocument resA = result(config, "A", "Search for the Standard Model Higgs Boson", "2003", "10.1016/j.jmb.2010.12.020");
192
		final MapDocument resB = result(config, "B", "Search the Standard Model Higgs Boson", "2003");
193

  
194
		final ScoreResult sr = new PaceDocumentDistance().between(resA, resB, config);
195
		double d = sr.getScore();
196
		System.out.println(String.format(" d ---> %s", d));
197

  
198
		assertTrue("a missing DOI, comparsion continues with the following conditions", (d > 0.9) && (d < 1.0));
199
	}
200

  
201
	@Test
202
	public void testDistanceResultCaseDoiMatch6() {
203
		final Config config = getResultConf();
204

  
205
		final MapDocument resA = result(config, "A", "Conference proceedings on X. Appendix", "2003", "10.1016/j.jmb.2010.12.024");
206
		final MapDocument resB = result(config, "B", "Conference proceedings on X. Appendix", "2003", "anotherDifferentDOI");
207

  
208
		final ScoreResult sr = new PaceDocumentDistance().between(resA, resB, config);
209
		double d = sr.getScore();
210
		System.out.println(String.format(" d ---> %s", d));
211

  
212
		assertTrue("different DOIs will NOT drop the score to 0, then evaluate other fields", d == 1.0);
213
	}
214

  
215
	@Test
216
	public void testDistanceResultCaseDoiMatch7() {
217
		final Config config = getResultConf();
218

  
219
		final MapDocument resA = result(config, "A", "Adrenal Insufficiency asd asd", "1951", Lists.newArrayList("PMC2037944", "axdsds"));
220
		final MapDocument resB = result(config, "B", "Adrenal Insufficiency", "1951", "PMC2037944");
221

  
222
		final ScoreResult sr = new PaceDocumentDistance().between(resA, resB, config);
223
		double d = sr.getScore();
224
		System.out.println(String.format(" d ---> %s", d));
225

  
226
		assertTrue("different DOIs will drop the score to 0, regardless of the other fields", d > 0.9 & d < 1);
227
	}
228

  
229
	// http://dx.doi.org/10.1594/PANGAEA.726855 doi:10.1594/PANGAEA.726855
230

  
231
	@Test
232
	public void testDistanceResultCaseAuthor1() {
233

  
234
		final Config config = getResultAuthorsConf();
235

  
236
		final List<String> authorsA = Lists.newArrayList("a", "b", "c", "d");
237
		final List<String> authorsB = Lists.newArrayList("a", "b", "c");
238
		final List<String> pid = Lists.newArrayList();
239

  
240
		final MapDocument resA = result(config, "A", "Search the Standard Model Higgs Boson", "2003", pid, authorsA);
241
		final MapDocument resB = result(config, "B", "Search the Standard Model Higgs Boson", "2003", pid, authorsB);
242

  
243
		final ScoreResult sr = new PaceDocumentDistance().between(resA, resB, config);
244
		final double d = sr.getScore();
245
		System.out.println(String.format(" d ---> %s", d));
246

  
247
		assertTrue(d == 0.0);
248
	}
249

  
250
	@Test
251
	public void testDistanceResultCaseAuthor2() {
252

  
253
		final Config config = getResultAuthorsConf();
254

  
255
		final List<String> authorsA = Lists.newArrayList("a", "b", "c");
256
		final List<String> authorsB = Lists.newArrayList("a", "b", "c");
257
		final List<String> pid = Lists.newArrayList();
258

  
259
		final MapDocument resA = result(config, "A", "Search the Standard Model Higgs Boson", "2003", pid, authorsA);
260
		final MapDocument resB = result(config, "B", "Search the Standard Model Higgs Boson", "2003", pid, authorsB);
261

  
262
		final ScoreResult sr = new PaceDocumentDistance().between(resA, resB, config);
263
		final double d = sr.getScore();
264
		System.out.println(String.format(" d ---> %s", d));
265

  
266
		assertTrue(d == 1.0);
267
	}
268

  
269
	@Test
270
	public void testDistanceResultCaseAuthor3() {
271

  
272
		final Config config = getResultAuthorsConf();
273

  
274
		final List<String> authorsA = Lists.newArrayList("Bardi, A.", "Manghi, P.", "Artini, M.");
275
		final List<String> authorsB = Lists.newArrayList("Bardi Alessia", "Manghi Paolo", "Artini Michele");
276
		final List<String> pid = Lists.newArrayList();
277

  
278
		final MapDocument resA = result(config, "A", "Search the Standard Model Higgs Boson", "2003", pid, authorsA);
279
		final MapDocument resB = result(config, "B", "Search the Standard Model Higgs Boson", "2003", pid, authorsB);
280

  
281
		final ScoreResult sr = new PaceDocumentDistance().between(resA, resB, config);
282
		double d = sr.getScore();
283
		System.out.println(String.format(" d ---> %s", d));
284

  
285
		assertTrue((d > 0.9) && (d < 1.0));
286
	}
287

  
288
	@Test
289
	public void testDistanceResultCaseAuthor4() {
290

  
291
		final Config config = getResultAuthorsConf();
292

  
293
		final List<String> authorsA = Lists.newArrayList("Bardi, Alessia", "Manghi, Paolo", "Artini, Michele", "a");
294
		final List<String> authorsB = Lists.newArrayList("Bardi Alessia", "Manghi Paolo", "Artini Michele");
295
		final List<String> pid = Lists.newArrayList();
296

  
297
		final MapDocument resA = result(config, "A", "Search the Standard Model Higgs Boson", "2003", pid, authorsA);
298
		final MapDocument resB = result(config, "B", "Search the Standard Model Higgs Boson", "2003", pid, authorsB);
299

  
300
		final ScoreResult sr = new PaceDocumentDistance().between(resA, resB, config);
301
		final double d = sr.getScore();
302
		System.out.println(String.format(" d ---> %s", d));
303

  
304
		// assertTrue(d.getScore() == 0.0);
305
	}
306

  
307
	@Test
308
	public void testDistanceResultFullConf() {
309

  
310
		final Config config = getResultFullConf();
311

  
312
		final List<String> authorsA = Lists.newArrayList("Nagarajan Pranesh", "Guy Vautier", "Punyanganie de Silva");
313
		final List<String> authorsB = Lists.newArrayList("Pranesh Nagarajan", "Vautier Guy", "de Silva Punyanganie");
314

  
315
		final MapDocument resA =
316
				result(config, "A", "Presentations of perforated colonic pathology in patients with polymyalgia rheumatica: two case reports", "2010",
317
						"10.1186/1752-1947-4-299", authorsA);
318

  
319
		final MapDocument resB =
320
				result(config, "B", "Presentations of perforated colonic pathology in patients with polymyalgia rheumatica: two case reports", "2010",
321
						"10.1186/1752-1947-4-299", authorsB);
322

  
323
		final ScoreResult sr = new PaceDocumentDistance().between(resA, resB, config);
324
		final double d = sr.getScore();
325
		System.out.println(String.format(" d ---> %s", d));
326

  
327
		// assertTrue(d.getScore() == 0.0);
328
	}
329
	
330
}
modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/src/test/java/eu/dnetlib/data/mapreduce/util/OafDecoderTest.java
1
package eu.dnetlib.data.mapreduce.util;
2

  
3
import static org.junit.Assert.assertFalse;
4
import static org.junit.Assert.assertNotNull;
5

  
6
import java.util.List;
7

  
8
import org.junit.Test;
9

  
10
import eu.dnetlib.data.proto.KindProtos.Kind;
11
import eu.dnetlib.miscutils.functional.xml.IndentXmlString;
12

  
13
public class OafDecoderTest {
14

  
15
	@Test
16
	public void testAsXml() {
17

  
18
		final OafDecoder decoder = OafTest.embed(OafTest.getResult("50|id_1"), Kind.entity);
19

  
20
		assertNotNull(decoder);
21

  
22
		assertNotNull(decoder.asXml());
23

  
24
		System.out.println(IndentXmlString.apply(decoder.asXml()));
25

  
26
	}
27

  
28
	@Test
29
	public void testGetFieldValues() {
30
		final OafDecoder decoder = OafTest.embed(OafTest.getResult("50|id_1"), Kind.entity);
31

  
32
		final String path = "result/metadata/title/value";
33
		final List<String> titles = decoder.decodeEntity().getFieldValues(path);
34

  
35
		assertNotNull(titles);
36
		assertFalse(titles.isEmpty());
37
	}
38
}
modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/src/test/java/eu/dnetlib/data/mapreduce/util/OafRowKeyDecoderTest.java
1
package eu.dnetlib.data.mapreduce.util;
2

  
3
import org.junit.Test;
4

  
5
public class OafRowKeyDecoderTest {
6

  
7
	@Test
8
	public void test() {
9

  
10
		String id1 = "50|acnbad______::0a454baf9c61e63d42fb83ab549f8062";
11

  
12
		OafRowKeyDecoder d = OafRowKeyDecoder.decode(id1);
13

  
14
		System.out.println(d.getId());
15
	}
16

  
17
}
modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/src/test/java/eu/dnetlib/data/mapreduce/util/OafRelDecoderTest.java
1
package eu.dnetlib.data.mapreduce.util;
2

  
3
import eu.dnetlib.data.proto.DedupProtos.Dedup.RelName;
4
import eu.dnetlib.data.proto.OafProtos.OafRel;
5
import eu.dnetlib.data.proto.RelTypeProtos.RelType;
6
import eu.dnetlib.data.proto.RelTypeProtos.SubRelType;
7
import org.junit.Before;
8
import org.junit.Test;
9

  
10
import static org.junit.Assert.assertEquals;
11
import static org.junit.Assert.assertNotNull;
12

  
13
public class OafRelDecoderTest {
14

  
15
	private OafRel oafRel;
16

  
17
	@Before
18
	public void setUp() {
19
		oafRel = OafTest.getDedupRel("ID_1", "ID_2", RelType.resultResult, "isMergedIn");
20
	}
21

  
22
	@Test
23
	public void testSetClass() {
24

  
25
		OafRelDecoder d1 = OafRelDecoder.decode(oafRel);
26

  
27
		assertNotNull(d1);
28
		assertEquals("isMergedIn", d1.getRelClass());
29

  
30
		OafRelDecoder d2 = OafRelDecoder.decode(d1.setClassId("isMergedIn").build());
31

  
32
		assertEquals("isMergedIn", d2.getRelClass());
33
		assertEquals("isMergedIn", d2.getRelMetadata().getSemantics().getClassid());
34
		assertEquals("isMergedIn", d2.getRelMetadata().getSemantics().getClassname());
35

  
36
	}
37

  
38
	@Test
39
	public void testGetCF() {
40
		assertEquals("resultResult_dedup_isMergedIn", OafRelDecoder.getCFQ(RelType.resultResult, SubRelType.dedup, RelName.isMergedIn));
41
		assertEquals("resultResult_dedup_isMergedIn", OafRelDecoder.getCFQ(RelType.resultResult, SubRelType.dedup, "isMergedIn"));
42
	}
43

  
44
}
modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/src/test/java/eu/dnetlib/data/transform/ParserToProtoIT.java
1
package eu.dnetlib.data.transform;
2

  
3
import java.io.IOException;
4
import java.io.InputStream;
5
import java.io.StringReader;
6
import java.util.List;
7
import java.util.Objects;
8
import java.util.Properties;
9
import java.util.concurrent.atomic.AtomicInteger;
10
import java.util.function.Function;
11
import java.util.stream.Collectors;
12
import java.util.stream.StreamSupport;
13

  
14
import com.google.protobuf.InvalidProtocolBufferException;
15
import com.mongodb.client.MongoCollection;
16
import com.mongodb.client.MongoDatabase;
17
import eu.dnetlib.data.proto.OafProtos.Oaf;
18
import eu.dnetlib.data.proto.OafProtos.OafEntity;
19
import eu.dnetlib.data.transform.xml2.DatasetToProto;
20
import eu.dnetlib.miscutils.collections.Pair;
21
import eu.dnetlib.miscutils.datetime.HumanTime;
22
import org.apache.commons.io.IOUtils;
23
import org.apache.commons.lang3.time.StopWatch;
24
import org.apache.commons.logging.Log;
25
import org.apache.commons.logging.LogFactory;
26
import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
27
import org.bson.Document;
28
import org.dom4j.DocumentException;
29
import org.dom4j.io.SAXReader;
30
import org.junit.Before;
31
import org.junit.Test;
32
import org.junit.runner.RunWith;
33
import org.springframework.beans.factory.annotation.Autowired;
34
import org.springframework.test.context.ContextConfiguration;
35
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
36

  
37
import static org.junit.Assert.assertFalse;
38
import static org.junit.Assert.assertNotNull;
39
import static org.junit.Assert.assertTrue;
40

  
41
@RunWith(SpringJUnit4ClassRunner.class)
42
@ContextConfiguration(classes = { ConfigurationTestConfig.class })
43
public class ParserToProtoIT {
44

  
45
	private static final Log log = LogFactory.getLog(ParserToProtoIT.class);
46

  
47
	private static final String DATACITE = "datacite";
48
	private static final String NARCIS = "narcis";
49

  
50
	private static final int BATCH_SIZE = 10000;
51
	private static final int LOG_FREQ = 5000;
52
	private static final int LIMIT = 10000;
53
	public static final String BODY = "body";
54

  
55
	private static String basePathProfiles = "/eu/dnetlib/test/profiles/TransformationRuleDSResources/TransformationRuleDSResourceType/";
56

  
57
	private int batchSize = BATCH_SIZE;
58
	private int logFreq = LOG_FREQ;
59
	private int limit = LIMIT;
60

  
61
	@Autowired
62
	private MongoDatabase db;
63

  
64
	@Autowired()
65
	private Properties testProperties;
66

  
67
	@Before
68
	public void setUp() {
69
		logFreq = Integer.valueOf(testProperties.getProperty("test.logFreq", String.valueOf(LOG_FREQ)));
70
		batchSize = Integer.valueOf(testProperties.getProperty("test.batchSize", String.valueOf(BATCH_SIZE)));
71
		limit = Integer.valueOf(testProperties.getProperty("test.limit", String.valueOf(limit)));
72
	}
73

  
74
	@Test
75
	public void testParseDataciteWithVTD() throws IOException {
76
		doTest(s -> new Pair<>(s, new DatasetToProto().apply(s)), DATACITE);
77
	}
78

  
79
	@Test
80
	public void testParseDataciteWithXSLT() throws IOException {
81
		final String xslt = IOUtils.toString(loadFromTransformationProfile("odf2hbase.xml"));
82
		final XsltRowTransformer transformer = XsltRowTransformerFactory.newInstance(xslt);
83

  
84
		doTest(rowToOaf(transformer), DATACITE);
85
	}
86

  
87
	@Test
88
	public void testParseNarcisWithXSLT() throws IOException {
89
		final String xslt = IOUtils.toString(loadFromTransformationProfile("oaf2hbase.xml"));
90
		final XsltRowTransformer transformer = XsltRowTransformerFactory.newInstance(xslt);
91

  
92
		doTest(rowToOaf(transformer), NARCIS);
93
	}
94

  
95
	//// HELPERS
96

  
97
	private void doTest(final Function<String, Pair<String, Oaf>> mapper, final String collectionName) {
98
		final MongoCollection<Document> collection = db.getCollection(collectionName);
99

  
100
		final long collectionSize = collection.count();
101
		log.info(String.format("found %s records in collection '%s'", collectionSize, collectionName));
102

  
103
		final AtomicInteger read = new AtomicInteger(0);
104
		final DescriptiveStatistics stats = new DescriptiveStatistics();
105

  
106
		final StopWatch recordTimer = new StopWatch();
107
		final StopWatch totalTimer = StopWatch.createStarted();
108

  
109
		StreamSupport.stream(collection.find().batchSize(batchSize).spliterator(), false)
110
				.limit(limit)
111
				.peek(d -> {
112
					if (read.addAndGet(1) % logFreq == 0) {
113
						log.info(String.format("records read so far %s", read.get()));
114
						//log.info(String.format("stats so far %s", stats.toString()));
115
					}
116
				})
117
				.map(d -> (String) d.get("body"))
118
				.filter(Objects::nonNull)
119
				.collect(Collectors.toList())   // load them in memory first
120
				.stream()
121
				.peek(s -> recordTimer.start())
122
				.map(mapper)
123
				.forEach(pair -> {
124
					recordTimer.stop();
125
					stats.addValue(recordTimer.getTime());
126
					recordTimer.reset();
127

  
128
					assertNotNull(pair);
129
					assertTrue(pair.getValue().hasEntity());
130

  
131
					try {
132
						final org.dom4j.Document doc = new SAXReader().read(new StringReader(pair.getKey()));
133
						final OafEntity entity = pair.getValue().getEntity();
134

  
135
						//TODO add more asserts
136
						assertTrue(entity.getId().contains(doc.valueOf("/*[local-name() = 'record']/*[local-name() = 'header']/*[local-name() = 'objIdentifier']/text()")));
137

  
138
					} catch (DocumentException e) {
139
						throw new IllegalArgumentException("unable to parse record " + pair.getKey(), e);
140
					}
141
				});
142

  
143
		totalTimer.stop();
144
		log.info(String.format("processed %s/%s records in %s", read.get(), collectionSize, HumanTime.exactly(totalTimer.getTime())));
145
		log.info(stats.toString());
146
	}
147

  
148
	private Function<String, Pair<String, Oaf>> rowToOaf(final XsltRowTransformer transformer) {
149
		return xml -> {
150
			final List<Row> rows = transformer.apply(xml);
151
			if (rows.isEmpty()) {
152
				return null;
153
			}
154

  
155
			return rows.stream()
156
					.filter(row -> row.getColumn(BODY) != null)
157
					.map(row -> row.getColumn(BODY))
158
					.map(c -> c.getValue())
159
					.map(b -> {
160
						try {
161
							return Oaf.parseFrom(b);
162
						} catch (InvalidProtocolBufferException e) {
163
							throw new IllegalStateException(e);
164
						}
165
					})
166
					.filter(Objects::nonNull)
167
					.map(oaf -> new Pair<>(xml, oaf))
168
					.findFirst()
169
					.get();
170
		};
171
	}
172

  
173
	private InputStream loadFromTransformationProfile(final String profilePath) {
174
		log.info("Loading xslt from: " + basePathProfiles + profilePath);
175
		InputStream profile = getClass().getResourceAsStream(basePathProfiles + profilePath);
176
		SAXReader saxReader = new SAXReader();
177
		org.dom4j.Document doc = null;
178
		try {
179
			doc = saxReader.read(profile);
180
		} catch (DocumentException e) {
181
			e.printStackTrace();
182
			throw new RuntimeException(e);
183
		}
184
		String xslt = doc.selectSingleNode("//SCRIPT/CODE/*[local-name()='stylesheet']").asXML();
185
		//log.info(xslt);
186
		return IOUtils.toInputStream(xslt);
187
	}
188

  
189

  
190
}
modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/src/test/java/eu/dnetlib/data/transform/xml/OpenTrialsXsltFunctionsTest.java
1
package eu.dnetlib.data.transform.xml;
2

  
3
import java.util.List;
4

  
5
import eu.dnetlib.data.transform.xml.OpenTrialsXsltFunctions.JsonProv;
6
import org.junit.After;
7
import org.junit.Before;
8
import org.junit.Test;
9

  
10
import static org.junit.Assert.assertEquals;
11

  
12

  
13
/**
14
 * OpenTrialsXsltFunctions Tester.
15
 *
16
 */
17
public class OpenTrialsXsltFunctionsTest {
18

  
19
	private String jsonProv = "[{\"url\" : \"http://apps.who.int/trialsearch/Trial3.aspx?trialid=NCT00378508\", \"sourceID\" : \"77eb42c5-0ec7-4e31-963a-5736b66f2d26\", \"sourceName\" : \"ictrp\"},{\"url\" : \"https://www.clinicaltrials.gov/ct2/show/NCT00378508?lup_e=02%2F04%2F2016&lup_s=01%2F01%2F2001&rank=175075&resultsxml=true\", \"sourceID\" : \"b389497c-0833-432b-a09b-930526b7b4d4\", \"sourceName\" : \"nct\"}]";
20
	private String jsonProvWithNull = "[{\"url\" : \"\", \"sourceID\" : \"77eb42c5-0ec7-4e31-963a-5736b66f2d26\", \"sourceName\" : \"ictrp\"},{\"url\" : \"https://www.clinicaltrials.gov/ct2/show/NCT00378508?lup_e=02%2F04%2F2016&lup_s=01%2F01%2F2001&rank=175075&resultsxml=true\", \"sourceID\" : \"b389497c-0833-432b-a09b-930526b7b4d4\", \"sourceName\" : \"nct\"}]";
21
	private String jidentifiers = "{112683,NCT00920439}";
22

  
23

  
24
	private String jsonRecord = "[{\"source_id\" : \"nct\", \"source_url\" : \"https://clinicaltrials.gov/ct2/show/NCT02321059\", \"is_primary\" : true},{\"source_id\" : \"ictrp\", \"source_url\" : \"http://apps.who.int/trialsearch/Trial3.aspx?trialid=NCT02321059\", \"is_primary\" : false}]";
25
	private String jsonRecordNull = "[{\"source_id\" : \"nct\", \"source_url\" : \"https://clinicaltrials.gov/ct2/show/NCT02321059\"},{\"source_id\" : \"ictrp\", \"source_url\" : \"http://apps.who.int/trialsearch/Trial3.aspx?trialid=NCT02321059\", \"is_primary\" : false}]";
26
	private String jsonRecordVoid = "[{\"source_id\" : \"\", \"source_url\" : \"\", \"is_primary\" : \"\"}]";
27
	private String jsonRecondPrimary = "[{\"source_id\" : \"nct\", \"source_url\" : \"https://clinicaltrials.gov/ct2/show/NCT02321059\", \"is_primary\" : false},{\"source_id\" : \"ictrp\", \"source_url\" : \"http://apps.who.int/trialsearch/Trial3.aspx?trialid=NCT02321059\", \"is_primary\" : false}]";
28

  
29
	private String jsonPeopleVoid ="[{\"person_name\" : null, \"person_id\" : null, \"person_role\" : null}]";
30
	private String jsonPeopleOne = "[{\"person_name\" : \"Henk Verheul, M.D., PhD\", \"person_id\" : \"116438e9-f8b1-46e5-a1f8-20f851cab73c\", \"person_role\" : \"principal_investigator\"}]";
31
	private String jsonPeopleMore = "[{\"person_name\" : \"Henk Verheul, M.D., PhD\", \"person_id\" : \"116438e9-f8b1-46e5-a1f8-20f851cab73c\", \"person_role\" : \"principal_investigator\"},{\"person_name\" : \"Miriam Pippolippo Baglioni, PhD\", \"person_id\" : \"fake\", \"person_role\" : \"principal_investigator\"}]";
32

  
33
	private String jsonOrganizationVoid = "[{\"organization_name\" : null, \"organization_id\" : null, \"organization_role\" : null}]";
34
	private String jsonOrganizationOne = "[{\"organization_name\" : \"Södertälje sjukhus AB\", \"organization_id\" : \"15f0d004-b82b-408c-8605-38a57352468d\", \"organization_role\" : \"sponsor\"}]";
35
	private String jsonOrganizationMore = "[{\"organization_name\" : \"Södertälje sjukhus AB\", \"organization_id\" : \"15f0d004-b82b-408c-8605-38a57352468d\", \"organization_role\" : \"sponsor\"},{\"organization_name\" : \"Miriam Baglioni AB\", \"organization_id\" : \"fake\", \"organization_role\" : \"primary_sponsor\"}]";
36

  
37
	private String jsonLocationVoid = "[{\"location_name\" : null}]";
38
	private String jsonLocationOne = "[{\"location_name\" : \"China\"}]";
39
	private String jsonLocationMore = "[{\"location_name\" : \"China\"},{\"location_name\" : \"North Korea\"}]";
40

  
41
	@Before
42
	public void before() throws Exception {
43
	}
44

  
45
	@After
46
	public void after() throws Exception {
47
	}
48

  
49
	/**
50
	 * Method: getProvs(String jsonProvList)
51
	 */
52
	@Test
53
	public void testGetProvs() throws Exception {
54
		List<JsonProv> list = OpenTrialsXsltFunctions.getProvs(jsonProv);
55
		assertEquals(2, list.size());
56
	}
57

  
58
	/**
59
	 * Method: getMainIdentifierURL(String jsonProvList)
60
	 */
61
	@Test
62
	public void testGetMainIdentifierURL() throws Exception {
63
		String url = OpenTrialsXsltFunctions.getMainIdentifierURL(jsonProv);
64
		assertEquals( "http://apps.who.int/trialsearch/Trial3.aspx?trialid=NCT00378508", url );
65
		url = OpenTrialsXsltFunctions.getMainIdentifierURL(jsonProvWithNull);
66
		assertEquals("https://www.clinicaltrials.gov/ct2/show/NCT00378508?lup_e=02%2F04%2F2016&lup_s=01%2F01%2F2001&rank=175075&resultsxml=true", url);
67
	}
68

  
69
	@Test
70
	public void testGetPrimaryRecordUrl(){
71
		String url = OpenTrialsXsltFunctions.getPrimaryRecordUrl(jsonRecord);
72
		assertEquals("https://clinicaltrials.gov/ct2/show/NCT02321059", url);
73
	}
74

  
75
	@Test
76
	public void testGetPrimaryRecordID(){
77
		String id = OpenTrialsXsltFunctions.getPrimaryRecordIdentifier(jsonRecord);
78
		assertEquals("nct", id);
79
	}
80

  
81
	@Test
82
	public void testGetPrimaryRecordUrlNull(){
83
		String url = OpenTrialsXsltFunctions.getPrimaryRecordUrl(jsonRecordNull);
84
		assertEquals("https://clinicaltrials.gov/ct2/show/NCT02321059", url);
85
	}
86

  
87
	@Test
88
	public void testGetPrimaryRecordUrlVoid(){
89
		String url = OpenTrialsXsltFunctions.getPrimaryRecordUrl(jsonRecordVoid);
90
		assertEquals("", url);
91
	}
92

  
93
	@Test
94
	public void testGetPrimaryRecordUrlNoPrimary(){
95
		String url = OpenTrialsXsltFunctions.getPrimaryRecordUrl(jsonRecondPrimary);
96
		assertEquals("https://clinicaltrials.gov/ct2/show/NCT02321059", url);
97
	}
98
	@Test
99
	public void testGetPrimaryRecordIDNoPrimary(){
100
		String id = OpenTrialsXsltFunctions.getPrimaryRecordIdentifier(jsonRecondPrimary);
101
		assertEquals("nct", id);
102
	}
103
	@Test
104
	public void testGetPrincipalInvestigatorsVoid(){
105
		String url = OpenTrialsXsltFunctions.getPrincipalInvestigators(jsonPeopleVoid);
106
		assertEquals("",url);
107
	}
108

  
109

  
110
	@Test
111
	public void testGetPrincipalInvestigatorsOne(){
112
		String url = OpenTrialsXsltFunctions.getPrincipalInvestigators(jsonPeopleOne);
113
		assertEquals("Verheul, Henk", url);
114
	}
115

  
116
	@Test
117
	public void testGetPrincipalInvestigatorsMore(){
118
		String url = OpenTrialsXsltFunctions.getPrincipalInvestigators(jsonPeopleMore);
119
		assertEquals("Verheul, Henk@@Baglioni, Miriam Pippolippo", url);
120
	}
121

  
122

  
123

  
124
	@Test
125
	public void testgGetTrialOrganizationsVoid(){
126
		String url = OpenTrialsXsltFunctions.getTrialOrganizations(jsonOrganizationVoid);
127
		assertEquals("",url);
128
	}
129

  
130

  
131
	@Test
132
	public void testgGetTrialOrganizationsOne(){
133
		String url = OpenTrialsXsltFunctions.getTrialOrganizations(jsonOrganizationOne);
134
		assertEquals("Södertälje sjukhus AB@sponsor", url);
135
	}
136

  
137
	@Test
138
	public void testgGetTrialOrganizationsMore(){
139
		String url = OpenTrialsXsltFunctions.getTrialOrganizations(jsonOrganizationMore);
140
		assertEquals("Södertälje sjukhus AB@sponsor@@Miriam Baglioni AB@sponsor", url);
141
	}
142

  
143
	@Test
144
	public void testgGetTrialLocationsVoid(){
145
		String url = OpenTrialsXsltFunctions.getTrialLocations(jsonLocationVoid);
146
		assertEquals("",url);
147
	}
148

  
149

  
150
	@Test
151
	public void testgGetTrialLocationsOne(){
152
		String url = OpenTrialsXsltFunctions.getTrialLocations(jsonLocationOne);
153
		assertEquals("China", url);
154
	}
155

  
156
	@Test
157
	public void testgGetTrialLocationsMore(){
158
		String url = OpenTrialsXsltFunctions.getTrialLocations(jsonLocationMore);
159
		assertEquals("China@@North Korea", url);
160
	}
161

  
162
	@Test
163
	public void testGetNotPrimaryRecordUrlPrimary(){
164
		String url = OpenTrialsXsltFunctions.getNotPrimaryRecordUrl(jsonRecondPrimary);
165
		assertEquals("http://apps.who.int/trialsearch/Trial3.aspx?trialid=NCT02321059", url);
166
	}
167

  
168
	@Test
169
	public void testGetNotPrimaryRecordUrlVoid(){
170
		String url = OpenTrialsXsltFunctions.getNotPrimaryRecordUrl(jsonRecordVoid);
171
		assertEquals("", url);
172
	}
173

  
174
	@Test
175
	public void testGetNotPrimaryRecordUrl(){
176
		String url = OpenTrialsXsltFunctions.getNotPrimaryRecordUrl(jsonRecord);
177
		assertEquals("http://apps.who.int/trialsearch/Trial3.aspx?trialid=NCT02321059", url);
178
	}
179

  
180

  
181
}
modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/src/test/java/eu/dnetlib/data/transform/xml/FWFXsltFunctionsTest.java
1
package eu.dnetlib.data.transform.xml;
2

  
3
import org.junit.After;
4
import org.junit.Before;
5
import org.junit.Test;
6

  
7
import static org.junit.Assert.assertEquals;
8
import static org.junit.Assert.assertNotNull;
9

  
10
/**
11
 *
12
 * Created by miriam on 04/05/2017.
13
 */
14
public class FWFXsltFunctionsTest {
15
	private String namesurname ="Gerhard SOMMER";
16
	private String noSurname = "Gerhard";
17
	private String noName = "SOMMER";
18
	private String twoNames = "Gerhard Pippo SOMMER";
19
	private String twoSurname = "Gerhard PIPPO SOMMER";
20
	private String nonamesurname = "";
21
	private String organization ="Universität Linz - Institut für Computational Perception; Universität für Musik und darstellende Kunst Graz - Institut 1: Komposition, Musiktheorie, Musikgeschichte und Dirigieren; Universität Mozarteum Salzburg - Institut für Musikalische Rezeptions- und Interpretationsgeschichte; Anton Bruckner Privatuniversität - Institut für Theorie und Geschichte der Musik; Eliette und Herbert von Karajan Institut - Eliette und Herbert von Karajan Institut";
22

  
23
	@Before
24
	public void before() throws Exception {
25
	}
26

  
27
	@After
28
	public void after() throws Exception {
29
	}
30

  
31
	@Test
32
	public void testGetNamesNameNoNameSurname() throws Exception {
33
		String ret = FWFXsltFunctions.getName(nonamesurname,true);
34
		assertEquals("",ret );
35
	}
36

  
37
	@Test
38
	public void testGetNamesSurnameNoNameSurname() throws Exception {
39
		String ret = FWFXsltFunctions.getName(nonamesurname,false);
40
		assertEquals("",ret );
41
	}
42

  
43
	@Test
44
	public void testGetNamesNameTwoSurname() throws Exception {
45
		String ret = FWFXsltFunctions.getName(twoSurname,true);
46
		assertEquals("Gerhard",ret );
47
	}
48

  
49
	@Test
50
	public void testGetNamesSurnameTwoSurname() throws Exception {
51
		String ret = FWFXsltFunctions.getName(twoSurname,false);
52
		assertEquals("PIPPO SOMMER",ret );
53
	}
54

  
55
	@Test
56
	public void testGetNamesNameTwoNames() throws Exception {
57
		String ret = FWFXsltFunctions.getName(twoNames,true);
58
		assertEquals("Gerhard Pippo",ret );
59
	}
60

  
61
	@Test
62
	public void testGetNamesSurnameTwoNames() throws Exception {
63
		String ret = FWFXsltFunctions.getName(twoNames,false);
64
		assertEquals("SOMMER",ret );
65
	}
66

  
67
	/**
68
	 * Method: getProvs(String jsonProvList)
69
	 */
70
	@Test
71
	public void testGetNamesName() throws Exception {
72
		String ret = FWFXsltFunctions.getName(namesurname,true);
73
		assertEquals("Gerhard",ret );
74
	}
75

  
76
	@Test
77
	public void testGetNamesSurname() throws Exception {
78
		String ret = FWFXsltFunctions.getName(namesurname,false);
79
		assertEquals("SOMMER",ret );
80
	}
81

  
82
	@Test
83
	public void testGetNamesNameNoSurname() throws Exception {
84
		String ret = FWFXsltFunctions.getName(noSurname,true);
85
		assertEquals("Gerhard",ret );
86
	}
87

  
88
	@Test
89
	public void testGetNamesSurnameNoSurname() throws Exception {
90
		String ret = FWFXsltFunctions.getName(noSurname,false);
91
		assertEquals("",ret );
92
	}
93

  
94
	@Test
95
	public void testGetNamesNameNoName() throws Exception {
96
		String ret = FWFXsltFunctions.getName(noName,true);
97
		assertEquals("",ret );
98
	}
99

  
100
	@Test
101
	public void testGetNamesSurnameNoName() throws Exception {
102
		String ret = FWFXsltFunctions.getName(noName,false);
103
		assertEquals("SOMMER",ret );
104
	}
105

  
106
	@Test
107
	public void TestGetMd5()throws Exception{
108
		String md5 = FWFXsltFunctions.getMd5(organization);
109
		System.out.println(md5);
110
		assertNotNull(md5);
111
	}
112

  
113
}
modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/src/test/java/eu/dnetlib/data/transform/xml2/VtdParserToProtoTest.java
1
package eu.dnetlib.data.transform.xml2;
2

  
3
import java.io.IOException;
4
import java.util.function.Function;
5

  
6
import eu.dnetlib.data.proto.OafProtos.Oaf;
7
import org.apache.commons.io.IOUtils;
8
import org.apache.commons.logging.Log;
9
import org.apache.commons.logging.LogFactory;
10
import org.junit.Test;
11

  
12
import static org.junit.Assert.assertNotNull;
13

  
14
public class VtdParserToProtoTest {
15

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff