jec-sandcat
Version:
JEC Sandcat - The default RESTful web services framework for GlassCat applications.
151 lines (135 loc) • 5.07 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, TestSorters, AfterAll } from "jec-juta";
import { expect } from "chai";
import * as sinon from "sinon";
import { SandcatAutowireProcessor } from "../../../../../src/com/onsoft/sandcat/core/SandcatAutowireProcessor";
import { SandcatLoggerProxy } from "../../../../../src/com/onsoft/sandcat/logging/SandcatLoggerProxy";
import { Sandcat } from "../../../../../src/com/onsoft/sandcat/Sandcat";
import { JcadContextError } from "jec-commons";
// Utilities:
import * as utils from "../../../../../utils/test-utils/utilities/SandcatAutowireProcessorTestUtils";
export class SandcatAutowireProcessorTest {
public processor:SandcatAutowireProcessor = null;
public sandcat:Sandcat = null;
public processCompleteHandler:Function = null;
public initTest():void {
this.processor = new SandcatAutowireProcessor();
this.sandcat = ({ } as Sandcat);
this.processCompleteHandler = function():void {};
}
public getSandcatContainerDefaultTest():void {
expect(this.processor.getSandcatContainer()).to.be.null;
}
public setSandcatContainerTest():void {
expect(this.processor.setSandcatContainer(this.sandcat)).to.be.undefined;
}
public getSandcatContainerTest():void {
expect(this.processor.getSandcatContainer()).to.equal(this.sandcat);
}
public processCompleteHandlerTest():void {
expect(this.processor).to.have.property("processCompleteHandler", null);
}
public processStartNoHandlerTest():void {
const processor:SandcatAutowireProcessor = this.processor;
const doProcessStart:Function = function():void {
processor.processStart(null, null);
};
expect(doProcessStart).to.throw(Error);
}
public processCompleteNoHandlerTest():void {
const processor:SandcatAutowireProcessor = this.processor;
const doProcessComplete:Function = function():void {
processor.processComplete(utils.buildDomainConnector(), null);
};
expect(doProcessComplete).to.throw(Error);
}
public setProcessCompleteHandlerTest():void {
this.processor.processCompleteHandler = this.processCompleteHandler;
}
public processStartTest():void {
expect(this.processor.processStart(null, null)).to.be.undefined;
}
public processTest():void {
const loggerSpy:any = sinon.spy(SandcatLoggerProxy.getInstance(), "log");
this.processor.process(utils.FILE, utils.buildDomainConnector());
sinon.assert.calledWith(
loggerSpy,
"autowired resource detected: source file='" + utils.FILE.name + "'"
);
sinon.restore();
}
public multipleInstancesErrorTest():void {
const newInstance:Function = function():SandcatAutowireProcessor {
return new SandcatAutowireProcessor();
};
expect(newInstance).to.throw(JcadContextError);
}
public processCompleteTest():void {
expect(
this.processor.processComplete(utils.buildDomainConnector(), null)
).to.be.undefined;
}
}