Skip to content

Commit 76b9d02

Browse files
committed
Improved testing
1 parent c6a0b74 commit 76b9d02

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/org/linkeddatafragments/datasource/JenaTDBDataSource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.linkeddatafragments.datasource;
22

3+
import com.hp.hpl.jena.graph.Graph;
34
import com.hp.hpl.jena.graph.GraphStatisticsHandler;
45
import com.hp.hpl.jena.graph.Node;
56
import com.hp.hpl.jena.query.Dataset;
@@ -8,7 +9,6 @@
89
import com.hp.hpl.jena.query.QueryExecutionFactory;
910
import com.hp.hpl.jena.query.QueryFactory;
1011
import com.hp.hpl.jena.query.QuerySolutionMap;
11-
import com.hp.hpl.jena.query.ReadWrite;
1212
import com.hp.hpl.jena.query.Syntax;
1313
import com.hp.hpl.jena.rdf.model.Model;
1414
import com.hp.hpl.jena.rdf.model.ModelFactory;
@@ -49,7 +49,6 @@ public TriplePatternFragment getFragment(Resource subject, Property predicate, R
4949

5050
query.setOffset(offset);
5151
query.setLimit(limit);
52-
5352

5453
Model triples = ModelFactory.createDefaultModel();
5554

@@ -65,6 +64,7 @@ public TriplePatternFragment getFragment(Resource subject, Property predicate, R
6564
long size = triples.size();
6665
long estimate = -1;
6766

67+
6868
GraphStatisticsHandler stats = model.getGraph().getStatisticsHandler();
6969
if (stats != null) {
7070
Node s = (subject != null) ? subject.asNode() : null;

src/test/java/org/linkeddatafragments/datasource/JenaTDBDataSourceTest.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import com.google.gson.JsonObject;
99
import com.hp.hpl.jena.query.Dataset;
1010
import com.hp.hpl.jena.rdf.model.Model;
11-
import com.hp.hpl.jena.rdf.model.ModelFactory;
1211
import com.hp.hpl.jena.rdf.model.Property;
1312
import com.hp.hpl.jena.rdf.model.Resource;
1413
import com.hp.hpl.jena.tdb.TDBFactory;
@@ -32,6 +31,8 @@ public class JenaTDBDataSourceTest {
3231
private static Dataset dataset;
3332
private static File jena;
3433

34+
private final static String PREFIX = "http://test.ldf.org/";
35+
3536
@BeforeClass
3637
public static void setUpClass() throws Exception {
3738
String tmpdir = System.getProperty("java.io.tmpdir");
@@ -54,8 +55,13 @@ public static void setUpClass() throws Exception {
5455

5556
@AfterClass
5657
public static void tearDownClass() throws Exception {
57-
dataset.end();
5858
TDBFactory.release(dataset);
59+
File[] files = jena.listFiles();
60+
for (File f : files) {
61+
f.delete();
62+
}
63+
jena.delete();
64+
5965
}
6066

6167
@Before
@@ -68,16 +74,16 @@ public void setUp() throws Exception {
6874
int objs = 17;
6975

7076
for (int s = 0; s < subjs; s++) {
71-
Resource subj = model.createResource("http://test.ldf.org/s/" + s);
77+
Resource subj = model.createResource(PREFIX + "s/" + s);
7278
for (int p = 0; p < preds ; p++) {
73-
Property pred = model.createProperty("http://test.ldf.org/p/" + p);
79+
Property pred = model.createProperty(PREFIX + "p/" + p);
7480
for (int o = 0; o < objs ; o++) {
75-
Resource obj = model.createResource("http://test.ldf.org/o/" + o);
81+
Resource obj = model.createResource(PREFIX + "o/" + o);
7682
model.add(subj, pred, obj);
7783
}
7884
}
7985
}
80-
model.commit();
86+
model.close();
8187
}
8288

8389
/**
@@ -88,21 +94,21 @@ public void setUp() throws Exception {
8894
public void testEstimate() {
8995
Model model = dataset.getDefaultModel();
9096

91-
Resource subj = model.createResource("http://test.ldf.org/s/1");
97+
Resource subj = model.createResource(PREFIX + "s/1");
9298
Property pred = null;
9399
Resource obj = null;
94100

95101
long offset = 0;
96102
long limit = 50;
103+
97104
TriplePatternFragment fragment =
98105
tdb.getFragment(subj, pred, obj, offset, limit);
99106
long totalSize = fragment.getTotalSize();
100-
101-
Assert.assertTrue("Estimate is fake", totalSize != 51);
107+
108+
Assert.assertTrue("Estimate is fake: " + totalSize, totalSize != 51);
102109
}
103110

104111
@After
105112
public void tearDown() throws Exception {
106113
}
107-
108114
}

0 commit comments

Comments
 (0)