Project

General

Profile

1
/**  '$RCSfile$'
2
 *  Copyright: 2010 Regents of the University of California and the
3
 *              National Center for Ecological Analysis and Synthesis
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 */
19
package edu.ucsb.nceas.metacat.annotation;
20

    
21
import java.util.Arrays;
22
import java.util.HashMap;
23
import java.util.List;
24
import java.util.Map;
25
import java.util.Map.Entry;
26

    
27
import junit.framework.Test;
28
import junit.framework.TestSuite;
29
import edu.ucsb.nceas.MCTestCase;
30

    
31
public class OrcidServiceTest extends MCTestCase {
32

    
33
	
34
	/**
35
	 * constructor for the test
36
	 */
37
	public OrcidServiceTest(String name) {
38
		super(name);
39
	}
40

    
41
	/**
42
	 * Establish a testing framework by initializing appropriate objects
43
	 */
44
	public void setUp() throws Exception {
45
		super.setUp();
46
	}
47

    
48
	/**
49
	 * Release any objects after tests are complete
50
	 */
51
	public void tearDown() {
52
	}
53

    
54
	/**
55
	 * Create a suite of tests to be run together
56
	 */
57
	public static Test suite() {
58
		TestSuite suite = new TestSuite();
59
		suite.addTest(new OrcidServiceTest("testLookup"));
60
		suite.addTest(new OrcidServiceTest("findMatches"));
61

    
62
		return suite;
63
	}
64
	
65
	public void testLookup() {
66
		List<String> otherNames = Arrays.asList("Matthew Bentley Jones");
67
		String orcid = OrcidService.lookupOrcid(null, null, null, otherNames);
68
		assertEquals("http://orcid.org/0000-0003-0077-4738", orcid);
69
	}
70
	
71
	public void findMatches() {
72
		
73
		int count = 0;
74
		Map<String, String> matches = new HashMap<String, String>();
75

    
76
		List<String> creators = OrcidService.lookupCreators(true);
77
		for (String creator: creators) {
78
			String orcid = OrcidService.lookupOrcid(null, null, null, Arrays.asList(creator));
79
			if (orcid != null) {
80
				matches.put(orcid, creator);
81
				count++;
82
			}
83
 		}
84
		assertTrue(count > 0);
85
		for (Entry<String, String> entry : matches.entrySet()) {
86
			System.out.println("Found ORCID: " + entry.getKey() + " for creator: " + entry.getValue());
87
		}
88
	}
89

    
90
}
(2-2/2)