Skip to content

Commit

Permalink
test: add tests for built/published resources
Browse files Browse the repository at this point in the history
  • Loading branch information
stempler committed Feb 2, 2024
1 parent b80949c commit 89e38d7
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 2 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/check-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,21 @@ jobs:

- name: Download resources and build Jars
run: |
./gradlew downloads jars
# TODO also test publishing (e.g. to local maven repo)
./gradlew downloads jars publishJarsToMavenLocal :test:test
- name: Publish Test Report
uses: mikepenz/action-junit-report@v3
if: always() # always run even if the previous step fails
with:
report_paths: "test/build/test-results/**/*.xml"
require_tests: true

# Workaround for check that is additionally created being associated
# to the wrong workflow/run. Instead not additional check is created.
# See https://github.com/mikepenz/action-junit-report/issues/40
annotate_only: true
detailed_summary: true
fail_on_failure: true

- name: Add git status to summary
run: |
Expand Down
11 changes: 11 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,17 @@ task('publishJars', type: GradleBuild) {
tasks = ['publish']
}

/**
* Task that publishes all Jars to the local maven repository.
*/
task('publishJarsToMavenLocal', type: GradleBuild) {
buildFile = file('publish.gradle')

startParameter.projectProperties.publications = jarFolder.getAbsolutePath()

tasks = ['publishToMavenLocal']
}

/**
* Task for creating resource bundles used by hale
*/
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
rootProject.name = 'offline-resources'
include 'test'
48 changes: 48 additions & 0 deletions test/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
plugins {
id 'java'
}

/*
* Dependencies
*/

repositories {
mavenLocal() // resources to be tested should come from here

mavenCentral()

maven {
url 'https://artifactory.wetransform.to/artifactory/local'
}

maven { // wetransform internal repository (for offline resources API)
url 'https://artifactory.wetransform.to/artifactory/private'
credentials {
username project.hasProperty('wetfArtifactoryUser') ? wetfArtifactoryUser : ''
password project.hasProperty('wetfArtifactoryPassword') ? wetfArtifactoryPassword : ''
}
}
}

dependencies {
implementation 'to.wetransform:offline-resources-api:1.0.0'
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'

// Testing
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.1'

// Offline resources for testing
// Always test current versions
testRuntimeOnly 'to.wetransform.offline-resources:www.w3.org:CURRENT-SNAPSHOT'
testRuntimeOnly 'to.wetransform.offline-resources:inspire.ec.europa.eu:CURRENT-SNAPSHOT'
}

test {
useJUnitPlatform()
}

configurations.all {
// ensure SNAPSHOTs are updated every time if needed
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package to.wetransform.offlineresources;

import org.junit.jupiter.api.Test;
import to.wetransform.offlineresources.api.OfflineResources;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.function.Supplier;

import static org.junit.jupiter.api.Assertions.*;

public class OfflineResourcesTest {

@Test
public void testLoadXmlSchema() throws IOException {
testLoadLocation(URI.create(
"https://www.w3.org/2001/XMLSchema.xsd"
));
}

@Test
public void testLoadInspireHyP4() throws IOException {
testLoadLocation(URI.create(
"https://inspire.ec.europa.eu/schemas/hy-p/4.0/HydroPhysicalWaters.xsd"
));
}

/**
* Test workaround for missing schemas in INSPIRE repository that are compensated with redirects on the INSPIRE website.
*
* See https://github.com/halestudio/hale-platform/blob/1e7e00c9684c9043c98a857338fd1ccfee05541b/modules/resources/build.gradle#L157
*/
@Test
public void testLoadInspireRedirectWorkaround() throws IOException {
testLoadLocation(URI.create(
"https://inspire.ec.europa.eu/schemas/lc/0.0/LandCover.xsd"
));

testLoadLocation(URI.create(
"https://inspire.ec.europa.eu/schemas/wfd/0.0/WaterFrameworkDirective.xsd"
));
}

@Test
public void testLoadNonExistentFail() throws IOException {
assertThrows(Exception.class, () -> {
testLoadLocation(URI.create(
"https://example.com/example.xsd"
));
});
}

// helpers

private void testLoadLocation(URI location) throws IOException {
OfflineResources or = new OfflineResources();

Supplier<InputStream> input = or.resolve(location);

try (InputStream in = input.get(); BufferedReader reader = new BufferedReader(
new InputStreamReader(in, StandardCharsets.UTF_8))) {
// consume content
reader.lines();
}
}

}

0 comments on commit 89e38d7

Please sign in to comment.