Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
biopet.biopet
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirrors
biopet.biopet
Commits
54c1b9c5
Commit
54c1b9c5
authored
10 years ago
by
Peter van 't Hof
Browse files
Options
Downloads
Patches
Plain Diff
Added more tests
parent
6448d113
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
public/biopet-framework/src/test/scala/nl/lumc/sasc/biopet/utils/TestConfigUtils.scala
+131
-1
131 additions, 1 deletion
...est/scala/nl/lumc/sasc/biopet/utils/TestConfigUtils.scala
with
131 additions
and
1 deletion
public/biopet-framework/src/test/scala/nl/lumc/sasc/biopet/utils/TestConfigUtils.scala
+
131
−
1
View file @
54c1b9c5
package
nl.lumc.sasc.biopet.utils
import
java.io.File
import
java.io.
{
PrintWriter
,
File
}
import
argonaut.Argonaut._
import
argonaut.Json
import
nl.lumc.sasc.biopet.core.config.
{
ConfigValueIndex
,
ConfigValue
}
import
org.scalatest.Matchers
import
org.scalatest.mock.MockitoSugar
...
...
@@ -13,7 +15,57 @@ import org.testng.annotations.Test
*/
class
TestConfigUtils
extends
TestNGSuite
with
MockitoSugar
with
Matchers
{
import
ConfigUtils._
import
TestConfigUtils._
// Merge maps
@Test
def
testMergeMaps
:
Unit
=
{
val
mergedMap
=
mergeMaps
(
map1
,
map2
)
//TODO: more tests needed
}
// Json to scala values
@Test
def
testFileToJson
:
Unit
=
{
fileToJson
(
file1
)
shouldBe
json1
fileToJson
(
file2
)
shouldBe
json2
intercept
[
IllegalStateException
]
{
fileToJson
(
corruptFile
)
}
}
@Test
def
testJsonToMap
:
Unit
=
{
jsonToMap
(
json1
)
shouldBe
map1
jsonToMap
(
json2
)
shouldBe
map2
intercept
[
IllegalStateException
]
{
jsonToMap
(
Json
.
jNumberOrString
(
1337
))
}
}
@Test
def
testFileToConfigMap
:
Unit
=
{
fileToConfigMap
(
file1
)
shouldBe
map1
fileToConfigMap
(
file2
)
shouldBe
map2
}
// Any/scala values to Json objects
@Test
def
testAnyToJson
:
Unit
=
{
anyToJson
(
"bla"
)
shouldBe
jString
(
"bla"
)
anyToJson
(
1337
)
shouldBe
Json
.
jNumberOrString
(
1337
)
anyToJson
(
13.37
)
shouldBe
Json
.
jNumberOrString
(
13.37
)
anyToJson
(
1337L
)
shouldBe
Json
.
jNumberOrString
(
1337L
)
anyToJson
(
13.37f
)
shouldBe
Json
.
jNumberOrString
(
13.37f
)
anyToJson
(
List
(
"bla"
))
shouldBe
Json
.
array
(
anyToJson
(
"bla"
))
anyToJson
(
anyToJson
(
"bla"
))
shouldBe
anyToJson
(
"bla"
)
anyToJson
(
Map
())
shouldBe
jEmptyObject
anyToJson
(
Map
(
"bla"
->
1337
))
shouldBe
(
"bla"
:=
1337
)
->:
jEmptyObject
}
@Test
def
testMapToJson
:
Unit
=
{
mapToJson
(
Map
())
shouldBe
jEmptyObject
mapToJson
(
Map
(
"bla"
->
1337
))
shouldBe
(
"bla"
:=
1337
)
->:
jEmptyObject
mapToJson
(
Map
(
"bla"
->
Map
()))
shouldBe
(
"bla"
:=
jEmptyObject
)
->:
jEmptyObject
mapToJson
(
Map
(
"bla"
->
Map
(
"nested"
->
1337
)))
shouldBe
(
"bla"
:=
((
"nested"
:=
1337
)
->:
jEmptyObject
))
->:
jEmptyObject
}
// Any to scala values
@Test
def
testAny2string
:
Unit
=
{
any2string
(
"bla"
)
shouldBe
"bla"
any2string
(
1337
)
shouldBe
"1337"
...
...
@@ -169,3 +221,81 @@ class TestConfigUtils extends TestNGSuite with MockitoSugar with Matchers {
}
}
}
object
TestConfigUtils
{
def
writeTemp
(
text
:
String
)
:
File
=
{
val
file
=
File
.
createTempFile
(
"TestConfigUtils."
,
".json"
)
val
w
=
new
PrintWriter
(
file
)
w
.
write
(
text
)
w
.
close
()
return
file
}
val
jsonText1
=
"""
|{
| "int": 1337,
| "double": 13.37,
| "string": "bla",
| "nested": {
| "1": 1,
| "2": 1
| },
| "list": ["a", "b", "c"],
| "dummy": { "dummy": 1}
|}
"""
.
stripMargin
val
file1
=
writeTemp
(
jsonText1
)
val
json1
=
{
(
"int"
:=
1337
)
->:
(
"double"
:=
13.37
)
->:
(
"string"
:=
"bla"
)
->:
(
"nested"
:=
((
"1"
:=
1
)
->:
(
"2"
:=
1
)
->:
jEmptyObject
))
->:
(
"list"
:=
List
(
"a"
,
"b"
,
"c"
))
->:
(
"dummy"
:=
(
"dummy"
:=
1
)
->:
jEmptyObject
)
->:
jEmptyObject
}
val
map1
=
Map
(
"int"
->
1337
,
"double"
->
13.37
,
"string"
->
"bla"
,
"nested"
->
Map
(
"1"
->
1
,
"2"
->
1
),
"list"
->
List
(
"a"
,
"b"
,
"c"
),
"dummy"
->
Map
(
"dummy"
->
1
))
val
jsonText2
=
"""
|{
| "int": 7331,
| "nested": {
| "2": 2,
| "3": 2
| },
| "dummy": 1
|}
"""
.
stripMargin
val
file2
=
writeTemp
(
jsonText2
)
val
json2
=
{
(
"int"
:=
7331
)
->:
(
"nested"
:=
((
"2"
:=
2
)
->:
(
"3"
:=
2
)
->:
jEmptyObject
))
->:
(
"dummy"
:=
1
)
->:
jEmptyObject
}
val
map2
=
Map
(
"int"
->
7331
,
"nested"
->
Map
(
"2"
->
2
,
"3"
->
2
),
"dummy"
->
1
)
val
corruptJson
=
"""
|{
| "int": 1337
| "double": 13.37
|}
"""
.
stripMargin
val
corruptFile
=
writeTemp
(
corruptJson
)
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment