use of org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary in project carbon-identity-framework by wso2.
the class FunctionLibraryDAOImpl method listFunctionLibraries.
/**
* Retrieve function library list in the tenant domain.
*
* @param tenantDomain Tenant domain
* @return A list of function libraries
* @throws FunctionLibraryManagementException
*/
public List<FunctionLibrary> listFunctionLibraries(String tenantDomain) throws FunctionLibraryManagementException {
int tenantID = MultitenantConstants.INVALID_TENANT_ID;
if (tenantDomain != null) {
tenantID = IdentityTenantUtil.getTenantId(tenantDomain);
}
List<FunctionLibrary> functionLibraries = new ArrayList<>();
try (Connection connection = IdentityDatabaseUtil.getDBConnection(false)) {
try (PreparedStatement getFunctionLibrariesStmt = connection.prepareStatement(FunctionLibMgtDBQueries.LOAD_FUNCTIONLIB_FROM_TENANTID)) {
getFunctionLibrariesStmt.setInt(1, tenantID);
try (ResultSet functionLibsResultSet = getFunctionLibrariesStmt.executeQuery()) {
while (functionLibsResultSet.next()) {
FunctionLibrary functionlib = new FunctionLibrary();
functionlib.setFunctionLibraryName(functionLibsResultSet.getString("NAME"));
functionlib.setDescription(functionLibsResultSet.getString("DESCRIPTION"));
functionLibraries.add(functionlib);
}
}
} catch (SQLException e1) {
throw FunctionLibraryExceptionManagementUtil.handleServerException(FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_RETRIEVE_SCRIPT_LIBRARIES, e1);
}
} catch (SQLException e) {
throw FunctionLibraryExceptionManagementUtil.handleServerException(FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_RETRIEVE_SCRIPT_LIBRARIES, e);
} catch (IdentityRuntimeException e) {
throw FunctionLibraryExceptionManagementUtil.handleServerException(FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_DATABASE_CONNECTION, e);
}
return functionLibraries;
}
use of org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary in project carbon-identity-framework by wso2.
the class FunctionLibraryManagementServiceTest method testFunctionLibraryNameRequired.
@Test(dataProvider = "testFunctionLibraryNameRequiredDataProvider")
public void testFunctionLibraryNameRequired(Object functionLibrary, String tenantDomain) {
FunctionLibraryDAOImpl functionLibraryDAO = PowerMockito.mock(FunctionLibraryDAOImpl.class);
try {
PowerMockito.whenNew(FunctionLibraryDAOImpl.class).withNoArguments().thenReturn(functionLibraryDAO);
when(functionLibraryDAO.getFunctionLibrary(((FunctionLibrary) functionLibrary).getFunctionLibraryName(), tenantDomain)).thenReturn((FunctionLibrary) functionLibrary);
FunctionLibraryManagementService functionLibraryManagementService = FunctionLibraryManagementServiceImpl.getInstance();
functionLibraryManagementService.createFunctionLibrary((FunctionLibrary) functionLibrary, tenantDomain);
} catch (FunctionLibraryManagementException e) {
assertEquals(e.getMessage(), "Script library name is required");
} catch (Exception e) {
fail("Exception", e);
}
}
use of org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary in project carbon-identity-framework by wso2.
the class FunctionLibraryManagementServiceTest method getFunctionLibrary.
@Test(dataProvider = "getFunctionLibraryDataProvider")
public void getFunctionLibrary(Object functionLibrary, String tenantDomain) {
try {
FunctionLibraryManagementService functionLibraryManagementService = FunctionLibraryManagementServiceImpl.getInstance();
FunctionLibraryDAOImpl functionLibraryDAO = PowerMockito.mock(FunctionLibraryDAOImpl.class);
PowerMockito.whenNew(FunctionLibraryDAOImpl.class).withNoArguments().thenReturn(functionLibraryDAO);
when(functionLibraryDAO.isFunctionLibraryExists(((FunctionLibrary) functionLibrary).getFunctionLibraryName(), tenantDomain)).thenReturn(false);
when(functionLibraryDAO.getFunctionLibrary(((FunctionLibrary) functionLibrary).getFunctionLibraryName(), tenantDomain)).thenReturn((FunctionLibrary) functionLibrary);
addFunctionLibraries(functionLibraryManagementService, Collections.singletonList(functionLibrary), tenantDomain);
assertTrue(functionLibraryManagementService.getFunctionLibrary(((FunctionLibrary) functionLibrary).getFunctionLibraryName(), tenantDomain) != null, "Failed to retrieve script library");
// Clean after test
deleteFunctionLibraries(functionLibraryManagementService, Collections.singletonList(functionLibrary), tenantDomain);
} catch (Exception e) {
fail("Exception", e);
}
}
use of org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary in project carbon-identity-framework by wso2.
the class FunctionLibraryManagementServiceTest method createFunctionLibrary.
@Test(dataProvider = "createFunctionLibraryDataProvider")
public void createFunctionLibrary(Object functionLibrary, String tenantDomain) {
FunctionLibraryDAOImpl functionLibraryDAO = PowerMockito.mock(FunctionLibraryDAOImpl.class);
try {
PowerMockito.whenNew(FunctionLibraryDAOImpl.class).withNoArguments().thenReturn(functionLibraryDAO);
when(functionLibraryDAO.getFunctionLibrary(((FunctionLibrary) functionLibrary).getFunctionLibraryName(), tenantDomain)).thenReturn((FunctionLibrary) functionLibrary);
FunctionLibraryManagementService functionLibraryManagementService = FunctionLibraryManagementServiceImpl.getInstance();
functionLibraryManagementService.createFunctionLibrary((FunctionLibrary) functionLibrary, tenantDomain);
assertEquals(functionLibraryManagementService.getFunctionLibrary(((FunctionLibrary) functionLibrary).getFunctionLibraryName(), tenantDomain).getFunctionLibraryName(), ((FunctionLibrary) functionLibrary).getFunctionLibraryName());
// Clean after test
functionLibraryManagementService.deleteFunctionLibrary(((FunctionLibrary) functionLibrary).getFunctionLibraryName(), tenantDomain);
} catch (Exception e) {
fail("Error test Create script library ", e);
}
}
use of org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary in project carbon-identity-framework by wso2.
the class FunctionLibraryManagementServiceTest method testIsRegexValidated.
@Test(dataProvider = "testIsRegexValidatedDataProvider")
public void testIsRegexValidated(Object functionLibrary, String tenantDomain) {
FunctionLibraryDAOImpl functionLibraryDAO = PowerMockito.mock(FunctionLibraryDAOImpl.class);
try {
PowerMockito.whenNew(FunctionLibraryDAOImpl.class).withNoArguments().thenReturn(functionLibraryDAO);
when(functionLibraryDAO.getFunctionLibrary(((FunctionLibrary) functionLibrary).getFunctionLibraryName(), tenantDomain)).thenReturn((FunctionLibrary) functionLibrary);
FunctionLibraryManagementService functionLibraryManagementService = FunctionLibraryManagementServiceImpl.getInstance();
functionLibraryManagementService.createFunctionLibrary((FunctionLibrary) functionLibrary, tenantDomain);
} catch (FunctionLibraryManagementException e) {
assertEquals(e.getMessage(), "The script library name is not valid! It is not adhering to the regex " + FunctionLibraryMgtUtil.FUNCTION_LIBRARY_NAME_VALIDATING_REGEX + ".");
} catch (Exception e) {
fail("Exception", e);
}
}
Aggregations