use of org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary 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.model.FunctionLibrary 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);
}
}
use of org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary in project carbon-identity-framework by wso2.
the class FunctionLibraryDAOImplTest method createFunctionLibraryData.
@DataProvider(name = "createFunctionLibraryDataProvider")
public Object[][] createFunctionLibraryData() {
FunctionLibrary functionLibrary1 = new FunctionLibrary();
functionLibrary1.setFunctionLibraryName("sample1");
functionLibrary1.setDescription("sample1");
functionLibrary1.setFunctionLibraryScript("samplefunction1");
FunctionLibrary functionLibrary2 = new FunctionLibrary();
functionLibrary2.setFunctionLibraryName("sample2");
functionLibrary2.setDescription("sample2");
functionLibrary2.setFunctionLibraryScript(null);
FunctionLibrary functionLibrary3 = new FunctionLibrary();
functionLibrary3.setFunctionLibraryName("sample3");
functionLibrary3.setDescription("sample3");
functionLibrary3.setFunctionLibraryScript("samplefunction3");
return new Object[][] { { functionLibrary1, SAMPLE_TENANT_DOMAIN }, { functionLibrary2, SAMPLE_TENANT_DOMAIN }, { functionLibrary3, SAMPLE_TENANT_DOMAIN2 } };
}
use of org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary in project carbon-identity-framework by wso2.
the class FunctionLibraryDAOImplTest method deleteFunctionLibraryException.
@Test(dataProvider = "deleteFunctionLibraryData", expectedExceptions = FunctionLibraryManagementException.class)
public void deleteFunctionLibraryException(Object functionLibrary, String tenantDomain) throws SQLException, FunctionLibraryManagementException {
FunctionLibraryDAO functionLibraryDAO = new FunctionLibraryDAOImpl();
addFunctionLibraries(functionLibraryDAO, Collections.singletonList(functionLibrary), tenantDomain);
functionLibraryDAO.deleteFunctionLibrary(((FunctionLibrary) functionLibrary).getFunctionLibraryName(), tenantDomain);
Assert.fail("Expected: " + FunctionLibraryManagementException.class.getName());
}
use of org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary in project carbon-identity-framework by wso2.
the class FunctionLibraryManagementServiceImpl method updateFunctionLibrary.
@Override
public void updateFunctionLibrary(String oldFunctionLibraryName, FunctionLibrary functionLibrary, String tenantDomain) throws FunctionLibraryManagementException {
validateInputs(functionLibrary);
FunctionLibraryDAO functionLibraryDAO = new FunctionLibraryDAOImpl();
if (!functionLibrary.getFunctionLibraryName().equals(oldFunctionLibraryName) && functionLibraryDAO.isFunctionLibraryExists(functionLibrary.getFunctionLibraryName(), tenantDomain)) {
throw FunctionLibraryExceptionManagementUtil.handleClientException(FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_ALREADY_EXIST_SCRIPT_LIBRARY, functionLibrary.getFunctionLibraryName());
}
String functionLibraryName = functionLibrary.getFunctionLibraryName();
if (!isRegexValidated(functionLibraryName)) {
throw FunctionLibraryExceptionManagementUtil.handleClientException(FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_INVALID_SCRIPT_LIBRARY_NAME, FunctionLibraryMgtUtil.FUNCTION_LIBRARY_NAME_VALIDATING_REGEX);
}
functionLibraryDAO.updateFunctionLibrary(oldFunctionLibraryName, functionLibrary, tenantDomain);
}
Aggregations