Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
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
Mapper Service
Commits
bf01c783
Commit
bf01c783
authored
Sep 23, 2021
by
Jonas Waeber
Browse files
Begin refactor of tests
parent
5323be02
Changes
6
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
bf01c783
...
...
@@ -7,4 +7,3 @@ build
.gradle
output/
data/
src/test/kotlin/TestPipeline.kt
0 → 100644
View file @
bf01c783
package
org.memobase
import
ch.memobase.reporting.Report
import
ch.memobase.testing.EmbeddedSftpServer
import
com.beust.klaxon.Klaxon
import
org.apache.kafka.common.header.internals.RecordHeader
import
org.apache.kafka.common.header.internals.RecordHeaders
import
org.apache.kafka.common.serialization.StringDeserializer
import
org.apache.kafka.common.serialization.StringSerializer
import
org.apache.kafka.streams.TestOutputTopic
import
org.apache.kafka.streams.TopologyTestDriver
import
org.apache.kafka.streams.test.TestRecord
import
org.assertj.core.api.Assertions.assertThat
import
org.junit.jupiter.api.Test
import
org.junit.jupiter.api.TestInstance
import
org.junit.jupiter.api.assertAll
import
java.io.File
import
java.nio.charset.Charset
@TestInstance
(
TestInstance
.
Lifecycle
.
PER_CLASS
)
class
TestPipeline
{
private
val
resourcePath
=
"src/test/resources/data"
private
fun
readFile
(
fileName
:
String
,
count
:
Int
):
String
{
return
File
(
"$resourcePath/$count/$fileName"
).
readText
(
Charset
.
defaultCharset
())
}
private
val
klaxon
=
Klaxon
()
private
val
regex
=
Regex
(
"(_:B[A-Za-z0-9]+)"
)
private
val
regexTime
=
Regex
(
"\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}"
)
private
fun
sort
(
source
:
String
):
String
{
return
source
.
lines
().
map
{
var
replacedString
=
it
for
(
matchResult
in
regex
.
findAll
(
it
))
{
replacedString
=
replacedString
.
replace
(
matchResult
.
groups
[
0
]
?.
value
.
orEmpty
(),
"_:B"
)
}
for
(
matchResult
in
regexTime
.
findAll
(
it
))
{
replacedString
=
replacedString
.
replace
(
matchResult
.
groups
[
0
]
?.
value
.
orEmpty
(),
"2020-10-10T09:10:22"
)
}
replacedString
}.
sorted
().
reduce
{
acc
,
s
->
acc
+
"\n"
+
s
}.
trim
()
}
private
fun
setupTest
(
fileName
:
String
,
count
:
Int
,
inputKey
:
String
):
Pair
<
TestOutputTopic
<
String
,
String
>,
TestOutputTopic
<
String
,
String
>>
{
val
service
=
Service
(
fileName
)
val
testDriver
=
TopologyTestDriver
(
KafkaTopology
(
service
.
settings
).
prepare
().
build
(),
service
.
settings
.
kafkaStreamsSettings
)
val
inputValue
=
readFile
(
"input.json"
,
count
)
val
headers
=
RecordHeaders
()
headers
.
add
(
RecordHeader
(
"sessionId"
,
"test-session-id"
.
toByteArray
()))
headers
.
add
(
RecordHeader
(
"recordSetId"
,
"rst-001"
.
toByteArray
()))
headers
.
add
(
RecordHeader
(
"institutionId"
,
"ins"
.
toByteArray
()))
val
inputTopic
=
testDriver
.
createInputTopic
(
service
.
settings
.
inputTopic
,
StringSerializer
(),
StringSerializer
())
val
inputRecord
=
TestRecord
<
String
,
String
>(
inputKey
,
inputValue
,
headers
)
inputTopic
.
pipeInput
(
inputRecord
)
val
configTopic
=
testDriver
.
createInputTopic
(
service
.
settings
.
appSettings
.
getProperty
(
"configTopic"
),
StringSerializer
(),
StringSerializer
()
)
configTopic
.
pipeInput
(
"rst-001#mapping"
,
readFile
(
"mapping.yml"
,
count
))
val
outputTopic
=
testDriver
.
createOutputTopic
(
service
.
settings
.
outputTopic
,
StringDeserializer
(),
StringDeserializer
())
val
outputReportTopic
=
testDriver
.
createOutputTopic
(
service
.
settings
.
processReportTopic
,
StringDeserializer
(),
StringDeserializer
()
)
return
Pair
(
outputTopic
,
outputReportTopic
)
}
private
fun
parseReport
(
data
:
String
):
Report
{
return
klaxon
.
parse
<
Report
>(
data
)
!!
}
@Test
fun
`test
1
minimal
configuration`
()
{
val
topics
=
setupTest
(
"app.yml"
,
1
,
"test-1"
)
val
record
=
topics
.
first
.
readRecord
()
val
recordValue
=
record
.
value
val
recordKey
=
record
.
key
assertAll
(
{
assertThat
(
sort
(
recordValue
))
.
isEqualTo
(
sort
(
readFile
(
"output.nt"
,
1
)))
},
{
assertThat
(
recordKey
)
.
isEqualTo
(
"https://memobase.ch/record/rst-001-1"
)
}
)
}
@Test
fun
`test
2
minimal
configuration
with
digital
and
physical
object
`
()
{
}
}
\ No newline at end of file
src/test/resources/
kafkaTest1
.yml
→
src/test/resources/
app
.yml
View file @
bf01c783
app
:
configTopic
:
mb-di-config-t
est
configTopic
:
mb-di-config-t
opic
reportingStepName
:
test
kafka
:
streams
:
...
...
src/test/resources/data/1/input.json
0 → 100644
View file @
bf01c783
{
"identifier"
:
"1"
,
"type"
:
"Film"
}
\ No newline at end of file
src/test/resources/data/1/mapping.yml
0 → 100644
View file @
bf01c783
record
:
uri
:
identifier
type
:
type
\ No newline at end of file
src/test/resources/data/1/output.nt
0 → 100644
View file @
bf01c783
_:Bcfb669e0X2D9972X2D426dX2Da422X2D42dda66e0e98 <https://www.ica.org/standards/RiC/ontology#identifier> "rst-001-1" .
_:Bcfb669e0X2D9972X2D426dX2Da422X2D42dda66e0e98 <https://www.ica.org/standards/RiC/ontology#type> "main" .
_:Bcfb669e0X2D9972X2D426dX2Da422X2D42dda66e0e98 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Identifier> .
<https://memobase.ch/record/rst-001-1> <https://memobase.ch/internal/isPublished> "false"^^<http://www.w3.org/2001/XMLSchema#boolean> .
<https://memobase.ch/record/rst-001-1> <https://www.ica.org/standards/RiC/ontology#identifiedBy> _:Bcfb669e0X2D9972X2D426dX2Da422X2D42dda66e0e98 .
<https://memobase.ch/record/rst-001-1> <https://www.ica.org/standards/RiC/ontology#heldBy> <https://memobase.ch/institution/ins> .
<https://memobase.ch/record/rst-001-1> <https://www.ica.org/standards/RiC/ontology#isPartOf> <https://memobase.ch/recordSet/rst-001> .
<https://memobase.ch/record/rst-001-1> <https://www.ica.org/standards/RiC/ontology#type> "Film" .
<https://memobase.ch/record/rst-001-1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Record> .
\ No newline at end of file
Write
Preview
Markdown
is supported
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