123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412 |
- /**
- * 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 Ember = require('ember');
- var App = require('app');
- require('controllers/global/background_operations_controller');
- require('views/common/modal_popup');
- require('utils/helper');
- require('utils/host_progress_popup');
- describe('App.HostPopup', function () {
- var services = [
- {
- displayName: "Start service WebHCat",
- hosts: [
- {
- logTasks: [
- {
- Tasks: {
- command: "START",
- host_name: "ip-10-12-123-90.ec2.internal",
- role: "WEBHCAT_SERVER",
- status: "QUEUED"
- },
- href: "http://ec2-54-224-233-43.compute-1.amazonaws.com:8080/api/v1/clusters/mycluster/requests/23/tasks/94"
- }
- ],
- name: "ip-10-12-123-90.ec2.internal",
- publicName: "ip-10-12-123-90.ec2.internal",
- serviceName: "Start service WebHCat"
- }
- ],
- isRunning: false
- },
- {
- displayName: "Start service Hive/HCat",
- hosts: [
- {
- logTasks: [
- {
- Tasks: {
- command: "INSTALL",
- host_name: "ip-10-12-123-90.ec2.internal",
- status: "COMPLETED"
- },
- href: "http://ec2-54-224-233-43.compute-1.amazonaws.com:8080/api/v1/clusters/mycluster/requests/15/tasks/76"
- }
- ],
- name: "ip-10-12-123-90.ec2.internal",
- publicName: "ip-10-12-123-90.ec2.internal",
- serviceName: "Start service Hive/HCat"
- },
- {
- logTasks: [
- {
- Tasks: {
- command: "START",
- host_name: "ip-10-33-7-23.ec2.internal",
- status: "COMPLETED"
- },
- href: "http://ec2-54-224-233-43.compute-1.amazonaws.com:8080/api/v1/clusters/mycluster/requests/15/tasks/78"
- },
- {
- Tasks: {
- command: "START",
- host_name: "ip-10-33-7-23.ec2.internal",
- status: "COMPLETED"
- },
- href: "http://ec2-54-224-233-43.compute-1.amazonaws.com:8080/api/v1/clusters/mycluster/requests/15/tasks/79"
- }
- ],
- name: "ip-10-33-7-23.ec2.internal",
- publicName: "ip-10-33-7-23.ec2.internal",
- serviceName: "Start service Hive/HCat"
- }
- ],
- isRunning: false
- }
- ];
- var test_tasks = [
- {
- t: [
- {
- Tasks: {
- status: 'COMPLETED',
- id: 2
- }
- },
- {
- Tasks: {
- status: 'COMPLETED',
- id: 3
- }
- },
- {
- Tasks: {
- status: 'COMPLETED',
- id: 1
- }
- }
- ],
- m: 'All COMPLETED',
- r: 'SUCCESS',
- p: 100,
- ids: [1,2,3]
- },
- {
- t: [
- {
- Tasks: {
- status: 'FAILED',
- id: 2
- }
- },
- {
- Tasks: {
- status: 'COMPLETED',
- id: 1
- }
- }
- ,
- {
- Tasks: {
- status: 'COMPLETED',
- id: 3
- }
- }
- ],
- m: 'One FAILED',
- r: 'FAILED',
- p: 100,
- ids: [1,2,3]
- },
- {
- t: [
- {
- Tasks: {
- status: 'ABORTED',
- id: 1
- }
- },
- {
- Tasks: {
- status: 'COMPLETED',
- id: 2
- }
- }
- ],
- m: 'One ABORTED',
- r: 'ABORTED',
- p: 100,
- ids: [1,2]
- },
- {
- t: [
- {
- Tasks: {
- status: 'TIMEDOUT',
- id: 3
- }
- },
- {
- Tasks: {
- status: 'COMPLETED',
- id: 1
- }
- }
- ],
- m: 'One TIMEDOUT',
- r: 'TIMEDOUT',
- p: 100,
- ids: [1,3]
- },
- {
- t: [
- {
- Tasks: {
- status: 'IN_PROGRESS',
- id: 1
- }
- },
- {
- Tasks: {
- status: 'COMPLETED',
- id: 2
- }
- }
- ],
- m: 'One IN_PROGRESS',
- r: 'IN_PROGRESS',
- p: 68,
- ids: [1,2]
- },
- {
- t: [
- {
- Tasks: {
- status: 'QUEUED',
- id: 2
- }
- },
- {
- Tasks: {
- status: 'COMPLETED',
- id: 3
- }
- }
- ],
- m: 'Something else',
- r: 'PENDING',
- p: 55,
- ids: [2,3]
- }
- ];
- describe('#setSelectCount', function () {
- var itemsForStatusTest = [
- {
- title: 'Empty',
- data: [],
- result: [0, 0, 0, 0, 0, 0, 0]
- },
- {
- title: 'All Pending',
- data: [
- {status: 'pending'},
- {status: 'queued'}
- ],
- result: [2, 2, 0, 0, 0, 0, 0]
- },
- {
- title: 'All Completed',
- data: [
- {status: 'success'},
- {status: 'completed'}
- ],
- result: [2, 0, 0, 0, 2, 0, 0]
- },
- {
- title: 'All Failed',
- data: [
- {status: 'failed'},
- {status: 'failed'}
- ],
- result: [2, 0, 0, 2, 0, 0, 0]
- },
- {
- title: 'All InProgress',
- data: [
- {status: 'in_progress'},
- {status: 'in_progress'}
- ],
- result: [2, 0, 2, 0, 0, 0, 0]
- },
- {
- title: 'All Aborted',
- data: [
- {status: 'aborted'},
- {status: 'aborted'}
- ],
- result: [2, 0, 0, 0, 0, 2, 0]
- },
- {
- title: 'All Timedout',
- data: [
- {status: 'timedout'},
- {status: 'timedout'}
- ],
- result: [2, 0, 0, 0, 0, 0, 2]
- },
- {
- title: 'Every Category',
- data: [
- {status: 'pending'},
- {status: 'queued'},
- {status: 'success'},
- {status: 'completed'},
- {status: 'failed'},
- {status: 'in_progress'},
- {status: 'aborted'},
- {status: 'timedout'}
- ],
- result: [8, 2, 1, 1, 2, 1, 1]
- }
- ];
- var categories = [
- Ember.Object.create({value: 'all'}),
- Ember.Object.create({value: 'pending'}),
- Ember.Object.create({value: 'in_progress'}),
- Ember.Object.create({value: 'failed'}),
- Ember.Object.create({value: 'completed'}),
- Ember.Object.create({value: 'aborted'}),
- Ember.Object.create({value: 'timedout'})
- ];
- itemsForStatusTest.forEach(function(statusTest) {
- it(statusTest.title, function() {
- App.HostPopup.setSelectCount(statusTest.data, categories);
- expect(categories.mapProperty('count')).to.deep.equal(statusTest.result);
- });
- });
- });
- describe('#getStatus', function() {
- test_tasks.forEach(function(test_task) {
- it(test_task.m, function() {
- expect(App.HostPopup.getStatus(test_task.t)[0]).to.equal(test_task.r);
- });
- });
- });
- describe('#getProgress', function() {
- test_tasks.forEach(function(test_task) {
- it(test_task.m, function() {
- expect(App.HostPopup.getProgress(test_task.t)).to.equal(test_task.p);
- });
- });
- });
- describe('#abortRequest', function () {
- beforeEach(function () {
- sinon.stub(App.ajax, 'send', Em.K);
- sinon.spy(App, 'showConfirmationPopup');
- App.HostPopup.createPopup();
- });
- afterEach(function () {
- App.HostPopup.get('isPopup').hide();
- App.ajax.send.restore();
- App.showConfirmationPopup.restore();
- });
- it('should show confirmation popup', function () {
- App.HostPopup.get('isPopup.bodyClass').create().abortRequest({
- context: Em.Object.create({
- name: 'name'
- })
- });
- expect(App.showConfirmationPopup.calledOnce).to.be.true;
- });
- });
- describe('#abortRequestSuccessCallback', function () {
- beforeEach(function () {
- App.HostPopup.createPopup();
- sinon.spy(App.ModalPopup, 'show');
- });
- afterEach(function () {
- App.HostPopup.get('isPopup').hide();
- App.ModalPopup.show.restore();
- });
- it('should open popup', function () {
- App.HostPopup.get('isPopup.bodyClass').create().abortRequestSuccessCallback(null, null, {
- requestName: 'name'
- });
- expect(App.ModalPopup.show.calledOnce).to.be.true;
- });
- });
- describe('#abortRequestErrorCallback', function () {
- var popup = App.HostPopup.createPopup();
- beforeEach(function () {
- sinon.stub(App.ajax, 'get', function(k) {
- if (k === 'modalPopup') return null;
- return Em.get(App, k);
- });
- sinon.spy(App.ModalPopup, 'show');
- sinon.stub(popup, 'get', function(k) {
- if (k === 'abortedRequests') return [0];
- return Em.get(popup, k);
- });
- popup.get('bodyClass').create().abortRequestErrorCallback({
- responseText: {
- message: 'message'
- },
- status: 404
- }, 'status', 'error', {
- url: 'url'
- }, {
- requestId: 0
- });
- });
- afterEach(function () {
- App.HostPopup.get('isPopup').hide();
- App.ModalPopup.show.restore();
- popup.get.restore();
- App.ajax.get.restore();
- });
- it('should open popup', function () {
- expect(App.ModalPopup.show.calledOnce).to.be.true;
- });
- it('should remove current request id from abortedRequests', function () {
- expect(App.HostPopup.get('abortedRequests')).to.be.empty;
- });
- });
- });
|