jec-sandcat
Version:
JEC Sandcat - The default RESTful web services framework for GlassCat applications.
203 lines (184 loc) • 7.28 kB
text/typescript
// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
//
// Copyright 2016-2018 Pascal ECHEMANN.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { TestSuite, Test, BeforeAll } from "jec-juta";
import { expect } from "chai";
import { MethodDescriptorBuilder } from "../../../../../src/com/onsoft/sandcat/builders/MethodDescriptorBuilder";
import { MethodDescriptor } from "../../../../../src/com/onsoft/sandcat/reflect/MethodDescriptor";
import { HttpMethodParams } from "jec-jars";
import { HttpMethod, SingletonError } from "jec-commons";
export class MethodDescriptorBuilderTest {
public propertyDescriptor:PropertyDescriptor = null;
public key:string = null;
public httpParams:HttpMethodParams = null;
public initTest():void {
const func:Function = function(param1:string, param2:string):void {};
this.propertyDescriptor = ( { value: func } as PropertyDescriptor );
this.key = "methodName";
this.httpParams = {
route: "foo/bar",
consumes: "application/json",
produces: "application/json",
crossDomainPolicy: "*"
};
}
public newInstanceTest():void {
const buildInstance:Function = function():void {
new MethodDescriptorBuilder();
};
expect(buildInstance).to.throw(SingletonError);
}
public getInstanceTest():void {
const builder:MethodDescriptorBuilder =
MethodDescriptorBuilder.getInstance();
expect(builder).to.be.an.instanceOf(MethodDescriptorBuilder);
}
public singletonTest():void {
const builder1:MethodDescriptorBuilder =
MethodDescriptorBuilder.getInstance();
const builder2:MethodDescriptorBuilder =
MethodDescriptorBuilder.getInstance();
expect(builder1).to.equal(builder2);
}
public buildTest():void {
expect(
MethodDescriptorBuilder.getInstance().build(
HttpMethod.GET, this.key, this.propertyDescriptor
)
).to.be.an.instanceOf(MethodDescriptor);
}
public nameTest():void {
const desc:MethodDescriptor =
MethodDescriptorBuilder.getInstance().build(
HttpMethod.GET, this.key, this.propertyDescriptor
);
expect(desc.name).to.equal(this.key);
}
public httpMethodTest():void {
const desc:MethodDescriptor =
MethodDescriptorBuilder.getInstance().build(
HttpMethod.GET, this.key, this.propertyDescriptor
);
expect(desc.httpMethod).to.equal(HttpMethod.GET);
}
public actionTest():void {
const desc:MethodDescriptor =
MethodDescriptorBuilder.getInstance().build(
HttpMethod.GET, this.key, this.propertyDescriptor
);
expect(desc.action).to.equal(this.propertyDescriptor.value);
}
public routeNullTest():void {
const desc:MethodDescriptor =
MethodDescriptorBuilder.getInstance().build(
HttpMethod.GET, this.key, this.propertyDescriptor
);
expect(desc.route).to.be.null;
}
public producesNullTest():void {
const desc:MethodDescriptor =
MethodDescriptorBuilder.getInstance().build(
HttpMethod.GET, this.key, this.propertyDescriptor
);
expect(desc.produces).to.be.null;
}
public crossDomainPolicyNullTest():void {
const desc:MethodDescriptor =
MethodDescriptorBuilder.getInstance().build(
HttpMethod.GET, this.key, this.propertyDescriptor
);
expect(desc.crossDomainPolicy).to.be.null;
}
public consumesNullTest():void {
const desc:MethodDescriptor =
MethodDescriptorBuilder.getInstance().build(
HttpMethod.GET, this.key, this.propertyDescriptor
);
expect(desc.consumes).to.be.null;
}
public routeTest():void {
const desc:MethodDescriptor = MethodDescriptorBuilder.getInstance().build(
HttpMethod.GET, this.key, this.propertyDescriptor, this.httpParams
);
expect(desc.route).to.equal(this.httpParams.route);
}
public consumesTest():void {
const desc:MethodDescriptor = MethodDescriptorBuilder.getInstance().build(
HttpMethod.GET, this.key, this.propertyDescriptor, this.httpParams
);
expect(desc.consumes).to.equal(this.httpParams.consumes);
}
public producesTest():void {
const desc:MethodDescriptor = MethodDescriptorBuilder.getInstance().build(
HttpMethod.GET, this.key, this.propertyDescriptor, this.httpParams
);
expect(desc.produces).to.equal(this.httpParams.produces);
}
public crossDomainPolicyTest():void {
const desc:MethodDescriptor = MethodDescriptorBuilder.getInstance().build(
HttpMethod.GET, this.key, this.propertyDescriptor, this.httpParams
);
expect(desc.crossDomainPolicy).to.equal(this.httpParams.crossDomainPolicy);
}
}