-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for built/published resources
- Loading branch information
Showing
5 changed files
with
151 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
rootProject.name = 'offline-resources' | ||
include 'test' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} |
71 changes: 71 additions & 0 deletions
71
test/src/test/java/to.wetransform.offlineresources/OfflineResourcesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
|
||
} |