add export missing model (#5757)

simplify api
This commit is contained in:
Eugenio Romano 2020-06-07 21:46:37 +01:00 committed by GitHub
parent 0257cf5748
commit 8e241a9e8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 77 additions and 62 deletions

View File

@ -15,24 +15,25 @@
* limitations under the License. * limitations under the License.
*/ */
import { AlfrescoApi } from '@alfresco/js-api';
import { browser } from 'protractor'; import { browser } from 'protractor';
import { ApiService } from './api.service';
export abstract class Api { export abstract class Api {
public api: AlfrescoApi;
constructor(root: string) { public api: ApiService;
this.api = this.configureApi(root);
constructor() {
this.api = this.configureApi();
} }
private configureApi(root: string): AlfrescoApi { private configureApi(): ApiService {
const config = browser.params.adminapp.apiConfig; const config = browser.params.adminapp.apiConfig;
return new AlfrescoApi({ return new ApiService({
provider: 'BPM', provider: 'BPM',
authType: config.authType, authType: config.authType,
oauth2: config.oauth2, oauth2: config.oauth2,
hostBpm: config.bpmHost + '/' + root hostBpm: config.bpmHost
}); });
} }

View File

@ -16,3 +16,4 @@
*/ */
export * from './user.model'; export * from './user.model';
export * from './application-model';

View File

@ -19,6 +19,9 @@ import { browser, by, element, ElementArrayFinder, ElementFinder, protractor } f
import { BrowserVisibility } from '../utils/browser-visibility'; import { BrowserVisibility } from '../utils/browser-visibility';
import { Logger } from './logger'; import { Logger } from './logger';
import * as path from 'path';
import * as fs from 'fs';
export class BrowserActions { export class BrowserActions {
static async click(elementFinder: ElementFinder): Promise<void> { static async click(elementFinder: ElementFinder): Promise<void> {
@ -124,4 +127,16 @@ export class BrowserActions {
// if the opened menu has only disabled items, pressing escape to close it won't work // if the opened menu has only disabled items, pressing escape to close it won't work
await browser.actions().sendKeys(protractor.Key.ENTER).perform(); await browser.actions().sendKeys(protractor.Key.ENTER).perform();
} }
static async takeScreenshot(screenshotFilePath: string, fileName: string) {
const pngData = await browser.takeScreenshot();
const filenameWithExt = `${fileName}.png`;
Logger.info('Taking screenshot: ', filenameWithExt);
const fileWithPath = path.join(screenshotFilePath, filenameWithExt);
const stream = fs.createWriteStream(fileWithPath);
stream.write(new Buffer(pngData, 'base64'));
stream.end();
}
} }

View File

@ -16,7 +16,6 @@
*/ */
import { E2eRequestApiHelper } from '../../core/actions/e2e-request-api.helper'; import { E2eRequestApiHelper } from '../../core/actions/e2e-request-api.helper';
import { Api } from '../../core/actions/api';
import { Logger } from '../../core/utils/logger'; import { Logger } from '../../core/utils/logger';
import { ResultSetPaging } from '@alfresco/js-api'; import { ResultSetPaging } from '@alfresco/js-api';
import { ApiService } from '../../core/actions/api.service'; import { ApiService } from '../../core/actions/api.service';
@ -26,7 +25,7 @@ export class Application {
requestApiHelper: E2eRequestApiHelper; requestApiHelper: E2eRequestApiHelper;
endPoint = `/deployment-service/v1/applications/`; endPoint = `/deployment-service/v1/applications/`;
constructor(api: Api | ApiService) { constructor(api: ApiService) {
this.requestApiHelper = new E2eRequestApiHelper(api); this.requestApiHelper = new E2eRequestApiHelper(api);
} }

View File

@ -17,56 +17,57 @@
import { NodeEntry } from '@alfresco/js-api'; import { NodeEntry } from '@alfresco/js-api';
import { E2eRequestApiHelper } from '../../core/actions/e2e-request-api.helper'; import { E2eRequestApiHelper } from '../../core/actions/e2e-request-api.helper';
import { Api } from '../../core/actions/api';
import { ApplicationRepresentation } from '../../core/models/application-model'; import { ApplicationRepresentation } from '../../core/models/application-model';
import { Logger } from '../../core/utils/logger'; import { Logger } from '../../core/utils/logger';
import { ApiUtil } from '../../core/actions/api.util'; import { ApiUtil } from '../../core/actions/api.util';
import { ApiService } from '../../core/actions/api.service';
export class Descriptor { export class Descriptor {
requestApiHelper: E2eRequestApiHelper;
endPoint = `/v1/descriptors/`;
constructor(api: Api) { requestApiHelper: E2eRequestApiHelper;
this.requestApiHelper = new E2eRequestApiHelper(api); endPoint = `deployment-service/v1/descriptors/`;
}
async create(model: ApplicationRepresentation): Promise<void> { constructor(api: ApiService) {
try { this.requestApiHelper = new E2eRequestApiHelper(api);
await this.requestApiHelper.post<NodeEntry>(this.endPoint, {
bodyParam: model
});
Logger.info(`[Descriptor] Descriptor has been created with name: ${model.name}.`);
} catch (error) {
Logger.error(`[Descriptor] Create descriptor ${model.name} failed with message: ${error.message}`);
throw error;
} }
}
async delete(name: string): Promise<void> { async create(model: ApplicationRepresentation): Promise<void> {
try { try {
await this.retryUntilDescriptorIsInStatus(name, `DescriptorCreated`); await this.requestApiHelper.post<NodeEntry>(this.endPoint, {
await this.requestApiHelper.delete(`${this.endPoint}${name}`); bodyParam: model
Logger.info(`[Descriptor] Descriptor '${name}' was deleted successfully.`); });
} catch (error) { Logger.info(`[Descriptor] Descriptor has been created with name: ${model.name}.`);
Logger.error(`[Descriptor] Delete descriptor ${name} failed with message: ${error.message}`); } catch (error) {
Logger.error(`[Descriptor] Create descriptor ${model.name} failed with message: ${error.message}`);
throw error;
}
} }
}
async get(name: string): Promise<any> { async delete(name: string): Promise<void> {
Logger.info(`[Descriptor] Get descriptor ${name} details.`); try {
try { await this.retryUntilDescriptorIsInStatus(name, `DescriptorCreated`);
return this.requestApiHelper.get<any>(`${this.endPoint}${name}`); await this.requestApiHelper.delete(`${this.endPoint}${name}`);
} catch (error) { Logger.info(`[Descriptor] Descriptor '${name}' was deleted successfully.`);
Logger.error(`[Descriptor] Get descriptor ${name} details failed with message: ${error.message}`); } catch (error) {
Logger.error(`[Descriptor] Delete descriptor ${name} failed with message: ${error.message}`);
}
} }
}
async retryUntilDescriptorIsInStatus(name: string, expectedStatus: string): Promise<any> { async get(name: string): Promise<any> {
const predicate = (result: { status: string }) => { Logger.info(`[Descriptor] Get descriptor ${name} details.`);
return result.status === expectedStatus; try {
}; return this.requestApiHelper.get<any>(`${this.endPoint}${name}`);
const apiCall = async () => this.get(name); } catch (error) {
Logger.error(`[Descriptor] Get descriptor ${name} details failed with message: ${error.message}`);
}
}
return ApiUtil.waitForApi(apiCall, predicate); async retryUntilDescriptorIsInStatus(name: string, expectedStatus: string): Promise<any> {
} const predicate = (result: { status: string }) => {
return result.status === expectedStatus;
};
const apiCall = async () => this.get(name);
return ApiUtil.waitForApi(apiCall, predicate);
}
} }

View File

@ -24,18 +24,18 @@ import { NodeEntry, ResultSetPaging } from '@alfresco/js-api';
export class ModelingAPI extends Api { export class ModelingAPI extends Api {
public project: Project; public project: Project;
constructor(ROOT: string = 'modeling-service') { constructor() {
super(ROOT); super();
} }
async setUp(): Promise<ModelingAPI> { async setUp(): Promise<ModelingAPI> {
await this.login(); await this.login();
this.project = new Project(this); this.project = new Project(this.api);
return this; return this;
} }
async tearDown(): Promise<void> { async tearDown(): Promise<void> {
await this.api.logout(); await this.api.apiService.logout();
} }
private async login(): Promise<void> { private async login(): Promise<void> {
@ -74,5 +74,4 @@ export class ModelingAPI extends Api {
const projects = await this.project.searchProjects(); const projects = await this.project.searchProjects();
return projects; return projects;
} }
} }

View File

@ -16,26 +16,25 @@
*/ */
import { browser } from 'protractor'; import { browser } from 'protractor';
import { ModelingAPI } from './modeling-api';
import { NodeEntry, ResultSetPaging } from '@alfresco/js-api'; import { NodeEntry, ResultSetPaging } from '@alfresco/js-api';
import { ApiUtil } from '../../core/actions/api.util'; import { ApiUtil } from '../../core/actions/api.util';
import { E2eRequestApiHelper, E2eRequestApiHelperOptions } from '../../core/actions/e2e-request-api.helper'; import { E2eRequestApiHelper, E2eRequestApiHelperOptions } from '../../core/actions/e2e-request-api.helper';
import * as fs from 'fs'; import * as fs from 'fs';
import { StringUtil } from '../../core/utils/string.util'; import { StringUtil } from '../../core/utils/string.util';
import { Logger } from '../../core/utils/logger'; import { Logger } from '../../core/utils/logger';
import { ApiService } from '../../core/actions/api.service';
export class Project { export class Project {
requestApiHelper: E2eRequestApiHelper; requestApiHelper: E2eRequestApiHelper;
endPoint = '/v1/projects/'; endPoint = 'modeling-service/v1/projects/';
namePrefix: string = browser.params.namePrefix; namePrefix: string = browser.params.namePrefix;
constructor(api: ModelingAPI) { constructor(api: ApiService) {
this.requestApiHelper = new E2eRequestApiHelper(api); this.requestApiHelper = new E2eRequestApiHelper(api);
} }
async create(modelName: string = this.getRandomName()): Promise<NodeEntry> { async create(modelName: string = this.getRandomName()): Promise<NodeEntry> {
const project = await this.requestApiHelper const project = await this.requestApiHelper.post<NodeEntry>(this.endPoint, {bodyParam: { name: modelName }});
.post<NodeEntry>(this.endPoint, {bodyParam: { name: modelName }});
Logger.info( Logger.info(
`[Project] Project created with name: ${project.entry.name} and id: ${ `[Project] Project created with name: ${project.entry.name} and id: ${
@ -57,11 +56,11 @@ export class Project {
} }
async get(projectId: string): Promise<NodeEntry> { async get(projectId: string): Promise<NodeEntry> {
return this.requestApiHelper.get<NodeEntry>(`/v1/projects/${projectId}`); return this.requestApiHelper.get<NodeEntry>(`${this.endPoint}${projectId}`);
} }
async delete(projectId: string): Promise<void> { async delete(projectId: string): Promise<void> {
await this.requestApiHelper.delete(`/v1/projects/${projectId}`); await this.requestApiHelper.delete(`${this.endPoint}${projectId}`);
Logger.info( Logger.info(
`[Project] Project '${projectId}' was deleted successfully.` `[Project] Project '${projectId}' was deleted successfully.`
); );
@ -70,7 +69,7 @@ export class Project {
async release(projectId: string): Promise<any> { async release(projectId: string): Promise<any> {
try { try {
const release = await this.requestApiHelper const release = await this.requestApiHelper
.post(`/v1/projects/${projectId}/releases`); .post(`${this.endPoint}${projectId}/releases`);
Logger.info(`[Project] Project '${projectId}' was released.`); Logger.info(`[Project] Project '${projectId}' was released.`);
return release; return release;
} catch (error) { } catch (error) {
@ -82,7 +81,7 @@ export class Project {
async getProjectRelease(projectId: string): Promise<any> { async getProjectRelease(projectId: string): Promise<any> {
try { try {
return await this.requestApiHelper return await this.requestApiHelper
.get<ResultSetPaging>(`/v1/projects/${projectId}/releases`); .get<ResultSetPaging>(`${this.endPoint}${projectId}/releases`);
} catch (error) { } catch (error) {
Logger.error(`[Project] Not able to fetch project release!`); Logger.error(`[Project] Not able to fetch project release!`);
throw error; throw error;
@ -97,7 +96,7 @@ export class Project {
}; };
try { try {
const project = await this.requestApiHelper const project = await this.requestApiHelper
.post<NodeEntry>(`/v1/projects/import`, requestOptions); .post<NodeEntry>(`${this.endPoint}import`, requestOptions);
Logger.info(`[Project] Project imported with name '${project.entry.name}' and id '${project.entry.id}'.`); Logger.info(`[Project] Project imported with name '${project.entry.name}' and id '${project.entry.id}'.`);
return project; return project;
} catch (error) { } catch (error) {