Project

General

Profile

« Previous | Next » 

Revision 47061

Added class for mapping of FWF (for the names of the principal investigators) and test class

View differences:

modules/dnet-openaireplus-mapping-utils/trunk/src/test/java/eu/dnetlib/data/transform/xml/FWDXsltFunctionsTest.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 java.util.List;
8

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

  
11
/**
12
 *
13
 * Created by miriam on 04/05/2017.
14
 */
15
public class FWDXsltFunctionsTest {
16
    private String namesurname ="Gerhard SOMMER";
17
    private String noSurname = "Gerhard";
18
    private String noName = "SOMMER";
19
    private String twoNames = "Gerhard Pippo SOMMER";
20
    private String twoSurname = "Gerhard PIPPO SOMMER";
21
    private String nonamesurname = "";
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
}
modules/dnet-openaireplus-mapping-utils/trunk/src/test/java/eu/dnetlib/data/transform/xml/OpenTrialsXsltFunctionsTest.java
9 9

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

  
12

  
12 13
/**
13 14
 * OpenTrialsXsltFunctions Tester.
14 15
 *
modules/dnet-openaireplus-mapping-utils/trunk/src/main/java/eu/dnetlib/data/transform/xml/FWFXsltFunctions.java
1
package eu.dnetlib.data.transform.xml;
2

  
3
/**
4
 * Created by miriam on 04/05/2017.
5
 */
6
public class FWFXsltFunctions {
7
    public static String getName(String name, boolean first){
8
        String[] split = name.split(" ");
9
        name ="";
10
        for (int i = 0; i< split.length; i++)
11
            if(!split[i].equals(split[i].toUpperCase())) {
12
                if (first)
13
                    name += split[i] + " ";
14
            }
15
            else{
16
                if(!first){
17
                    name += split[i] + " ";
18
                }
19
            }
20
        return name.trim();
21
    }
22
}

Also available in: Unified diff