use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE in project product-iots by wso2.
the class AppOperations method addApplication.
public static boolean addApplication(String name, MobileApplication mblApp, boolean isEnterpriseApp) {
HashMap<String, String> headers = new HashMap<String, String>();
String appEndpoint = EMMQSGConfig.getInstance().getEmmHost() + appmPublisherAppsUrl;
// Set the application payload
JSONObject application = new JSONObject();
application.put("name", name);
application.put("description", "Sample application");
application.put("type", "enterprise");
// Set appMeta data
JSONObject appMeta = new JSONObject();
appMeta.put("package", mblApp.getPackageId());
appMeta.put("version", mblApp.getVersion());
if (isEnterpriseApp) {
application.put("marketType", "enterprise");
appMeta.put("path", mblApp.getAppId());
} else {
application.put("marketType", "public");
}
application.put("provider", "admin");
application.put("displayName", name);
application.put("category", "Business");
application.put("thumbnailUrl", mblApp.getIcon());
application.put("version", mblApp.getVersion());
application.put("banner", mblApp.getBanner());
application.put("platform", mblApp.getPlatform());
application.put("appType", mblApp.getPlatform());
// application.put("appUrL", mblApp.getAppId());
application.put("mediaType", "application/vnd.wso2-mobileapp+xml");
// Set screenshots
JSONArray screenshots = new JSONArray();
screenshots.add(mblApp.getScreenshot1());
screenshots.add(mblApp.getScreenshot2());
screenshots.add(mblApp.getScreenshot3());
application.put("appmeta", appMeta);
application.put("screenshots", screenshots);
// Set the headers
headers.put(Constants.Header.CONTENT_TYPE, Constants.ContentType.APPLICATION_JSON);
HTTPResponse httpResponse = HTTPInvoker.sendHTTPPostWithOAuthSecurity(appEndpoint, application.toJSONString(), headers);
if (Constants.HTTPStatus.OK == httpResponse.getResponseCode()) {
return true;
}
return false;
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE in project ballerina by ballerina-lang.
the class WorkspacePackageRepositoryTest method testCompilePackageWithDirtyContent.
// @Test
public void testCompilePackageWithDirtyContent() {
Compiler compiler = Compiler.getInstance(prepareCompilerContext());
BLangPackage packageNode = compiler.compile(pkg);
Assert.assertEquals(packageNode.getFunctions().size(), 1, "Package should contain one function which is in persisted file.");
Assert.assertEquals(packageNode.getFunctions().get(0).getName().getValue(), "sayHello", "Name of the function should be equal to sayHello.");
// open the file in document manager and set content without the function
final Path filePath = Paths.get(sourceRoot, "org.pkg1", "file1.bal");
documentManager.openFile(filePath, "package org.pkg1;");
compiler = Compiler.getInstance(prepareCompilerContext());
compiler.compile(pkg);
Assert.assertEquals(packageNode.getFunctions().size(), 0, "Package should now contain no functions as we removed it in file1.bal dirty content.");
// now update the file and add two public functions
documentManager.updateFile(filePath, "package org.pkg1; public function f1(){} " + "public function f2(){}");
compiler = Compiler.getInstance(prepareCompilerContext());
compiler.compile(pkg);
Assert.assertEquals(packageNode.getFunctions().size(), 2, "Package should now contain two functions.");
Assert.assertEquals(packageNode.getFunctions().get(0).getName().getValue(), "f1", "Name of the first function should be equal to f1.");
Assert.assertEquals(packageNode.getFunctions().get(1).getName().getValue(), "f2", "Name of the first function should be equal to f2.");
// now close file without saving new content to disk
documentManager.closeFile(filePath);
compiler = Compiler.getInstance(prepareCompilerContext());
compiler.compile(pkg);
Assert.assertEquals(packageNode.getFunctions().size(), 1, "Package should now contain a single function which is in the file on disk.");
Assert.assertEquals(packageNode.getFunctions().get(0).getName().getValue(), "sayHello", "Name of the function should be equal to sayHello.");
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE 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.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE 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.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE in project ballerina by ballerina-lang.
the class GlobalVarServicePkgTest method testAssigningGlobalVarToServiceVarFromDiffPkg.
@Test(description = "Test assigning global variable to service variable from different package", enabled = false)
public void testAssigningGlobalVarToServiceVarFromDiffPkg() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/globalvar-pkg/assign-to-service-var-from-diff-pkg", "GET");
HTTPCarbonMessage response = Services.invokeNew(result, cMsg);
Assert.assertNotNull(response);
// Expected Json message : {"serviceVarString":"stringval"}
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("serviceVarString").asText(), "stringval");
}
Aggregations