Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@

class GovernedVersionsTest {

/**
* Fixtures normally belong in the nanopub test suite rather than in this repository (#620),
* but these two stay here: they are hand-built, unsigned, and carry placeholder artifact
* codes, because they exist to exercise Nanodash's own governance logic rather than to test
* whether an implementation reads nanopublications correctly. A suite for validating
* nanopublication implementations is not their home, and an unsigned nanopub with a made-up
* code has no business in its {@code valid/} folder.
*/
private static Nanopub load(String fileName) throws MalformedNanopubException, IOException {
return new NanopubImpl(new File("src/test/resources/" + fileName), RDFFormat.TRIG);
}
Expand Down
21 changes: 18 additions & 3 deletions src/test/java/com/knowledgepixels/nanodash/GrlcQueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import org.mockito.MockedStatic;
import org.nanopub.*;
import org.nanopub.extra.services.QueryRef;
import org.nanopub.testsuite.NanopubTestSuite;
import org.nanopub.testsuite.TestSuiteCategory;
import org.nanopub.testsuite.TestSuiteEntry;
import org.nanopub.vocabulary.KPXL_GRLC;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
Expand Down Expand Up @@ -42,6 +44,19 @@ class GrlcQueryTest {
*/
private static final String SPARQL_WITH_NON_BREAKING_SPACE = "select ?thing where { ?thing ?p\u00A0?o }";

/**
* The published "Get participation links" query. It lives in the nanopub test suite rather
* than in this repository, so that the fixture is shared with the other implementations
* instead of being copied into each of them (#620). Its absence is a failure rather than a
* reason to skip: it would mean the entry has been renamed or removed.
*/
private static Nanopub queryNanopub() throws MalformedNanopubException, IOException {
TestSuiteEntry entry = NanopubTestSuite.getLatest()
.getByArtifactCode(NANOPUB_ID, TestSuiteCategory.VALID)
.orElseThrow(() -> new IllegalStateException("Not in the nanopub test suite: " + NANOPUB_ID));
return new NanopubImpl(entry.toFile(), RDFFormat.TRIG);
}

@AfterEach
void tearDown() throws NoSuchFieldException, IllegalAccessException {
// Using reflection to clear the instance map to ensure a fresh start for each test
Expand Down Expand Up @@ -198,7 +213,7 @@ void getQuerySuffix() {
@Test
void getNanopub() throws MalformedNanopubException, IOException {
GrlcQuery query = GrlcQuery.get(NANOPUB_URI);
Nanopub nanopub = new NanopubImpl(new File("src/test/resources/np-grlc-query.trig"), RDFFormat.TRIG);
Nanopub nanopub = queryNanopub();
assertEquals(query.getNanopub(), nanopub);
}

Expand Down Expand Up @@ -247,7 +262,7 @@ void createParamFields() {
void getSparql() throws MalformedNanopubException, IOException {
GrlcQuery query = GrlcQuery.get(NANOPUB_URI);
String sparql = query.getSparql();
Nanopub nanopub = new NanopubImpl(new File("src/test/resources/np-grlc-query.trig"), RDFFormat.TRIG);
Nanopub nanopub = queryNanopub();
AtomicReference<String> sparqlFromNanopub = new AtomicReference<>();
nanopub.getAssertion().forEach(st -> {
if (st.getPredicate().equals(KPXL_GRLC.SPARQL)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.nanopub.NanopubImpl;
import org.nanopub.extra.security.MalformedCryptoElementException;
import org.nanopub.extra.security.SignatureUtils;
import org.nanopub.testsuite.NanopubTestSuite;
import org.nanopub.testsuite.TestSuiteCategory;
import org.nanopub.vocabulary.NPX;

import java.io.File;
Expand All @@ -23,7 +25,17 @@

class NanopubElementTest {

private final File np = new File("src/test/resources/np-grlc-query.trig");
/**
* The published "Get participation links" query. It lives in the nanopub test suite rather
* than in this repository, so that the fixture is shared with the other implementations
* instead of being copied into each of them (#620).
*/
private static final String QUERY_CODE = "RA6T-YLqLnYd5XfnqR9PaGUjCzudvHdYjcG4GvOc7fdpA";

private final File np = NanopubTestSuite.getLatest()
.getByArtifactCode(QUERY_CODE, TestSuiteCategory.VALID)
.orElseThrow(() -> new IllegalStateException("Not in the nanopub test suite: " + QUERY_CODE))
.toFile();

@Test
void getWithURI() throws MalformedNanopubException, IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@
import org.nanopub.vocabulary.KPXL_GRLC;
import org.nanopub.vocabulary.NTEMPLATE;

import java.util.Optional;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -124,7 +121,8 @@ void onlyTheSparqlHoldingPlaceholderIsRecognised() throws Exception {
* The artifact code of the published "Defining a grlc query" template, which is what query
* nanopublications are created from. It lives in the nanopub test suite rather than in this
* repository, so that the fixture is shared with the other implementations instead of being
* copied into each of them.
* copied into each of them. Its absence is a failure rather than a reason to skip: it would
* mean the entry has been renamed or removed.
*/
private static final String QUERY_TEMPLATE_CODE = "RAEFAt-QcFK0ZhqfvlsmS10BnzGJA0xwOICZXkO-ai87k";

Expand All @@ -133,11 +131,11 @@ void onlyTheSparqlHoldingPlaceholderIsRecognised() throws Exception {
// version of that template moves the SPARQL field, this fails rather than quietly skipping.
@Test
void theRealQueryTemplateHasItsSparqlFieldRecognised() throws Exception {
Optional<TestSuiteEntry> entry = NanopubTestSuite.getLatest()
.getByArtifactCode(QUERY_TEMPLATE_CODE, TestSuiteCategory.VALID);
assumeTrue(entry.isPresent(),
"The grlc query template is not in the test suite yet: Nanopublication/nanopub-testsuite#5");
Nanopub np = new NanopubImpl(entry.get().toFile(), RDFFormat.TRIG);
TestSuiteEntry entry = NanopubTestSuite.getLatest()
.getByArtifactCode(QUERY_TEMPLATE_CODE, TestSuiteCategory.VALID)
.orElseThrow(() -> new IllegalStateException(
"Not in the nanopub test suite: " + QUERY_TEMPLATE_CODE));
Nanopub np = new NanopubImpl(entry.toFile(), RDFFormat.TRIG);
Template template = TemplateTestUtil.parseTemplate(np);
String base = np.getUri().stringValue() + "/";
assertTrue(template.isSparqlPlaceholder(vf.createIRI(base + "sparql")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import org.nanopub.NanopubImpl;
import org.nanopub.extra.services.ApiResponse;
import org.nanopub.extra.services.ApiResponseEntry;
import org.nanopub.testsuite.NanopubTestSuite;
import org.nanopub.testsuite.TestSuiteCategory;
import org.nanopub.testsuite.TestSuiteEntry;

import java.io.File;

Expand All @@ -20,6 +23,15 @@

class StatusLineTest {

/**
* A published retraction, which is one of the shapes a status line is drawn from. It lives
* in the nanopub test suite rather than in this repository, so that the fixture is shared
* with the other implementations instead of being copied into each of them (#620). Its
* absence is a failure rather than a reason to skip: it would mean the entry has been
* renamed or removed.
*/
private static final String RETRACTION_CODE = "RA58YcJyv1h-UmS8jI6UfFP6_LTAh59GTgpU_4lvBv7a4";

private WicketTester wicketTester;

@BeforeEach
Expand All @@ -37,7 +49,10 @@ private static ApiResponseEntry entry(String newerVersion, String retractedBy, S

@Test
void createComponentReturnsNonNullComponent() throws Exception {
Nanopub np = new NanopubImpl(new File("src/test/resources/np-statusline-example.trig"), RDFFormat.TRIG);
TestSuiteEntry entry = NanopubTestSuite.getLatest()
.getByArtifactCode(RETRACTION_CODE, TestSuiteCategory.VALID)
.orElseThrow(() -> new IllegalStateException("Not in the nanopub test suite: " + RETRACTION_CODE));
Nanopub np = new NanopubImpl(entry.toFile(), RDFFormat.TRIG);
Component component = StatusLine.createComponent("statusLine", np);
assertNotNull(component);

Expand Down
73 changes: 0 additions & 73 deletions src/test/resources/np-grlc-query.trig

This file was deleted.

39 changes: 0 additions & 39 deletions src/test/resources/np-statusline-example.trig

This file was deleted.

47 changes: 0 additions & 47 deletions src/test/resources/templates/new-style-assertion-template.trig

This file was deleted.