http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/2f343e1b/nifi-registry-web-ui/src/main/webapp/services/nf-registry.api.js ---------------------------------------------------------------------- diff --git a/nifi-registry-web-ui/src/main/webapp/services/nf-registry.api.js b/nifi-registry-web-ui/src/main/webapp/services/nf-registry.api.js index 253aef2..c2b9e44 100644 --- a/nifi-registry-web-ui/src/main/webapp/services/nf-registry.api.js +++ b/nifi-registry-web-ui/src/main/webapp/services/nf-registry.api.js @@ -61,7 +61,7 @@ NfRegistryApi.prototype = { url += '/versions'; return this.http.get(url) .map(function (response) { - return response || []; + return response; }) .catch(function (error) { self.dialogService.openConfirm({ @@ -70,7 +70,7 @@ NfRegistryApi.prototype = { acceptButton: 'Ok', acceptButtonColor: 'fds-warn' }); - return rxjs.Observable.throw(error.message); + return rxjs.Observable.of(error); }); }, @@ -101,7 +101,7 @@ NfRegistryApi.prototype = { self.router.navigateByUrl('/nifi-registry/explorer/grid-list/buckets/' + bucketId); } }); - return rxjs.Observable.throw(error.message); + return rxjs.Observable.of(error); }); }, @@ -131,7 +131,7 @@ NfRegistryApi.prototype = { acceptButton: 'Ok', acceptButtonColor: 'fds-warn' }); - return rxjs.Observable.throw(error.message); + return rxjs.Observable.of(error); }); }, @@ -150,7 +150,7 @@ NfRegistryApi.prototype = { var self = this; return this.http.delete('/nifi-registry-api/' + dropletUri, headers) .map(function (response) { - return response || {}; + return response; }) .catch(function (error) { self.dialogService.openConfirm({ @@ -159,7 +159,7 @@ NfRegistryApi.prototype = { acceptButton: 'Ok', acceptButtonColor: 'fds-warn' }); - return rxjs.Observable.throw(error.message); + return rxjs.Observable.of(error); }); }, @@ -173,7 +173,7 @@ NfRegistryApi.prototype = { var self = this; return this.http.post('/nifi-registry-api/buckets', {'name': name}, headers) .map(function (response) { - return response || {}; + return response; }) .catch(function (error) { self.dialogService.openConfirm({ @@ -182,7 +182,7 @@ NfRegistryApi.prototype = { acceptButton: 'Ok', acceptButtonColor: 'fds-warn' }); - return rxjs.Observable.throw(error.message); + return rxjs.Observable.of(error); }); }, @@ -196,7 +196,7 @@ NfRegistryApi.prototype = { var self = this; return this.http.delete('/nifi-registry-api/buckets/' + bucketId, headers) .map(function (response) { - return response || {}; + return response; }) .catch(function (error) { self.dialogService.openConfirm({ @@ -205,7 +205,7 @@ NfRegistryApi.prototype = { acceptButton: 'Ok', acceptButtonColor: 'fds-warn' }); - return rxjs.Observable.throw(error.message); + return rxjs.Observable.of(error); }); }, @@ -220,7 +220,7 @@ NfRegistryApi.prototype = { var url = '/nifi-registry-api/buckets/' + bucketId; return this.http.get(url) .map(function (response) { - return response || {}; + return response; }) .catch(function (error) { self.dialogService.openConfirm({ @@ -234,7 +234,7 @@ NfRegistryApi.prototype = { self.router.navigateByUrl('/nifi-registry/explorer/grid-list'); } }); - return rxjs.Observable.throw(error.message); + return rxjs.Observable.of(error); }); }, @@ -251,7 +251,7 @@ NfRegistryApi.prototype = { var url = '/nifi-registry-api/buckets'; return this.http.get(url) .map(function (response) { - return response || []; + return response; }) .catch(function (error) { self.dialogService.openConfirm({ @@ -260,7 +260,7 @@ NfRegistryApi.prototype = { acceptButton: 'Ok', acceptButtonColor: 'fds-warn' }); - return rxjs.Observable.throw(error.message); + return rxjs.Observable.of(error); }); }, @@ -269,7 +269,7 @@ NfRegistryApi.prototype = { var self = this; return this.http.get('/nifi-registry-api/users/' + userId) .map(function (response) { - return response || {}; + return response; }) .catch(function (error) { self.dialogService.openConfirm({ @@ -296,7 +296,7 @@ NfRegistryApi.prototype = { 'identity': identity }, headers) .map(function (response) { - return response || {}; + return response; }) .catch(function (error) { self.dialogService.openConfirm({ @@ -305,7 +305,7 @@ NfRegistryApi.prototype = { acceptButton: 'Ok', acceptButtonColor: 'fds-warn' }); - return rxjs.Observable.throw(error.message); + return rxjs.Observable.of(error); }); }, @@ -316,9 +316,9 @@ NfRegistryApi.prototype = { */ getUsers: function () { var self = this; - return this.http.get('nifi-registry-api/tenants/users') + return this.http.get('/nifi-registry-api/tenants/users') .map(function (response) { - return response || []; + return response; }) .catch(function (error) { self.dialogService.openConfirm({ @@ -327,7 +327,7 @@ NfRegistryApi.prototype = { acceptButton: 'Ok', acceptButtonColor: 'fds-warn' }); - return rxjs.Observable.throw(error.message); + return rxjs.Observable.of(error); }); }, @@ -341,7 +341,7 @@ NfRegistryApi.prototype = { var self = this; return this.http.delete('/nifi-registry-api/tenants/users/' + userId, headers) .map(function (response) { - return response || {}; + return response; }) .catch(function (error) { self.dialogService.openConfirm({ @@ -350,7 +350,7 @@ NfRegistryApi.prototype = { acceptButton: 'Ok', acceptButtonColor: 'fds-warn' }); - return rxjs.Observable.throw(error.message); + return rxjs.Observable.of(error); }); }, @@ -361,9 +361,9 @@ NfRegistryApi.prototype = { */ getUserGroups: function () { var self = this; - return this.http.get('nifi-registry-api/tenants/user-groups') + return this.http.get('/nifi-registry-api/tenants/user-groups') .map(function (response) { - return response || []; + return response; }) .catch(function (error) { self.dialogService.openConfirm({ @@ -372,7 +372,7 @@ NfRegistryApi.prototype = { acceptButton: 'Ok', acceptButtonColor: 'fds-warn' }); - return rxjs.Observable.throw(error.message); + return rxjs.Observable.of(error); }); }, @@ -386,7 +386,7 @@ NfRegistryApi.prototype = { var self = this; return this.http.get('/nifi-registry-api/tenants/user-groups/' + groupId) .map(function (response) { - return response || {}; + return response; }) .catch(function (error) { self.dialogService.openConfirm({ @@ -395,7 +395,7 @@ NfRegistryApi.prototype = { acceptButton: 'Ok', acceptButtonColor: 'fds-warn' }); - return rxjs.Observable.throw(error.message); + return rxjs.Observable.of(error); }); }, @@ -409,7 +409,7 @@ NfRegistryApi.prototype = { var self = this; return this.http.delete('/nifi-registry-api/tenants/user-groups/' + userGroupId, headers) .map(function (response) { - return response || {}; + return response; }) .catch(function (error) { self.dialogService.openConfirm({ @@ -418,7 +418,7 @@ NfRegistryApi.prototype = { acceptButton: 'Ok', acceptButtonColor: 'fds-warn' }); - return rxjs.Observable.throw(error.message); + return rxjs.Observable.of(error); }); }, @@ -438,7 +438,7 @@ NfRegistryApi.prototype = { 'users': users }, headers) .map(function (response) { - return response || {}; + return response; }) .catch(function (error) { self.dialogService.openConfirm({ @@ -447,7 +447,7 @@ NfRegistryApi.prototype = { acceptButton: 'Ok', acceptButtonColor: 'fds-warn' }); - return rxjs.Observable.throw(error.message); + return rxjs.Observable.of(error); }); }, @@ -467,7 +467,7 @@ NfRegistryApi.prototype = { 'users': users }, headers) .map(function (response) { - return response || {}; + return response; }) .catch(function (error) { self.dialogService.openConfirm({ @@ -476,7 +476,7 @@ NfRegistryApi.prototype = { acceptButton: 'Ok', acceptButtonColor: 'fds-warn' }); - return rxjs.Observable.throw(error.message); + return rxjs.Observable.of(error); }); },
http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/2f343e1b/nifi-registry-web-ui/src/main/webapp/services/nf-registry.api.spec.js ---------------------------------------------------------------------- diff --git a/nifi-registry-web-ui/src/main/webapp/services/nf-registry.api.spec.js b/nifi-registry-web-ui/src/main/webapp/services/nf-registry.api.spec.js index da57d29..eee6858 100644 --- a/nifi-registry-web-ui/src/main/webapp/services/nf-registry.api.spec.js +++ b/nifi-registry-web-ui/src/main/webapp/services/nf-registry.api.spec.js @@ -103,265 +103,1011 @@ describe('NfRegistry Service API w/ Angular testing utils', function () { // NfRegistryService from the root injector nfRegistryService = ngCoreTesting.TestBed.get(NfRegistryService); nfRegistryApi = ngCoreTesting.TestBed.get(NfRegistryApi); - spyOn(nfRegistryApi, 'ticketExchange').and.callFake(function () {}).and.returnValue(rxjs.Observable.of({})); - spyOn(nfRegistryService, 'loadCurrentUser').and.callFake(function () {}).and.returnValue(rxjs.Observable.of({})); + spyOn(nfRegistryApi, 'ticketExchange').and.callFake(function () { + }).and.returnValue(rxjs.Observable.of({})); + spyOn(nfRegistryService, 'loadCurrentUser').and.callFake(function () { + }).and.returnValue(rxjs.Observable.of({})); }); it('should GET droplet snapshot metadata.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { - // The function to test - nfRegistryApi.getDropletSnapshotMetadata('flow/test').subscribe(function(response) { - var req = httpMock.expectOne('/nifi-registry-api/access/token/kerberos'); - req.flush({}); - req = httpMock.expectOne('/nifi-registry-api/access'); - req.flush({}); - httpMock.verify(); - // the request it made - req = httpMock.expectOne('/nifi-registry-api/flow/test/versions'); - expect(req.request.method).toEqual('GET'); - - // Next, fulfill the request by transmitting a response. - req.flush({ - snapshotMetadata: [ - {bucketIdentifier: '2f7f9e54-dc09-4ceb-aa58-9fe581319cdc', version: 999} - ] - }); - httpMock.verify(); + // api call + nfRegistryApi.getDropletSnapshotMetadata('flow/test').subscribe(function (response) { }); + // the request it made + req = httpMock.expectOne('/nifi-registry-api/flow/test/versions'); + expect(req.request.method).toEqual('GET'); + + // Next, fulfill the request by transmitting a response. + req.flush({ + snapshotMetadata: [ + {identifier: '2f7f9e54-dc09-4ceb-aa58-9fe581319cdc', version: 999} + ] + }); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); + + it('should fail to GET droplet snapshot metadata.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // Spy + spyOn(nfRegistryApi.dialogService, 'openConfirm').and.callFake(function () { + }); + + // api call + nfRegistryApi.getDropletSnapshotMetadata('flow/test').subscribe(function (response) { + expect(response.message).toEqual('Http failure response for /nifi-registry-api/flow/test/versions: 401 GET droplet mock error'); + var dialogServiceCall = nfRegistryApi.dialogService.openConfirm.calls.first(); + expect(dialogServiceCall.args[0].title).toBe('Error'); + expect(dialogServiceCall.args[0].message).toBe('Http failure response for /nifi-registry-api/flow/test/versions: 401 GET droplet mock error'); + expect(dialogServiceCall.args[0].acceptButton).toBe('Ok'); + expect(dialogServiceCall.args[0].acceptButtonColor).toBe('fds-warn'); + }); + // the request it made + req = httpMock.expectOne('/nifi-registry-api/flow/test/versions'); + expect(req.request.method).toEqual('GET'); + + // Next, fulfill the request by transmitting a response. + req.flush(null, {status: 401, statusText: 'GET droplet mock error'}); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); })); it('should GET droplet by type and ID.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { - // The function to test - nfRegistryApi.getDroplet('2f7f9e54-dc09-4ceb-aa58-9fe581319cdc', 'flows', '2e04b4fb-9513-47bb-aa74-1ae34616bfdc').subscribe(function(response) { - var req = httpMock.expectOne('/nifi-registry-api/access/token/kerberos'); - req.flush({}); - req = httpMock.expectOne('/nifi-registry-api/access'); - req.flush({}); - httpMock.verify(); - // the request it made - req = httpMock.expectOne('/nifi-registry-api/buckets/2f7f9e54-dc09-4ceb-aa58-9fe581319cdc/flows/2e04b4fb-9513-47bb-aa74-1ae34616bfdc'); - expect(req.request.method).toEqual('GET'); - - // Next, fulfill the request by transmitting a response. - req.flush({ - 'identifier': '2e04b4fb-9513-47bb-aa74-1ae34616bfdc', - 'name': 'Flow #1', - 'description': 'This is flow #1', - 'bucketIdentifier': '2f7f9e54-dc09-4ceb-aa58-9fe581319cdc', - 'createdTimestamp': 1505931890999, - 'modifiedTimestamp': 1505931890999, - 'type': 'FLOW', - 'snapshotMetadata': null, - 'link': { - 'params': { - 'rel': 'self' - }, - 'href': 'flows/2e04b4fb-9513-47bb-aa74-1ae34616bfdc' - } - }); - httpMock.verify(); - expect(droplet.identifier).toEqual('2e04b4fb-9513-47bb-aa74-1ae34616bfdc'); - expect(droplet.type).toEqual('FLOW'); - expect(droplet.name).toEqual('Flow #1'); + // api call + nfRegistryApi.getDroplet('2f7f9e54-dc09-4ceb-aa58-9fe581319cdc', 'flows', '2e04b4fb-9513-47bb-aa74-1ae34616bfdc').subscribe(function (response) { + expect(response.identifier).toEqual('2e04b4fb-9513-47bb-aa74-1ae34616bfdc'); + expect(response.type).toEqual('FLOW'); + expect(response.name).toEqual('Flow #1'); }); + // the request it made + req = httpMock.expectOne('/nifi-registry-api/buckets/2f7f9e54-dc09-4ceb-aa58-9fe581319cdc/flows/2e04b4fb-9513-47bb-aa74-1ae34616bfdc'); + expect(req.request.method).toEqual('GET'); + + // Next, fulfill the request by transmitting a response. + req.flush({ + 'identifier': '2e04b4fb-9513-47bb-aa74-1ae34616bfdc', + 'name': 'Flow #1', + 'description': 'This is flow #1', + 'bucketIdentifier': '2f7f9e54-dc09-4ceb-aa58-9fe581319cdc', + 'createdTimestamp': 1505931890999, + 'modifiedTimestamp': 1505931890999, + 'type': 'FLOW', + 'snapshotMetadata': null, + 'link': { + 'params': { + 'rel': 'self' + }, + 'href': 'flows/2e04b4fb-9513-47bb-aa74-1ae34616bfdc' + } + }); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); + + it('should fail to GET droplet by type and ID.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // Spy + spyOn(nfRegistryApi.dialogService, 'openConfirm').and.callFake(function () { + return { + afterClosed: function() { return rxjs.Observable.of(true); } + } + }); + + // api call + nfRegistryApi.getDroplet('2f7f9e54-dc09-4ceb-aa58-9fe581319cdc', 'flows', '2e04b4fb-9513-47bb-aa74-1ae34616bfdc').subscribe(function (response) { + expect(response.message).toEqual('Http failure response for /nifi-registry-api/buckets/2f7f9e54-dc09-4ceb-aa58-9fe581319cdc/flows/2e04b4fb-9513-47bb-aa74-1ae34616bfdc: 401 GET droplet mock error'); + var dialogServiceCall = nfRegistryApi.dialogService.openConfirm.calls.first(); + expect(dialogServiceCall.args[0].title).toBe('Error'); + expect(dialogServiceCall.args[0].message).toBe('Http failure response for /nifi-registry-api/buckets/2f7f9e54-dc09-4ceb-aa58-9fe581319cdc/flows/2e04b4fb-9513-47bb-aa74-1ae34616bfdc: 401 GET droplet mock error'); + expect(dialogServiceCall.args[0].acceptButton).toBe('Ok'); + expect(dialogServiceCall.args[0].acceptButtonColor).toBe('fds-warn'); + }); + + // the request it made + req = httpMock.expectOne('/nifi-registry-api/buckets/2f7f9e54-dc09-4ceb-aa58-9fe581319cdc/flows/2e04b4fb-9513-47bb-aa74-1ae34616bfdc'); + expect(req.request.method).toEqual('GET'); + + // Next, fulfill the request by transmitting a response. + req.flush(null, {status: 401, statusText: 'GET droplet mock error'}); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); })); it('should GET all droplets across all buckets.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { - // The function to test - nfRegistryApi.getDroplets().subscribe(function(response) { - var req = httpMock.expectOne('/nifi-registry-api/access/token/kerberos'); - req.flush({}); - req = httpMock.expectOne('/nifi-registry-api/access'); - req.flush({}); - httpMock.verify(); - // the request it made - req = httpMock.expectOne('/nifi-registry-api/items'); - expect(req.request.method).toEqual('GET'); - - // Next, fulfill the request by transmitting a response. - req.flush([{ - 'identifier': '2e04b4fb-9513-47bb-aa74-1ae34616bfdc', - 'name': 'Flow #1', - 'description': 'This is flow #1', - 'bucketIdentifier': '9q7f9e54-dc09-4ceb-aa58-9fe581319cdc', - 'createdTimestamp': 1505931890999, - 'modifiedTimestamp': 1505931890999, - 'type': 'FLOW', - 'snapshotMetadata': null, - 'link': { - 'params': { - 'rel': 'self' - }, - 'href': 'flows/2e04b4fb-9513-47bb-aa74-1ae34616bfdc' - } - }, { - 'identifier': '5d04b4fb-9513-47bb-aa74-1ae34616bfdc', - 'name': 'Flow #2', - 'description': 'This is flow #2', - 'bucketIdentifier': '2f7f9e54-dc09-4ceb-aa58-9fe581319cdc', - 'createdTimestamp': 1505931890999, - 'modifiedTimestamp': 1505931890999, - 'type': 'FLOW', - 'snapshotMetadata': null, - 'link': { - 'params': { - 'rel': 'self' - }, - 'href': 'flows/5d04b4fb-9513-47bb-aa74-1ae34616bfdc' - } - }]); - httpMock.verify(); - expect(droplets.length).toBe(2); - expect(droplets[0].bucketIdentifier).toEqual('9q7f9e54-dc09-4ceb-aa58-9fe581319cdc'); - expect(droplets[1].bucketIdentifier).toEqual('2f7f9e54-dc09-4ceb-aa58-9fe581319cdc'); - expect(droplets[0].name).toEqual('Flow #1'); - expect(droplets[1].name).toEqual('Flow #2'); + // api call + nfRegistryApi.getDroplets().subscribe(function (response) { + expect(response.length).toBe(2); + expect(response[0].bucketIdentifier).toEqual('9q7f9e54-dc09-4ceb-aa58-9fe581319cdc'); + expect(response[1].bucketIdentifier).toEqual('2f7f9e54-dc09-4ceb-aa58-9fe581319cdc'); + expect(response[0].name).toEqual('Flow #1'); + expect(response[1].name).toEqual('Flow #2'); }); + // the request it made + req = httpMock.expectOne('/nifi-registry-api/items'); + expect(req.request.method).toEqual('GET'); + + // Next, fulfill the request by transmitting a response. + req.flush([{ + 'identifier': '2e04b4fb-9513-47bb-aa74-1ae34616bfdc', + 'name': 'Flow #1', + 'description': 'This is flow #1', + 'bucketIdentifier': '9q7f9e54-dc09-4ceb-aa58-9fe581319cdc', + 'createdTimestamp': 1505931890999, + 'modifiedTimestamp': 1505931890999, + 'type': 'FLOW', + 'snapshotMetadata': null, + 'link': { + 'params': { + 'rel': 'self' + }, + 'href': 'flows/2e04b4fb-9513-47bb-aa74-1ae34616bfdc' + } + }, { + 'identifier': '5d04b4fb-9513-47bb-aa74-1ae34616bfdc', + 'name': 'Flow #2', + 'description': 'This is flow #2', + 'bucketIdentifier': '2f7f9e54-dc09-4ceb-aa58-9fe581319cdc', + 'createdTimestamp': 1505931890999, + 'modifiedTimestamp': 1505931890999, + 'type': 'FLOW', + 'snapshotMetadata': null, + 'link': { + 'params': { + 'rel': 'self' + }, + 'href': 'flows/5d04b4fb-9513-47bb-aa74-1ae34616bfdc' + } + }]); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); + + it('should fail to GET all droplets across all buckets.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // Spy + spyOn(nfRegistryApi.dialogService, 'openConfirm').and.callFake(function () { + }); + + // api call + nfRegistryApi.getDroplets().subscribe(function (response) { + expect(response.message).toEqual('Http failure response for /nifi-registry-api/items: 401 GET droplet mock error'); + var dialogServiceCall = nfRegistryApi.dialogService.openConfirm.calls.first(); + expect(dialogServiceCall.args[0].title).toBe('Error'); + expect(dialogServiceCall.args[0].message).toBe('Http failure response for /nifi-registry-api/items: 401 GET droplet mock error'); + expect(dialogServiceCall.args[0].acceptButton).toBe('Ok'); + expect(dialogServiceCall.args[0].acceptButtonColor).toBe('fds-warn'); + }); + + // the request it made + req = httpMock.expectOne('/nifi-registry-api/items'); + expect(req.request.method).toEqual('GET'); + + // Next, fulfill the request by transmitting a response. + req.flush(null, {status: 401, statusText: 'GET droplet mock error'}); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); })); it('should GET all droplets across a single bucket.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { - // The function to test - nfRegistryApi.getDroplets('2f7f9e54-dc09-4ceb-aa58-9fe581319cdc').subscribe(function(response) { - var req = httpMock.expectOne('/nifi-registry-api/access/token/kerberos'); - req.flush({}); - req = httpMock.expectOne('/nifi-registry-api/access'); - req.flush({}); - httpMock.verify(); - // the request it made - req = httpMock.expectOne('/nifi-registry-api/items/2f7f9e54-dc09-4ceb-aa58-9fe581319cdc'); - expect(req.request.method).toEqual('GET'); - - // Next, fulfill the request by transmitting a response. - req.flush([{ - 'identifier': '2e04b4fb-9513-47bb-aa74-1ae34616bfdc', - 'name': 'Flow #1', - 'description': 'This is flow #1', - 'bucketIdentifier': '2f7f9e54-dc09-4ceb-aa58-9fe581319cdc', - 'createdTimestamp': 1505931890999, - 'modifiedTimestamp': 1505931890999, - 'type': 'FLOW', - 'snapshotMetadata': null, - 'link': { - 'params': { - 'rel': 'self' - }, - 'href': 'flows/2e04b4fb-9513-47bb-aa74-1ae34616bfdc' - } - }]); - httpMock.verify(); - expect(droplets.length).toBe(1); - expect(droplets[0].bucketIdentifier).toEqual('2f7f9e54-dc09-4ceb-aa58-9fe581319cdc'); - expect(droplets[0].name).toEqual('Flow #1'); + // api call + nfRegistryApi.getDroplets('2f7f9e54-dc09-4ceb-aa58-9fe581319cdc').subscribe(function (response) { + expect(response.length).toBe(1); + expect(response[0].bucketIdentifier).toEqual('2f7f9e54-dc09-4ceb-aa58-9fe581319cdc'); + expect(response[0].name).toEqual('Flow #1'); + }); + // the request it made + req = httpMock.expectOne('/nifi-registry-api/items/2f7f9e54-dc09-4ceb-aa58-9fe581319cdc'); + expect(req.request.method).toEqual('GET'); + + // Next, fulfill the request by transmitting a response. + req.flush([{ + 'identifier': '2e04b4fb-9513-47bb-aa74-1ae34616bfdc', + 'name': 'Flow #1', + 'description': 'This is flow #1', + 'bucketIdentifier': '2f7f9e54-dc09-4ceb-aa58-9fe581319cdc', + 'createdTimestamp': 1505931890999, + 'modifiedTimestamp': 1505931890999, + 'type': 'FLOW', + 'snapshotMetadata': null, + 'link': { + 'params': { + 'rel': 'self' + }, + 'href': 'flows/2e04b4fb-9513-47bb-aa74-1ae34616bfdc' + } + }]); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); + + it('should fail to GET all droplets across a single bucket.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // Spy + spyOn(nfRegistryApi.dialogService, 'openConfirm').and.callFake(function () { }); + + // api call + nfRegistryApi.getDroplets('2f7f9e54-dc09-4ceb-aa58-9fe581319cdc').subscribe(function (response) { + expect(response.message).toEqual('Http failure response for /nifi-registry-api/items/2f7f9e54-dc09-4ceb-aa58-9fe581319cdc: 401 GET droplet mock error'); + var dialogServiceCall = nfRegistryApi.dialogService.openConfirm.calls.first(); + expect(dialogServiceCall.args[0].title).toBe('Error'); + expect(dialogServiceCall.args[0].message).toBe('Http failure response for /nifi-registry-api/items/2f7f9e54-dc09-4ceb-aa58-9fe581319cdc: 401 GET droplet mock error'); + expect(dialogServiceCall.args[0].acceptButton).toBe('Ok'); + expect(dialogServiceCall.args[0].acceptButtonColor).toBe('fds-warn'); + }); + + // the request it made + req = httpMock.expectOne('/nifi-registry-api/items/2f7f9e54-dc09-4ceb-aa58-9fe581319cdc'); + expect(req.request.method).toEqual('GET'); + + // Next, fulfill the request by transmitting a response. + req.flush(null, {status: 401, statusText: 'GET droplet mock error'}); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); })); it('should DELETE a droplet.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { - // The function to test - nfRegistryApi.deleteDroplet('flows/1234').subscribe(function(response) { - var req = httpMock.expectOne('/nifi-registry-api/access/token/kerberos'); - req.flush({}); - req = httpMock.expectOne('/nifi-registry-api/access'); - req.flush({}); - httpMock.verify(); - // the request it made - req = httpMock.expectOne('/nifi-registry-api/flows/1234'); - expect(req.request.method).toEqual('DELETE'); + // api call + nfRegistryApi.deleteDroplet('flows/1234').subscribe(function (response) { + }); + + // the request it made + req = httpMock.expectOne('/nifi-registry-api/flows/1234'); + expect(req.request.method).toEqual('DELETE'); + + // Next, fulfill the request by transmitting a response. + req.flush({}); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); - // Next, fulfill the request by transmitting a response. - req.flush({}); - httpMock.verify(); + it('should fail to DELETE a droplet.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // Spy + spyOn(nfRegistryApi.dialogService, 'openConfirm').and.callFake(function () { }); + + // api call + nfRegistryApi.deleteDroplet('flows/1234').subscribe(function (response) { + expect(response.message).toEqual('Http failure response for /nifi-registry-api/flows/1234: 401 DELETE droplet mock error'); + var dialogServiceCall = nfRegistryApi.dialogService.openConfirm.calls.first(); + expect(dialogServiceCall.args[0].title).toBe('Error'); + expect(dialogServiceCall.args[0].message).toBe('Http failure response for /nifi-registry-api/flows/1234: 401 DELETE droplet mock error'); + expect(dialogServiceCall.args[0].acceptButton).toBe('Ok'); + expect(dialogServiceCall.args[0].acceptButtonColor).toBe('fds-warn'); + }); + + // the request it made + req = httpMock.expectOne('/nifi-registry-api/flows/1234'); + expect(req.request.method).toEqual('DELETE'); + + // Next, fulfill the request by transmitting a response. + req.flush(null, {status: 401, statusText: 'DELETE droplet mock error'}); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); })); it('should POST to create a new bucket.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { - //Spy - spyOn(nfRegistryApi.http, 'post').and.callThrough(); - - // The function to test - nfRegistryApi.createBucket('test').subscribe(function(response) { - var req = httpMock.expectOne('/nifi-registry-api/access/token/kerberos'); - req.flush({}); - req = httpMock.expectOne('/nifi-registry-api/access'); - req.flush({}); - httpMock.verify(); - // the request it made - req = httpMock.expectOne('/nifi-registry-api/buckets'); - expect(req.request.method).toEqual('POST'); - - // Next, fulfill the request by transmitting a response. - req.flush({ - identifier: '1234' - }); - httpMock.verify(); - expect(createDropletCall.args[1].name).toBe('test'); - expect(bucket.identifier).toBe('1234'); + // api call + nfRegistryApi.createBucket('test').subscribe(function (response) { + expect(response.identifier).toBe('1234'); }); + // the request it made + req = httpMock.expectOne('/nifi-registry-api/buckets'); + expect(req.request.method).toEqual('POST'); + + // Next, fulfill the request by transmitting a response. + req.flush({ + identifier: '1234' + }); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); + + it('should fail to POST to create a new bucket.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // Spy + spyOn(nfRegistryApi.dialogService, 'openConfirm').and.callFake(function () { + }); + + // api call + nfRegistryApi.createBucket('test').subscribe(function (response) { + expect(response.message).toEqual('Http failure response for /nifi-registry-api/buckets: 401 POST bucket mock error'); + var dialogServiceCall = nfRegistryApi.dialogService.openConfirm.calls.first(); + expect(dialogServiceCall.args[0].title).toBe('Error'); + expect(dialogServiceCall.args[0].message).toBe('Http failure response for /nifi-registry-api/buckets: 401 POST bucket mock error'); + expect(dialogServiceCall.args[0].acceptButton).toBe('Ok'); + expect(dialogServiceCall.args[0].acceptButtonColor).toBe('fds-warn'); + }); + + // the request it made + req = httpMock.expectOne('/nifi-registry-api/buckets'); + expect(req.request.method).toEqual('POST'); + + // Next, fulfill the request by transmitting a response. + req.flush(null, {status: 401, statusText: 'POST bucket mock error'}); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); })); it('should DELETE a bucket.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { - //Spy - spyOn(nfRegistryApi.http, 'post').and.callThrough(); + // api call + nfRegistryApi.deleteBucket('1234').subscribe(function (response) { + }); + // the request it made + req = httpMock.expectOne('/nifi-registry-api/buckets/1234'); + expect(req.request.method).toEqual('DELETE'); - // The function to test - nfRegistryApi.deleteBucket('1234').subscribe(function(response) { - var req = httpMock.expectOne('/nifi-registry-api/access/token/kerberos'); - req.flush({}); - req = httpMock.expectOne('/nifi-registry-api/access'); - req.flush({}); - httpMock.verify(); - // the request it made - req = httpMock.expectOne('/nifi-registry-api/buckets/1234'); - expect(req.request.method).toEqual('DELETE'); + // Next, fulfill the request by transmitting a response. + req.flush({}); - // Next, fulfill the request by transmitting a response. - req.flush({}); - httpMock.verify(); + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); + + it('should fail to DELETE a bucket.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // Spy + spyOn(nfRegistryApi.dialogService, 'openConfirm').and.callFake(function () { }); + + // api call + nfRegistryApi.deleteBucket('1234').subscribe(function (response) { + expect(response.message).toEqual('Http failure response for /nifi-registry-api/buckets/1234: 401 DELETE bucket mock error'); + var dialogServiceCall = nfRegistryApi.dialogService.openConfirm.calls.first(); + expect(dialogServiceCall.args[0].title).toBe('Error'); + expect(dialogServiceCall.args[0].message).toBe('Http failure response for /nifi-registry-api/buckets/1234: 401 DELETE bucket mock error'); + expect(dialogServiceCall.args[0].acceptButton).toBe('Ok'); + expect(dialogServiceCall.args[0].acceptButtonColor).toBe('fds-warn'); + }); + // the request it made + req = httpMock.expectOne('/nifi-registry-api/buckets/1234'); + expect(req.request.method).toEqual('DELETE'); + + // Next, fulfill the request by transmitting a response. + req.flush(null, {status: 401, statusText: 'DELETE bucket mock error'}); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); })); it('should GET bucket by ID.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // Spy + spyOn(nfRegistryApi.dialogService, 'openConfirm').and.callFake(function () { + return { + afterClosed: function() { return rxjs.Observable.of(true); } + } + }); - // The function to test - nfRegistryApi.getBucket('2f7f9e54-dc09-4ceb-aa58-9fe581319cdc').subscribe(function(response) { - var req = httpMock.expectOne('/nifi-registry-api/access/token/kerberos'); - req.flush({}); - req = httpMock.expectOne('/nifi-registry-api/access'); - req.flush({}); - httpMock.verify(); - // the request it made - req = httpMock.expectOne('/nifi-registry-api/buckets/2f7f9e54-dc09-4ceb-aa58-9fe581319cdc'); - expect(req.request.method).toEqual('GET'); - - // Next, fulfill the request by transmitting a response. - req.flush({ - 'identifier': '2f7f9e54-dc09-4ceb-aa58-9fe581319cdc', - 'name': 'Bucket #1' - }); - httpMock.verify(); + // api call + nfRegistryApi.getBucket('2f7f9e54-dc09-4ceb-aa58-9fe581319cdc').subscribe(function (response) { expect(response.identifier).toEqual('2f7f9e54-dc09-4ceb-aa58-9fe581319cdc'); expect(response.name).toEqual('Bucket #1'); }); + // the request it made + req = httpMock.expectOne('/nifi-registry-api/buckets/2f7f9e54-dc09-4ceb-aa58-9fe581319cdc'); + expect(req.request.method).toEqual('GET'); + + // Next, fulfill the request by transmitting a response. + req.flush({ + 'identifier': '2f7f9e54-dc09-4ceb-aa58-9fe581319cdc', + 'name': 'Bucket #1' + }); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); + + it('should fail to GET bucket by ID.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // Spy + spyOn(nfRegistryApi.dialogService, 'openConfirm').and.callFake(function () { + return { + afterClosed: function() { return rxjs.Observable.of(true); } + } + }); + + // api call + nfRegistryApi.getBucket('2f7f9e54-dc09-4ceb-aa58-9fe581319cdc').subscribe(function (response) { + expect(response.message).toEqual('Http failure response for /nifi-registry-api/buckets/2f7f9e54-dc09-4ceb-aa58-9fe581319cdc: 401 GET bucket mock error'); + var dialogServiceCall = nfRegistryApi.dialogService.openConfirm.calls.first(); + expect(dialogServiceCall.args[0].title).toBe('Error'); + expect(dialogServiceCall.args[0].message).toBe('Http failure response for /nifi-registry-api/buckets/2f7f9e54-dc09-4ceb-aa58-9fe581319cdc: 401 GET bucket mock error'); + expect(dialogServiceCall.args[0].acceptButton).toBe('Ok'); + expect(dialogServiceCall.args[0].acceptButtonColor).toBe('fds-warn'); + }); + + // the request it made + req = httpMock.expectOne('/nifi-registry-api/buckets/2f7f9e54-dc09-4ceb-aa58-9fe581319cdc'); + expect(req.request.method).toEqual('GET'); + + // Next, fulfill the request by transmitting a response. + req.flush(null, {status: 401, statusText: 'GET bucket mock error'}); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); })); it('should GET metadata for all buckets in the registry for which the client is authorized.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { - // The function to test - nfRegistryApi.getBuckets().subscribe(function(response) { - var req = httpMock.expectOne('/nifi-registry-api/access/token/kerberos'); - req.flush({}); - req = httpMock.expectOne('/nifi-registry-api/access'); - req.flush({}); - httpMock.verify(); - // the request it made - req = httpMock.expectOne('/nifi-registry-api/buckets'); - expect(req.request.method).toEqual('GET'); - - // Next, fulfill the request by transmitting a response. - req.flush([{ - 'identifier': '2f7f9e54-dc09-4ceb-aa58-9fe581319cdc', - 'name': 'Bucket #1' - }]); - httpMock.verify(); + // api call + nfRegistryApi.getBuckets().subscribe(function (response) { expect(response[0].identifier).toEqual('2f7f9e54-dc09-4ceb-aa58-9fe581319cdc'); expect(response[0].name).toEqual('Bucket #1'); }); + // the request it made + req = httpMock.expectOne('/nifi-registry-api/buckets'); + expect(req.request.method).toEqual('GET'); + + // Next, fulfill the request by transmitting a response. + req.flush([{ + 'identifier': '2f7f9e54-dc09-4ceb-aa58-9fe581319cdc', + 'name': 'Bucket #1' + }]); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); + + it('should fail to GET metadata for all buckets in the registry for which the client is authorized.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // Spy + spyOn(nfRegistryApi.dialogService, 'openConfirm').and.callFake(function () { + }); + + // api call + nfRegistryApi.getBuckets().subscribe(function (response) { + expect(response.message).toEqual('Http failure response for /nifi-registry-api/buckets: 401 GET metadata mock error'); + var dialogServiceCall = nfRegistryApi.dialogService.openConfirm.calls.first(); + expect(dialogServiceCall.args[0].title).toBe('Error'); + expect(dialogServiceCall.args[0].message).toBe('Http failure response for /nifi-registry-api/buckets: 401 GET metadata mock error'); + expect(dialogServiceCall.args[0].acceptButton).toBe('Ok'); + expect(dialogServiceCall.args[0].acceptButtonColor).toBe('fds-warn'); + }); + + // the request it made + req = httpMock.expectOne('/nifi-registry-api/buckets'); + expect(req.request.method).toEqual('GET'); + + // Next, fulfill the request by transmitting a response. + req.flush(null, {status: 401, statusText: 'GET metadata mock error'}); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); + + it('should POST to add a new user.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // api call + nfRegistryApi.addUser('test').subscribe(function (response) { + expect(response.identifier).toBe('1234'); + }); + + // the request it made + req = httpMock.expectOne('/nifi-registry-api/tenants/users'); + expect(req.request.method).toEqual('POST'); + + // Next, fulfill the request by transmitting a response. + req.flush({ + identifier: '1234' + }); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); + + it('should fail to POST to add a new user.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // Spy + spyOn(nfRegistryApi.dialogService, 'openConfirm').and.callFake(function () { + }); + + // api call + nfRegistryApi.addUser('test').subscribe(function (response) { + expect(response.message).toEqual('Http failure response for /nifi-registry-api/tenants/users: 401 POST add user mock error'); + var dialogServiceCall = nfRegistryApi.dialogService.openConfirm.calls.first(); + expect(dialogServiceCall.args[0].title).toBe('Error'); + expect(dialogServiceCall.args[0].message).toBe('Http failure response for /nifi-registry-api/tenants/users: 401 POST add user mock error'); + expect(dialogServiceCall.args[0].acceptButton).toBe('Ok'); + expect(dialogServiceCall.args[0].acceptButtonColor).toBe('fds-warn'); + }); + + // the request it made + req = httpMock.expectOne('/nifi-registry-api/tenants/users'); + expect(req.request.method).toEqual('POST'); + + // Next, fulfill the request by transmitting a response. + req.flush(null, {status: 401, statusText: 'POST add user mock error'}); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); + + it('should GET users.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // api call + nfRegistryApi.getUsers().subscribe(function (response) { + expect(response[0].identity).toEqual('User #1'); + }); + + // the request it made + req = httpMock.expectOne('/nifi-registry-api/tenants/users'); + expect(req.request.method).toEqual('GET'); + + // Next, fulfill the request by transmitting a response. + req.flush([{ + 'identifier': 123, + 'identity': 'User #1' + }]); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); + + it('should fail GET users.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // Spy + spyOn(nfRegistryApi.dialogService, 'openConfirm').and.callFake(function () { + }); + + // api call + nfRegistryApi.getUsers().subscribe(function (response) { + expect(response.message).toEqual('Http failure response for /nifi-registry-api/tenants/users: 401 GET users mock error'); + var dialogServiceCall = nfRegistryApi.dialogService.openConfirm.calls.first(); + expect(dialogServiceCall.args[0].title).toBe('Error'); + expect(dialogServiceCall.args[0].message).toBe('Http failure response for /nifi-registry-api/tenants/users: 401 GET users mock error'); + expect(dialogServiceCall.args[0].acceptButton).toBe('Ok'); + expect(dialogServiceCall.args[0].acceptButtonColor).toBe('fds-warn'); + }); + + // the request it made + req = httpMock.expectOne('/nifi-registry-api/tenants/users'); + expect(req.request.method).toEqual('GET'); + + // Next, fulfill the request by transmitting a response. + req.flush(null, {status: 401, statusText: 'GET users mock error'}); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); + + it('should DELETE users.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // api call + nfRegistryApi.deleteUser(123).subscribe(function (response) { + expect(response.identity).toEqual('User #1'); + }); + + // the request it made + req = httpMock.expectOne('/nifi-registry-api/tenants/users/123'); + expect(req.request.method).toEqual('DELETE'); + + // Next, fulfill the request by transmitting a response. + req.flush({ + 'identifier': 123, + 'identity': 'User #1' + }); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); + + it('should fail to DELETE users.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // Spy + spyOn(nfRegistryApi.dialogService, 'openConfirm').and.callFake(function () { + }); + + // api call + nfRegistryApi.deleteUser(123).subscribe(function (response) { + expect(response.message).toEqual('Http failure response for /nifi-registry-api/tenants/users/123: 401 DELETE users mock error'); + var dialogServiceCall = nfRegistryApi.dialogService.openConfirm.calls.first(); + expect(dialogServiceCall.args[0].title).toBe('Error'); + expect(dialogServiceCall.args[0].message).toBe('Http failure response for /nifi-registry-api/tenants/users/123: 401 DELETE users mock error'); + expect(dialogServiceCall.args[0].acceptButton).toBe('Ok'); + expect(dialogServiceCall.args[0].acceptButtonColor).toBe('fds-warn'); + }); + + // the request it made + req = httpMock.expectOne('/nifi-registry-api/tenants/users/123'); + expect(req.request.method).toEqual('DELETE'); + + // Next, fulfill the request by transmitting a response. + req.flush(null, {status: 401, statusText: 'DELETE users mock error'}); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); + + it('should GET user groups.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // api call + nfRegistryApi.getUserGroups().subscribe(function (response) { + expect(response[0].identity).toEqual('Group #1'); + }); + + // the request it made + req = httpMock.expectOne('/nifi-registry-api/tenants/user-groups'); + expect(req.request.method).toEqual('GET'); + + // Next, fulfill the request by transmitting a response. + req.flush([{ + 'identifier': 123, + 'identity': 'Group #1' + }]); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); + + it('should fail to GET user groups.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // Spy + spyOn(nfRegistryApi.dialogService, 'openConfirm').and.callFake(function () { + }); + + // api call + nfRegistryApi.getUserGroups().subscribe(function (response) { + expect(response.message).toEqual('Http failure response for /nifi-registry-api/tenants/user-groups: 401 GET user groups mock error'); + var dialogServiceCall = nfRegistryApi.dialogService.openConfirm.calls.first(); + expect(dialogServiceCall.args[0].title).toBe('Error'); + expect(dialogServiceCall.args[0].message).toBe('Http failure response for /nifi-registry-api/tenants/user-groups: 401 GET user groups mock error'); + expect(dialogServiceCall.args[0].acceptButton).toBe('Ok'); + expect(dialogServiceCall.args[0].acceptButtonColor).toBe('fds-warn'); + }); + + // the request it made + req = httpMock.expectOne('/nifi-registry-api/tenants/user-groups'); + expect(req.request.method).toEqual('GET'); + + // Next, fulfill the request by transmitting a response. + req.flush(null, {status: 401, statusText: 'GET user groups mock error'}); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); + + it('should GET a user group.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // api call + nfRegistryApi.getUserGroup(123).subscribe(function (response) { + expect(response.identity).toEqual('Group #1'); + }); + + // the request it made + req = httpMock.expectOne('/nifi-registry-api/tenants/user-groups/123'); + expect(req.request.method).toEqual('GET'); + + // Next, fulfill the request by transmitting a response. + req.flush({ + 'identifier': 123, + 'identity': 'Group #1' + }); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); + + it('should fail to GET a user group.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // Spy + spyOn(nfRegistryApi.dialogService, 'openConfirm').and.callFake(function () { + }); + + // api call + nfRegistryApi.getUserGroup(123).subscribe(function (response) { + expect(response.message).toEqual('Http failure response for /nifi-registry-api/tenants/user-groups/123: 401 GET user groups mock error'); + var dialogServiceCall = nfRegistryApi.dialogService.openConfirm.calls.first(); + expect(dialogServiceCall.args[0].title).toBe('Error'); + expect(dialogServiceCall.args[0].message).toBe('Http failure response for /nifi-registry-api/tenants/user-groups/123: 401 GET user groups mock error'); + expect(dialogServiceCall.args[0].acceptButton).toBe('Ok'); + expect(dialogServiceCall.args[0].acceptButtonColor).toBe('fds-warn'); + }); + + // the request it made + req = httpMock.expectOne('/nifi-registry-api/tenants/user-groups/123'); + expect(req.request.method).toEqual('GET'); + + // Next, fulfill the request by transmitting a response. + req.flush(null, {status: 401, statusText: 'GET user groups mock error'}); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); + + it('should DELETE a user group.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // api call + nfRegistryApi.deleteUserGroup(123).subscribe(function (response) { + expect(response.identity).toEqual('Group #1'); + }); + + // the request it made + req = httpMock.expectOne('/nifi-registry-api/tenants/user-groups/123'); + expect(req.request.method).toEqual('DELETE'); + + // Next, fulfill the request by transmitting a response. + req.flush({ + 'identifier': 123, + 'identity': 'Group #1' + }); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); + + it('should fail to DELETE a user group.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // Spy + spyOn(nfRegistryApi.dialogService, 'openConfirm').and.callFake(function () { + }); + + // api call + nfRegistryApi.deleteUserGroup(123).subscribe(function (response) { + expect(response.message).toEqual('Http failure response for /nifi-registry-api/tenants/user-groups/123: 401 DELETE user groups mock error'); + var dialogServiceCall = nfRegistryApi.dialogService.openConfirm.calls.first(); + expect(dialogServiceCall.args[0].title).toBe('Error'); + expect(dialogServiceCall.args[0].message).toBe('Http failure response for /nifi-registry-api/tenants/user-groups/123: 401 DELETE user groups mock error'); + expect(dialogServiceCall.args[0].acceptButton).toBe('Ok'); + expect(dialogServiceCall.args[0].acceptButtonColor).toBe('fds-warn'); + }); + + // the request it made + req = httpMock.expectOne('/nifi-registry-api/tenants/user-groups/123'); + expect(req.request.method).toEqual('DELETE'); + + // Next, fulfill the request by transmitting a response. + req.flush(null, {status: 401, statusText: 'DELETE user groups mock error'}); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); + + it('should POST to create a user group.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // api call + nfRegistryApi.createNewGroup(123, 'Group #1', [{identity: 'User #1', identifier: 9999}]).subscribe(function (response) { + expect(response.identifier).toEqual(123); + expect(response.identity).toEqual('Group #1'); + expect(response.users[0].identity).toEqual('User #1'); + }); + + // the request it made + req = httpMock.expectOne('/nifi-registry-api/tenants/user-groups'); + expect(req.request.method).toEqual('POST'); + + // Next, fulfill the request by transmitting a response. + req.flush({ + 'identifier': 123, + 'identity': 'Group #1', + 'users': [{identity: 'User #1', identifier: 9999}] + }); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); + + it('should fail to POST to create a user group.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // Spy + spyOn(nfRegistryApi.dialogService, 'openConfirm').and.callFake(function () { + }); + + // api call + nfRegistryApi.createNewGroup(123, 'Group #1', [{identity: 'User #1', identifier: 9999}]).subscribe(function (response) { + expect(response.message).toEqual('Http failure response for /nifi-registry-api/tenants/user-groups: 401 POST user groups mock error'); + var dialogServiceCall = nfRegistryApi.dialogService.openConfirm.calls.first(); + expect(dialogServiceCall.args[0].title).toBe('Error'); + expect(dialogServiceCall.args[0].message).toBe('Http failure response for /nifi-registry-api/tenants/user-groups: 401 POST user groups mock error'); + expect(dialogServiceCall.args[0].acceptButton).toBe('Ok'); + expect(dialogServiceCall.args[0].acceptButtonColor).toBe('fds-warn'); + }); + + // the request it made + req = httpMock.expectOne('/nifi-registry-api/tenants/user-groups'); + expect(req.request.method).toEqual('POST'); + + // Next, fulfill the request by transmitting a response. + req.flush(null, {status: 401, statusText: 'POST user groups mock error'}); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); + + it('should PUT to update a user group.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // api call + nfRegistryApi.updateUserGroup(123, 'Group #1', [{identity: 'User #1', identifier: 9999}]).subscribe(function (response) { + expect(response.identifier).toEqual(123); + expect(response.identity).toEqual('Group #1'); + expect(response.users[0].identity).toEqual('User #1'); + }); + + // the request it made + req = httpMock.expectOne('/nifi-registry-api/tenants/user-groups/123'); + expect(req.request.method).toEqual('PUT'); + + // Next, fulfill the request by transmitting a response. + req.flush({ + 'identifier': 123, + 'identity': 'Group #1', + 'users': [{identity: 'User #1', identifier: 9999}] + }); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); + + it('should fail to PUT to update a user group.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // Spy + spyOn(nfRegistryApi.dialogService, 'openConfirm').and.callFake(function () { + }); + + // api call + nfRegistryApi.updateUserGroup('123', 'Group #1', [{identity: 'User #1', identifier: '9999'}]).subscribe(function (response) { + var dialogServiceCall = nfRegistryApi.dialogService.openConfirm.calls.first(); + expect(dialogServiceCall.args[0].title).toBe('Error'); + expect(dialogServiceCall.args[0].message).toBe('Http failure response for /nifi-registry-api/tenants/user-groups/123: 401 PUT user groups mock error'); + expect(dialogServiceCall.args[0].acceptButton).toBe('Ok'); + expect(dialogServiceCall.args[0].acceptButtonColor).toBe('fds-warn'); + }); + + // the request it made + req = httpMock.expectOne('/nifi-registry-api/tenants/user-groups/123'); + expect(req.request.method).toEqual('PUT'); + + // Next, fulfill the request by transmitting a response. + req.flush(null, {status: 401, statusText: 'PUT user groups mock error'}); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); +}); + +describe('NfRegistry Service API w/ Angular testing utils', function () { + var comp; + var fixture; + var nfRegistryApi; + var nfRegistryService; + + beforeEach(function () { + ngCoreTesting.TestBed.configureTestingModule({ + imports: [ + ngMoment.MomentModule, + ngHttp.HttpModule, + ngHttp.JsonpModule, + ngCommonHttp.HttpClientModule, + fdsCore, + NfRegistryRoutes, + ngCommonHttpTesting.HttpClientTestingModule + ], + declarations: [ + FdsDemo, + NfRegistry, + NfRegistryExplorer, + NfRegistryAdministration, + NfRegistryUsersAdministration, + NfRegistryUserDetails, + NfRegistryUserPermissions, + NfRegistryUserGroupPermissions, + NfRegistryBucketPermissions, + NfRegistryAddUser, + NfRegistryWorkflowAdministration, + NfRegistryGridListViewer, + NfRegistryBucketGridListViewer, + NfRegistryDropletGridListViewer, + NfPageNotFoundComponent + ], + providers: [ + NfRegistryService, + NfRegistryAuthService, + NfRegistryApi, + NfStorage, + { + provide: ngCommonHttp.HTTP_INTERCEPTORS, + useClass: NfRegistryTokenInterceptor, + multi: true + }, + { + provide: ngCommon.APP_BASE_HREF, + useValue: '/' + } + ], + bootstrap: [NfRegistry] + }); + fixture = ngCoreTesting.TestBed.createComponent(NfRegistry); + fixture.detectChanges(); + comp = fixture.componentInstance; + + // NfRegistryService from the root injector + nfRegistryService = ngCoreTesting.TestBed.get(NfRegistryService); + nfRegistryApi = ngCoreTesting.TestBed.get(NfRegistryApi); + }); + + it('should POST to exchange tickets.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // Spy + spyOn(nfRegistryApi.nfStorage, 'setItem').and.callThrough(); + + // api call + nfRegistryApi.ticketExchange().subscribe(function (response) { + var setItemCall = nfRegistryApi.nfStorage.setItem.calls.first(); + expect(setItemCall.args[1]).toBe('eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJiYmVuZGVATklGSS5BUEFDSEUuT1JHIiwiaXNzIjoiS2VyYmVyb3NTcG5lZ29JZGVudGl0eVByb3ZpZGVyIiwiYXVkIjoiS2VyYmVyb3NTcG5lZ29JZGVudGl0eVByb3ZpZGVyIiwicHJlZmVycmVkX3VzZXJuYW1lIjoiYmJlbmRlQE5JRkkuQVBBQ0hFLk9SRyIsImtpZCI6IjQ3NWQwZWEyLTkzZGItNDhiNi05MjcxLTgyOGM3MzQ5ZTFkNiIsImlhdCI6MTUxMjQ4NTY4NywiZXhwIjoxNTEyNTI4ODg3fQ.lkaWPQw1ld7Qqb6-Zu8mAqu6r8mUVHBNP0ZfNpES3rA'); + expect(response).toBe('eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJiYmVuZGVATklGSS5BUEFDSEUuT1JHIiwiaXNzIjoiS2VyYmVyb3NTcG5lZ29JZGVudGl0eVByb3ZpZGVyIiwiYXVkIjoiS2VyYmVyb3NTcG5lZ29JZGVudGl0eVByb3ZpZGVyIiwicHJlZmVycmVkX3VzZXJuYW1lIjoiYmJlbmRlQE5JRkkuQVBBQ0hFLk9SRyIsImtpZCI6IjQ3NWQwZWEyLTkzZGItNDhiNi05MjcxLTgyOGM3MzQ5ZTFkNiIsImlhdCI6MTUxMjQ4NTY4NywiZXhwIjoxNTEyNTI4ODg3fQ.lkaWPQw1ld7Qqb6-Zu8mAqu6r8mUVHBNP0ZfNpES3rA'); + }); + + // the request it made + req = httpMock.expectOne('/nifi-registry-api/access/token/kerberos'); + expect(req.request.method).toEqual('POST'); + + // Next, fulfill the request by transmitting a response. + req.flush('eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJiYmVuZGVATklGSS5BUEFDSEUuT1JHIiwiaXNzIjoiS2VyYmVyb3NTcG5lZ29JZGVudGl0eVByb3ZpZGVyIiwiYXVkIjoiS2VyYmVyb3NTcG5lZ29JZGVudGl0eVByb3ZpZGVyIiwicHJlZmVycmVkX3VzZXJuYW1lIjoiYmJlbmRlQE5JRkkuQVBBQ0hFLk9SRyIsImtpZCI6IjQ3NWQwZWEyLTkzZGItNDhiNi05MjcxLTgyOGM3MzQ5ZTFkNiIsImlhdCI6MTUxMjQ4NTY4NywiZXhwIjoxNTEyNTI4ODg3fQ.lkaWPQw1ld7Qqb6-Zu8mAqu6r8mUVHBNP0ZfNpES3rA'); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); + + it('should load jwt from local storage.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // Spy + spyOn(nfRegistryApi.nfStorage, 'hasItem').and.callFake(function () { + return true; + }); + spyOn(nfRegistryApi.nfStorage, 'getItem').and.callFake(function () { + return 123; + }); + + // api call + nfRegistryApi.ticketExchange().subscribe(function (response) { + expect(response).toBe(123); + }); + })); + + it('should fail to POST to exchange tickets.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // Spy + spyOn(nfRegistryApi.nfStorage, 'hasItem').and.callFake(function () { + return false; + }); + // api call + nfRegistryApi.ticketExchange().subscribe(function (response) { + expect(response).toEqual(''); + }); + + // the request it made + req = httpMock.expectOne('/nifi-registry-api/access/token/kerberos'); + expect(req.request.method).toEqual('POST'); + + // Next, fulfill the request by transmitting a response. + req.flush(null, {status: 401, statusText: 'POST exchange tickets mock error'}); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); + + it('should GET to load the current user.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // api call + nfRegistryApi.loadCurrentUser().subscribe(function (response) { + expect(response.identifier).toBe(123); + expect(response.identity).toBe('Admin User'); + }); + + // the request it made + req = httpMock.expectOne('/nifi-registry-api/access'); + expect(req.request.method).toEqual('GET'); + + // Next, fulfill the request by transmitting a response. + req.flush({ + 'identifier': 123, + 'identity': 'Admin User' + }); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); + })); + + it('should fail to GET to load the current user.', ngCoreTesting.inject([ngCommonHttpTesting.HttpTestingController], function (httpMock) { + // Spy + spyOn(nfRegistryApi.router, 'navigateByUrl').and.callFake(function () {}); + + // api call + nfRegistryApi.loadCurrentUser().subscribe(function (response) { + var navigateByUrlCall = nfRegistryApi.router.navigateByUrl.calls.first(); + expect(navigateByUrlCall.args[0]).toBe('/nifi-registry/login'); + }); + + // the request it made + req = httpMock.expectOne('/nifi-registry-api/access'); + expect(req.request.method).toEqual('GET'); + + // Next, fulfill the request by transmitting a response. + req.flush(null, {status: 401, statusText: 'GET current user mock error'}); + + // Finally, assert that there are no outstanding requests. + httpMock.verify(); })); }); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/2f343e1b/nifi-registry-web-ui/src/main/webapp/services/nf-registry.service.js ---------------------------------------------------------------------- diff --git a/nifi-registry-web-ui/src/main/webapp/services/nf-registry.service.js b/nifi-registry-web-ui/src/main/webapp/services/nf-registry.service.js index f796f7a..3b49ae1 100644 --- a/nifi-registry-web-ui/src/main/webapp/services/nf-registry.service.js +++ b/nifi-registry-web-ui/src/main/webapp/services/nf-registry.service.js @@ -37,14 +37,21 @@ require('rxjs/add/operator/map'); * @constructor */ function NfRegistryService(nfRegistryApi, nfStorage, tdDataTableService, router, fdsDialogService, fdsSnackBarService) { + this.registry = { + name: "Nifi Registry" + }; + + // Services this.router = router; this.api = nfRegistryApi; this.nfStorage = nfStorage; this.dialogService = fdsDialogService; this.snackBarService = fdsSnackBarService; - this.registry = { - name: "Nifi Registry" - }; + this.dataTableService = tdDataTableService; + + //<editor-fold desc="application state objects"> + + // General this.bucket = {}; this.buckets = []; this.droplet = {}; @@ -58,14 +65,16 @@ function NfRegistryService(nfRegistryApi, nfStorage, tdDataTableService, router, this.explorerViewType = ''; this.perspective = ''; this.breadCrumbState = 'out'; - this.dataTableService = tdDataTableService; + // Droplets this.filteredDroplets = []; - this.dropletActions = [{ - name: 'Delete', - icon: 'fa fa-trash', - tooltip: 'Delete' - }]; + this.dropletActions = [ + { + name: 'Delete', + icon: 'fa fa-trash', + tooltip: 'Delete' + } + ]; this.dropletColumns = [ { name: 'name', @@ -81,6 +90,7 @@ function NfRegistryService(nfRegistryApi, nfStorage, tdDataTableService, router, this.autoCompleteDroplets = []; this.dropletsSearchTerms = []; + // Buckets this.filteredBuckets = []; this.bucketColumns = [ { @@ -92,10 +102,10 @@ function NfRegistryService(nfRegistryApi, nfStorage, tdDataTableService, router, ]; this.allBucketsSelected = false; this.autoCompleteBuckets = []; - this.selectedBuckets = []; this.bucketsSearchTerms = []; this.isMultiBucketActionsDisabled = true; + // Users and Groups this.filteredUsers = []; this.filteredUserGroups = []; this.userColumns = [ @@ -109,10 +119,9 @@ function NfRegistryService(nfRegistryApi, nfStorage, tdDataTableService, router, ]; this.allUsersAndGroupsSelected = false; this.autoCompleteUsersAndGroups = []; - this.selectedUsers = []; this.usersSearchTerms = []; - this.isMultiUserActionsDisabled = true; - this.isMultiUserGroupActionsDisabled = false; + + //</editor-fold> }; NfRegistryService.prototype = { @@ -571,7 +580,7 @@ NfRegistryService.prototype = { * * @param column The column to sort by. */ - sortUsersAndGroups: function (sortEvent, column) { + sortUsersAndGroups: function (column) { if (column.sortable) { var sortBy = column.name; var sortOrder = column.sortOrder = (column.sortOrder === 'ASC') ? 'DESC' : 'ASC'; @@ -595,19 +604,19 @@ NfRegistryService.prototype = { var self = this; // get the current user return rxjs.Observable.of(this.api.loadCurrentUser().subscribe(function (currentUser) { - // if the user is logged, we want to determine if they were logged in using a certificate - if (currentUser.status !== "UNKNOWN") { - // render the users name - self.currentUser = currentUser; - - // render the logout button if there is a token locally - if (self.nfStorage.getItem('jwt') !== null) { - self.currentUser.canLogout = true; - } - } else { - // set the anonymous user label - self.nfRegistryService.currentUser.identity = 'Anonymous'; + // if the user is logged, we want to determine if they were logged in using a certificate + if (currentUser.status !== "UNKNOWN") { + // render the users name + self.currentUser = currentUser; + + // render the logout button if there is a token locally + if (self.nfStorage.getItem('jwt') !== null) { + self.currentUser.canLogout = true; } + } else { + // set the anonymous user label + self.nfRegistryService.currentUser.identity = 'Anonymous'; + } })); }, @@ -688,39 +697,47 @@ NfRegistryService.prototype = { /** * Checks each of the `filteredUsers` and each of the `filteredUserGroups` `checked` property state and sets - * the `allUsersAndGroupsSelected`, `isMultiUserGroupActionsDisabled`, and the `isMultiUserActionsDisabled` - * properties accordingly. + * the `allUsersAndGroupsSelected` property accordingly. */ determineAllUsersAndGroupsSelectedState: function () { - var selected = 0; var allSelected = true; - this.isMultiUserGroupActionsDisabled = false; this.filteredUserGroups.forEach(function (c) { - if (c.checked) { - selected++; - } if (c.checked === undefined || c.checked === false) { allSelected = false; } }); - if (selected > 0) { - this.isMultiUserGroupActionsDisabled = true; - } - this.filteredUsers.forEach(function (c) { - if (c.checked) { - selected++; - } if (c.checked === undefined || c.checked === false) { allSelected = false; } }); - this.isMultiUserActionsDisabled = (selected > 0) ? false : true; this.allUsersAndGroupsSelected = allSelected; }, /** + * Gets the currently selected groups. + * + * @returns {Array.<T>} The selected groups. + */ + getSelectedGroups: function () { + return this.filteredUserGroups.filter(function (filteredUserGroup) { + return filteredUserGroup.checked; + }); + }, + + /** + * Gets the currently selected users. + * + * @returns {Array.<T>} The selected users. + */ + getSelectedUsers: function () { + return this.filteredUsers.filter(function (filteredUser) { + return filteredUser.checked; + }); + }, + + /** * Checks the `allUsersAndGroupsSelected` property state and either selects * or deselects all `filteredUsers` and each `filteredUserGroups`. */ @@ -734,8 +751,7 @@ NfRegistryService.prototype = { /** * Sets the `checked` property of each `filteredUsers` and each `filteredUserGroups` to true and sets - * the `allUsersAndGroupsSelected`, `isMultiUserGroupActionsDisabled`, and the `isMultiUserActionsDisabled` - * properties accordingly. + * the `allUsersAndGroupsSelected` properties accordingly. */ selectAllUsersAndGroups: function () { this.filteredUsers.forEach(function (c) { @@ -744,15 +760,12 @@ NfRegistryService.prototype = { this.filteredUserGroups.forEach(function (c) { c.checked = true; }); - this.isMultiUserGroupActionsDisabled = (this.filteredUserGroups.length > 0) ? true : false; this.allUsersAndGroupsSelected = true; - this.isMultiUserActionsDisabled = false; }, /** * Sets the `checked` property of each `filteredUsers` and each `filteredUserGroups` to false and sets - * the `allUsersAndGroupsSelected`, `isMultiUserGroupActionsDisabled`, and the `isMultiUserActionsDisabled` - * properties accordingly. + * the `allUsersAndGroupsSelected` properties accordingly. */ deselectAllUsersAndGroups: function () { this.filteredUsers.forEach(function (c) { @@ -762,8 +775,6 @@ NfRegistryService.prototype = { c.checked = false; }); this.allUsersAndGroupsSelected = false; - this.isMultiUserGroupActionsDisabled = false; - this.isMultiUserActionsDisabled = true; }, /** @@ -933,7 +944,7 @@ NfRegistryService.prototype = { * @param ignoreCase Ignore case. * @returns {*} */ - filterData: function(data, searchTerm, ignoreCase) { + filterData: function (data, searchTerm, ignoreCase) { var field = ''; if (searchTerm.indexOf(":") > -1) { field = searchTerm.split(':')[0].trim();
