use of org.wso2.carbon.apimgt.core.models.Function in project ballerina by ballerina-lang.
the class BallerinaDocGenForCurrentPackageTest method testStruct.
@Test(description = "Test a bal file with a function in the current package")
public void testStruct() {
try {
Map<String, BLangPackage> docsMap = BallerinaDocGenerator.generatePackageDocsFromBallerina(sourceRoot, "balFileInCurrentPackage.bal");
Assert.assertNotNull(docsMap);
Assert.assertEquals(docsMap.size(), 1);
BLangPackage balPackage = docsMap.get(".");
List<BLangFunction> functions = balPackage.getFunctions();
Assert.assertEquals(functions.size(), 1);
BLangFunction function = functions.iterator().next();
Assert.assertEquals(function.getParameters().size(), 1);
Assert.assertEquals(function.getAnnotationAttachments().size(), 2);
} catch (IOException e) {
Assert.fail();
} finally {
BallerinaDocGenTestUtils.cleanUp();
}
}
use of org.wso2.carbon.apimgt.core.models.Function in project ballerina by ballerina-lang.
the class BallerinaFunctionDocGenTest method testABalWithMultipleFunctions.
@Test(description = "Test a Bal file with multiple Functions")
public void testABalWithMultipleFunctions() {
try {
Map<String, BLangPackage> docsMap = BallerinaDocGenerator.generatePackageDocsFromBallerina(sourceRoot, "balWith2Functions.bal");
Assert.assertNotNull(docsMap);
Assert.assertEquals(docsMap.size(), 1);
BallerinaDocGenTestUtils.printDocMap(docsMap);
BLangPackage doc = docsMap.get(".");
Collection<BLangFunction> functions = doc.getFunctions();
Assert.assertEquals(functions.size(), 2);
Iterator<BLangFunction> iterator = functions.iterator();
BLangFunction function = iterator.next();
Assert.assertEquals(function.getParameters().size(), 1);
Assert.assertEquals(function.getReturnParameters().size(), 1);
BLangFunction function1 = iterator.next();
Assert.assertEquals(function1.getParameters().size(), 2);
Assert.assertEquals(function1.getReturnParameters().size(), 0);
} catch (IOException e) {
Assert.fail();
} finally {
BallerinaDocGenTestUtils.cleanUp();
}
}
use of org.wso2.carbon.apimgt.core.models.Function in project ballerina by ballerina-lang.
the class CreateSessionIfAbsent method execute.
@Override
public void execute(Context context) {
try {
BStruct requestStruct = ((BStruct) context.getRefArgument(0));
// TODO check below line
HTTPCarbonMessage httpCarbonMessage = HttpUtil.getCarbonMsg(requestStruct, HttpUtil.createHttpCarbonMessage(true));
String cookieHeader = httpCarbonMessage.getHeader(HttpConstants.COOKIE_HEADER);
String path = (String) httpCarbonMessage.getProperty(HttpConstants.BASE_PATH);
Session session = (Session) httpCarbonMessage.getProperty(HttpConstants.HTTP_SESSION);
if (cookieHeader != null) {
try {
String sessionId = HttpUtil.getSessionID(cookieHeader);
// return value from cached session
if (session != null && sessionId.equals(session.getId())) {
session = session.setAccessed();
context.setReturnValues(HttpUtil.createSessionStruct(context, session));
return;
}
session = SessionManager.getInstance().getHTTPSession(sessionId);
} catch (NoSuchElementException e) {
// ignore throwable
logger.info("Failed to get session: Incorrect Session cookie");
}
if (session == null) {
session = SessionManager.getInstance().createHTTPSession(path);
} else if (session != null && session.getPath().equals(path)) {
// path validity check
session.setNew(false);
session.setAccessed();
} else {
throw new BallerinaException("Failed to get session: " + path + " is not an allowed path");
}
} else {
// cached session will return of this function is called twice.
if (session != null) {
session = session.setAccessed();
context.setReturnValues(HttpUtil.createSessionStruct(context, session));
return;
}
// create session since request doesn't have a cookie
session = SessionManager.getInstance().createHTTPSession(path);
}
httpCarbonMessage.setProperty(HttpConstants.HTTP_SESSION, session);
httpCarbonMessage.removeHeader(HttpConstants.COOKIE_HEADER);
context.setReturnValues(HttpUtil.createSessionStruct(context, session));
return;
} catch (IllegalStateException e) {
throw new BallerinaException(e.getMessage(), e);
}
}
use of org.wso2.carbon.apimgt.core.models.Function in project ballerina by ballerina-lang.
the class GlobalVarServicePkgTest method testAssigningFuncInvFromDiffPkg.
@Test(description = "Test assigning function invocation from different package", enabled = false)
public void testAssigningFuncInvFromDiffPkg() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/globalvar-pkg/func-inv-from-diff-pkg", "GET");
HTTPCarbonMessage response = Services.invokeNew(result, cMsg);
Assert.assertNotNull(response);
// Expected Json message : {"glbVarPkgFunc":8876}
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("glbVarPkgFunc").asText(), "8876");
}
use of org.wso2.carbon.apimgt.core.models.Function in project ballerina by ballerina-lang.
the class GlobalVarServicePkgTest method testAssigningFuncInvFromSamePkg.
@Test(description = "Test assigning function invocation from same package", enabled = false)
public void testAssigningFuncInvFromSamePkg() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/globalvar-pkg/func-inv-from-same-pkg", "GET");
HTTPCarbonMessage response = Services.invokeNew(result, cMsg);
Assert.assertNotNull(response);
// Expected Json message : {"glbVarFunc":423277.72343}
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("glbVarFunc").asText(), "423277.72343");
}
Aggregations