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
Text File Validation
Commits
d57b099b
Commit
d57b099b
authored
Apr 07, 2020
by
Jonas Waeber
Browse files
Implement embedded kafka as extension
Makes it easier to use the embedded kafka container.
parent
deaed694
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/test/kotlin/EmbeddedKafkaExtension.kt
0 → 100644
View file @
d57b099b
/*
* sftp-reader
* 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
import
org.junit.jupiter.api.extension.BeforeAllCallback
import
org.junit.jupiter.api.extension.ExtensionContext
class
EmbeddedKafkaExtension
:
BeforeAllCallback
{
lateinit
var
kafka
:
KafkaEmbedded
private
val
testTopic
:
String
=
"test"
private
val
port
:
Int
=
12345
override
fun
beforeAll
(
context
:
ExtensionContext
?)
{
kafka
=
KafkaEmbedded
(
port
,
testTopic
)
val
wrapper
=
KafkaWrapper
(
kafka
)
if
(
context
!=
null
)
{
context
.
getStore
(
ExtensionContext
.
Namespace
.
create
(
EmbeddedKafkaExtension
::
class
.
java
))
.
put
(
"redis"
,
wrapper
)
Runtime
.
getRuntime
().
addShutdownHook
(
Thread
(
Runnable
{
wrapper
.
close
()
}))
}
}
class
KafkaWrapper
(
private
val
embedded
:
KafkaEmbedded
)
:
ExtensionContext
.
Store
.
CloseableResource
{
override
fun
close
()
{
embedded
.
close
()
}
}
}
src/test/kotlin/SftpServerExtension.kt
0 → 100644
View file @
d57b099b
/*
* sftp-reader
* 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
import
org.junit.jupiter.api.extension.BeforeAllCallback
import
org.junit.jupiter.api.extension.ExtensionContext
class
SftpServerExtension
:
BeforeAllCallback
{
override
fun
beforeAll
(
context
:
ExtensionContext
?)
{
TODO
(
"Not yet implemented"
)
}
class
SftpServerWrapper
(
private
val
embedded
:
KafkaEmbedded
)
:
ExtensionContext
.
Store
.
CloseableResource
{
override
fun
close
()
{
embedded
.
close
()
}
}
}
src/test/kotlin/Tests.kt
View file @
d57b099b
...
...
@@ -17,24 +17,15 @@
*/
package
org.memobase
import
org.junit.jupiter.api.Assertions.assertEquals
import
org.junit.jupiter.api.Test
import
org.junit.jupiter.api.TestInstance
import
org.junit.jupiter.api.
assertAll
import
org.junit.jupiter.api.
extension.ExtendWith
@ExtendWith
(
EmbeddedKafkaExtension
::
class
)
@TestInstance
(
TestInstance
.
Lifecycle
.
PER_CLASS
)
class
Tests
{
private
val
kafkaEmbedded
=
KafkaEmbedded
(
12301
,
"test"
)
private
val
testResourceCsv
=
ClassLoader
.
getSystemResourceAsStream
(
"test.csv"
)
@Test
fun
testValidCsvSend
()
{
kafkaEmbedded
.
use
{
assertAll
(
"test case 1"
,
{
assertEquals
(
"null"
,
"null"
)
},
{
assertEquals
(
"null"
,
"null"
)
}
)
}
}
}
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