step1_controller_test.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. require('controllers/main/service/reassign/step1_controller');
  20. require('models/host_component');
  21. var testHelpers = require('test/helpers');
  22. describe('App.ReassignMasterWizardStep1Controller', function () {
  23. var controller = App.ReassignMasterWizardStep1Controller.create({
  24. content: Em.Object.create({
  25. reassign: Em.Object.create({}),
  26. services: []
  27. })
  28. });
  29. controller.set('_super', Em.K);
  30. describe('#loadConfigTags', function() {
  31. beforeEach(function() {
  32. this.stub = sinon.stub(App.router, 'get');
  33. });
  34. afterEach(function() {
  35. this.stub.restore();
  36. });
  37. it('tests loadConfigTags', function() {
  38. controller.loadConfigsTags();
  39. var args = testHelpers.findAjaxRequest('name', 'config.tags');
  40. expect(args).exists;
  41. });
  42. it('tests saveDatabaseType with type', function() {
  43. this.stub.returns({ saveDatabaseType: Em.K});
  44. controller.saveDatabaseType(true);
  45. expect(App.router.get.calledOnce).to.be.true;
  46. });
  47. it('tests saveDatabaseType without type', function() {
  48. this.stub.returns({ saveDatabaseType: Em.K});
  49. controller.saveDatabaseType(false);
  50. expect(App.router.get.called).to.be.false;
  51. });
  52. it('tests saveServiceProperties with properties', function() {
  53. this.stub.returns({ saveServiceProperties: Em.K});
  54. controller.saveServiceProperties(true);
  55. expect(App.router.get.calledOnce).to.be.true;
  56. });
  57. it('tests saveServiceProperties without properties', function() {
  58. this.stub.returns({ saveServiceProperties: Em.K});
  59. controller.saveServiceProperties(false);
  60. expect(App.router.get.called).to.be.false;
  61. });
  62. it('tests getDatabaseHost', function() {
  63. controller.set('content.serviceProperties', {
  64. 'javax.jdo.option.ConnectionURL': "jdbc:mysql://c6401/hive?createDatabaseIfNotExist=true"
  65. });
  66. controller.set('content.reassign.service_id', 'HIVE');
  67. controller.set('databaseType', 'mysql');
  68. expect(controller.getDatabaseHost()).to.equal('c6401')
  69. });
  70. });
  71. describe('#onLoadConfigs', function() {
  72. var reassignCtrl;
  73. beforeEach(function() {
  74. controller = App.ReassignMasterWizardStep1Controller.create({
  75. content: Em.Object.create({
  76. reassign: Em.Object.create({
  77. 'component_name': 'OOZIE_SERVER',
  78. 'service_id': 'OOZIE'
  79. }),
  80. services: []
  81. })
  82. });
  83. controller.set('_super', Em.K);
  84. sinon.stub(controller, 'getDatabaseHost', Em.K);
  85. sinon.stub(controller, 'saveDatabaseType', Em.K);
  86. sinon.stub(controller, 'saveServiceProperties', Em.K);
  87. reassignCtrl = App.router.reassignMasterController;
  88. reassignCtrl.set('content.hasManualSteps', true);
  89. });
  90. afterEach(function() {
  91. controller.getDatabaseHost.restore();
  92. controller.saveDatabaseType.restore();
  93. controller.saveServiceProperties.restore();
  94. });
  95. it('should not set hasManualSteps to false for oozie with derby db', function() {
  96. var data = {
  97. items: [
  98. {
  99. properties: {
  100. 'oozie.service.JPAService.jdbc.driver': 'jdbc:derby:${oozie.data.dir}/${oozie.db.schema.name}-db;create=true'
  101. }
  102. }
  103. ]
  104. };
  105. expect(reassignCtrl.get('content.hasManualSteps')).to.be.true;
  106. controller.onLoadConfigs(data);
  107. expect(reassignCtrl.get('content.hasManualSteps')).to.be.true;
  108. });
  109. it('should set hasManualSteps to false for oozie without derby db', function() {
  110. var data = {
  111. items: [
  112. {
  113. properties: {
  114. 'oozie.service.JPAService.jdbc.driver': 'mysql'
  115. }
  116. }
  117. ]
  118. };
  119. expect(reassignCtrl.get('content.hasManualSteps')).to.be.true;
  120. controller.onLoadConfigs(data);
  121. expect(reassignCtrl.get('content.hasManualSteps')).to.be.false;
  122. });
  123. });
  124. describe("#getConfigUrlParams()", function() {
  125. it("unknown component", function() {
  126. expect(controller.getConfigUrlParams("", {})).to.be.empty;
  127. });
  128. it("OOZIE_SERVER component", function() {
  129. var data = {
  130. Clusters: {
  131. desired_configs: {
  132. 'oozie-site': {
  133. tag: 'tag'
  134. },
  135. 'oozie-env': {
  136. tag: 'tag'
  137. }
  138. }
  139. }
  140. };
  141. expect(controller.getConfigUrlParams("OOZIE_SERVER", data)).to.eql([
  142. "(type=oozie-site&tag=tag)",
  143. "(type=oozie-env&tag=tag)"
  144. ]);
  145. });
  146. it("HIVE_SERVER component", function() {
  147. var data = {
  148. Clusters: {
  149. desired_configs: {
  150. 'hive-site': {
  151. tag: 'tag'
  152. },
  153. 'hive-env': {
  154. tag: 'tag'
  155. }
  156. }
  157. }
  158. };
  159. expect(controller.getConfigUrlParams("HIVE_SERVER", data)).to.eql([
  160. "(type=hive-site&tag=tag)",
  161. "(type=hive-env&tag=tag)"
  162. ]);
  163. });
  164. });
  165. describe("#onLoadConfigsTags()", function () {
  166. beforeEach(function () {
  167. this.mock = sinon.stub(controller, 'getConfigUrlParams');
  168. });
  169. afterEach(function () {
  170. this.mock.restore();
  171. });
  172. it("empty params", function () {
  173. this.mock.returns([]);
  174. controller.onLoadConfigsTags();
  175. var args = testHelpers.findAjaxRequest('name', 'reassign.load_configs');
  176. expect(args).not.exists;
  177. });
  178. it("correct params", function () {
  179. this.mock.returns(['p1', 'p2']);
  180. controller.onLoadConfigsTags();
  181. var args = testHelpers.findAjaxRequest('name', 'reassign.load_configs');
  182. expect(args[0]).exists;
  183. expect(args[0].sender).to.be.eql(controller);
  184. expect(args[0].data).to.be.eql({
  185. urlParams: 'p1|p2'
  186. });
  187. });
  188. });
  189. });