1
|
package eu.dnetlib.grid.process.utils;
|
2
|
|
3
|
import static org.junit.Assert.assertEquals;
|
4
|
|
5
|
import java.io.FileInputStream;
|
6
|
import java.io.FileNotFoundException;
|
7
|
import java.io.InputStream;
|
8
|
import java.io.UnsupportedEncodingException;
|
9
|
import java.security.MessageDigest;
|
10
|
import java.security.NoSuchAlgorithmException;
|
11
|
import java.util.HashSet;
|
12
|
import java.util.Set;
|
13
|
import java.util.stream.Collectors;
|
14
|
|
15
|
import org.apache.commons.codec.binary.Hex;
|
16
|
import org.junit.Before;
|
17
|
import org.junit.Ignore;
|
18
|
import org.junit.Test;
|
19
|
|
20
|
import eu.dnetlib.grid.process.model.GridOrganization;
|
21
|
import eu.dnetlib.miscutils.functional.hash.Hashing;
|
22
|
|
23
|
@Ignore
|
24
|
public class GridUtilsTest {
|
25
|
|
26
|
@Before
|
27
|
public void setUp() throws Exception {}
|
28
|
|
29
|
@Test
|
30
|
@Ignore
|
31
|
public void test() throws FileNotFoundException {
|
32
|
// final InputStream is = getClass().getResourceAsStream("grid_example.json");
|
33
|
final InputStream is = new FileInputStream("/Users/michele/Desktop/grid.json");
|
34
|
int i = 0;
|
35
|
final Set<String> s = new HashSet<>();
|
36
|
for (final GridOrganization o : GridUtils.getOrganizations(is)) {
|
37
|
System.out.println(++i + " " + o.getId());
|
38
|
o.getAddresses().forEach(a -> s.add(a.getCountry_code()));
|
39
|
}
|
40
|
System.out.println(s.stream().collect(Collectors.joining(", ")));
|
41
|
|
42
|
}
|
43
|
|
44
|
@Test
|
45
|
@Ignore
|
46
|
public void testMd5() throws UnsupportedEncodingException, NoSuchAlgorithmException {
|
47
|
final String md5_1 = Hashing.md5("grid");
|
48
|
|
49
|
final MessageDigest md = MessageDigest.getInstance("MD5");
|
50
|
md.update("grid".getBytes("UTF-8"));
|
51
|
final String md5_2 = new String(Hex.encodeHex(md.digest()));
|
52
|
|
53
|
assertEquals(md5_1, md5_2);
|
54
|
}
|
55
|
|
56
|
}
|