package jetbrains.mps.baseLanguage.unitTest.execution.server;
/*Generated by MPS */
import org.junit.runner.Request;
import jetbrains.mps.baseLanguage.unitTest.execution.client.ITestNodeWrapper;
import jetbrains.mps.smodel.ModelAccess;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import jetbrains.mps.smodel.behaviour.BHReflection;
import jetbrains.mps.core.aspects.behaviour.SMethodTrimmedId;
public class InProcessExecutionFilter implements Filter {
@Override
public boolean accept(final Request request) throws Filter.FilterException {
assert request instanceof TestNodeRequest;
final ITestNodeWrapper testNodeWrapper = ((TestNodeRequest) request).getTestNode();
final Filter.FilterException[] result = {null};
ModelAccess.instance().runReadAction(new Runnable() {
@Override
public void run() {
SNode testNode = testNodeWrapper.getNode();
SNode rootNode = SNodeOperations.getContainingRoot(testNode);
if (!(SNodeOperations.isInstanceOf(testNode, MetaAdapterFactory.getInterfaceConcept(0xf61473f9130f42f6L, 0xb98d6c438812c2f6L, 0x11b08a01119L, "jetbrains.mps.baseLanguage.unitTest.structure.ITestable")))) {
result[0] = new Filter.FilterException("The test concept must be an instance on ITestable concept. Test " + testNodeWrapper.getName() + " is ignored.");
}
if (((boolean) (Boolean) BHReflection.invoke(SNodeOperations.asSConcept(MetaAdapterFactory.getConcept(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, 0x46bca02bfb6e730aL, "jetbrains.mps.lang.test.structure.TestInfo")), SMethodTrimmedId.create("reOpenProject", MetaAdapterFactory.getConcept(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, 0x46bca02bfb6e730aL, "jetbrains.mps.lang.test.structure.TestInfo"), "ThWTaQhG7P"), SNodeOperations.getModel(rootNode)))) {
result[0] = new Filter.FilterException("The project properties given in the TestInfo file is impossible to set in-process. Test " + testNodeWrapper.getName() + " is ignored.");
}
if (SNodeOperations.isInstanceOf(testNode, MetaAdapterFactory.getInterfaceConcept(0xf61473f9130f42f6L, 0xb98d6c438812c2f6L, 0x11b2709bd56L, "jetbrains.mps.baseLanguage.unitTest.structure.ITestCase"))) {
if (!(((boolean) (Boolean) BHReflection.invoke(SNodeOperations.cast(testNode, MetaAdapterFactory.getInterfaceConcept(0xf61473f9130f42f6L, 0xb98d6c438812c2f6L, 0x11b2709bd56L, "jetbrains.mps.baseLanguage.unitTest.structure.ITestCase")), SMethodTrimmedId.create("canRunInProcess", null, "5_jSk8paieB"))))) {
result[0] = new Filter.FilterException("The test is set not to be executed in-process. Test " + testNodeWrapper.getName() + " is ignored.");
}
}
// cannot run (in-process) test methods from TestCase, which is not executable in the same process
if (SNodeOperations.isInstanceOf(rootNode, MetaAdapterFactory.getInterfaceConcept(0xf61473f9130f42f6L, 0xb98d6c438812c2f6L, 0x11b2709bd56L, "jetbrains.mps.baseLanguage.unitTest.structure.ITestCase"))) {
if (!(((boolean) (Boolean) BHReflection.invoke(SNodeOperations.cast(rootNode, MetaAdapterFactory.getInterfaceConcept(0xf61473f9130f42f6L, 0xb98d6c438812c2f6L, 0x11b2709bd56L, "jetbrains.mps.baseLanguage.unitTest.structure.ITestCase")), SMethodTrimmedId.create("canRunInProcess", null, "5_jSk8paieB"))))) {
if (SNodeOperations.isInstanceOf(rootNode, MetaAdapterFactory.getConcept(0xf61473f9130f42f6L, 0xb98d6c438812c2f6L, 0x110dc94e923L, "jetbrains.mps.baseLanguage.unitTest.structure.BTestCase"))) {
result[0] = new Filter.FilterException("The test " + testNodeWrapper.getName() + " is BTestCase which is not executed in-process. It is ignored for now.");
} else {
result[0] = new Filter.FilterException("The test is set not to be executed in-process. Test " + testNodeWrapper.getName() + " is ignored.");
}
}
}
}
});
if (result[0] != null) {
throw result[0];
}
return true;
}
}