summaryrefslogtreecommitdiffstats
path: root/openecomp-ui/test/softwareProduct/components/monitoring
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2017-02-19 12:57:33 +0200
committerMichael Lando <ml636r@att.com>2017-02-19 13:47:13 +0200
commitefa037d34be7b1570efdc767c79fad8d4005f10e (patch)
treecf1036ba2728dea8a61492b678fa91954e629403 /openecomp-ui/test/softwareProduct/components/monitoring
parentf5f13c4f6b6fe3b4d98e349dfd7db59339803436 (diff)
Add new code new version
Change-Id: Ic02a76313503b526f17c3df29eb387a29fe6a42a Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'openecomp-ui/test/softwareProduct/components/monitoring')
-rw-r--r--openecomp-ui/test/softwareProduct/components/monitoring/SoftwareProductComponentsMonitoring.test.js101
-rw-r--r--openecomp-ui/test/softwareProduct/components/monitoring/test.js215
2 files changed, 316 insertions, 0 deletions
diff --git a/openecomp-ui/test/softwareProduct/components/monitoring/SoftwareProductComponentsMonitoring.test.js b/openecomp-ui/test/softwareProduct/components/monitoring/SoftwareProductComponentsMonitoring.test.js
new file mode 100644
index 0000000000..2f1ea12c01
--- /dev/null
+++ b/openecomp-ui/test/softwareProduct/components/monitoring/SoftwareProductComponentsMonitoring.test.js
@@ -0,0 +1,101 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ * ============LICENSE_END=========================================================
+ */
+
+import expect from 'expect';
+import React from 'react';
+import TestUtils from 'react-addons-test-utils';
+import {mapStateToProps} from 'sdc-app/onboarding/softwareProduct/components/monitoring/SoftwareProductComponentsMonitoring.js';
+import SoftwareProductComponentsMonitoringView from 'sdc-app/onboarding/softwareProduct/components/monitoring/SoftwareProductComponentsMonitoringView.jsx';
+
+describe('SoftwareProductComponentsMonitoring Module Tests', function () {
+
+ it('should mapper exist', () => {
+ expect(mapStateToProps).toExist();
+ });
+
+ it('should return empty file names', () => {
+ let softwareProduct = {softwareProductEditor: {data: {}}, softwareProductComponents: {monitoring: {}}};
+ var results = mapStateToProps({softwareProduct});
+ expect(results.trapFilename).toEqual(undefined);
+ expect(results.pollFilename).toEqual(undefined);
+ });
+
+ it('should return trap file name', () => {
+ const monitoring = {
+ trapFilename: '123'
+ };
+ let softwareProduct = {softwareProductEditor: {data: {}}, softwareProductComponents: {monitoring}};
+ var results = mapStateToProps({softwareProduct});
+ expect(results.trapFilename).toEqual(monitoring.trapFilename);
+ expect(results.pollFilename).toEqual(undefined);
+ });
+
+ it('should return poll file names', () => {
+ const monitoring = {
+ pollFilename: '123'
+ };
+ let softwareProduct = {softwareProductEditor: {data: {}}, softwareProductComponents: {monitoring}};
+ var results = mapStateToProps({softwareProduct});
+ expect(results.trapFilename).toEqual(undefined);
+ expect(results.pollFilename).toEqual(monitoring.pollFilename);
+
+ let renderer = TestUtils.createRenderer();
+ renderer.render(<SoftwareProductComponentsMonitoringView {...results} />);
+ let renderedOutput = renderer.getRenderOutput();
+ expect(renderedOutput).toExist();
+ });
+
+ it('should return both file names', () => {
+ const monitoring = {
+ trapFilename: '1234',
+ trapFilename: '123'
+ };
+ let softwareProduct = {softwareProductEditor: {data: {}}, softwareProductComponents: {monitoring}};
+ var results = mapStateToProps({softwareProduct});
+ expect(results.trapFilename).toEqual(monitoring.trapFilename);
+ expect(results.pollFilename).toEqual(monitoring.pollFilename);
+
+ let renderer = TestUtils.createRenderer();
+ renderer.render(<SoftwareProductComponentsMonitoringView {...results} />);
+ let renderedOutput = renderer.getRenderOutput();
+ expect(renderedOutput).toExist();
+ });
+
+ it('should change state to dragging', done => {
+ var view = TestUtils.renderIntoDocument(<SoftwareProductComponentsMonitoringView />);
+ expect(view.state.dragging).toBe(false);
+ view.handleOnDragEnter(false);
+ setTimeout(()=> {
+ expect(view.state.dragging).toBe(true);
+ done();
+ }, 100);
+ });
+
+ it('should not change state to dragging', done => {
+ var view = TestUtils.renderIntoDocument(<SoftwareProductComponentsMonitoringView />);
+ expect(view.state.dragging).toBe(false);
+ view.handleOnDragEnter(true);
+ setTimeout(()=> {
+ expect(view.state.dragging).toBe(false);
+ done();
+ }, 0);
+ });
+
+});
diff --git a/openecomp-ui/test/softwareProduct/components/monitoring/test.js b/openecomp-ui/test/softwareProduct/components/monitoring/test.js
new file mode 100644
index 0000000000..172db653e9
--- /dev/null
+++ b/openecomp-ui/test/softwareProduct/components/monitoring/test.js
@@ -0,0 +1,215 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ * ============LICENSE_END=========================================================
+ */
+
+import expect from 'expect';
+import mockRest from 'test-utils/MockRest.js';
+import {storeCreator} from 'sdc-app/AppStore.js';
+import SoftwareProductComponentsMonitoringConstants from 'sdc-app/onboarding/softwareProduct/components/monitoring/SoftwareProductComponentsMonitoringConstants.js';
+import SoftwareProductComponentsMonitoringActionHelper from 'sdc-app/onboarding/softwareProduct/components/monitoring/SoftwareProductComponentsMonitoringActionHelper.js';
+
+const softwareProductId = '123';
+const componentId = '123';
+
+describe('Software Product Components Monitoring Module Tests', function () {
+
+ let store;
+
+ beforeEach(()=> {
+ store = storeCreator();
+ });
+
+
+ it('Fetch for existing files - no files', done => {
+
+ let emptyResult = Object.freeze({
+ snmpTrap: undefined,
+ snmpPoll: undefined
+ });
+
+ mockRest.addHandler('fetch', ({ baseUrl}) => {
+ expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/components/${componentId}/monitors/snmp`);
+ return emptyResult;
+ });
+
+ SoftwareProductComponentsMonitoringActionHelper.fetchExistingFiles(store.dispatch, {
+ softwareProductId,
+ componentId
+ });
+ setTimeout(()=> {
+ var {softwareProduct: {softwareProductComponents: {monitoring}}} = store.getState();
+ expect(monitoring.pollFilename).toEqual(emptyResult.snmpPoll);
+ expect(monitoring.trapFilename).toEqual(emptyResult.snmpTrap);
+ done();
+ }, 0);
+
+ });
+
+ it('Fetch for existing files - only snmp trap file exists', done => {
+ let response = Object.freeze({
+ snmpTrap: 'asdfasdf',
+ snmpPoll: undefined
+ });
+
+ mockRest.addHandler('fetch', ({ baseUrl}) => {
+ expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/components/${componentId}/monitors/snmp`);
+ return response;
+ });
+
+ SoftwareProductComponentsMonitoringActionHelper.fetchExistingFiles(store.dispatch, {
+ softwareProductId,
+ componentId
+ });
+ setTimeout(()=> {
+ var {softwareProduct: {softwareProductComponents: {monitoring}}} = store.getState();
+ expect(monitoring.pollFilename).toEqual(response.snmpPoll);
+ expect(monitoring.trapFilename).toEqual(response.snmpTrap);
+ done();
+ }, 0);
+ });
+
+ it('Fetch for existing files - only snmp poll file exists', done => {
+ let response = Object.freeze({
+ snmpPoll: 'asdfasdf',
+ snmpTrap: undefined
+ });
+
+ mockRest.addHandler('fetch', ({baseUrl}) => {
+ expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/components/${componentId}/monitors/snmp`);
+ return response;
+ });
+
+ SoftwareProductComponentsMonitoringActionHelper.fetchExistingFiles(store.dispatch, {
+ softwareProductId,
+ componentId
+ });
+ setTimeout(()=> {
+ var {softwareProduct: {softwareProductComponents: {monitoring}}} = store.getState();
+ expect(monitoring.pollFilename).toEqual(response.snmpPoll);
+ expect(monitoring.trapFilename).toEqual(response.snmpTrap);
+ done();
+ }, 0);
+ });
+
+ it('Fetch for existing files - both files exist', done => {
+ let response = Object.freeze({
+ snmpPoll: 'asdfasdf',
+ snmpTrap: 'asdfgg'
+ });
+
+ mockRest.addHandler('fetch', ({baseUrl}) => {
+ expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/components/${componentId}/monitors/snmp`);
+ return response;
+ });
+
+ SoftwareProductComponentsMonitoringActionHelper.fetchExistingFiles(store.dispatch, {
+ softwareProductId,
+ componentId
+ });
+ setTimeout(()=> {
+ var {softwareProduct: {softwareProductComponents: {monitoring}}} = store.getState();
+ expect(monitoring.pollFilename).toEqual(response.snmpPoll);
+ expect(monitoring.trapFilename).toEqual(response.snmpTrap);
+ done();
+ }, 0);
+ });
+
+ it('Upload snmp trap file', done => {
+
+ mockRest.addHandler('create', ({baseUrl}) => {
+ expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/components/${componentId}/monitors/snmp-trap/upload`);
+ return {};
+ });
+ var debug = {hello: 'world'};
+ let file = new Blob([JSON.stringify(debug, null, 2)], {type: 'application/json'});;
+ let formData = new FormData();
+ formData.append('upload', file);
+ SoftwareProductComponentsMonitoringActionHelper.uploadSnmpFile(store.dispatch, {
+ softwareProductId,
+ componentId,
+ formData,
+ fileSize: file.size,
+ type: SoftwareProductComponentsMonitoringConstants.SNMP_TRAP
+ });
+ setTimeout(()=> {
+ var {softwareProduct: {softwareProductComponents: {monitoring}}} = store.getState();
+ expect(monitoring.pollFilename).toEqual(undefined);
+ expect(monitoring.trapFilename).toEqual('blob');
+ done();
+ }, 0);
+ });
+
+ it('Upload snmp poll file', done => {
+ mockRest.addHandler('create', ({baseUrl}) => {
+ expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/components/${componentId}/monitors/snmp/upload`);
+ return {};
+ });
+ var debug = {hello: 'world'};
+ let file = new Blob([JSON.stringify(debug, null, 2)], {type: 'application/json'});;
+ let formData = new FormData();
+ formData.append('upload', file);
+ SoftwareProductComponentsMonitoringActionHelper.uploadSnmpFile(store.dispatch, {
+ softwareProductId,
+ componentId,
+ formData,
+ fileSize: file.size,
+ type: SoftwareProductComponentsMonitoringConstants.SNMP_POLL
+ });
+ setTimeout(()=> {
+ var {softwareProduct: {softwareProductComponents: {monitoring}}} = store.getState();
+ expect(monitoring.pollFilename).toEqual('blob');
+ expect(monitoring.trapFilename).toEqual(undefined);
+ done();
+ }, 0);
+ });
+
+ it('Delete snmp trap file', done => {
+ mockRest.addHandler('destroy', ({baseUrl}) => {
+ expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/components/${componentId}/monitors/snmp-trap`);
+ return {};
+ });
+ SoftwareProductComponentsMonitoringActionHelper.deleteSnmpFile(store.dispatch, {
+ softwareProductId,
+ componentId,
+ type: SoftwareProductComponentsMonitoringConstants.SNMP_TRAP
+ });
+ setTimeout(()=> {
+ var {softwareProduct: {softwareProductComponents: {monitoring}}} = store.getState();
+ expect(monitoring.trapFilename).toEqual(undefined);
+ done();
+ }, 0);
+ });
+
+ it('Delete snmp poll file', done => {
+ mockRest.addHandler('destroy', ({baseUrl}) => {
+ expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/components/${componentId}/monitors/snmp`);
+ return {};
+ });
+ SoftwareProductComponentsMonitoringActionHelper.deleteSnmpFile(store.dispatch, {
+ softwareProductId,
+ componentId,
+ type: SoftwareProductComponentsMonitoringConstants.SNMP_POLL
+ });
+ setTimeout(()=> {
+ var {softwareProduct: {softwareProductComponents: {monitoring}}} = store.getState();
+ expect(monitoring.pollFilename).toEqual(undefined);
+ done();
+ }, 0);
+ });
+});