• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

knowledgepixels / nanopub-query / 17039726108

18 Aug 2025 11:49AM UTC coverage: 30.826% (+2.9%) from 27.92%
17039726108

push

github

ashleycaselli
test(JellyNanopubLoader): add unit test for loadInitial method

144 of 494 branches covered (29.15%)

Branch coverage included in aggregate %.

397 of 1261 relevant lines covered (31.48%)

1.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.44
src/main/java/com/knowledgepixels/query/LocalNanopubLoader.java
1
package com.knowledgepixels.query;
2

3
import org.eclipse.rdf4j.rio.RDFFormat;
4
import org.nanopub.MalformedNanopubException;
5
import org.nanopub.MultiNanopubRdfHandler;
6

7
import java.io.BufferedReader;
8
import java.io.File;
9
import java.io.FileReader;
10
import java.io.IOException;
11

12
/**
13
 * Local loader left here in case it's needed for testing or when the Jelly loader breaks.
14
 */
15
public class LocalNanopubLoader {
16

17
    private LocalNanopubLoader() {
18
    }  // no instances allowed
19

20
    /**
21
     * File containing URIs of nanopubs to load.
22
     */
23
    public final static File loadUrisFile = new File("load/nanopub-uris.txt");
5✔
24

25
    /**
26
     * File containing nanopubs in TRIG format to load.
27
     */
28
    public final static File loadNanopubsFile = new File("load/nanopubs.trig.gz");
5✔
29

30
    private static final int WAIT_SECONDS = Utils.getEnvInt("INIT_WAIT_SECONDS", 120);
5✔
31

32
    /**
33
     * Load nanopubs from local files.
34
     *
35
     * @return true if local nanopubs were found and loaded, false otherwise
36
     */
37
    public static boolean init() {
38
        // FIXME should this be loadNanopubsFile.exists() || loadUrisFile.exists()?
39
        if (!(loadNanopubsFile.exists() || loadNanopubsFile.exists())) {
6!
40
            System.err.println("No local nanopub files for loading found. Moving on to loading " +
3✔
41
                    "via Jelly...");
42
            return false;
2✔
43
        }
44
        System.err.println("Waiting " + WAIT_SECONDS + " seconds to make sure the triple store is up...");
4✔
45
        try {
46
            for (int w = 0; w < WAIT_SECONDS; w++) {
7✔
47
                System.err.println("Waited " + w + " seconds...");
4✔
48
                Thread.sleep(1000);
2✔
49
            }
50
        } catch (InterruptedException ex) {
×
51
            ex.printStackTrace();
×
52
        }
1✔
53

54
        System.err.println("Loading the local list of nanopubs...");
3✔
55
        load();
1✔
56
        return true;
2✔
57
    }
58

59
    static void load() {
60
        if (!loadUrisFile.exists()) {
3✔
61
            System.err.println("No local nanopub URI file found.");
4✔
62
        } else {
63
            try (BufferedReader reader = new BufferedReader(new FileReader(loadUrisFile))) {
8✔
64
                String line = reader.readLine();
3✔
65
                while (line != null) {
2✔
66
                    NanopubLoader.load(line);
2✔
67
                    line = reader.readLine();
4✔
68
                }
69
            } catch (IOException ex) {
×
70
                ex.printStackTrace();
×
71
            }
1✔
72
        }
73
        if (!loadNanopubsFile.exists()) {
3✔
74
            System.err.println("No local nanopub file found.");
4✔
75
        } else {
76
            try {
77
                MultiNanopubRdfHandler.process(RDFFormat.TRIG, loadNanopubsFile, np -> NanopubLoader.load(np, -1));
×
78
            } catch (IOException | MalformedNanopubException ex) {
1✔
79
                ex.printStackTrace();
2✔
80
            }
×
81
        }
82
    }
1✔
83

84
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc