Skip to content

Commit

Permalink
test: add integration test running a transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
stempler committed Aug 30, 2024
1 parent 2f5f95f commit 73567e8
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 0 deletions.
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ mainClassName = 'to.wetransform.halecli.CLI'
applicationName = 'hale'
applicationDefaultJvmArgs = defaultJvmArgs

test {
// debug classloading
// jvmArgs '-verbose:class'
}

/*
* plugin.xml and OSGi manifest
*
Expand Down
101 changes: 101 additions & 0 deletions src/test/groovy/to/wetransform/halecli/TransformTest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@

/*
* Copyright (c) 2024 wetransform GmbH
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution. If not, see <http://www.gnu.org/licenses/>.
*/
package to.wetransform.halecli

import static org.junit.Assert.*

import java.nio.file.Files
import java.nio.file.StandardCopyOption

import org.junit.BeforeClass
import org.junit.Rule
import org.junit.Test
import org.junit.contrib.java.lang.system.SystemOutRule
import org.junit.rules.TemporaryFolder

import eu.esdihumboldt.hale.common.core.HalePlatform
import eu.esdihumboldt.util.cli.Runner
import eu.esdihumboldt.util.io.IOUtils
import eu.esdihumboldt.util.nonosgi.Init
import groovy.xml.XmlUtil

/**
* Simple tests for CLI runner.
*
* @author Simon Templer
*/
class TransformTest {

@BeforeClass
static void init() {
Init.init()
}

@Rule
public final SystemOutRule out = new SystemOutRule().enableLog()

@Rule
public final TemporaryFolder folder = new TemporaryFolder()

@Test
void testTransformExample() {
File tempFolder = folder.newFolder()

def projectFileName = 'hydroEx.halez'
def sourceDataName = 'hydroEx_River_1Feature.gml'
def expectedResultName = 'expected.gml'

// copy files to folder
[
projectFileName,
sourceDataName,
expectedResultName
].each {fileName ->
def resPath = "testdata/hydroex/$fileName"
def targetFile = new File(tempFolder, fileName)

getClass().getClassLoader().getResourceAsStream(resPath).withStream {
Files.copy(it, targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING)
}
}

def projectFile = new File(tempFolder, projectFileName)
def sourceFile = new File(tempFolder, sourceDataName)
def targetFile = new File(tempFolder, 'target.gml')

int code = new Runner('hale').run(
'transform',
'-project',
projectFile.absolutePath,
'-source',
sourceFile.absolutePath,
'-target',
targetFile.absolutePath,
'-providerId',
'eu.esdihumboldt.hale.io.gml.writer'
)
assertEquals(0, code)

assertTrue(out.log.contains('Transformation completed'))

assertTrue(targetFile.exists())
assertTrue(targetFile.length() > 0)

def expectedResult = new File(tempFolder, expectedResultName)

def expectedXml = new XmlSlurper().parse(expectedResult)
def resultXml = new XmlSlurper().parse(targetFile)

assertEquals(XmlUtil.serialize(expectedXml.featureMember), XmlUtil.serialize(resultXml.featureMember))
}
}
1 change: 1 addition & 0 deletions src/test/resources/testdata/hydroex/expected.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" ?><gml:FeatureCollection xmlns:hy="http://inspire.ec.europa.eu/schemas/hy/4.0" xmlns:hy-p="http://inspire.ec.europa.eu/schemas/hy-p/4.0" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:gn="http://inspire.ec.europa.eu/schemas/gn/4.0" xmlns:base="http://inspire.ec.europa.eu/schemas/base/3.3" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:ns1="http://www.w3.org/1999/xhtml" xmlns:gss="http://www.isotc211.org/2005/gss" xmlns:gsr="http://www.isotc211.org/2005/gsr" xmlns:gts="http://www.isotc211.org/2005/gts" xmlns:hy-n="http://inspire.ec.europa.eu/schemas/hy-n/4.0" xmlns:sr="http://inspire.ec.europa.eu/schemas/sr/4.0" xmlns:net="http://inspire.ec.europa.eu/schemas/net/4.0" xmlns:sc="http://www.interactive-instruments.de/ShapeChange/AppInfo" xmlns:omor="http://inspire.ec.europa.eu/schemas/omor/3.0" xmlns:omop="http://inspire.ec.europa.eu/schemas/omop/3.0" xmlns:om="http://www.opengis.net/om/2.0" xmlns:hfp="http://www.w3.org/2001/XMLSchema-hasFacetAndProperty" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://inspire.ec.europa.eu/schemas/hy-p/4.0 http://inspire.ec.europa.eu/schemas/hy-p/4.0/HydroPhysicalWaters.xsd http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/deprecatedTypes.xsd"><gml:featureMember><hy-p:Watercourse gml:id="_d1a6215e-3185-429f-b9b1-f160437e4f99"><gml:description>Contains Ordnance Survey data © Crown copyright and database right 2011</gml:description><gml:name></gml:name><hy-p:geographicalName><gn:GeographicalName><gn:language>eng</gn:language><gn:nativeness xlink:href="http://inspire.ec.europa.eu/codelist/NativenessValue/endonym"></gn:nativeness><gn:nameStatus xlink:href="http://inspire.ec.europa.eu/codelist/NameStatusValue/official"></gn:nameStatus><gn:sourceOfName nilReason="other:unpopulated" xsi:nil="true"></gn:sourceOfName><gn:pronunciation nilReason="other:unpopulated" xsi:nil="true"></gn:pronunciation><gn:spelling><gn:SpellingOfName><gn:text></gn:text><gn:script>Latn</gn:script></gn:SpellingOfName></gn:spelling></gn:GeographicalName></hy-p:geographicalName><hy-p:beginLifespanVersion xsi:nil="true"/><hy-p:geometry><gml:Polygon srsName="EPSG:27700" srsDimension="2"><gml:exterior><gml:LinearRing><gml:posList>389065.2778650138 603671.3321135609 389321.82097369706 603680.8337101787 389331.3778515117 603682.1336809961 389340.49748487346 603685.2731276092 389348.8294113867 603690.1314028451 389356.053439788 603696.5218059111 389361.8919547173 603704.1987572012 389366.1205853201 603712.8672357824 389368.57682769373 603722.1941168845 389369.1662898213 603731.8209736971 389367.86631900386 603741.3778515117 389364.7268723908 603750.4974848735 389359.86859715485 603758.8294113866 389353.47819408885 603766.053439788 389345.8012427988 603771.8919547173 389337.1327642175 603776.12058532 389327.80588311545 603778.5768276937 389318.17902630294 603779.1662898213 389048.17902630294 603769.1662898213 389039.49725475995 603768.0659166398 389031.1477680726 603765.4448385558 389023.39472650737 603761.3859809885 388888.5864051159 603674.7234886654 388693.28110761906 603609.6217228331 388512.58589458966 603619.1319972031 388502.9510301945 603618.6924226618 388493.58705375594 603616.3816256247 388484.853817637 603612.2884087259 388477.08693520416 603606.5700719954 388470.58488339355 603599.4463679068 388465.5975324099 603591.1910564132 388462.31654335454 603582.1213845059 388460.86800279684 603572.5858945897 388461.3075773381 603562.9510301945 388463.6183743753 603553.587053756 388467.7115912741 603544.8538176371 388473.4299280046 603537.0869352042 388480.55363209324 603530.5848833936 388488.8089435867 603525.5975324099 388497.8786154941 603522.3165433545 388507.41410541034 603520.8680027969 388697.41410541034 603510.8680027969 388706.6015493888 603511.2449023622 388715.55840608804 603513.3247817359 388925.55840608804 603583.3247817359 388936.60527349263 603588.6140190115 389065.2778650138 603671.3321135609</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></hy-p:geometry><hy-p:inspireId><base:Identifier><base:localId>_d1a6215e-3185-429f-b9b1-f160437e4f99</base:localId><base:namespace>_example</base:namespace></base:Identifier></hy-p:inspireId><hy-p:origin xsi:nil="true"/><hy-p:persistence xsi:nil="true"/><hy-p:tidal xsi:nil="true"/><hy-p:drainsBasin xsi:nil="true"/><hy-p:delineationKnown xsi:nil="true"/><hy-p:length uom="m" xsi:nil="true"></hy-p:length><hy-p:level xsi:nil="true"/><hy-p:width><hy-p:WidthRange><hy-p:lower uom="m">4.573170731707317</hy-p:lower><hy-p:upper uom="m">4.573170731707317</hy-p:upper></hy-p:WidthRange></hy-p:width></hy-p:Watercourse></gml:featureMember></gml:FeatureCollection>
Binary file not shown.
21 changes: 21 additions & 0 deletions src/test/resources/testdata/hydroex/hydroEx_River_1Feature.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" ?>
<gml:FeatureCollection xmlns:ns1="http://www.w3.org/1999/xhtml" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:ex="eu:esdihumboldt:hale:example" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:hfp="http://www.w3.org/2001/XMLSchema-hasFacetAndProperty" xmlns:gsr="http://www.isotc211.org/2005/gsr" xmlns:gts="http://www.isotc211.org/2005/gts" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:gss="http://www.isotc211.org/2005/gss" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" gml:id="_bbd0a395-6f0b-499d-b0d7-3eb6e79ccbf0">
<gml:featureMember>
<ex:River gml:id="_d1a6215e-3185-429f-b9b1-f160437e4f99">
<gml:description>Contains Ordnance Survey data © Crown copyright and database right 2011</gml:description>
<gml:name></gml:name>
<ex:geometry>
<gml:Polygon gml:id="_361ba140-f9b3-4e17-b6be-e7da6d545b02" srsName="EPSG:27700" srsDimension="2">
<gml:exterior>
<gml:LinearRing>
<gml:posList>389065.2778650138 603671.3321135609 389321.82097369706 603680.8337101787 389331.3778515117 603682.1336809961 389340.49748487346 603685.2731276092 389348.8294113867 603690.1314028451 389356.053439788 603696.5218059111 389361.8919547173 603704.1987572012 389366.1205853201 603712.8672357824 389368.57682769373 603722.1941168845 389369.1662898213 603731.8209736971 389367.86631900386 603741.3778515117 389364.7268723908 603750.4974848735 389359.86859715485 603758.8294113866 389353.47819408885 603766.053439788 389345.8012427988 603771.8919547173 389337.1327642175 603776.12058532 389327.80588311545 603778.5768276937 389318.17902630294 603779.1662898213 389048.17902630294 603769.1662898213 389039.49725475995 603768.0659166398 389031.1477680726 603765.4448385558 389023.39472650737 603761.3859809885 388888.5864051159 603674.7234886654 388693.28110761906 603609.6217228331 388512.58589458966 603619.1319972031 388502.9510301945 603618.6924226618 388493.58705375594 603616.3816256247 388484.853817637 603612.2884087259 388477.08693520416 603606.5700719954 388470.58488339355 603599.4463679068 388465.5975324099 603591.1910564132 388462.31654335454 603582.1213845059 388460.86800279684 603572.5858945897 388461.3075773381 603562.9510301945 388463.6183743753 603553.587053756 388467.7115912741 603544.8538176371 388473.4299280046 603537.0869352042 388480.55363209324 603530.5848833936 388488.8089435867 603525.5975324099 388497.8786154941 603522.3165433545 388507.41410541034 603520.8680027969 388697.41410541034 603510.8680027969 388706.6015493888 603511.2449023622 388715.55840608804 603513.3247817359 388925.55840608804 603583.3247817359 388936.60527349263 603588.6140190115 389065.2778650138 603671.3321135609</gml:posList>
</gml:LinearRing>
</gml:exterior>
</gml:Polygon>
</ex:geometry>
<ex:code>6223</ex:code>
<ex:identifier>3889100603630</ex:identifier>
<ex:width>15.0</ex:width>
</ex:River>
</gml:featureMember>
</gml:FeatureCollection>

0 comments on commit 73567e8

Please sign in to comment.