Просмотр исходного кода

AMBARI-5464. Add unit tests for jobs controllers/views. (akovalenko)

Aleksandr Kovalenko 11 лет назад
Родитель
Сommit
e124c7d809

+ 4 - 0
ambari-web/app/assets/test/tests.js

@@ -47,6 +47,8 @@ require('test/controllers/main/service/reassign_controller_test');
 require('test/controllers/main/dashboard_test');
 require('test/controllers/main/host_test');
 require('test/controllers/main/item_test');
+require('test/controllers/main/jobs_controller_test');
+require('test/controllers/main/jobs/hive_job_details_controller_test');
 require('test/controllers/main/service_test');
 require('test/controllers/wizard/stack_upgrade/step3_controller_test');
 require('test/controllers/installer_test');
@@ -115,7 +117,9 @@ require('test/views/main/dashboard/widgets/namenode_cpu_test');
 require('test/views/main/host/summary_test');
 require('test/views/main/host/details/host_component_view_test');
 require('test/views/main/host/details/host_component_views/decommissionable_test');
+require('test/views/main/jobs_view_test');
 require('test/views/main/jobs/hive_job_details_tez_dag_view_test');
+require('test/views/main/jobs/hive_job_details_view_test');
 require('test/views/main/charts/heatmap/heatmap_host_test');
 require('test/views/main/charts/heatmap/heatmap_rack_test');
 require('test/views/main/service/info/config_test');

+ 68 - 0
ambari-web/test/controllers/main/jobs/hive_job_details_controller_test.js

@@ -0,0 +1,68 @@
+/**
+ * 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');
+var jobsUtils = require('utils/jobs');
+require('models/service/yarn');
+require('mappers/jobs/hive_job_mapper');
+require('utils/ajax/ajax');
+require('utils/http_client');
+require('models/jobs/tez_dag');
+require('controllers/main/jobs/hive_job_details_controller');
+
+describe('App.MainHiveJobDetailsController', function () {
+  var yarnService = {
+    id: 'YARN',
+    ahsWebPort: 8188
+  };
+  App.store.load(App.YARNService, yarnService);
+  var job = {
+    id: 'hrt_qa_20140311131919_1d932567-71c2-4341-9b50-6df1f58a9114',
+    queryText: 'show tables',
+    name: 'hrt_qa_20140311131919_1d932567-71c2-4341-9b50-6df1f58a9114',
+    user: ['hrt_qa'],
+    hasTezDag: true,
+    failed: false,
+    startTime: 1394569191001,
+    jobType: 'hive',
+    tezDag: {
+      id: 'hrt_qa_20140311131919_1d932567-71c2-4341-9b50-6df1f58a9114:1',
+      instanceId: 'dag_1394502141829_0425_1',
+      name: 'hrt_qa_20140311131919_1d932567-71c2-4341-9b50-6df1f58a9114:1',
+      yarnApplicationId: 'application_1395263571423_0014',
+      stage: 'Stage-1'
+    }
+  };
+  var mainHiveJobDetailsController = App.MainHiveJobDetailsController.create({
+    job: Ember.Object.create(job),
+    content: {
+      id: 'id'
+    }
+  });
+  mainHiveJobDetailsController.set('job', mainHiveJobDetailsController.get('content'));
+  describe('#loaded', function () {
+    it('content loading from model', function () {
+      jobsUtils.refreshHiveJobDetails = function (hiveJob, successCallback, errorCallback) {
+        successCallback();
+      };
+      mainHiveJobDetailsController.loadJobDetails();
+      expect(mainHiveJobDetailsController.get('loaded')).to.equal(true);
+      expect(mainHiveJobDetailsController.get('content.id')).to.equal(mainHiveJobDetailsController.get('job.id'));
+    });
+  });
+});

+ 118 - 0
ambari-web/test/controllers/main/jobs_controller_test.js

@@ -0,0 +1,118 @@
+/**
+ * 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('mappers/jobs/hive_jobs_mapper');
+require('models/service/yarn');
+require('models/jobs/job');
+require('models/jobs/hive_job');
+require('controllers/main/jobs_controller');
+
+describe('App.MainJobsController', function () {
+  var mainJobsController = App.MainJobsController.create();
+  var filterObject = mainJobsController.get('filterObject');
+  describe('#totalOfJobs', function () {
+    it('should be equal to content.length', function () {
+      mainJobsController.set('content', [
+        Ember.Object.create({
+          id: 'id0',
+          queryText: 'show tables',
+          name: 'id0',
+          user: ['user1'],
+          hasTezDag: true,
+          failed: false,
+          startTime: 1393443850756,
+          endTime: 1393443875265,
+          tezDagId: 'id0:1'
+        })
+      ]);
+      expect(mainJobsController.get('totalOfJobs')).to.equal(1);
+    });
+  });
+  describe('#sortingDone', function () {
+    it('should be true after automatically ran sorting', function () {
+      expect(mainJobsController.get('sortingDone')).to.equal(true);
+    });
+  });
+  describe('#sortProperty', function () {
+    it('should change according to sortingColumn.name', function () {
+      mainJobsController.set('sortingColumn').set('name', 'id');
+      expect(mainJobsController.get('sortProperty')).to.equal('id');
+    });
+  });
+  describe('#sortAscending', function () {
+    it('sorting should be ascending as default', function () {
+      mainJobsController.set('sortingColumn').set('status', '');
+      expect(mainJobsController.get('sortAscending')).to.equal(true);
+    });
+  });
+  describe('#filterObject.isIdFilterApplied', function () {
+    it('should be true if id field is not empty', function () {
+      filterObject.set('id', 'some_id');
+      expect(filterObject.get('isIdFilterApplied')).to.equal(true);
+    });
+  });
+  describe('#filterObject.isAnyFilterApplied', function () {
+    it('should be true if id field is not empty', function () {
+      filterObject.createJobsFiltersLink();
+      expect(filterObject.get('isAnyFilterApplied')).to.equal(true);
+    });
+  });
+  describe('#sortedContent', function () {
+    it('sorting by different properties', function () {
+      mainJobsController.get('content').push(Ember.Object.create({
+        id: 'id1',
+        queryText: 'show tables',
+        name: 'id1',
+        user: ['user0'],
+        failed: false,
+        startTime: 1393443850757,
+        endTime: 1393443875264,
+        tezDagId: null
+      }));
+      mainJobsController.contentAndSortUpdater();
+      expect(mainJobsController.get('sortedContent')[0].get('user')).to.eql(['user1']);
+      mainJobsController.toggleProperty('sortAscending');
+      mainJobsController.contentAndSortUpdater();
+      expect(mainJobsController.get('sortedContent')[0].get('user')).to.eql(['user0']);
+      mainJobsController.set('sortProperty', 'user');
+      mainJobsController.contentAndSortUpdater();
+      expect(mainJobsController.get('sortedContent')[0].get('id')).to.equal('id0');
+      mainJobsController.get('content').push(Ember.Object.create({
+        id: 'id2',
+        queryText: 'show tables',
+        name: 'id2',
+        user: ['user2'],
+        failed: false,
+        startTime: 1393443850758,
+        endTime: 1393443875263,
+        tezDagId: null
+      }));
+      mainJobsController.contentAndSortUpdater();
+      mainJobsController.set('sortProperty', 'startTime');
+      expect(mainJobsController.get('sortedContent')[0].get('id')).to.equal('id2');
+      mainJobsController.set('sortProperty', 'endTime');
+      mainJobsController.contentAndSortUpdater();
+      expect(mainJobsController.get('sortedContent')[0].get('id')).to.equal('id0');
+      mainJobsController.set('sortProperty', 'duration');
+      mainJobsController.toggleProperty('sortAscending');
+      mainJobsController.contentAndSortUpdater();
+      expect(mainJobsController.get('sortedContent')[0].get('user')).to.eql(['user1']);
+    });
+  });
+});

Разница между файлами не показана из-за своего большого размера
+ 59 - 0
ambari-web/test/views/main/jobs/hive_job_details_view_test.js


+ 102 - 0
ambari-web/test/views/main/jobs_view_test.js

@@ -0,0 +1,102 @@
+/**
+ * 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('views/main/jobs_view');
+
+describe('App.MainJobsView', function () {
+  var mainJobsView = App.MainJobsView.create({
+    controller: Ember.Object.create({
+      filterObject: Ember.Object.create(),
+      navIDs: Ember.Object.create({
+        backIDs: ['id0', 'id1'],
+        nextID: 'id2'
+      }),
+      content: [
+        Ember.Object.create({
+          id: 'id',
+          query_text: 'show tables',
+          name: 'id',
+          user: ['user'],
+          failed: false,
+          startTime: 1393443850756,
+          endTime: 1393443875265,
+          tezDagId: 'id:1',
+          hasTezDag: true
+        })
+      ]
+    })
+  });
+  mainJobsView.get('controller').set('sortedContent', mainJobsView.controller.get('content').toArray());
+  var jobNameView = mainJobsView.jobNameView.create();
+  jobNameView.set('job', mainJobsView.get('controller.content').objectAt(0));
+  describe('#noDataToShow', function () {
+    it('should be false if content is not empty', function () {
+      mainJobsView.noDataToShowObserver();
+      expect(mainJobsView.get('noDataToShow')).to.equal(false);
+    });
+  });
+  describe('#rowsPerPageSelectView.disabled', function() {
+    it('should be true if controller.navIDs.backIDs.length > 1', function () {
+      var rowsPerPageSelectView = mainJobsView.rowsPerPageSelectView.create({
+        parentView: Ember.View.create({
+          hasBackLinks: true
+        })
+      });
+      rowsPerPageSelectView.disabledObserver();
+      expect(rowsPerPageSelectView.get('disabled')).to.equal(true);
+    });
+  });
+  describe('#hasNextJobs', function () {
+    it('should be true if controller.navIDs.nextID is not empty', function () {
+      expect(mainJobsView.get('hasNextJobs')).to.equal(true);
+    });
+  });
+  describe('#hasBackLinks', function () {
+    it('should be true if there are several controller.navIDs.backIDs', function () {
+      expect(mainJobsView.get('hasBackLinks')).to.equal(true);
+    });
+  });
+  describe('#jobsPaginationLeft.class', function () {
+    it('should be paginate_next if there are new jobs and no filter is applied', function () {
+      mainJobsView.get('controller.filterObject').set('isAnyFilterApplied', false);
+      var jobsPaginationLeft = mainJobsView.jobsPaginationLeft.create({
+        parentView: Ember.View.create({
+          hasBackLinks: true
+        })
+      });
+      expect(jobsPaginationLeft.get('class')).to.equal('paginate_previous');
+    });
+  });
+  describe('#jobsPaginationRight.class', function () {
+    it('should be paginate_next if there are new jobs and no filter is applied', function () {
+      var jobsPaginationRight = mainJobsView.jobsPaginationRight.create({
+        parentView: Ember.View.create({
+          hasNextJobs: true
+        })
+      });
+      expect(jobsPaginationRight.get('class')).to.equal('paginate_next');
+    });
+  });
+  describe('#jobNameView.isLink', function () {
+    it('should be empty if job has Tez DAG', function () {
+      jobNameView.isLinkObserver();
+      expect(jobNameView.get('isLink')).to.equal('');
+    });
+  });
+});

Некоторые файлы не были показаны из-за большого количества измененных файлов