Search in sources :

Example 61 with PACKAGE

use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE 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");
}
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 62 with PACKAGE

use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE in project ballerina by ballerina-lang.

the class GlobalVarServicePkgTest method testChangeAndAccessGlobalVarInDiffPkg.

@Test(description = "Test change global var in different package and access it", enabled = false)
public void testChangeAndAccessGlobalVarInDiffPkg() {
    HTTPTestRequest cMsgChange = MessageUtils.generateHTTPMessage("/globalvar-pkg/change-global-var-diff-pkg", "GET");
    Services.invokeNew(result, cMsgChange);
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/globalvar-second-pkg/get-changed-resource-level", "GET");
    HTTPCarbonMessage response = Services.invokeNew(result, cMsg);
    Assert.assertNotNull(response);
    // Expected Json message : {"changeVarFloat":345432.454}
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("changeVarFloat").asText(), "345432.454");
}
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 63 with PACKAGE

use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE in project carbon-apimgt by wso2.

the class AdditionalSubscriptionInfoMappingUtil method mapSolaceTopicObjects.

/**
 * Map SolaceTopicsObjectDTO details from Solace package to DevPortal DTOs
 *
 * @param solaceTopicsObject SolaceTopicsObjectDTO object from Solace package
 * @return AdditionalSubscriptionInfoSolaceTopicsObjectDTO object
 */
private static AdditionalSubscriptionInfoSolaceTopicsObjectDTO mapSolaceTopicObjects(SolaceTopicsObjectDTO solaceTopicsObject) {
    AdditionalSubscriptionInfoSolaceTopicsObjectDTO solaceTopicsObjectDTO = new AdditionalSubscriptionInfoSolaceTopicsObjectDTO();
    // Set default syntax object
    org.wso2.carbon.apimgt.solace.dtos.SolaceTopicsDTO defaultSyntaxObject = solaceTopicsObject.getDefaultSyntax();
    SolaceTopicsDTO storeDefaultSolaceTopicObject = new SolaceTopicsDTO();
    storeDefaultSolaceTopicObject.setPublishTopics(defaultSyntaxObject.getPublishTopics());
    storeDefaultSolaceTopicObject.setSubscribeTopics(defaultSyntaxObject.getSubscribeTopics());
    solaceTopicsObjectDTO.setDefaultSyntax(storeDefaultSolaceTopicObject);
    // Set mqtt syntax object
    org.wso2.carbon.apimgt.solace.dtos.SolaceTopicsDTO mqttSyntaxObject = solaceTopicsObject.getMqttSyntax();
    SolaceTopicsDTO storeMQTTSolaceTopicObject = new SolaceTopicsDTO();
    storeMQTTSolaceTopicObject.setPublishTopics(mqttSyntaxObject.getPublishTopics());
    storeMQTTSolaceTopicObject.setSubscribeTopics(mqttSyntaxObject.getSubscribeTopics());
    solaceTopicsObjectDTO.setMqttSyntax(storeMQTTSolaceTopicObject);
    return solaceTopicsObjectDTO;
}
Also used : SolaceTopicsDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.SolaceTopicsDTO) AdditionalSubscriptionInfoSolaceTopicsObjectDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoSolaceTopicsObjectDTO)

Example 64 with PACKAGE

use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE in project carbon-apimgt by wso2.

the class EndpointsApiServiceImplTestCase method endpointsEndpointIdGatewayConfigGetTest.

@Test
public void endpointsEndpointIdGatewayConfigGetTest() throws Exception {
    APIMgtAdminServiceImpl apiMgtAdminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
    PowerMockito.mockStatic(APIManagerFactory.class);
    PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
    Mockito.when(instance.getAPIMgtAdminService()).thenReturn(apiMgtAdminService);
    EndpointsApiServiceImpl endpointsApiService = new EndpointsApiServiceImpl();
    String endpointId = UUID.randomUUID().toString();
    String endpointGatewayConfig = "package deployment.org.wso2.apim;\n" + "import ballerina.net.http;\n" + "\n" + "@http:BasePath(\"/aaa1\")\n" + "service aaa1_1489666767745 {\n" + "\n" + "    @http:GET\n" + "    @http:Path(\"/*\")\n" + "    resource get_star_ (message m) {\n" + "        http:ClientConnector productionEndpoint = create http:ClientConnector(getUrlFromKey" + "(\"aaa1_1.0.0__ep\"));\n   http:ClientConnector sandboxEndpoint = create http:ClientConnector" + "(getUrlFromKey(\"aaa1_1.0.0__ep\"));\n message response;\n string endpointType;\n string " + "productionType;\n \n \n      endpointType = \"production\";\n productionType = \"production\";\n" + "\n      if (endpointType == productionType) {\n" + "            response = http:ClientConnector.execute(productionEndpoint, \"get\", \"\", m);\n" + "        } else {\n" + "            response = http:ClientConnector.execute(sandboxEndpoint, \"get\", \"\", m);\n" + "        }\n" + "\n" + "        reply response;\n" + "    }\n" + "}";
    Mockito.when(apiMgtAdminService.getEndpointGatewayConfig(endpointId)).thenReturn(endpointGatewayConfig);
    Response response = endpointsApiService.endpointsEndpointIdGatewayConfigGet(endpointId, null, getRequest());
    Assert.assertEquals(response.getStatus(), 200);
}
Also used : Response(javax.ws.rs.core.Response) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 65 with PACKAGE

use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE in project carbon-business-process by wso2.

the class HumanTaskApplicationAdmin method getHumanTaskAppData.

/**
 * Gives a HumanTaskAppMetadata object with all humantask packages deployed through the
 * given app.
 *
 * @param appName - input app name
 * @return - HumanTaskAppMetadata object with found artifact info
 * @throws Exception - error on retrieving metadata
 */
public HumanTaskAppMetadata getHumanTaskAppData(String appName) throws Exception {
    HumanTaskAppMetadata data = new HumanTaskAppMetadata();
    String tenantId = AppDeployerUtils.getTenantIdString(getAxisConfig());
    // Check whether there is an application in the system from the given name
    ArrayList<CarbonApplication> appList = HumanTaskAppMgtServiceComponent.getAppManager().getCarbonApps(tenantId);
    CarbonApplication currentApplication = null;
    for (CarbonApplication application : appList) {
        if (appName.equals(application.getAppNameWithVersion())) {
            currentApplication = application;
            break;
        }
    }
    // If the app not found, throw an exception
    if (currentApplication == null) {
        String msg = "No Carbon Application found of the name : " + appName;
        log.error(msg);
        throw new Exception(msg);
    }
    // get all dependent artifacts of the cApp
    List<Artifact.Dependency> deps = currentApplication.getAppConfig().getApplicationArtifact().getDependencies();
    // we use the humantask backend admin service to get tasks from a humantask package
    HumanTaskPackageManagementSkeleton humantaskAdmin = new HumanTaskPackageManagementSkeleton();
    // package list to return
    List<PackageMetadata> packageList = new ArrayList<PackageMetadata>();
    String packageName;
    for (Artifact.Dependency dep : deps) {
        Artifact artifact = dep.getArtifact();
        packageName = artifact.getRuntimeObjectName();
        if (packageName == null) {
            continue;
        }
        if (HumanTaskAppDeployer.HUMANTASK_TYPE.equals(artifact.getType())) {
            PackageMetadata packageMetadata = new PackageMetadata();
            packageMetadata.setPackageName(packageName);
            // get the list of tasks
            List<String> taskList = new ArrayList<String>();
            Task_type0[] tasksInPackage = humantaskAdmin.listTasksInPackage(packageName);
            for (Task_type0 taskInfo : tasksInPackage) {
                taskList.add(taskInfo.getName());
            }
            String[] tasks = new String[taskList.size()];
            packageMetadata.setTaskList(tasks);
            packageList.add(packageMetadata);
        }
    }
    // convert the List into an array
    data.setPackages(packageList.toArray(new PackageMetadata[packageList.size()]));
    return data;
}
Also used : ArrayList(java.util.ArrayList) CarbonApplication(org.wso2.carbon.application.deployer.CarbonApplication) Artifact(org.wso2.carbon.application.deployer.config.Artifact) HumanTaskPackageManagementSkeleton(org.wso2.carbon.humantask.skeleton.mgt.services.HumanTaskPackageManagementSkeleton) Task_type0(org.wso2.carbon.humantask.skeleton.mgt.services.types.Task_type0)

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