[ADF-847] upgrade to use application configuration service (#1986)

* migrate core lib to use server-side app config

* fix unit tests

* update Search tests

- update tests
- upgrade tests to use TestBed

* update UserInfo tests

* update Social tests

* update tests

* update unit tests

* cleanup old code

* update about page

* update demo shell readme

* dev and prod configurations
This commit is contained in:
Denys Vuika
2017-06-20 11:47:01 +01:00
committed by Eugenio Romano
parent f5b94e1bb4
commit d5f64fa9fc
45 changed files with 469 additions and 760 deletions

View File

@@ -19,54 +19,29 @@ import { Injectable } from '@angular/core';
import { AlfrescoApi } from 'alfresco-js-api';
import * as alfrescoApi from 'alfresco-js-api';
import { AlfrescoSettingsService } from './alfresco-settings.service';
import { AppConfigService } from './app-config.service';
import { StorageService } from './storage.service';
@Injectable()
export class AlfrescoApiService {
private alfrescoApi: AlfrescoApi;
private provider: string;
private ticketEcm: string;
private ticketBpm: string;
private hostEcm: string;
private hostBpm: string;
private contextRoot: string;
private disableCsrf: boolean;
public getInstance(): AlfrescoApi {
return this.alfrescoApi;
}
constructor(private settingsService: AlfrescoSettingsService,
constructor(private appConfig: AppConfigService,
private settingsService: AlfrescoSettingsService,
private storage: StorageService) {
this.provider = this.settingsService.getProviders();
this.ticketEcm = this.getTicketEcm();
this.ticketBpm = this.getTicketBpm();
this.hostEcm = this.settingsService.ecmHost;
this.hostBpm = this.settingsService.bpmHost;
this.contextRoot = 'alfresco';
this.disableCsrf = false;
this.init();
settingsService.bpmHostSubject.subscribe((hostBpm) => {
this.hostBpm = hostBpm;
this.init();
});
settingsService.ecmHostSubject.subscribe((hostEcm) => {
this.hostEcm = hostEcm;
this.init();
});
settingsService.csrfSubject.subscribe((disableCsrf) => {
this.disableCsrf = disableCsrf;
this.init();
@@ -81,29 +56,12 @@ export class AlfrescoApiService {
private init() {
this.alfrescoApi = <AlfrescoApi>new alfrescoApi({
provider: this.provider,
ticketEcm: this.ticketEcm,
ticketBpm: this.ticketBpm,
hostEcm: this.hostEcm,
hostBpm: this.hostBpm,
contextRoot: this.contextRoot,
ticketEcm: this.storage.getItem('ticket-ECM'),
ticketBpm: this.storage.getItem('ticket-BPM'),
hostEcm: this.appConfig.get<string>('ecmHost'),
hostBpm: this.appConfig.get<string>('bpmHost'),
contextRoot: 'alfresco',
disableCsrf: this.disableCsrf
});
}
/**
* The method return the ECM ticket stored in the Storage
* @returns ticket
*/
private getTicketEcm(): string {
return this.storage.getItem('ticket-ECM');
}
/**
* The method return the BPM ticket stored in the Storage
* @returns ticket
*/
private getTicketBpm(): string {
return this.storage.getItem('ticket-BPM');
}
}

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { ReflectiveInjector } from '@angular/core';
import { TestBed, async } from '@angular/core/testing';
import { AlfrescoSettingsService } from './alfresco-settings.service';
import { AlfrescoAuthenticationService } from './alfresco-authentication.service';
import { AlfrescoApiService } from './alfresco-api.service';
@@ -23,30 +23,39 @@ import { StorageService } from './storage.service';
import { CookieService } from './cookie.service';
import { CookieServiceMock } from './../assets/cookie.service.mock';
import { LogService } from './log.service';
import { AppConfigModule } from './app-config.service';
declare let jasmine: any;
describe('AlfrescoAuthenticationService', () => {
let injector;
let apiService: AlfrescoApiService;
let authService: AlfrescoAuthenticationService;
let settingsService: AlfrescoSettingsService;
let storage: StorageService;
let cookie: CookieService;
beforeEach(() => {
injector = ReflectiveInjector.resolveAndCreate([
AlfrescoSettingsService,
AlfrescoApiService,
AlfrescoAuthenticationService,
StorageService,
{ provide: CookieService, useClass: CookieServiceMock },
LogService
]);
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
AppConfigModule
],
providers: [
AlfrescoSettingsService,
AlfrescoApiService,
AlfrescoAuthenticationService,
StorageService,
{ provide: CookieService, useClass: CookieServiceMock },
LogService
]
}).compileComponents();
}));
authService = injector.get(AlfrescoAuthenticationService);
settingsService = injector.get(AlfrescoSettingsService);
cookie = injector.get(CookieService);
storage = injector.get(StorageService);
beforeEach(() => {
apiService = TestBed.get(AlfrescoApiService);
authService = TestBed.get(AlfrescoAuthenticationService);
settingsService = TestBed.get(AlfrescoSettingsService);
cookie = TestBed.get(CookieService);
storage = TestBed.get(StorageService);
storage.clear();
jasmine.Ajax.install();
@@ -350,32 +359,6 @@ describe('AlfrescoAuthenticationService', () => {
});
});
describe('Setting service change should reflect in the api', () => {
beforeEach(() => {
settingsService.setProviders('ALL');
});
it('should host ecm url change be reflected in the api configuration', () => {
settingsService.ecmHost = '127.99.99.99';
expect(authService.alfrescoApi.getInstance().config.hostEcm).toBe('127.99.99.99');
});
it('should host bpm url change be reflected in the api configuration', () => {
settingsService.bpmHost = '127.99.99.99';
expect(authService.alfrescoApi.getInstance().config.hostBpm).toBe('127.99.99.99');
});
it('should host bpm provider change be reflected in the api configuration', () => {
settingsService.setProviders('ECM');
expect(authService.alfrescoApi.getInstance().config.provider).toBe('ECM');
});
});
describe('when the setting is both ECM and BPM ', () => {
beforeEach(() => {

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { ReflectiveInjector } from '@angular/core';
import { TestBed, async } from '@angular/core/testing';
import { AlfrescoSettingsService } from './alfresco-settings.service';
import { AlfrescoAuthenticationService } from './alfresco-authentication.service';
import { AlfrescoContentService } from './alfresco-content.service';
@@ -24,12 +24,13 @@ import { StorageService } from './storage.service';
import { CookieService } from './cookie.service';
import { CookieServiceMock } from './../assets/cookie.service.mock';
import { LogService } from './log.service';
import { AppConfigModule } from './app-config.service';
declare let jasmine: any;
describe('AlfrescoContentService', () => {
let injector, contentService: AlfrescoContentService;
let contentService: AlfrescoContentService;
let authService: AlfrescoAuthenticationService;
let settingsService: AlfrescoSettingsService;
let storage: StorageService;
@@ -37,21 +38,30 @@ describe('AlfrescoContentService', () => {
const nodeId = 'fake-node-id';
beforeEach(() => {
injector = ReflectiveInjector.resolveAndCreate([
AlfrescoApiService,
AlfrescoContentService,
AlfrescoAuthenticationService,
AlfrescoSettingsService,
StorageService,
{ provide: CookieService, useClass: CookieServiceMock },
LogService
]);
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
AppConfigModule
],
declarations: [
],
providers: [
AlfrescoApiService,
AlfrescoContentService,
AlfrescoAuthenticationService,
AlfrescoSettingsService,
StorageService,
{ provide: CookieService, useClass: CookieServiceMock },
LogService
]
}).compileComponents();
}));
authService = injector.get(AlfrescoAuthenticationService);
settingsService = injector.get(AlfrescoSettingsService);
contentService = injector.get(AlfrescoContentService);
storage = injector.get(StorageService);
beforeEach(() => {
authService = TestBed.get(AlfrescoAuthenticationService);
settingsService = TestBed.get(AlfrescoSettingsService);
contentService = TestBed.get(AlfrescoContentService);
storage = TestBed.get(StorageService);
storage.clear();
node = {
@@ -73,7 +83,7 @@ describe('AlfrescoContentService', () => {
it('should return a valid content URL', (done) => {
authService.login('fake-username', 'fake-password').subscribe(() => {
expect(contentService.getContentUrl(node)).toBe('http://localhost:8080/alfresco/api/' +
expect(contentService.getContentUrl(node)).toBe('http://localhost:3000/ecm/alfresco/api/' +
'-default-/public/alfresco/versions/1/nodes/fake-node-id/content?attachment=false&alf_ticket=fake-post-ticket');
done();
});
@@ -88,7 +98,7 @@ describe('AlfrescoContentService', () => {
it('should return a valid thumbnail URL', (done) => {
authService.login('fake-username', 'fake-password').subscribe(() => {
expect(contentService.getDocumentThumbnailUrl(node))
.toBe('http://localhost:8080/alfresco/api/-default-/public/alfresco' +
.toBe('http://localhost:3000/ecm/alfresco/api/-default-/public/alfresco' +
'/versions/1/nodes/fake-node-id/renditions/doclib/content?attachment=false&alf_ticket=fake-post-ticket');
done();
});

View File

@@ -15,35 +15,32 @@
* limitations under the License.
*/
import { TestBed, async } from '@angular/core/testing';
import { AppConfigModule } from './app-config.service';
import { AlfrescoSettingsService } from './alfresco-settings.service';
describe('AlfrescoSettingsService', () => {
let service: AlfrescoSettingsService;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
AppConfigModule
],
declarations: [
],
providers: [
AlfrescoSettingsService
]
}).compileComponents();
}));
beforeEach(() => {
service = new AlfrescoSettingsService();
service = TestBed.get(AlfrescoSettingsService);
});
it('should have default ECM host', () => {
expect(service.ecmHost).toBe(AlfrescoSettingsService.DEFAULT_ECM_ADDRESS);
});
it('should change host ECM', () => {
// this test ensures 'host' getter/setter working properly
let address = 'http://192.168.0.1';
service.ecmHost = address;
expect(service.ecmHost).toBe(address);
});
it('should have default BPM host', () => {
expect(service.bpmHost).toBe(AlfrescoSettingsService.DEFAULT_BPM_ADDRESS);
});
it('should change host BPM', () => {
// this test ensures 'host' getter/setter working properly
let address = 'http://192.168.0.1';
service.bpmHost = address;
expect(service.bpmHost).toBe(address);
it('should be exposed by the module', () => {
expect(service).toBeDefined();
});
});

View File

@@ -17,31 +17,23 @@
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs/Subject';
import { AppConfigService } from './app-config.service';
@Injectable()
export class AlfrescoSettingsService {
static DEFAULT_ECM_ADDRESS: string = 'http://' + window.location.hostname + ':8080';
static DEFAULT_BPM_ADDRESS: string = 'http://' + window.location.hostname + ':9999';
static DEFAULT_CSRF_CONFIG: boolean = false;
static DEFAULT_BPM_CONTEXT_PATH: string = '/activiti-app';
private _ecmHost: string = AlfrescoSettingsService.DEFAULT_ECM_ADDRESS;
private _bpmHost: string = AlfrescoSettingsService.DEFAULT_BPM_ADDRESS;
private _csrfDisabled: boolean = AlfrescoSettingsService.DEFAULT_CSRF_CONFIG;
private _bpmContextPath = AlfrescoSettingsService.DEFAULT_BPM_CONTEXT_PATH;
private providers: string = 'ALL'; // ECM, BPM , ALL
public bpmHostSubject: Subject<string> = new Subject<string>();
public ecmHostSubject: Subject<string> = new Subject<string>();
public csrfSubject: Subject<boolean> = new Subject<boolean>();
public providerSubject: Subject<string> = new Subject<string>();
constructor(private appConfig: AppConfigService) {}
public get ecmHost(): string {
return this._ecmHost;
return this.appConfig.get<string>('ecmHost');
}
public set csrfDisabled(csrfDisabled: boolean) {
@@ -49,22 +41,24 @@ export class AlfrescoSettingsService {
this._csrfDisabled = csrfDisabled;
}
/* @deprecated in 1.6.0 */
public set ecmHost(ecmHostUrl: string) {
this.ecmHostSubject.next(ecmHostUrl);
this._ecmHost = ecmHostUrl;
console.log('AlfrescoSettingsService.ecmHost is deprecated. Use AppConfigService instead.');
}
public get bpmHost(): string {
return this._bpmHost;
return this.appConfig.get<string>('bpmHost');
}
/* @deprecated in 1.6.0 */
public set bpmHost(bpmHostUrl: string) {
this.bpmHostSubject.next(bpmHostUrl);
this._bpmHost = bpmHostUrl;
console.log('AlfrescoSettingsService.bpmHost is deprecated. Use AppConfigService instead.');
}
/* @deprecated in 1.6.0 */
public getBPMApiBaseUrl(): string {
return this._bpmHost + this._bpmContextPath;
console.log('AlfrescoSettingsService.getBPMApiBaseUrl is deprecated.');
return this.bpmHost + '/activiti-app';
}
public getProviders(): string {

View File

@@ -16,7 +16,7 @@
*/
import { Injectable, APP_INITIALIZER, NgModule, ModuleWithProviders } from '@angular/core';
import { Http } from '@angular/http';
import { HttpModule, Http } from '@angular/http';
import { ObjectUtils } from '../utils/object-utils';
@Injectable()
@@ -70,6 +70,9 @@ export function InitAppConfigServiceProvider(resource: string): any {
}
@NgModule({
imports: [
HttpModule
],
providers: [
AppConfigService
]

View File

@@ -15,6 +15,10 @@
* limitations under the License.
*/
import { TestBed, async, inject } from '@angular/core/testing';
import { Router} from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { AlfrescoSettingsService } from './alfresco-settings.service';
import { AlfrescoAuthenticationService } from './alfresco-authentication.service';
import { AlfrescoApiService } from './alfresco-api.service';
@@ -23,24 +27,29 @@ import { LogService } from './log.service';
import { CookieService } from './cookie.service';
import { CookieServiceMock } from './../assets/cookie.service.mock';
import { AuthGuardBpm } from './auth-guard-bpm.service';
import { Router} from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { TestBed, async, inject } from '@angular/core/testing';
import { AppConfigModule } from './app-config.service';
describe('AuthGuardService BPM', () => {
beforeEach(() => {
beforeEach(async(() => {
TestBed.configureTestingModule({
providers: [AuthGuardBpm,
imports: [
AppConfigModule,
RouterTestingModule
],
declarations: [
],
providers: [
AuthGuardBpm,
AlfrescoSettingsService,
AlfrescoApiService,
AlfrescoAuthenticationService,
StorageService,
{ provide: CookieService, useClass: CookieServiceMock },
LogService],
imports: [RouterTestingModule]
});
});
LogService
]
}).compileComponents();
}));
it('if the alfresco js api is logged in should canActivate be true',
async(inject([AuthGuardBpm, Router, AlfrescoSettingsService, StorageService, AlfrescoAuthenticationService], (auth, router, settingsService, storage, authService) => {

View File

@@ -15,6 +15,10 @@
* limitations under the License.
*/
import { TestBed, async, inject } from '@angular/core/testing';
import { Router} from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { AlfrescoSettingsService } from './alfresco-settings.service';
import { AlfrescoAuthenticationService } from './alfresco-authentication.service';
import { AlfrescoApiService } from './alfresco-api.service';
@@ -23,24 +27,29 @@ import { CookieService } from './cookie.service';
import { CookieServiceMock } from './../assets/cookie.service.mock';
import { LogService } from './log.service';
import { AuthGuardEcm } from './auth-guard-ecm.service';
import { Router} from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { TestBed, async, inject } from '@angular/core/testing';
import { AppConfigModule } from './app-config.service';
describe('AuthGuardService ECM', () => {
beforeEach(() => {
beforeEach(async(() => {
TestBed.configureTestingModule({
providers: [AuthGuardEcm,
imports: [
AppConfigModule,
RouterTestingModule
],
declarations: [
],
providers: [
AuthGuardEcm,
AlfrescoSettingsService,
AlfrescoApiService,
AlfrescoAuthenticationService,
StorageService,
{ provide: CookieService, useClass: CookieServiceMock },
LogService],
imports: [RouterTestingModule]
});
});
LogService
]
}).compileComponents();
}));
it('if the alfresco js api is logged in should canActivate be true',
async(inject([AuthGuardEcm, Router, AlfrescoSettingsService, StorageService, AlfrescoAuthenticationService], (auth, router, settingsService, storage, authService) => {

View File

@@ -15,6 +15,10 @@
* limitations under the License.
*/
import { TestBed, async, inject } from '@angular/core/testing';
import { Router} from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { AlfrescoSettingsService } from './alfresco-settings.service';
import { AlfrescoAuthenticationService } from './alfresco-authentication.service';
import { AlfrescoApiService } from './alfresco-api.service';
@@ -23,24 +27,27 @@ import { CookieService } from './cookie.service';
import { CookieServiceMock } from './../assets/cookie.service.mock';
import { LogService } from './log.service';
import { AuthGuard } from './auth-guard.service';
import { Router} from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { TestBed, async, inject } from '@angular/core/testing';
import { AppConfigModule } from './app-config.service';
describe('AuthGuardService', () => {
beforeEach(() => {
beforeEach(async(() => {
TestBed.configureTestingModule({
providers: [AuthGuard,
imports: [
AppConfigModule,
RouterTestingModule
],
providers: [
AuthGuard,
AlfrescoSettingsService,
AlfrescoApiService,
AlfrescoAuthenticationService,
StorageService,
{ provide: CookieService, useClass: CookieServiceMock },
LogService],
imports: [RouterTestingModule]
});
});
LogService
]
}).compileComponents();
}));
it('if the alfresco js api is logged in should canActivate be true',
async(inject([AuthGuard, Router, AlfrescoSettingsService, StorageService, AlfrescoAuthenticationService], (auth, router, settingsService, storage, authService) => {

View File

@@ -15,33 +15,40 @@
* limitations under the License.
*/
import { ReflectiveInjector } from '@angular/core';
import { TestBed, async } from '@angular/core/testing';
import { AlfrescoApiService } from './alfresco-api.service';
import { RenditionsService } from './renditions.service';
import { AlfrescoSettingsService } from './alfresco-settings.service';
import { StorageService } from './storage.service';
import { LogService } from './log.service';
import { fakeRedition, fakeReditionCreated, fakeReditionsList } from '../assets/renditionsService.mock';
import { AppConfigModule } from './app-config.service';
declare let jasmine: any;
declare let AlfrescoApi: any;
describe('RenditionsService', () => {
let service, injector;
let service: RenditionsService;
beforeEach(() => {
injector = ReflectiveInjector.resolveAndCreate([
AlfrescoApiService,
RenditionsService,
AlfrescoSettingsService,
StorageService,
LogService
]);
});
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
AppConfigModule
],
declarations: [
],
providers: [
AlfrescoApiService,
RenditionsService,
AlfrescoSettingsService,
StorageService,
LogService
]
}).compileComponents();
}));
beforeEach(() => {
jasmine.Ajax.install();
service = injector.get(RenditionsService);
service = TestBed.get(RenditionsService);
});
afterEach(() => {
@@ -63,7 +70,7 @@ describe('RenditionsService', () => {
it('Create redition service should call the server with the ID passed and the asked encoding', (done) => {
service.createRendition('fake-node-id', 'pdf').subscribe((res) => {
expect(jasmine.Ajax.requests.mostRecent().url).toBe('http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/fake-node-id/renditions');
expect(jasmine.Ajax.requests.mostRecent().url).toBe('http://localhost:3000/ecm/alfresco/api/-default-/public/alfresco/versions/1/nodes/fake-node-id/renditions');
done();
});