Project

General

Profile

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
	final String heProjectFromZenodo = "info:eu-repo/grantAgreement/EC/Horizon Europe Framework Programme - HORIZON-CSA\\HORIZON Action Grant Budget-Based/101058527/";
36
    final String chistera = "info:eu-repo/grantAgreement/CHIST-ERA//CHIST-ERA-19-XAI-002/";
37

    
38
	@Before
39
	public void setup(){
40
		utils = mock(OpenAIRESubmitterUtils.class, withSettings().defaultAnswer(CALLS_REAL_METHODS));
41
		doReturn(Lists.newArrayList("dh-ch", "dariah", "bar", "x")).when(utils).translateZenodoCommunity("https://zenodo.org/communities/dimpo");
42
		doReturn(Lists.newArrayList()).when(utils).translateZenodoCommunity("https://zenodo.org/communities/dumbo");
43

    
44
	}
45

    
46
	@Test
47
	public void testCalculateProjectInfoCHISTERA() {
48
		final Map<String, String> project = utils.calculateProjectInfo(chistera);
49
		print(project);
50
		Assert.assertEquals("CHIST-ERA-19-XAI-002", project.get("code"));
51
		Assert.assertEquals("chistera____::289ec73ce0e9ece89a0cbdf74c445cd8", project.get("id"));
52

    
53
	}
54

    
55
	@Test
56
	public void testCalculateProjectInfoZenodo() {
57
		final Map<String, String> project = utils.calculateProjectInfo(onlyId);
58
		print(project);
59
		Assert.assertEquals("244909", project.get("code"));
60

    
61
	}
62

    
63
	@Test
64
	public void testCalculateProjectInfoZenodoHE() {
65
		final Map<String, String> project = utils.calculateProjectInfo(heProjectFromZenodo);
66
		print(project);
67
		Assert.assertEquals("101058527", project.get("code"));
68
		Assert.assertEquals("corda_____he::eab43774d3762e87f5e66030c6e01d2b", project.get("id"));
69

    
70
	}
71

    
72
	@Test
73
	public void testCalculateProjectInfoEscaped() {
74
		final Map<String, String> project = utils.calculateProjectInfo(escapedId);
75
		print(project);
76
		Assert.assertEquals("NE/L003066/1", project.get("code"));
77
	}
78

    
79
	@Test
80
	public void testCalculateProjectInfoFull() {
81
		final Map<String, String> project = utils.calculateProjectInfo(fullProject);
82
		print(project);
83
		Assert.assertEquals(10, project.size());
84
		for(String k : project.keySet()){
85
			Assert.assertNotNull(project.get(k));
86
			Assert.assertNotSame("", project.get(k));
87
		}
88
	}
89

    
90
	@Test
91
	public void testCalculateProjectInfoOnlyId() {
92
		final Map<String, String> project = utils.calculateProjectInfo(onlyId);
93
		print(project);
94
		Assert.assertEquals("244909", project.get("code"));
95
	}
96

    
97
	@Test
98
	public void testCalculateProjectInfoMinimalAcro() {
99
		final Map<String, String> project = utils.calculateProjectInfo(minimalProject);
100
		print(project);
101
		Assert.assertEquals("244909", project.get("code"));
102
		Assert.assertEquals("WorkAble", project.get("acronym"));
103
	}
104

    
105
	@Test
106
	public void testCalculateProjectInfoOnlyTitle() {
107
		final Map<String, String> project = utils.calculateProjectInfo(onlyTitle);
108
		print(project);
109
		Assert.assertEquals("244909", project.get("code"));
110
		Assert.assertEquals("Making Capabilities Work", project.get("title"));
111
	}
112

    
113
	@Test
114
	public void testJerusalem(){
115
		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";
116
		final Map<String, String> project = utils.calculateProjectInfo(s);
117
		print(project);
118
		Assert.assertEquals("337895", project.get("code"));
119
		Assert.assertEquals("Opening Jerusalem Archives: For a connected History of ‘Citadinité’ in the Holy City (1840-1940)", project.get("title"));
120
		Assert.assertEquals("OPEN-JERUSALEM", project.get("acronym"));
121
	}
122

    
123
	private void print(final Map<String, String> map) {
124
		for (final Entry e : map.entrySet()) {
125
			System.out.println(e.getKey() + " = " + e.getValue());
126
		}
127
	}
128

    
129
	@Test
130
	public void testContext(){
131
		List<String> zenodoCommunities = new ArrayList<>();
132
		zenodoCommunities.add("https://zenodo.org/communities/dimpo");
133
		zenodoCommunities.add("https://zenodo.org/communities/dumbo");
134
		Map<String, String> labelMap = Maps.newHashMap();
135
		labelMap.put("dariah", "DARIAH" );
136
		labelMap.put("dh-ch", "DH-CH" );
137
		labelMap.put("foo", "FOO" );
138
		labelMap.put("bar", "" );
139

    
140
		List<OpenAIRESubmitterUtils.ContextInfo> tmp = utils.processContexts(zenodoCommunities, labelMap);
141
		Assert.assertEquals(2, tmp.size());
142

    
143
		Assert.assertTrue(tmp.get(0).getId().equals("dh-ch") || tmp.get(1).getId().equalsIgnoreCase("dh-ch"));
144
		Assert.assertTrue(tmp.get(0).getId().equals("dariah") || tmp.get(1).getId().equalsIgnoreCase("dariah"));
145
	}
146

    
147
	@Test
148
	public void testWrongH2020(){
149
		String link = "info:eu-repo/grantAgreement/EC/Horizon 2020 Framework Programme - Research and Innovation action/881825/";
150
		Map<String, String> info = utils.calculateProjectInfo(link);
151
		System.out.println(info);
152
		Assert.assertEquals("H2020", info.get("fundingName"));
153
	}
154

    
155
}
    (1-1/1)