-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow some more File tests to run on Native (#408)
* Added PublicApiFileTest for JVM/Native * Add PublicApiFileTest
- Loading branch information
Showing
6 changed files
with
218 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
sconfig/jvm-native/src/test/scala/org/ekrich/config/impl/PublicApiFileTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/** | ||
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com> | ||
*/ | ||
package org.ekrich.config.impl | ||
|
||
import org.junit.Assert._ | ||
import org.junit._ | ||
|
||
import org.ekrich.config._ | ||
|
||
import FileUtils._ | ||
|
||
/** | ||
* Most of the File tests should work but internally and externally they use URL | ||
* and Native doesn't support URL. Once the API use URI internally more test | ||
* support should be available. | ||
*/ | ||
class PublicApiFileTest extends TestUtils { | ||
|
||
// dupe in PublicApiTest | ||
private def assertNotFound(e: ConfigException): Unit = { | ||
assertTrue( | ||
"Message text: " + e.getMessage, | ||
e.getMessage.contains("No such") || | ||
e.getMessage.contains("not found") || | ||
e.getMessage.contains("were found") || | ||
e.getMessage.contains("java.io.FileNotFoundException") | ||
) | ||
} | ||
|
||
@Test | ||
def allowMissing(): Unit = { | ||
val e = intercept[ConfigException.IO] { | ||
ConfigFactory.parseFile( | ||
resourceFile("nonexistent.conf"), | ||
ConfigParseOptions.defaults.setAllowMissing(false) | ||
) | ||
} | ||
assertNotFound(e) | ||
|
||
val conf = ConfigFactory.parseFile( | ||
resourceFile("nonexistent.conf"), | ||
ConfigParseOptions.defaults.setAllowMissing(true) | ||
) | ||
assertTrue("is empty", conf.isEmpty) | ||
} | ||
|
||
@Test | ||
def allowMissingFileAnySyntax(): Unit = { | ||
val e = intercept[ConfigException.IO] { | ||
ConfigFactory.parseFileAnySyntax( | ||
resourceFile("nonexistent"), | ||
ConfigParseOptions.defaults.setAllowMissing(false) | ||
) | ||
} | ||
assertNotFound(e) | ||
|
||
val conf = ConfigFactory.parseFileAnySyntax( | ||
resourceFile("nonexistent"), | ||
ConfigParseOptions.defaults.setAllowMissing(true) | ||
) | ||
assertTrue("is empty", conf.isEmpty) | ||
} | ||
|
||
@Test | ||
def anySyntaxJvmNative(): Unit = { | ||
// Kept in JVM as anySyntax() this is only a partial test | ||
// as resource loading not supported yet in Native | ||
|
||
// test01 has all three syntaxes; first load with basename | ||
val conf = ConfigFactory.parseFileAnySyntax( | ||
resourceFile("test01"), | ||
ConfigParseOptions.defaults | ||
) | ||
assertEquals(42, conf.getInt("ints.fortyTwo")) | ||
assertEquals("A", conf.getString("fromJsonA")) | ||
assertEquals("true", conf.getString("fromProps.bool")) | ||
|
||
// now include a suffix, should only load one of them | ||
val onlyProps = ConfigFactory.parseFileAnySyntax( | ||
resourceFile("test01.properties"), | ||
ConfigParseOptions.defaults | ||
) | ||
assertFalse(onlyProps.hasPath("ints.fortyTwo")) | ||
assertFalse(onlyProps.hasPath("fromJsonA")) | ||
assertEquals("true", onlyProps.getString("fromProps.bool")) | ||
|
||
// force only one syntax via options | ||
val onlyPropsViaOptions = ConfigFactory.parseFileAnySyntax( | ||
resourceFile("test01.properties"), | ||
ConfigParseOptions.defaults.setSyntax(ConfigSyntax.PROPERTIES) | ||
) | ||
assertFalse(onlyPropsViaOptions.hasPath("ints.fortyTwo")) | ||
assertFalse(onlyPropsViaOptions.hasPath("fromJsonA")) | ||
assertEquals("true", onlyPropsViaOptions.getString("fromProps.bool")) | ||
|
||
// TODO: continue test when resourse work on native | ||
// val fromResources = ConfigFactory.parseResourcesAnySyntax( | ||
// classOf[PublicApiFileTest], | ||
// "/test01", | ||
// ConfigParseOptions.defaults | ||
// ) | ||
// assertEquals(42, fromResources.getInt("ints.fortyTwo")) | ||
// assertEquals("A", fromResources.getString("fromJsonA")) | ||
// assertEquals("true", fromResources.getString("fromProps.bool")) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
{ | ||
"ints" : { | ||
"fortyTwo" : 42, | ||
"fortyTwoAgain" : ${ints.fortyTwo} | ||
}, | ||
|
||
"floats" : { | ||
"fortyTwoPointOne" : 42.1, | ||
"fortyTwoPointOneAgain" : ${floats.fortyTwoPointOne}, | ||
"pointThirtyThree": .33 | ||
"pointThirtyThreeAgain": ${floats.pointThirtyThree} | ||
}, | ||
|
||
"strings" : { | ||
"abcd" : "abcd", | ||
"abcdAgain" : ${strings.a}${strings.b}${strings.c}${strings.d}, | ||
"a" : "a", | ||
"b" : "b", | ||
"c" : "c", | ||
"d" : "d", | ||
"concatenated" : null bar 42 baz true 3.14 hi, | ||
"double" : "3.14", | ||
"doubleStartingWithDot": ".33", | ||
"number" : "57", | ||
"null" : "null", | ||
"true" : "true", | ||
"yes" : "yes", | ||
"false" : "false", | ||
"no" : "no" | ||
}, | ||
|
||
"arrays" : { | ||
"empty" : [], | ||
"ofInt" : [1, 2, 3], | ||
"ofString" : [ ${strings.a}, ${strings.b}, ${strings.c} ], | ||
"ofDouble" : [3.14, 4.14, 5.14], | ||
"ofNull" : [null, null, null], | ||
"ofBoolean" : [true, false], | ||
"ofArray" : [${arrays.ofString}, ${arrays.ofString}, ${arrays.ofString}], | ||
"ofObject" : [${ints}, ${booleans}, ${strings}], | ||
"firstElementNotASubst" : [ "a", ${strings.b} ] | ||
}, | ||
|
||
"booleans" : { | ||
"true" : true, | ||
"trueAgain" : ${booleans.true}, | ||
"false" : false, | ||
"falseAgain" : ${booleans.false} | ||
}, | ||
|
||
"nulls" : { | ||
"null" : null, | ||
"nullAgain" : ${nulls.null} | ||
}, | ||
|
||
"durations" : { | ||
"second" : 1s, | ||
"secondsList" : [1s,2seconds,3 s, 4000], | ||
"secondAsNumber" : 1000, | ||
"halfSecond" : 0.5s, | ||
"millis" : 1 milli, | ||
"micros" : 2000 micros, | ||
"largeNanos" : 4878955355435272204ns, | ||
"plusLargeNanos" : "+4878955355435272204ns", | ||
"minusLargeNanos" : -4878955355435272204ns | ||
}, | ||
|
||
"periods" : { | ||
"day" : 1d, | ||
"dayAsNumber": 2, | ||
"week": 3 weeks, | ||
"month": 5 mo, | ||
"year": 8y | ||
}, | ||
|
||
"memsizes" : { | ||
"meg" : 1M, | ||
"megsList" : [1M, 1024K, 1048576], | ||
"megAsNumber" : 1048576, | ||
"halfMeg" : 0.5M | ||
}, | ||
|
||
"system" : { | ||
"javaversion" : ${?java.version}, | ||
"userhome" : ${?user.home}, | ||
"home" : ${?HOME}, | ||
"pwd" : ${?PWD}, | ||
"shell" : ${?SHELL}, | ||
"lang" : ${?LANG}, | ||
"path" : ${?PATH}, | ||
"not_here" : ${?NOT_HERE}, | ||
"concatenated" : Your Java version is ${?system.javaversion} and your user.home is ${?system.userhome} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"fromJson1" : 1, | ||
"fromJsonA" : "A" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# .properties file | ||
fromProps.abc=abc | ||
fromProps.one=1 | ||
fromProps.bool=true | ||
fromProps.specialChars=hello^^ |