Search in sources :

Example 21 with FunctionLibrary

use of org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary in project product-is by wso2.

the class FunctionLibraryManagementTestCase method testListFunctionLibraries.

@Test(alwaysRun = true, description = "Test listing Function Libraries")
public void testListFunctionLibraries() {
    String functionLibraryName = "TestFunctionLibrary";
    try {
        FunctionLibrary[] functionLibraries = functionLibraryManagementServiceClient.listFunctionLibraries();
        boolean functionLibraryExists = false;
        for (FunctionLibrary functionLibrary : functionLibraries) {
            if (functionLibrary.getFunctionLibraryName().equals(functionLibraryName)) {
                Assert.assertEquals(functionLibrary.getDescription(), "This is a Test Function Library", "Reading description failed");
                functionLibraryExists = true;
            }
        }
        if (!functionLibraryExists) {
            Assert.fail("Could not find function library " + functionLibraryName);
        }
    } catch (AxisFault axisFault) {
        Assert.fail("Error while trying to retrieve a list of function libraries", axisFault);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) FunctionLibrary(org.wso2.carbon.identity.functions.library.mgt.model.xsd.FunctionLibrary) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Example 22 with FunctionLibrary

use of org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary in project product-is by wso2.

the class FunctionLibraryManagementTestCase method testUpdateFunctionLibrary.

@Test(alwaysRun = true, description = "Test updating a Function Library")
public void testUpdateFunctionLibrary() {
    String functionLibraryName = "TestFunctionLibrary";
    try {
        FunctionLibrary functionLibrary = functionLibraryManagementServiceClient.getFunctionLibrary(functionLibraryName);
        functionLibrary.setDescription("updated description");
        functionLibrary.setFunctionLibraryScript("function updatedTest(name){};module.exports.updatedTet = updatedTest;");
        functionLibraryManagementServiceClient.updateFunctionLibrary(functionLibraryName, functionLibrary);
        FunctionLibrary updatedFunctionLibrary = null;
        updatedFunctionLibrary = functionLibraryManagementServiceClient.getFunctionLibrary(functionLibraryName);
        Assert.assertEquals(updatedFunctionLibrary.getDescription(), "updated description", "Failed update function library description");
        Assert.assertEquals(updatedFunctionLibrary.getFunctionLibraryScript(), "function updatedTest(name){};module.exports.updatedTet = updatedTest;", "Failed update function library script");
    } catch (AxisFault axisFault) {
        Assert.fail("Error while trying to update FunctionLibrary", axisFault);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) FunctionLibrary(org.wso2.carbon.identity.functions.library.mgt.model.xsd.FunctionLibrary) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Example 23 with FunctionLibrary

use of org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary in project product-is by wso2.

the class FunctionLibraryManagementTestCase method createFunctionLibrary.

private void createFunctionLibrary(String functionLibraryName) {
    try {
        FunctionLibrary functionLibrary = new FunctionLibrary();
        functionLibrary.setFunctionLibraryName(functionLibraryName);
        functionLibrary.setDescription("This is a Test Function Library");
        functionLibrary.setFunctionLibraryScript("function test(name){}; module.exports.test=test;");
        functionLibraryManagementServiceClient.createFunctionLibrary(functionLibrary);
    } catch (AxisFault axisFault) {
        Assert.fail("Error while trying to create Function Library", axisFault);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) FunctionLibrary(org.wso2.carbon.identity.functions.library.mgt.model.xsd.FunctionLibrary)

Example 24 with FunctionLibrary

use of org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary in project identity-api-server by wso2.

the class ServerScriptLibrariesService method createScriptLibrary.

/**
 * Create script library object.
 *
 * @param scriptLibraryPOSTRequest ScriptLibraryPOSTRequest
 * @return functionLibrary
 */
private FunctionLibrary createScriptLibrary(ScriptLibraryPOSTRequest scriptLibraryPOSTRequest) {
    FunctionLibrary functionLibrary = new FunctionLibrary();
    functionLibrary.setFunctionLibraryName(scriptLibraryPOSTRequest.getName());
    functionLibrary.setDescription(scriptLibraryPOSTRequest.getDescription());
    functionLibrary.setFunctionLibraryScript(String.valueOf(scriptLibraryPOSTRequest.getContent()));
    return functionLibrary;
}
Also used : FunctionLibrary(org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary)

Example 25 with FunctionLibrary

use of org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary in project identity-api-server by wso2.

the class ServerScriptLibrariesService method updateScriptLibrary.

/**
 * Update a script library identified by resource ID.
 *
 * @param scriptLibraryName  Name of the script library.
 * @param contentInputStream Content of the script library code.
 * @param description        Description of the script library
 */
public void updateScriptLibrary(String scriptLibraryName, InputStream contentInputStream, String description) {
    ScriptLibraryPUTRequest scriptLibraryPUTRequest = new ScriptLibraryPUTRequest();
    scriptLibraryPUTRequest.setDescription(description);
    try {
        scriptLibraryPUTRequest.setContent(new File(IOUtils.toString(contentInputStream, StandardCharsets.UTF_8.name())));
    } catch (IOException e) {
        log.error("Error occurred while reading contentInputStream: " + e);
        throw handleScriptLibraryClientError(Constants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_SCRIPT_LIBRARY, Response.Status.INTERNAL_SERVER_ERROR);
    }
    if (isScriptLibraryAvailable(scriptLibraryName)) {
        FunctionLibrary functionLibrary = createScriptLibraryPut(scriptLibraryName, scriptLibraryPUTRequest);
        try {
            ScriptLibraryServiceHolder.getScriptLibraryManagementService().updateFunctionLibrary(scriptLibraryName, functionLibrary, ContextLoader.getTenantDomainFromContext());
        } catch (FunctionLibraryManagementException e) {
            throw handleScriptLibraryError(e, Constants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_SCRIPT_LIBRARY);
        }
    } else {
        throw handleScriptLibraryClientError(Constants.ErrorMessage.ERROR_SCRIPT_LIBRARY_NOT_FOUND, Response.Status.NOT_FOUND, scriptLibraryName, ContextLoader.getTenantDomainFromContext());
    }
}
Also used : ScriptLibraryPUTRequest(org.wso2.carbon.identity.api.server.script.library.v1.model.ScriptLibraryPUTRequest) FunctionLibraryManagementException(org.wso2.carbon.identity.functions.library.mgt.exception.FunctionLibraryManagementException) FunctionLibrary(org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary) IOException(java.io.IOException) File(java.io.File)

Aggregations

FunctionLibrary (org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary)31 Test (org.testng.annotations.Test)19 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)15 PowerMockIdentityBaseTest (org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)15 DataProvider (org.testng.annotations.DataProvider)13 FunctionLibraryManagementException (org.wso2.carbon.identity.functions.library.mgt.exception.FunctionLibraryManagementException)11 FunctionLibraryDAO (org.wso2.carbon.identity.functions.library.mgt.dao.FunctionLibraryDAO)10 Connection (java.sql.Connection)9 FunctionLibraryDAOImpl (org.wso2.carbon.identity.functions.library.mgt.dao.impl.FunctionLibraryDAOImpl)9 SQLException (java.sql.SQLException)5 AxisFault (org.apache.axis2.AxisFault)5 FunctionLibrary (org.wso2.carbon.identity.functions.library.mgt.model.xsd.FunctionLibrary)5 IOException (java.io.IOException)4 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)4 PreparedStatement (java.sql.PreparedStatement)3 IdentityRuntimeException (org.wso2.carbon.identity.base.IdentityRuntimeException)3 File (java.io.File)2 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1