1
|
package eu.dnetlib.download.plugin;
|
2
|
|
3
|
import org.apache.commons.io.IOUtils;
|
4
|
import org.apache.commons.lang3.StringUtils;
|
5
|
import org.apache.commons.logging.Log;
|
6
|
import org.apache.commons.logging.LogFactory;
|
7
|
import org.junit.After;
|
8
|
import org.junit.Assert;
|
9
|
import org.junit.Before;
|
10
|
import org.junit.Test;
|
11
|
import org.junit.rules.TemporaryFolder;
|
12
|
|
13
|
import java.io.File;
|
14
|
import java.io.IOException;
|
15
|
import java.util.Arrays;
|
16
|
|
17
|
public class PathRetreiverTest {
|
18
|
|
19
|
private static final Log log = LogFactory.getLog(PathRetreiverTest.class); // NOPMD by marko on 11/24/08 5:02 PM
|
20
|
|
21
|
private TemporaryFolder t = new TemporaryFolder();
|
22
|
|
23
|
private final PathRetreiver pt = new PathRetreiver();
|
24
|
|
25
|
@Before
|
26
|
public void setUp() throws IOException {
|
27
|
t.create();
|
28
|
|
29
|
IOUtils.readLines(getClass().getResourceAsStream("pmc_dirs.txt")).forEach(t::newFolder);
|
30
|
for(final File dir : t.getRoot().listFiles(pathname -> pathname.isDirectory())) {
|
31
|
int lower = Integer.parseInt(StringUtils.substringBefore(dir.getName(), "_").replaceAll("PMC", ""));
|
32
|
int upper = Integer.parseInt(StringUtils.substringAfter(dir.getName(), "_").replaceAll("PMC", ""));
|
33
|
|
34
|
for(int i=lower;i<lower+3 && i<upper;i++) {
|
35
|
t.newFile(dir.getName() + "/" + i + ".xml");
|
36
|
}
|
37
|
for(int i=upper;i>upper-3 && i>lower;i--) {
|
38
|
t.newFile(dir.getName() + "/" + i + ".xml");
|
39
|
}
|
40
|
}
|
41
|
|
42
|
pt.setBase_path(t.getRoot().getPath());
|
43
|
}
|
44
|
|
45
|
|
46
|
@Test
|
47
|
public void testPathRetriever() {
|
48
|
|
49
|
String pathForPMCID = pt.getPathForPMCID(4676029);
|
50
|
Assert.assertNotNull(pathForPMCID);
|
51
|
log.info(pathForPMCID);
|
52
|
|
53
|
pathForPMCID = pt.getPathForPMCID(4676028);
|
54
|
Assert.assertNotNull(pathForPMCID);
|
55
|
log.info(pathForPMCID);
|
56
|
|
57
|
pathForPMCID = pt.getPathForPMCID(4676026);
|
58
|
Assert.assertNull(pathForPMCID);
|
59
|
}
|
60
|
|
61
|
@After
|
62
|
public void tearDown() {
|
63
|
t.delete();
|
64
|
}
|
65
|
}
|