blob: 940248514aebc85f8a961131e6c1645884a36e6b [file] [log] [blame]
/*******************************************************************************
* Copyright © 2012, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*
*******************************************************************************/
package org.eclipse.edt.eunit.runtime;
import eglx.http.IHttp;
import eglx.lang.AnyException;
import eglx.lang.SysLib;
import eglx.services.ServiceInvocationException;
delegate runTestMethod()
end
enumeration ServiceBindingType
DEDICATED = 1,
DEVELOP = 2,
DEPLOYED = 3
end
/**
* managing 2 lists
* 1. list of libraries
* 2. list of test methods in the library that's running
* this list gets reset for each library
**/
Library TestListMgr
bindingType ServiceBindingType = ServiceBindingType.DEDICATED;
ms MultiStatus; //multiStatus for current test library
testIndex int = 1; //current test method index
testMethodNames String[]; //list of the test method names within a library (excluding the generatedLib.endTest())
runTestMtds runTestMethod[]; //list of test methods within a library including an extra generatedLib.endTest()
testLibName String; //current test library name (testdescription.name)
LibraryStartTests runTestMethod[]; //list of test libraries
private libIndex int = 1; //current test library index
function nextTest()
testId String = getTestIdString();
SysLib.writeStdOut("Running test: " + testId);
//accumulate the status of each test method result into the multiStatus for one library
ms.addStatus(testId);
if(testIndex < runTestMtds.getSize())
testIndex += 1;
runTestMtds[testIndex]();
end
end
private function getTestIdString() returns (String)
testMethodNamesSize int = testMethodNames.getSize();
testId String = testLibName + "::";
if(testIndex <= testMethodNamesSize)
testId += testMethodNames[testIndex];
else
if(testIndex == (testMethodNamesSize+1))
testId += "endTest";
else
testId +="INVALIDINDEXFOUND!!!";
end
end
return (testId);
end
function nextTestLibrary()
if(libIndex < LibraryStartTests.getSize())
libIndex += 1;
LibraryStartTests[libIndex]();
end
end
//helper functions to handle asynchronize call exceptions
function handleCallBackException(exp AnyException in, http IHttp in)
str String = "Caught service exception: " + exp.messageID + ": " + exp.message;
if(exp isa ServiceInvocationException)
sexp ServiceInvocationException = exp as ServiceInvocationException;
s1 String = "detail1:" + sexp.detail1;
s2 String = "detail2:" + sexp.detail2;
s3 String = "detail3:" + sexp.detail3;
str = str + ConstantsLib.NEWLINE;
str = str + s1 + ConstantsLib.NEWLINE;
str = str + s2 + ConstantsLib.NEWLINE;
str = str + s3 + ConstantsLib.NEWLINE;
str = str + "Original request body: " + http.getRequest().body + ConstantsLib.NEWLINE;
str = str + "Raw response body: " + http.getResponse().body + ConstantsLib.NEWLINE;
end
LogResult.error(str);
testId String = TestListMgr.testMethodNames[TestListMgr.testIndex];
TestListMgr.nextTest();
end
function caughtFailedAssertion(exp AssertionFailedException in)
//prepend the assertion failure error message to Status
sysLib.writeStdOut("AssertionFail - " + exp.message);
end
function caughtAnyException(exp AnyException in)
//caught the exception from the test
expMsg String = "uncaught exception for: " + getTestIdString();
expMsg += ConstantsLib.NEWLINE + " => " + exp.messageID + ": " + exp.message;
//StatusLib.error(expMsg, s);
LogResult.error(expMsg);
end
function getBindingTypeString(bType ServiceBindingType) returns (String)
case(bType)
when(ServiceBindingType.DEDICATED)
return ("DEDICATED_BINDING");
when(ServiceBindingType.DEVELOP)
return ("DEVELOP_BINDING");
when(ServiceBindingType.DEPLOYED)
return ("DEPLOYED_BINDING");
otherwise
return ("UNKNOWN Binding Type - NOT supported");
end
end
end