1
1
package edu .harvard .iq .dataverse .api .imports ;
2
2
3
3
import edu .harvard .iq .dataverse .api .dto .DatasetDTO ;
4
+ import edu .harvard .iq .dataverse .api .dto .DatasetVersionDTO ;
5
+
6
+ import org .apache .commons .io .FileUtils ;
7
+ import com .google .gson .Gson ;
8
+ import java .io .File ;
9
+ import java .io .IOException ;
10
+
4
11
import org .junit .jupiter .api .Test ;
5
12
import org .junit .jupiter .api .extension .ExtendWith ;
6
13
import org .mockito .InjectMocks ;
7
14
import org .mockito .junit .jupiter .MockitoExtension ;
8
15
import static org .junit .jupiter .api .Assertions .assertEquals ;
9
16
import static org .junit .jupiter .api .Assertions .assertNull ;
10
17
18
+ import java .nio .charset .StandardCharsets ;
19
+
11
20
@ ExtendWith (MockitoExtension .class )
12
21
public class ImportGenericServiceBeanTest {
13
22
14
23
@ InjectMocks
15
24
private ImportGenericServiceBean importGenericService ;
16
25
17
26
@ Test
18
- public void testReassignIdentifierAsGlobalId () {
27
+ void testIdentifierHarvestableWithOtherID () throws IOException {
28
+ // "otherIdValue" containing the value : doi:10.7910/DVN/TJCLKP
29
+ File file = new File ("src/test/resources/json/importGenericWithOtherId.json" );
30
+ String text = FileUtils .readFileToString (file , StandardCharsets .UTF_8 );
31
+ DatasetVersionDTO dto = new Gson ().fromJson (text , DatasetVersionDTO .class );
32
+
33
+ assertEquals ("doi:10.7910/DVN/TJCLKP" , importGenericService .selectIdentifier (dto , "https://doi.org/10.7910/DVN/TJCLKP" ));
34
+ // junk or null
35
+ assertEquals ("doi:10.7910/DVN/TJCLKP" , importGenericService .selectIdentifier (dto , "junk" ));
36
+ assertEquals ("doi:10.7910/DVN/TJCLKP" , importGenericService .selectIdentifier (dto , null ));
37
+ assertEquals ("doi:10.7910/DVN/TJCLKP" , importGenericService .selectIdentifier (dto , "http://www.example.com" ));
38
+ assertEquals ("doi:10.7910/DVN/TJCLKP" , importGenericService .selectIdentifier (dto , "https://dataverse.org" ));
39
+ }
40
+
41
+ @ Test
42
+ void testIdentifierHarvestableWithoutOtherID () throws IOException {
43
+ // Does not contain data of type "otherIdValue"
44
+ File file = new File ("src/test/resources/json/importGenericWithoutOtherId.json" );
45
+ String text = FileUtils .readFileToString (file , StandardCharsets .UTF_8 );
46
+ DatasetVersionDTO dto = new Gson ().fromJson (text , DatasetVersionDTO .class );
47
+
48
+ // non-URL
49
+ assertEquals ("doi:10.7910/DVN/TJCLKP" , importGenericService .selectIdentifier (dto , "doi:10.7910/DVN/TJCLKP" ));
50
+ assertEquals ("hdl:10.7910/DVN/TJCLKP" , importGenericService .selectIdentifier (dto , "hdl:10.7910/DVN/TJCLKP" ));
51
+ // HTTPS
52
+ assertEquals ("https://doi.org/10.7910/DVN/TJCLKP" , importGenericService .selectIdentifier (dto , "https://doi.org/10.7910/DVN/TJCLKP" ));
53
+ assertEquals ("https://dx.doi.org/10.7910/DVN/TJCLKP" , importGenericService .selectIdentifier (dto , "https://dx.doi.org/10.7910/DVN/TJCLKP" ));
54
+ assertEquals ("https://hdl.handle.net/10.7910/DVN/TJCLKP" , importGenericService .selectIdentifier (dto , "https://hdl.handle.net/10.7910/DVN/TJCLKP" ));
55
+ // HTTP (no S)
56
+ assertEquals ("http://doi.org/10.7910/DVN/TJCLKP" , importGenericService .selectIdentifier (dto , "http://doi.org/10.7910/DVN/TJCLKP" ));
57
+ assertEquals ("http://dx.doi.org/10.7910/DVN/TJCLKP" , importGenericService .selectIdentifier (dto , "http://dx.doi.org/10.7910/DVN/TJCLKP" ));
58
+ assertEquals ("http://hdl.handle.net/10.7910/DVN/TJCLKP" , importGenericService .selectIdentifier (dto , "http://hdl.handle.net/10.7910/DVN/TJCLKP" ));
59
+ // junk or null
60
+ assertNull (importGenericService .selectIdentifier (dto , "junk" ));
61
+ assertNull (importGenericService .selectIdentifier (dto , null ));
62
+ assertNull (importGenericService .selectIdentifier (dto , "http://www.example.com" ));
63
+ assertNull (importGenericService .selectIdentifier (dto , "https://dataverse.org" ));
64
+ }
65
+
66
+ @ Test
67
+ void testReassignIdentifierAsGlobalId () {
19
68
// non-URL
20
69
assertEquals ("doi:10.7910/DVN/TJCLKP" , importGenericService .reassignIdentifierAsGlobalId ("doi:10.7910/DVN/TJCLKP" , new DatasetDTO ()));
21
70
assertEquals ("hdl:10.7910/DVN/TJCLKP" , importGenericService .reassignIdentifierAsGlobalId ("hdl:10.7910/DVN/TJCLKP" , new DatasetDTO ()));
@@ -29,6 +78,8 @@ public void testReassignIdentifierAsGlobalId() {
29
78
assertEquals ("hdl:10.7910/DVN/TJCLKP" , importGenericService .reassignIdentifierAsGlobalId ("http://hdl.handle.net/10.7910/DVN/TJCLKP" , new DatasetDTO ()));
30
79
// junk
31
80
assertNull (importGenericService .reassignIdentifierAsGlobalId ("junk" , new DatasetDTO ()));
81
+ assertNull (importGenericService .reassignIdentifierAsGlobalId ("http://www.example.com" , new DatasetDTO ()));
82
+ assertNull (importGenericService .reassignIdentifierAsGlobalId ("https://dataverse.org" , new DatasetDTO ()));
32
83
}
33
84
34
85
}
0 commit comments