1
|
package eu.dnetlib.parthenos.virtuoso;
|
2
|
|
3
|
import java.io.IOException;
|
4
|
|
5
|
import eu.dnetlib.parthenos.publisher.ParthenosPublisherException;
|
6
|
import eu.dnetlib.parthenos.publisher.SaxonHelper;
|
7
|
import eu.dnetlib.parthenos.rdf.RecordParserHelper;
|
8
|
import net.sf.saxon.s9api.SaxonApiException;
|
9
|
import org.apache.commons.io.IOUtils;
|
10
|
import org.apache.commons.logging.Log;
|
11
|
import org.apache.commons.logging.LogFactory;
|
12
|
import org.junit.Assert;
|
13
|
import org.junit.Before;
|
14
|
import org.junit.Ignore;
|
15
|
import org.junit.Test;
|
16
|
import org.junit.runner.RunWith;
|
17
|
import org.junit.runners.JUnit4;
|
18
|
import org.springframework.core.io.ClassPathResource;
|
19
|
import virtuoso.jena.driver.VirtModel;
|
20
|
|
21
|
/**
|
22
|
* Created by Alessia Bardi on 12/07/2017.
|
23
|
*
|
24
|
* @author Alessia Bardi
|
25
|
*/
|
26
|
@Ignore
|
27
|
@RunWith(JUnit4.class)
|
28
|
public class VirtuosoClientTest {
|
29
|
|
30
|
private static final Log log = LogFactory.getLog(VirtuosoClientTest.class);
|
31
|
|
32
|
private String testGraph = "virt:test";
|
33
|
//private String connectionString = "jdbc:virtuoso://localhost:1111";
|
34
|
private String connectionString = "jdbc:virtuoso://virtuoso.parthenos.d4science.org:1111";
|
35
|
private String testUser = "dba";
|
36
|
private String testPwd = "dba";
|
37
|
private String defaultURIBaseURl = "http://test/";
|
38
|
|
39
|
private String recordPath = "eu/dnetlib/parthenos/virtuoso/test_record_plain.xml";
|
40
|
|
41
|
private VirtuosoClient client;
|
42
|
|
43
|
private SaxonHelper saxonHelper = new SaxonHelper();
|
44
|
|
45
|
|
46
|
@Before
|
47
|
public void prepare() throws SaxonApiException {
|
48
|
RecordParserHelper rph = new RecordParserHelper();
|
49
|
rph.setSaxonHelper(saxonHelper);
|
50
|
rph.init();
|
51
|
client = new VirtuosoClient(connectionString, testUser, testPwd, rph, defaultURIBaseURl);
|
52
|
}
|
53
|
|
54
|
@Test
|
55
|
public void testConnection(){
|
56
|
VirtModel.openDatabaseModel("x", connectionString, testUser, testPwd);
|
57
|
}
|
58
|
|
59
|
|
60
|
|
61
|
@Test
|
62
|
public void testFeedProvenance(){
|
63
|
long res = client.feedProvenance("ariadne_____::0002b8b77eb2d6c62f61c6e1a1ce6891", "2017-05-14T12:06:38.152+02:00" , "2017-05-14T12:11:55.573", "ARIADNE", "ariadne_api");
|
64
|
Assert.assertEquals(3, res);
|
65
|
}
|
66
|
|
67
|
@Test
|
68
|
public void testRecord() throws ParthenosPublisherException {
|
69
|
System.out.println(client.feed(getString(recordPath)));
|
70
|
}
|
71
|
|
72
|
@Test
|
73
|
public void testRemoveFromProvenance(){
|
74
|
long res = client.feedProvenance("ariadne_____::0002b8b77eb2d6c62f61c6e1a1ce6891", "2017-05-14T12:06:38.152+02:00" , "2017-05-14T12:11:55.573", "ARIADNE", "ariadne_api");
|
75
|
Assert.assertEquals(3, res);
|
76
|
long deleted = client.drop("ariadne_api");
|
77
|
Assert.assertEquals(0, deleted);
|
78
|
}
|
79
|
|
80
|
private String getString(final String classpath) {
|
81
|
try {
|
82
|
final ClassPathResource resource = new ClassPathResource(classpath);
|
83
|
return IOUtils.toString(resource.getInputStream(), "UTF-8");
|
84
|
}catch(IOException e){
|
85
|
return null;
|
86
|
}
|
87
|
}
|
88
|
}
|