add_controller_test.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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/wizard');
  20. require('controllers/main/service/add_controller');
  21. var addServiceController = null;
  22. describe('App.AddServiceController', function() {
  23. beforeEach(function () {
  24. addServiceController = App.AddServiceController.create({});
  25. });
  26. describe('#installAdditionalClients', function() {
  27. var t = {
  28. additionalClients: {
  29. componentName: "TEZ_CLIENT",
  30. hostNames: ["hostName1", "hostName2"]
  31. },
  32. additionalClientsWithoutHosts: {
  33. componentName: "TEZ_CLIENT",
  34. hostNames: []
  35. },
  36. RequestInfo: {
  37. "context": Em.I18n.t('requestInfo.installHostComponent') + ' ' + App.format.role("TEZ_CLIENT"),
  38. "query": "HostRoles/component_name=TEZ_CLIENT&HostRoles/host_name.in(hostName1,hostName2)"
  39. },
  40. Body: {
  41. HostRoles: {
  42. state: 'INSTALLED'
  43. }
  44. }
  45. };
  46. beforeEach(function () {
  47. sinon.spy($, 'ajax');
  48. sinon.stub(App, 'get', function(k) {
  49. if ('clusterName' === k) return 'tdk';
  50. return Em.get(App, k);
  51. });
  52. });
  53. afterEach(function () {
  54. $.ajax.restore();
  55. App.get.restore();
  56. });
  57. it('send request to install client', function () {
  58. addServiceController.set("content.additionalClients", [t.additionalClients]);
  59. addServiceController.installAdditionalClients();
  60. expect($.ajax.calledOnce).to.equal(true);
  61. expect(JSON.parse($.ajax.args[0][0].data).Body).to.deep.eql(t.Body);
  62. expect(JSON.parse($.ajax.args[0][0].data).RequestInfo).to.eql(t.RequestInfo);
  63. });
  64. it('should not send request to install client', function () {
  65. addServiceController.set("content.additionalClients", [t.additionalClientsWithoutHosts]);
  66. expect($.ajax.called).to.be.false;
  67. });
  68. });
  69. });