View Javadoc

1   /*
2    * Copyright © 2012 Eirik Bjornset.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package net.grinderscript.dotnet.scriptengine;
18  
19  import grinderscript.net.core.IGrinderTest;
20  import net.grinder.script.Grinder.ScriptContext;
21  import net.grinder.script.InvalidContextException;
22  
23  import org.slf4j.Logger;
24  import org.slf4j.LoggerFactory;
25  
26  public class DotNetTestBridge implements IGrinderTest {
27  
28  	private final Logger logger = LoggerFactory
29  			.getLogger(DotNetTestBridge.class);
30  
31  	private final IGrinderTest testAction;
32  	private final ScriptContext scriptContext;
33  
34  	public DotNetTestBridge(ScriptContext scriptContext, IGrinderTest testAction) {
35  		logger.trace("ctor: Enter, scriptContext = {}, testAction = {}", scriptContext, testAction);
36  		this.scriptContext = scriptContext;
37  		this.testAction = testAction;
38  		logger.trace("ctor: Exit");
39  	}
40  
41  	@Override
42  	public void Run() {
43  		logger.trace("run: Enter");
44  		try {
45  			testAction.Run();
46  		} catch (system.Exception clrEx) {
47  			try {
48  				scriptContext.getStatistics().getForCurrentTest()
49  						.setSuccess(false);
50  			} catch (InvalidContextException e) {
51  				throw new DotNetCheckedExceptionMarshall(e);
52  			}
53  		}
54  		logger.trace("run: Exit");
55  	}
56  
57  	IGrinderTest getTestAction() {
58  		return testAction;
59  	}
60  	
61  	ScriptContext getScriptContext() {
62  		return scriptContext;
63  	}
64  }