[ambari] branch trunk updated: AMBARI-25116. Bug at AbstractProviderModule class (dlysnichenko) (#2774)
This is an automated email from the ASF dual-hosted git repository. dmitriusan pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ambari.git The following commit(s) were added to refs/heads/trunk by this push: new 10f955b AMBARI-25116. Bug at AbstractProviderModule class (dlysnichenko) (#2774) 10f955b is described below commit 10f955b8da9283a41deceb34387dbb7b71bc46e2 Author: Lisnichenko Dmitro AuthorDate: Tue Jan 22 17:43:34 2019 +0200 AMBARI-25116. Bug at AbstractProviderModule class (dlysnichenko) (#2774) * AMBARI-25116. Bug at AbstractProviderModule class (dlysnichenko) * Fix mocks (test hangs on jenkins due to console input prompt) at TestSensitiveDataEncryption.py --- .../controller/internal/AbstractProviderModule.java | 14 -- .../src/test/python/TestSensitiveDataEncryption.py | 16 +++- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java index cbafea7..90c0616 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java @@ -18,6 +18,7 @@ package org.apache.ambari.server.controller.internal; +import static java.util.Collections.emptyMap; import static org.apache.ambari.server.controller.metrics.MetricsServiceProvider.MetricsService.GANGLIA; import static org.apache.ambari.server.controller.metrics.MetricsServiceProvider.MetricsService.TIMELINE_METRICS; @@ -968,13 +969,14 @@ public abstract class AbstractProviderModule implements ProviderModule, ConfigurationResourceProvider.TYPE, ConfigurationResourceProvider.TAG), configPredicate); } catch (NoSuchResourceException e) { - LOG.info("Resource for the desired config not found. " + e); - return Collections.emptyMap(); + LOG.info("Resource for the desired config not found.", e); + return emptyMap(); } -for (Resource res : configResources) { - return res.getPropertiesMap().get(PROPERTIES_CATEGORY); -} -return Collections.emptyMap(); +return configResources.stream() +.findFirst() +.map(res -> res.getPropertiesMap() +.get(PROPERTIES_CATEGORY)) +.orElse(emptyMap()); } private Map getDesiredConfigMap(String clusterName, String versionTag, diff --git a/ambari-server/src/test/python/TestSensitiveDataEncryption.py b/ambari-server/src/test/python/TestSensitiveDataEncryption.py index 4e839c4..8ff6588 100644 --- a/ambari-server/src/test/python/TestSensitiveDataEncryption.py +++ b/ambari-server/src/test/python/TestSensitiveDataEncryption.py @@ -488,7 +488,8 @@ class TestSensitiveDataEncryption(TestCase): @patch("ambari_server.setupSecurity.is_root") @patch("ambari_server.setupSecurity.sensitive_data_encryption") @patch("ambari_server.setupSecurity.get_is_secure") - def test_reset_master_key_persisted(self, get_is_secure_method, sensitive_data_encryption_metod, is_root_method, + @patch("ambari_server.setupSecurity.get_is_persisted") + def test_reset_master_key_persisted(self, get_is_persisted_method, get_is_secure_method, sensitive_data_encryption_metod, is_root_method, get_ambari_properties_method, search_file_message, get_YN_input_method, save_master_key_method, update_properties_method, @@ -511,6 +512,7 @@ class TestSensitiveDataEncryption(TestCase): master_key = "aaa" +get_is_persisted_method.return_value = (True, "filepath") get_is_secure_method.return_value = True get_YN_input_method.side_effect = [False, True, True] read_master_key_method.return_value = master_key @@ -518,7 +520,6 @@ class TestSensitiveDataEncryption(TestCase): save_passwd_for_alias_method.return_value = 0 exists_mock.return_value = False - options = self._create_empty_options_mock() setup_sensitive_data_encryption(options) calls = [call(options, "decryption"), call(options, "encryption")] @@ -547,7 +548,6 @@ class TestSensitiveDataEncryption(TestCase): self.assertEquals(sorted_x, sorted_y) pass - @patch("ambari_server.setupSecurity.read_master_key") @patch("os.path.exists") @patch("ambari_server.setupSecurity.read_ambari_user") @patch("ambari_server.setupSecurity.save_passwd_for_alias") @@ -559,13 +559,13 @@ class TestSensitiveDataEncryption(TestCase): @patch("ambari_server.setupSecurity.is_root") @patch("ambari_server.setupSecurity.sensitive_data_encryption") @patch("ambari_server.setupSecurity.get_is_secure") - def test_decrypt_sensitive_data(self, get_is_secure_m
[ambari] branch trunk updated: AMBARI-25112 Cover errors utils with unit tests. (ababiichuk)
This is an automated email from the ASF dual-hosted git repository. ababiichuk pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ambari.git The following commit(s) were added to refs/heads/trunk by this push: new 3ad2ab8 AMBARI-25112 Cover errors utils with unit tests. (ababiichuk) 3ad2ab8 is described below commit 3ad2ab8fb49e4f330fa4b4a2e23c8c68de27f161 Author: aBabiichuk AuthorDate: Tue Jan 22 18:38:40 2019 +0200 AMBARI-25112 Cover errors utils with unit tests. (ababiichuk) --- ambari-web/app/assets/test/tests.js | 2 + ambari-web/test/utils/errors/assertions_test.js | 654 +++ ambari-web/test/utils/errors/definitions_test.js | 127 + 3 files changed, 783 insertions(+) diff --git a/ambari-web/app/assets/test/tests.js b/ambari-web/app/assets/test/tests.js index 68ce6c1..e1808da 100644 --- a/ambari-web/app/assets/test/tests.js +++ b/ambari-web/app/assets/test/tests.js @@ -233,6 +233,8 @@ var files = [ 'test/utils/db_test', 'test/utils/ember_computed_test', 'test/utils/ember_reopen_test', + 'test/utils/errors/assertions_test', + 'test/utils/errors/definitions_test', 'test/utils/form_field_test', 'test/utils/file_utils_test', 'test/utils/handlebars_helpers_test', diff --git a/ambari-web/test/utils/errors/assertions_test.js b/ambari-web/test/utils/errors/assertions_test.js new file mode 100644 index 000..276deba --- /dev/null +++ b/ambari-web/test/utils/errors/assertions_test.js @@ -0,0 +1,654 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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. + */ + +var App = require('app'); +require('utils/errors/assertions'); + +describe('Error assertions', function () { + describe('#App.assert', function () { +var errorCases = [ + { +args: [null, false], +errorType: Error, +desc: '', +title: 'default error object, no description' + }, + { +args: ['desc0', false], +errorType: Error, +desc: ' Info: desc0', +title: 'default error object, custom description' + }, + { +args: [null, false, TypeError], +errorType: TypeError, +desc: '', +title: 'custom error object, no description' + }, + { +args: ['desc1', false, TypeError], +errorType: TypeError, +desc: ' Info: desc1', +title: 'custom error object, custom description' + } +]; +errorCases.forEach(function (test) { + it(test.title, function () { +var testFunction = function () { + App.assert.apply(null, test.args); +}; +expect(testFunction).to.throw(test.errorType, test.desc); + }); +}); +it('no error', function () { + expect(App.assert.bind(null, 'desc2', true)).to.not.throw(); +}); + }); + + describe('#App.assertExists', function () { +var errorCases = [ +{ + value: null, + desc: 'desc0', + title: 'null' +}, +{ + value: undefined, + desc: 'desc1', + title: 'undefined' +} + ], + noErrorCases = [ +{ + value: [], + title: 'empty array' +}, +{ + value: [0], + title: 'non-empty array' +}, +{ + value: {}, + title: 'empty object' +}, +{ + value: { +a: '' + }, + title: 'non-empty object' +}, +{ + value: Em.Object.create(), + title: 'empty Ember object' +}, +{ + value: Em.Object.create({ +a: '' + }), + title: 'non-empty Ember object' +}, +{ + value: 0, + title: '0' +}, +{ + value: 1, + title: 'non-zero number' +}, +{ + value: NaN, + title: 'NaN' +}, +{ + value: Infinity, + title: 'Infinity' +}, +{ + value: false, + title: 'false' +}, +{ + value: true, + title: 'true' +}, +{ + value: '', + title: 'empty string'