Skip to content

Instantly share code, notes, and snippets.

@daliborfilus
Last active December 20, 2015 00:08
Show Gist options
  • Save daliborfilus/6039088 to your computer and use it in GitHub Desktop.
Save daliborfilus/6039088 to your computer and use it in GitHub Desktop.
ElasticSearch test 0.90.0, 0.90.2 JSON/YAML with empty strings
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.test.unit.common.settings.loader;
import org.elasticsearch.common.settings.Settings;
import org.testng.annotations.Test;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
*
*/
public class JsonSettingsLoaderTests {
@Test
public void testSimpleJsonSettings() throws Exception {
Settings settings = settingsBuilder()
.loadFromClasspath("org/elasticsearch/test/unit/common/settings/loader/test-settings.json")
.build();
assertThat(settings.get("test1.value1"), equalTo("value1"));
assertThat(settings.get("test1.test2.value2"), equalTo("value2"));
assertThat(settings.getAsInt("test1.test2.value3", -1), equalTo(2));
// check array
assertThat(settings.get("test1.test3.0"), equalTo("test3-1"));
assertThat(settings.get("test1.test3.1"), equalTo("test3-2"));
assertThat(settings.getAsArray("test1.test3").length, equalTo(2));
assertThat(settings.getAsArray("test1.test3")[0], equalTo("test3-1"));
assertThat(settings.getAsArray("test1.test3")[1], equalTo("test3-2"));
// check correct difference between string and null
assertThat(settings.get("test5"), equalTo(null));
assertThat(settings.get("test4"), equalTo(""));
}
}
JSON:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.elasticsearch.test.unit.common.settings.loader.JsonSettingsLoaderTests
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@55d15445
[2013-07-19 15:27:27,486][INFO ][test ] ==> Test Starting [unit.common.settings.loader.JsonSettingsLoaderTests#testSimpleJsonSettings]
[2013-07-19 15:27:27,644][ERROR][test ] ==> Test Failure [unit.common.settings.loader.JsonSettingsLoaderTests#testSimpleJsonSettings]
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.891 sec <<< FAILURE!
testSimpleJsonSettings(org.elasticsearch.test.unit.common.settings.loader.JsonSettingsLoaderTests) Time elapsed: 174 sec <<< FAILURE!
java.lang.AssertionError:
Expected: ""
but: was null
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:8)
at org.elasticsearch.test.unit.common.settings.loader.JsonSettingsLoaderTests.testSimpleJsonSettings(JsonSettingsLoaderTests.java:51)
Results :
Failed tests: testSimpleJsonSettings(org.elasticsearch.test.unit.common.settings.loader.JsonSettingsLoaderTests): (..)
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.030s
[INFO] Finished at: Fri Jul 19 15:27:27 CEST 2013
[INFO] Final Memory: 12M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.3:test (default-test) on project elasticsearch: There are test failures.
[ERROR]
[ERROR] Please refer to /Users/noice/code/java/elasticsearch/target/surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
YAML:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.elasticsearch.test.unit.common.settings.loader.YamlSettingsLoaderTests
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@41fc2fb
[2013-07-19 15:23:42,555][INFO ][test ] ==> Test Starting [unit.common.settings.loader.YamlSettingsLoaderTests#testSimpleYamlSettings]
[2013-07-19 15:23:42,750][INFO ][test ] ==> Test Success [unit.common.settings.loader.YamlSettingsLoaderTests#testSimpleYamlSettings]
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.874 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.109s
[INFO] Finished at: Fri Jul 19 15:23:43 CEST 2013
[INFO] Final Memory: 12M/81M
[INFO] ------------------------------------------------------------------------
JSON:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.elasticsearch.test.unit.common.settings.loader.JsonSettingsLoaderTests
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@41fc2fb
[2013-07-19 15:56:09,474][INFO ][test ] ==> Test Starting [unit.common.settings.loader.JsonSettingsLoaderTests#testSimpleJsonSettings]
[2013-07-19 15:56:09,913][ERROR][test ] ==> Test Failure [unit.common.settings.loader.JsonSettingsLoaderTests#testSimpleJsonSettings]
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 1.641 sec <<< FAILURE!
testSimpleJsonSettings(org.elasticsearch.test.unit.common.settings.loader.JsonSettingsLoaderTests) Time elapsed: 444 sec <<< FAILURE!
java.lang.AssertionError:
Expected: ""
but: was null
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:8)
at org.elasticsearch.test.unit.common.settings.loader.JsonSettingsLoaderTests.testSimpleJsonSettings(JsonSettingsLoaderTests.java:53)
Results :
Failed tests: testSimpleJsonSettings(org.elasticsearch.test.unit.common.settings.loader.JsonSettingsLoaderTests): (..)
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:38.376s
[INFO] Finished at: Fri Jul 19 15:56:10 CEST 2013
[INFO] Final Memory: 18M/114M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.3:test (default-test) on project elasticsearch: There are test failures.
[ERROR]
[ERROR] Please refer to /Users/noice/code/java/elasticsearch/target/surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
YAML:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.elasticsearch.test.unit.common.settings.loader.YamlSettingsLoaderTests
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@4139eeda
[2013-07-19 16:00:59,691][INFO ][test ] ==> Test Starting [unit.common.settings.loader.YamlSettingsLoaderTests#testSimpleYamlSettings]
[2013-07-19 16:00:59,898][INFO ][test ] ==> Test Success [unit.common.settings.loader.YamlSettingsLoaderTests#testSimpleYamlSettings]
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.017 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- forbiddenapis:1.3:check (check-forbidden-apis) @ elasticsearch ---
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar
Downloaded: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar (165 KB at 63.0 KB/sec)
[INFO] Reading bundled API signatures: jdk-unsafe
[INFO] Reading bundled API signatures: jdk-deprecated
[INFO] Reading API signatures: /Users/noice/code/java/elasticsearch/core-signatures.txt
[INFO] Loading classes to check...
[INFO] Scanning for API signatures and dependencies...
[INFO] Scanned 4419 (and 1152 related) class file(s) for forbidden API invocations (in 6.85s), 0 error(s).
[INFO]
[INFO] --- forbiddenapis:1.3:testCheck (check-forbidden-test-apis) @ elasticsearch ---
[INFO] Reading bundled API signatures: jdk-unsafe
[INFO] Reading bundled API signatures: jdk-deprecated
[INFO] Loading classes to check...
[INFO] Scanning for API signatures and dependencies...
[INFO] Scanned 577 (and 1299 related) class file(s) for forbidden API invocations (in 1.96s), 0 error(s).
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 21.671s
[INFO] Finished at: Fri Jul 19 16:01:11 CEST 2013
[INFO] Final Memory: 13M/123M
[INFO] ------------------------------------------------------------------------
{
test1:{
value1:"value1",
test2:{
value2:"value2",
value3:2
},
test3:["test3-1", "test3-2"],
test4: "",
test5: null
}
}
test1:
value1: value1
test2:
value2: value2
value3: 2
test3:
- test3-1
- test3-2
test4: ""
test5: null
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.test.unit.common.settings.loader;
import org.elasticsearch.common.settings.Settings;
import org.testng.annotations.Test;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
*
*/
public class YamlSettingsLoaderTests {
@Test
public void testSimpleYamlSettings() throws Exception {
Settings settings = settingsBuilder()
.loadFromClasspath("org/elasticsearch/test/unit/common/settings/loader/test-settings.yml")
.build();
assertThat(settings.get("test1.value1"), equalTo("value1"));
assertThat(settings.get("test1.test2.value2"), equalTo("value2"));
assertThat(settings.getAsInt("test1.test2.value3", -1), equalTo(2));
// check array
assertThat(settings.get("test1.test3.0"), equalTo("test3-1"));
assertThat(settings.get("test1.test3.1"), equalTo("test3-2"));
assertThat(settings.getAsArray("test1.test3").length, equalTo(2));
assertThat(settings.getAsArray("test1.test3")[0], equalTo("test3-1"));
assertThat(settings.getAsArray("test1.test3")[1], equalTo("test3-2"));
// check correct difference between string and null
assertThat(settings.get("test1.test5"), equalTo(null));
assertThat(settings.get("test1.test4"), equalTo(""));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment