Skip to content

Commit

Permalink
Merge pull request #1496 from NatLibFi/issue1488-phpunit-fuseki-docker
Browse files Browse the repository at this point in the history
Use dockerized Fuseki for PHPUnit tests
  • Loading branch information
osma authored Sep 1, 2023
2 parents fe8e74a + e541940 commit cfedf5d
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 43 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,8 @@ jobs:
with:
fetch-depth: 0

- name: Cache Fuseki installation
uses: actions/cache@v3
with:
path: tests/apache-jena-fuseki-*
key: fuseki-${{ hashFiles('tests/init_fuseki.sh') }}

- name: Start up Fuseki
run: cd tests; sh ./init_fuseki.sh
run: cd tests; ./init_fuseki.sh

- name: Cache Composer dependencies
uses: actions/cache@v3
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/config/skosmos.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

:tdb_dataset_readwrite rdf:type tdb2:DatasetTDB2 ;
tdb2:location "/fuseki/databases/skosmos" ;
# tdb2:unionDefaultGraph true ;
tdb2:unionDefaultGraph true ;
.

<#indexLucene> rdf:type text:TextIndexLucene ;
Expand Down
1 change: 1 addition & 0 deletions tests/JenaTextSparqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ public function testQueryConceptsDefaultGraph()
*/
public function testQueryConceptsAlphabeticalOrderBy()
{
$this->markTestSkipped("disabled because ARQ collation doesn't work in dockerized Fuseki (Jena issue #1998)");
$vocab = $this->model->getVocabulary('collation');
$graph = $vocab->getGraph();
$sparql = new JenaTextSparql($this->endpoint, $graph, $this->model);
Expand Down
2 changes: 1 addition & 1 deletion tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function testGetVocabularyByGraphUri()
public function testGetVocabularyByInvalidGraphUri()
{
$this->expectException(ValueError::class);
$this->expectExceptionMessage("no vocabulary found for graph http://no/address and endpoint http://localhost:13030/skosmos-test/sparql");
$this->expectExceptionMessage("no vocabulary found for graph http://no/address and endpoint http://localhost:9030/skosmos/sparql");
$vocab = $this->model->getVocabularyByGraph('http://no/address');
$this->assertInstanceOf('Vocabulary', $vocab);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/VocabularyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testGetEndpoint()
{
$vocab = $this->model->getVocabulary('testdiff');
$endpoint = $vocab->getEndpoint();
$this->assertEquals('http://localhost:13030/skosmos-test/sparql', $endpoint);
$this->assertEquals('http://localhost:9030/skosmos/sparql', $endpoint);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// make sure that a SPARQL endpoint is set by an environment variable
$endpoint = getenv('SKOSMOS_SPARQL_ENDPOINT');
if (!$endpoint) {
// default to Fuseki running on localhost:13030 as provided by init_fuseki.sh
putenv('SKOSMOS_SPARQL_ENDPOINT=http://localhost:13030/skosmos-test/sparql');
// default to Fuseki running on localhost:9030 as provided by init_fuseki.sh
putenv('SKOSMOS_SPARQL_ENDPOINT=http://localhost:9030/skosmos/sparql');
}

# Allow running git commands in the php-actions/phpunit container
Expand Down
46 changes: 16 additions & 30 deletions tests/init_fuseki.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,23 @@
#!/bin/bash
# Note: This script must be sourced from within bash, e.g. ". init_fuseki.sh"

FUSEKI_VERSION=${FUSEKI_VERSION:-4.4.0}
# Build and start up containers (skosmos, skosmos-cache, fuseki)
cd ../dockerfiles
docker compose up -d --build

if [ "$FUSEKI_VERSION" = "SNAPSHOT" ]; then
# find out the latest snapshot version and its download URL by parsing Apache directory listings
snapshotdir="https://repository.apache.org/content/repositories/snapshots/org/apache/jena/apache-jena-fuseki/"
latestdir=$(wget -q -O- "$snapshotdir" | grep 'a href=' | cut -d '"' -f 2 | grep SNAPSHOT | tail -n 1)
FUSEKI_VERSION=$(basename "$latestdir")
fusekiurl=$(wget -q -O- "$latestdir" | grep 'a href=' | cut -d '"' -f 2 | grep '\.tar\.gz$' | tail -n 1)
else
fusekiurl="https://repository.apache.org/content/repositories/releases/org/apache/jena/apache-jena-fuseki/$FUSEKI_VERSION/apache-jena-fuseki-$FUSEKI_VERSION.tar.gz"
fi

if [ ! -f "apache-jena-fuseki-$FUSEKI_VERSION/fuseki-server" ]; then
echo "fuseki server file not found - downloading it"
wget --no-verbose --output-document=fuseki-dist.tar.gz "$fusekiurl"
echo "uncompressing fuseki distribution"
tar -zxf fuseki-dist.tar.gz
fi

cd "apache-jena-fuseki-$FUSEKI_VERSION"
chmod +x fuseki-server bin/s-put
./fuseki-server --port=13030 --config ../fuseki-assembler.ttl &
until curl --output /dev/null --silent --head --fail http://localhost:13030; do
printf '.'
sleep 2
echo "Waiting for Fuseki to get ready"
while true; do
if curl -fs http://localhost:9030/skosmos/ -o /dev/null; then
echo "Fuseki is up!"
break
else
echo "...waiting..."
sleep 1
fi
done

for fn in ../test-vocab-data/*.ttl; do
for fn in ../tests/test-vocab-data/*.ttl; do
name=$(basename "${fn}" .ttl)
$(./bin/s-put http://localhost:13030/skosmos-test/data "http://www.skosmos.skos/$name/" "$fn")
echo "Loading test vocabulary $name"
curl -I -X POST -H Content-Type:text/turtle -T "$fn" -G http://localhost:9030/skosmos/data --data-urlencode graph="http://www.skosmos.skos/$name/"
echo
done

cd ..

2 changes: 1 addition & 1 deletion tests/testconfig.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

:config a skosmos:Configuration ;
# SPARQL endpoint defaults to $SKOSMOS_SPARQL_ENDPOINT environment var
# skosmos:sparqlEndpoint <http://localhost:13030/skosmos-test/sparql> ;
# skosmos:sparqlEndpoint <http://localhost:9030/skosmos/sparql> ;
# sparql-query extension, or "Generic" for plain SPARQL 1.1
# set to "JenaText" instead if you use Fuseki with jena-text index
# skosmos:sparqlDialect "JenaText" ;
Expand Down

0 comments on commit cfedf5d

Please sign in to comment.