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);
}
}
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);
}
}
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);
}
}
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;
}
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());
}
}
Aggregations