Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
memoriav
Memobase 2020
services
Import Process
XML Data Transform
Commits
5fa97705
Commit
5fa97705
authored
Jul 16, 2020
by
Jonas Waeber
Browse files
add tests
parent
49668161
Changes
10
Show whitespace changes
Inline
Side-by-side
src/test/kotlin/TestParams.kt
0 → 100644
View file @
5fa97705
/*
* xml data import
* Copyright (C) 2020 Memoriav
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package
org.memobase
data class
TestParams
(
val
count
:
Int
,
val
name
:
String
,
val
inputKey
:
String
,
val
outputKey
:
String
,
val
expectedOutputReport
:
Report
,
val
expectedOutputProcessReport
:
Report
)
src/test/kotlin/Tests.kt
0 → 100644
View file @
5fa97705
/*
* record-parser
* Copyright (C) 2019 Memobase
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package
org.memobase
import
com.beust.klaxon.Klaxon
import
java.io.File
import
java.io.FileInputStream
import
java.nio.charset.Charset
import
java.nio.file.Paths
import
java.util.stream.Stream
import
org.apache.kafka.common.serialization.StringDeserializer
import
org.apache.kafka.common.serialization.StringSerializer
import
org.apache.kafka.streams.TopologyTestDriver
import
org.apache.kafka.streams.test.ConsumerRecordFactory
import
org.apache.logging.log4j.LogManager
import
org.assertj.core.api.Assertions.assertThat
import
org.junit.jupiter.api.TestInstance
import
org.junit.jupiter.params.ParameterizedTest
import
org.junit.jupiter.params.provider.MethodSource
import
org.memobase.testing.EmbeddedSftpServer
@TestInstance
(
TestInstance
.
Lifecycle
.
PER_CLASS
)
class
Tests
{
private
val
log
=
LogManager
.
getLogger
(
"TestLogger"
)
private
val
resourcePath
=
"src/test/resources/data"
private
fun
readFile
(
fileName
:
String
):
String
{
return
File
(
"$resourcePath/$fileName"
).
readText
(
Charset
.
defaultCharset
())
}
private
val
sftpServer
=
EmbeddedSftpServer
(
22000
,
"user"
,
"password"
)
init
{
val
files
=
listOf
(
1
,
2
).
map
{
Pair
(
"/memobase/test$it/data.xml"
,
"$it/data.xml"
)
}
for
(
pair
in
files
)
{
sftpServer
.
putFile
(
Paths
.
get
(
pair
.
first
,
pair
.
second
).
toString
(),
FileInputStream
(
Paths
.
get
(
"src/test/resources/data"
,
pair
.
second
).
toFile
())
)
}
}
@ParameterizedTest
@MethodSource
(
"testParams"
)
fun
`test
inputs`
(
params
:
TestParams
)
{
val
service
=
Service
(
"test${params.count}.yml"
)
val
testDriver
=
TopologyTestDriver
(
service
.
topology
,
service
.
settings
.
kafkaStreamsSettings
)
val
factory
=
ConsumerRecordFactory
(
StringSerializer
(),
StringSerializer
()
)
testDriver
.
pipeInput
(
factory
.
create
(
service
.
settings
.
inputTopic
,
params
.
inputKey
,
readFile
(
"${params.count}/input.json"
)
)
)
val
record
=
testDriver
.
readOutput
(
service
.
settings
.
outputTopic
,
StringDeserializer
(),
StringDeserializer
()
)
assertThat
(
record
)
.
isNotNull
.
hasFieldOrPropertyWithValue
(
"key"
,
params
.
outputKey
)
.
hasFieldOrPropertyWithValue
(
"value"
,
readFile
(
"${params.count}/output.json"
))
val
reportedRecord
=
testDriver
.
readOutput
(
"${service.settings.outputTopic}-reporting"
,
StringDeserializer
(),
StringDeserializer
()
)
if
(
reportedRecord
!=
null
)
{
val
data
=
reportedRecord
.
value
()
val
report
=
Klaxon
().
parse
<
Report
>(
data
)
assertThat
(
report
)
.
isNotNull
.
isEqualTo
(
params
.
expectedOutputReport
)
}
else
{
log
.
error
(
"No report for record $record."
)
}
val
processReport
=
testDriver
.
readOutput
(
service
.
settings
.
processReportTopic
,
StringDeserializer
(),
StringDeserializer
()
)
assertThat
(
Klaxon
().
parse
<
Report
>(
processReport
.
value
()))
.
isNotNull
.
isEqualTo
(
params
.
expectedOutputProcessReport
)
}
private
fun
testParams
()
=
Stream
.
of
(
TestParams
(
1
,
"test-flat-input"
,
"key"
,
"key"
,
Report
(
""
,
""
,
""
),
Report
(
""
,
""
,
""
)
)
)
}
src/test/resources/data/1/config/transform.xslt
View file @
5fa97705
<?xml version="1.0"?>
<!--
~ xml-data-transform
~ Copyright (C) 2020 Memoriav
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU Affero General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU Affero General Public License for more details.
~
~ You should have received a copy of the GNU Affero General Public License
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<xsl:stylesheet
version=
"1.0"
xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform"
>
<xsl:template
name=
"root"
>
<creator>
</creator>
</xsl:template>
</xsl:stylesheet>
\ No newline at end of file
src/test/resources/data/1/
input
.xml
→
src/test/resources/data/1/
data
.xml
View file @
5fa97705
File moved
src/test/resources/data/1/input.json
0 → 100644
View file @
5fa97705
{
"path"
:
"/memobase/test1/data.xml"
,
"format"
:
"XML"
}
\ No newline at end of file
src/test/resources/data/2/config/transform.xslt
0 → 100644
View file @
5fa97705
<?xml version="1.0"?>
<!--
~ xml-data-transform
~ Copyright (C) 2020 Memoriav
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU Affero General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU Affero General Public License for more details.
~
~ You should have received a copy of the GNU Affero General Public License
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<xsl:stylesheet
version=
"1.0"
xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform"
>
</xsl:stylesheet>
\ No newline at end of file
src/test/resources/data/2/data.xml
0 → 100644
View file @
5fa97705
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ xml-data-transform
~ Copyright (C) 2020 Memoriav
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU Affero General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU Affero General Public License for more details.
~
~ You should have received a copy of the GNU Affero General Public License
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<root>
<creator>
<name>
Sebastian
</name>
<role>
Autor
</role>
</creator>
<date>
1928
</date>
</root>
src/test/resources/data/2/input.json
0 → 100644
View file @
5fa97705
{
"path"
:
"/memobase/test1/data.xml"
,
"format"
:
"ERROR"
}
\ No newline at end of file
src/test/resources/data/2/output.json
0 → 100644
View file @
5fa97705
ERROR
\ No newline at end of file
src/test/resources/test1.yml
View file @
5fa97705
...
...
@@ -6,6 +6,7 @@ sftp:
app
:
xsltFilePath
:
src/test/resources/data/1/config/transform.xslt
identifierFieldName
:
id
recordTag
:
root
kafka
:
streams
:
bootstrap.servers
:
localhost:12345
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment