Search in sources :

Example 56 with PACKAGE

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;
}
Also used : JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) HTTPResponse(org.wso2.mdm.qsg.dto.HTTPResponse) JSONArray(org.json.simple.JSONArray)

Example 57 with PACKAGE

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.");
}
Also used : Path(java.nio.file.Path) Compiler(org.wso2.ballerinalang.compiler.Compiler) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage)

Example 58 with PACKAGE

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();
    }
}
Also used : BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Example 59 with PACKAGE

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");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 60 with PACKAGE

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");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Aggregations

BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)49 ArrayList (java.util.ArrayList)34 Test (org.testng.annotations.Test)29 Page (org.ballerinalang.docgen.model.Page)18 File (java.io.File)16 CompilerContext (org.wso2.ballerinalang.compiler.util.CompilerContext)16 IOException (java.io.IOException)15 Path (java.nio.file.Path)13 List (java.util.List)13 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)11 PackageID (org.ballerinalang.model.elements.PackageID)10 Compiler (org.wso2.ballerinalang.compiler.Compiler)10 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)10 CompilerOptions (org.wso2.ballerinalang.compiler.util.CompilerOptions)10 Collectors (java.util.stream.Collectors)9 Arrays (java.util.Arrays)8 CompilerPhase (org.ballerinalang.compiler.CompilerPhase)7 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)6 BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)6 BLangNode (org.wso2.ballerinalang.compiler.tree.BLangNode)6