jec-sandcat
Version:
JEC Sandcat - The default RESTful web services framework for GlassCat applications.
119 lines (105 loc) • 4 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, AfterAll, Before, After } from "jec-juta";
import { expect } from "chai";
import { RootPathDescriptorUtil } from "../../../../../src/com/onsoft/sandcat/utils/RootPathDescriptorUtil";
import { RootPathDescriptor } from "../../../../../src/com/onsoft/sandcat/reflect/RootPathDescriptor";
import { SingletonError } from "jec-commons";
export class RootPathDescriptorUtilTest {
public descriptor:RootPathDescriptor = null;
public rootPath:any = null;
public initTest():void {
this.descriptor = new RootPathDescriptor();
}
public initRootPathTest():void {
this.rootPath = {};
}
public resetTest():void {
this.descriptor = null;
}
public resetRootPathTest():void {
this.rootPath = null;
}
public newInstanceTest():void {
const buildInstance:Function = function():void {
new RootPathDescriptorUtil();
};
expect(buildInstance).to.throw(SingletonError);
}
public getInstanceTest():void {
const util:RootPathDescriptorUtil = RootPathDescriptorUtil.getInstance();
expect(util).to.be.an.instanceOf(RootPathDescriptorUtil);
}
public singletonTest():void {
const util1:RootPathDescriptorUtil = RootPathDescriptorUtil.getInstance();
const util2:RootPathDescriptorUtil = RootPathDescriptorUtil.getInstance();
expect(util1).to.equal(util2);
}
public decoratePropertyTest():void {
RootPathDescriptorUtil.getInstance()
.decorate(this.rootPath, this.descriptor);
expect(this.rootPath).to.have.property("__sandcatRootPathDescriptor");
}
public decorateImmutablePropertyTest():void {
RootPathDescriptorUtil.getInstance()
.decorate(this.rootPath, this.descriptor);
const doOverride:Function = function():void {
this.rootPath.__sandcatRootPathDescriptor = {};
};
expect(doOverride.bind(this)).to.throw(TypeError);
}
public decorateMethodTest():void {
RootPathDescriptorUtil.getInstance()
.decorate(this.rootPath, this.descriptor);
expect(this.rootPath.getRootPathDescriptor).to.not.be.undefined;
}
public decorateImmutableMethodTest():void {
RootPathDescriptorUtil.getInstance()
.decorate(this.rootPath, this.descriptor);
const doOverride:Function = function():void {
this.rootPath.getRootPathDescriptor = function():void {};
};
expect(doOverride.bind(this)).to.throw(TypeError);
}
}