use of org.wso2.carbon.identity.functions.library.mgt.exception.FunctionLibraryManagementException 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());
}
}
use of org.wso2.carbon.identity.functions.library.mgt.exception.FunctionLibraryManagementException in project carbon-identity-framework by wso2.
the class FunctionLibraryDAOImplTest method listFunctionLibraries.
@Test(dataProvider = "listFunctionLibraryDataProvider")
public void listFunctionLibraries(List<Object> functionLibraries, String tenantDomain) throws FunctionLibraryManagementException {
try (Connection connection = DAOUtils.getConnection(DB_NAME)) {
FunctionLibraryDAO functionLibraryDAO = new FunctionLibraryDAOImpl();
addFunctionLibraries(functionLibraryDAO, functionLibraries, tenantDomain);
when(IdentityDatabaseUtil.getDBConnection(false)).thenReturn(connection);
List<FunctionLibrary> functionLibrariesList = functionLibraryDAO.listFunctionLibraries(tenantDomain);
assertTrue(functionLibrariesList != null && functionLibrariesList.size() != 0, "Failed to retrieve script libraries.");
// Clean after test
deleteFunctionLibraries(functionLibraryDAO, functionLibraries, tenantDomain);
} catch (SQLException e) {
log.error("SQLException");
}
}
use of org.wso2.carbon.identity.functions.library.mgt.exception.FunctionLibraryManagementException in project carbon-identity-framework by wso2.
the class FunctionLibraryDAOImplTest method updateFunctionLibrary.
@Test(dataProvider = "updateFunctionLibraryDataProvider")
public void updateFunctionLibrary(Object functionLibrary, String tenantDomain) throws SQLException, FunctionLibraryManagementException {
try (Connection connection1 = DAOUtils.getConnection(DB_NAME);
Connection connection2 = DAOUtils.getConnection(DB_NAME)) {
FunctionLibraryDAO functionLibraryDAO = new FunctionLibraryDAOImpl();
addFunctionLibraries(functionLibraryDAO, Collections.singletonList(functionLibrary), tenantDomain);
FunctionLibrary funLib = (FunctionLibrary) functionLibrary;
String oldName = funLib.getFunctionLibraryName();
funLib.setFunctionLibraryName("updatedName");
when(IdentityDatabaseUtil.getDBConnection()).thenReturn(connection1);
functionLibraryDAO.updateFunctionLibrary(oldName, funLib, tenantDomain);
when(IdentityDatabaseUtil.getDBConnection(false)).thenReturn(connection2);
assertNotNull(functionLibraryDAO.getFunctionLibrary(funLib.getFunctionLibraryName(), tenantDomain), "Failed to update script library.");
// Clean after test
deleteFunctionLibraries(functionLibraryDAO, Collections.singletonList(functionLibrary), tenantDomain);
}
}
use of org.wso2.carbon.identity.functions.library.mgt.exception.FunctionLibraryManagementException in project carbon-identity-framework by wso2.
the class FunctionLibraryDAOImplTest method updateFunctionLibraryException.
@Test(dataProvider = "updateFunctionLibraryDataProvider", expectedExceptions = FunctionLibraryManagementException.class)
public void updateFunctionLibraryException(Object functionLibrary, String tenantDomain) throws SQLException, FunctionLibraryManagementException {
FunctionLibraryDAO functionLibraryDAO = new FunctionLibraryDAOImpl();
addFunctionLibraries(functionLibraryDAO, Collections.singletonList(functionLibrary), tenantDomain);
FunctionLibrary funLib = (FunctionLibrary) functionLibrary;
String oldName = funLib.getFunctionLibraryName();
funLib.setFunctionLibraryName("updatedName");
functionLibraryDAO.updateFunctionLibrary(oldName, funLib, tenantDomain);
Assert.fail("Expected: " + FunctionLibraryManagementException.class.getName());
// Clean after test
deleteFunctionLibraries(functionLibraryDAO, Collections.singletonList(functionLibrary), tenantDomain);
}
use of org.wso2.carbon.identity.functions.library.mgt.exception.FunctionLibraryManagementException in project carbon-identity-framework by wso2.
the class FunctionLibraryDAOImplTest method isFunctionLibraryExists.
@Test(dataProvider = "isFunctionLibraryExistsDataProvider")
public void isFunctionLibraryExists(Object functionLibrary, String tenantDomain) throws SQLException, FunctionLibraryManagementException {
try (Connection connection1 = DAOUtils.getConnection(DB_NAME);
Connection connection2 = DAOUtils.getConnection(DB_NAME)) {
FunctionLibraryDAO functionLibraryDAO = new FunctionLibraryDAOImpl();
addFunctionLibraries(functionLibraryDAO, Collections.singletonList(functionLibrary), tenantDomain);
when(IdentityDatabaseUtil.getDBConnection(false)).thenReturn(connection1);
assertTrue(functionLibraryDAO.isFunctionLibraryExists(((FunctionLibrary) functionLibrary).getFunctionLibraryName(), tenantDomain), "Failed to check existence " + "by script library name.");
when(IdentityDatabaseUtil.getDBConnection(false)).thenReturn(connection2);
assertFalse(functionLibraryDAO.isFunctionLibraryExists("InvalidName", tenantDomain), "Failed to check existence " + "by script library name.");
// Clean after test
deleteFunctionLibraries(functionLibraryDAO, Collections.singletonList(functionLibrary), tenantDomain);
}
}
Aggregations