Search in sources :

Example 41 with FunctionLibrary

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

the class FunctionLibraryManagementServiceTest method testIsRegexValidatedDataProvider.

@DataProvider(name = "testIsRegexValidatedDataProvider")
public Object[][] testIsRegexValidatedDataProvider() {
    FunctionLibrary functionLibrary15 = new FunctionLibrary();
    functionLibrary15.setFunctionLibraryName("sample15$%");
    functionLibrary15.setDescription("sample15");
    functionLibrary15.setFunctionLibraryScript("function samplefunction15(){}");
    FunctionLibrary functionLibrary16 = new FunctionLibrary();
    functionLibrary16.setFunctionLibraryName("%%sample16");
    functionLibrary16.setDescription("sample16");
    functionLibrary16.setFunctionLibraryScript("function samplefunction16(){}");
    FunctionLibrary functionLibrary17 = new FunctionLibrary();
    functionLibrary17.setFunctionLibraryName("$%sample17");
    functionLibrary17.setDescription("sample17");
    functionLibrary17.setFunctionLibraryScript("function samplefunction17(){}");
    return new Object[][] { { functionLibrary15, SAMPLE_TENANT_DOMAIN2 }, { functionLibrary16, SAMPLE_TENANT_DOMAIN2 }, { functionLibrary17, SAMPLE_TENANT_DOMAIN2 } };
}
Also used : FunctionLibrary(org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary) DataProvider(org.testng.annotations.DataProvider)

Example 42 with FunctionLibrary

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

the class FunctionLibraryManagementTestCase method testDeleteFunctionLibrary.

@Test(alwaysRun = true, description = "Test deleting a Function Library")
public void testDeleteFunctionLibrary() {
    String functionLibraryName = "TestFunctionLibrary";
    try {
        deleteFunctionLibrary(functionLibraryName);
        FunctionLibrary[] functionLibraries = functionLibraryManagementServiceClient.listFunctionLibraries();
        boolean functionLibraryExists = false;
        if (functionLibraries != null) {
            for (FunctionLibrary functionLibrary : functionLibraries) {
                if (functionLibrary.getFunctionLibraryName().equals(functionLibraryName)) {
                    functionLibraryExists = true;
                }
            }
        }
        Assert.assertFalse(functionLibraryExists, functionLibraryName + " has not been deleted.");
    } catch (AxisFault axisFault) {
        Assert.fail("Error while trying to delete a function library", 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 43 with FunctionLibrary

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

the class ServerScriptLibrariesService method createScriptLibrariesList.

/**
 * Create a script libraries list response.
 *
 * @param scriptLibraries list of script libraries.
 * @param limit           Item per page.
 * @param offset          offset
 * @return scriptLibraryListResponse
 */
private ScriptLibraryListResponse createScriptLibrariesList(List<FunctionLibrary> scriptLibraries, Integer limit, Integer offset) {
    ScriptLibraryListResponse scriptLibraryListResponse = new ScriptLibraryListResponse();
    if (CollectionUtils.isNotEmpty(scriptLibraries)) {
        List<ScriptLibrary> scriptLibraryItem = new ArrayList<>();
        for (FunctionLibrary functionLibrary : scriptLibraries) {
            ScriptLibrary scriptLibrary = new ScriptLibrary();
            scriptLibrary.setName(functionLibrary.getFunctionLibraryName());
            scriptLibrary.setDescription(functionLibrary.getDescription());
            scriptLibrary.setSelf(ContextLoader.buildURIForBody(String.format(V1_API_PATH_COMPONENT + SCRIPT_LIBRARY_PATH_COMPONENT + "/%s", functionLibrary.getFunctionLibraryName())).toString());
            scriptLibraryItem.add(scriptLibrary);
        }
        scriptLibraryListResponse.setScriptLibraries(scriptLibraryItem.subList(Math.min(scriptLibraryItem.size(), offset), Math.min(scriptLibraryItem.size(), offset + limit)));
        scriptLibraryListResponse.setCount(scriptLibraryListResponse.getScriptLibraries().size());
        scriptLibraryListResponse.setTotalResults(scriptLibraries.size());
        scriptLibraryListResponse.setStartIndex(offset + 1);
    } else {
        scriptLibraryListResponse.setCount(0);
    }
    return scriptLibraryListResponse;
}
Also used : ScriptLibraryListResponse(org.wso2.carbon.identity.api.server.script.library.v1.model.ScriptLibraryListResponse) ArrayList(java.util.ArrayList) FunctionLibrary(org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary) ScriptLibrary(org.wso2.carbon.identity.api.server.script.library.v1.model.ScriptLibrary)

Example 44 with FunctionLibrary

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

the class ServerScriptLibrariesService method createScriptLibraryPut.

/**
 * Create a function library object from ScriptLibraryPUTRequest.
 *
 * @param scriptLibraryName       Script library name.
 * @param scriptLibraryPUTRequest ScriptLibraryPUTRequest
 * @return functionLibrary
 */
private FunctionLibrary createScriptLibraryPut(String scriptLibraryName, ScriptLibraryPUTRequest scriptLibraryPUTRequest) {
    FunctionLibrary functionLibrary = new FunctionLibrary();
    functionLibrary.setFunctionLibraryName(scriptLibraryName);
    functionLibrary.setDescription(scriptLibraryPUTRequest.getDescription());
    functionLibrary.setFunctionLibraryScript(String.valueOf(scriptLibraryPUTRequest.getContent()));
    return functionLibrary;
}
Also used : FunctionLibrary(org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary)

Example 45 with FunctionLibrary

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

the class ServerScriptLibrariesService method addScriptLibrary.

/**
 * Add a script library.
 *
 * @param name               Name of the script library.
 * @param contentInputStream Content of the script library code.
 * @param description        Description of the script library
 */
public void addScriptLibrary(String name, InputStream contentInputStream, String description) {
    ScriptLibraryPOSTRequest scriptLibraryPOSTRequest = new ScriptLibraryPOSTRequest();
    scriptLibraryPOSTRequest.setName(name);
    scriptLibraryPOSTRequest.setDescription(description);
    try {
        scriptLibraryPOSTRequest.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_ADDING_SCRIPT_LIBRARY, Response.Status.INTERNAL_SERVER_ERROR);
    }
    if (isScriptLibraryAvailable(scriptLibraryPOSTRequest.getName())) {
        throw handleScriptLibraryClientError(Constants.ErrorMessage.ERROR_SCRIPT_LIBRARY_ALREADY_FOUND, Response.Status.CONFLICT, scriptLibraryPOSTRequest.getName(), ContextLoader.getTenantDomainFromContext());
    } else {
        FunctionLibrary functionLibrary = createScriptLibrary(scriptLibraryPOSTRequest);
        try {
            if (scriptLibraryPOSTRequest.getName().contains(Constants.SCRIPT_LIBRARY_EXTENSION)) {
                ScriptLibraryServiceHolder.getScriptLibraryManagementService().createFunctionLibrary(functionLibrary, ContextLoader.getTenantDomainFromContext());
            } else {
                throw handleScriptLibraryClientError(Constants.ErrorMessage.ERROR_SCRIPT_LIBRARY_NAME_VALIDATION, Response.Status.BAD_REQUEST);
            }
        } catch (FunctionLibraryManagementException e) {
            throw handleScriptLibraryError(e, Constants.ErrorMessage.ERROR_CODE_ERROR_ADDING_SCRIPT_LIBRARY);
        }
    }
}
Also used : FunctionLibraryManagementException(org.wso2.carbon.identity.functions.library.mgt.exception.FunctionLibraryManagementException) ScriptLibraryPOSTRequest(org.wso2.carbon.identity.api.server.script.library.v1.model.ScriptLibraryPOSTRequest) 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