1
|
package eu.dnetlib.openaire.directindex.api;
|
2
|
|
3
|
import java.util.ArrayList;
|
4
|
import java.util.Collection;
|
5
|
import java.util.List;
|
6
|
import java.util.Map;
|
7
|
import java.util.Map.Entry;
|
8
|
|
9
|
import com.google.common.collect.Lists;
|
10
|
import com.google.common.collect.Maps;
|
11
|
import org.junit.Assert;
|
12
|
import org.junit.Before;
|
13
|
import org.junit.Test;
|
14
|
|
15
|
import org.junit.runner.RunWith;
|
16
|
import org.mockito.runners.MockitoJUnitRunner;
|
17
|
|
18
|
import static org.mockito.Mockito.*;
|
19
|
|
20
|
/**
|
21
|
* Created by Alessia Bardi on 26/05/2017.
|
22
|
*
|
23
|
* @author Alessia Bardi
|
24
|
*/
|
25
|
@RunWith(MockitoJUnitRunner.class)
|
26
|
public class OpenAIRESubmitterUtilsTest {
|
27
|
|
28
|
private OpenAIRESubmitterUtils utils;
|
29
|
|
30
|
final String fullProject = "info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work/WorkAble";
|
31
|
final String minimalProject = "info:eu-repo/grantAgreement/EC/FP7/244909///WorkAble";
|
32
|
final String onlyId = "info:eu-repo/grantAgreement/EC/FP7/244909/";
|
33
|
final String onlyTitle = "info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work";
|
34
|
final String escapedId = "info:eu-repo/grantAgreement/RCUK//NE%2FL003066%2F1/";
|
35
|
|
36
|
|
37
|
@Before
|
38
|
public void setup(){
|
39
|
utils = mock(OpenAIRESubmitterUtils.class, withSettings().defaultAnswer(CALLS_REAL_METHODS));
|
40
|
doReturn(Lists.newArrayList("dh-ch", "dariah", "bar", "x")).when(utils).translateZenodoCommunity("https://zenodo.org/communities/dimpo");
|
41
|
doReturn(Lists.newArrayList()).when(utils).translateZenodoCommunity("https://zenodo.org/communities/dumbo");
|
42
|
|
43
|
}
|
44
|
|
45
|
@Test
|
46
|
public void testCalculateProjectInfoEscaped() {
|
47
|
final Map<String, String> project = utils.calculateProjectInfo(escapedId);
|
48
|
print(project);
|
49
|
Assert.assertEquals("NE/L003066/1", project.get("code"));
|
50
|
}
|
51
|
|
52
|
@Test
|
53
|
public void testCalculateProjectInfoFull() {
|
54
|
final Map<String, String> project = utils.calculateProjectInfo(fullProject);
|
55
|
print(project);
|
56
|
Assert.assertEquals(10, project.size());
|
57
|
for(String k : project.keySet()){
|
58
|
Assert.assertNotNull(project.get(k));
|
59
|
Assert.assertNotSame("", project.get(k));
|
60
|
}
|
61
|
}
|
62
|
|
63
|
@Test
|
64
|
public void testCalculateProjectInfoOnlyId() {
|
65
|
final Map<String, String> project = utils.calculateProjectInfo(onlyId);
|
66
|
print(project);
|
67
|
Assert.assertEquals("44909", project.get("code"));
|
68
|
}
|
69
|
|
70
|
@Test
|
71
|
public void testCalculateProjectInfoMinimalAcro() {
|
72
|
final Map<String, String> project = utils.calculateProjectInfo(minimalProject);
|
73
|
print(project);
|
74
|
Assert.assertEquals("44909", project.get("code"));
|
75
|
Assert.assertEquals("WorkAble", project.get("acronym"));
|
76
|
}
|
77
|
|
78
|
@Test
|
79
|
public void testCalculateProjectInfoOnlyTitle() {
|
80
|
final Map<String, String> project = utils.calculateProjectInfo(onlyTitle);
|
81
|
print(project);
|
82
|
Assert.assertEquals("44909", project.get("code"));
|
83
|
Assert.assertEquals("Making Capabilities Work", project.get("title"));
|
84
|
}
|
85
|
|
86
|
@Test
|
87
|
public void testJerusalem(){
|
88
|
String s = "info:eu-repo/grantAgreement/EC/FP7/337895/EU/Opening Jerusalem Archives: For a connected History of ‘Citadinité’ in the Holy City (1840-1940)/OPEN-JERUSALEM";
|
89
|
final Map<String, String> project = utils.calculateProjectInfo(s);
|
90
|
print(project);
|
91
|
Assert.assertEquals("337895", project.get("code"));
|
92
|
Assert.assertEquals("Opening Jerusalem Archives: For a connected History of ‘Citadinité’ in the Holy City (1840-1940)", project.get("title"));
|
93
|
Assert.assertEquals("OPEN-JERUSALEM", project.get("acronym"));
|
94
|
}
|
95
|
|
96
|
private void print(final Map<String, String> map) {
|
97
|
for (final Entry e : map.entrySet()) {
|
98
|
System.out.println(e.getKey() + " = " + e.getValue());
|
99
|
}
|
100
|
}
|
101
|
|
102
|
@Test
|
103
|
public void testContext(){
|
104
|
List<String> zenodoCommunities = new ArrayList<>();
|
105
|
zenodoCommunities.add("https://zenodo.org/communities/dimpo");
|
106
|
zenodoCommunities.add("https://zenodo.org/communities/dumbo");
|
107
|
Map<String, String> labelMap = Maps.newHashMap();
|
108
|
labelMap.put("dariah", "DARIAH" );
|
109
|
labelMap.put("dh-ch", "DH-CH" );
|
110
|
labelMap.put("foo", "FOO" );
|
111
|
labelMap.put("bar", "" );
|
112
|
|
113
|
List<OpenAIRESubmitterUtils.ContextInfo> tmp = utils.processContexts(zenodoCommunities, labelMap);
|
114
|
Assert.assertEquals(2, tmp.size());
|
115
|
|
116
|
Assert.assertTrue(tmp.get(0).getId().equals("dh-ch") || tmp.get(1).getId().equalsIgnoreCase("dh-ch"));
|
117
|
Assert.assertTrue(tmp.get(0).getId().equals("dariah") || tmp.get(1).getId().equalsIgnoreCase("dariah"));
|
118
|
}
|
119
|
|
120
|
}
|