jec-sandcat
Version:
JEC Sandcat - The default RESTful web services framework for GlassCat applications.
149 lines (132 loc) • 4.83 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, TestSorters, BeforeAll, AfterAll } from "jec-juta";
import { expect } from "chai";
import * as sinon from "sinon";
import { DefaultSandcatContainer } from "../../../../../src/com/onsoft/sandcat/core/DefaultSandcatContainer";
import { RootPathDescriptor } from "../../../../../src/com/onsoft/sandcat/reflect/RootPathDescriptor";
import { SandcatLoggerProxy } from "../../../../../src/com/onsoft/sandcat/logging/SandcatLoggerProxy";
import { SandcatError } from "../../../../../src/com/onsoft/sandcat/exceptions/SandcatError";
// Utilities:
import * as utils from "../../../../../utils/test-utils/utilities/DefaultSandcatContainerTestUtils";
export class DefaultSandcatContainerTest {
public container:DefaultSandcatContainer = null;
public loggerProxySpy: any = null;
public initTest():void {
this.container = new DefaultSandcatContainer();
this.loggerProxySpy = sinon.spy(SandcatLoggerProxy.getInstance(), "log");
}
public resetTest():void {
this.container = null;
sinon.restore();
this.loggerProxySpy = null;
}
public processErrorTest():void {
this.container.process((err:SandcatError)=> {
expect(err).to.not.be.null;
});
}
public getDomainContainerDefaultTest():void {
expect(this.container.getDomainContainer()).to.be.null;
}
public setDomainContainerDefaultTest():void {
this.container.setDomainContainer(utils.CONTAINER);
expect(
this.container.getDomainContainer()
).to.equal(utils.CONTAINER);
}
public setLoggerTest():void {
const loggerSpy:any =
sinon.spy(SandcatLoggerProxy.getInstance(), "setLogger");
this.container.setDomainContainer(utils.CONTAINER);
sinon.assert.calledOnce(loggerSpy);
}
public getRootPathDefaultTest():void {
expect(this.container.getRootPath(utils.ROOT_PATH_REF)).to.be.undefined;
}
public addRootPathTest():void {
this.container.addRootPath(utils.ROOT_PATH);
expect(
this.container.getRootPath(utils.ROOT_PATH_REF)
).to.equal(utils.ROOT_PATH);
}
public getRootPathTest():void {
expect(
this.container.getRootPath(utils.ROOT_PATH_REF)
).to.be.an.instanceOf(RootPathDescriptor);
}
public processTest():void {
this.container.process((err:SandcatError)=> {
expect(err).to.be.null;
});
}
public processStartMessageTest():void {
this.container.process((err:SandcatError)=> {
sinon.assert.calledWith(this.loggerProxySpy, utils.START_MESSAGE);
});
}
public processEndMessageTest():void {
this.container.process((err:SandcatError)=> {
expect(this.loggerProxySpy).to.have.been.called.with(utils.END_MESSAGE);
});
}
}