use of org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary in project carbon-identity-framework by wso2.
the class FunctionLibraryManagementServiceTest method tesAlreadyExistFunctionLibraryDataProvider.
@DataProvider(name = "tesAlreadyExistFunctionLibraryDataProvider")
public Object[][] tesAlreadyExistFunctionLibraryDataProvider() {
FunctionLibrary functionLibrary18 = new FunctionLibrary();
functionLibrary18.setFunctionLibraryName("sample");
functionLibrary18.setDescription("sample18");
functionLibrary18.setFunctionLibraryScript("function samplefunction18(){}");
FunctionLibrary functionLibrary19 = new FunctionLibrary();
functionLibrary19.setFunctionLibraryName("sample");
functionLibrary19.setDescription("sample19");
functionLibrary19.setFunctionLibraryScript("function samplefunction19(){}");
return new Object[][] { { functionLibrary18, SAMPLE_TENANT_DOMAIN2 }, { functionLibrary19, SAMPLE_TENANT_DOMAIN2 } };
}
use of org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary in project carbon-identity-framework by wso2.
the class FunctionLibraryManagementServiceTest method updateFunctionLibrary.
@Test(dataProvider = "updateFunctionLibraryDataProvider")
public void updateFunctionLibrary(Object functionLibrary, String tenantDomain) throws Exception {
FunctionLibraryManagementService functionLibraryManagementService = FunctionLibraryManagementServiceImpl.getInstance();
FunctionLibraryDAOImpl functionLibraryDAO = PowerMockito.mock(FunctionLibraryDAOImpl.class);
PowerMockito.whenNew(FunctionLibraryDAOImpl.class).withNoArguments().thenReturn(functionLibraryDAO);
addFunctionLibraries(functionLibraryManagementService, Collections.singletonList(functionLibrary), tenantDomain);
FunctionLibrary funLib = (FunctionLibrary) functionLibrary;
String oldName = funLib.getFunctionLibraryName();
if (oldName.equals("sample11")) {
funLib.setFunctionLibraryName("");
} else if (oldName.equals("sample12")) {
funLib.setFunctionLibraryName("#$%^%^");
} else if (oldName.equals("sample13")) {
funLib.setFunctionLibraryName("sample");
} else {
funLib.setFunctionLibraryName("updated");
}
try {
when(functionLibraryDAO.isFunctionLibraryExists("sample", tenantDomain)).thenReturn(true);
when(functionLibraryDAO.getFunctionLibrary(funLib.getFunctionLibraryName(), tenantDomain)).thenReturn(funLib);
functionLibraryManagementService.updateFunctionLibrary(oldName, funLib, tenantDomain);
assertNotNull(functionLibraryManagementService.getFunctionLibrary(funLib.getFunctionLibraryName(), tenantDomain), "Failed to update script library.");
// Clean after test
deleteFunctionLibraries(functionLibraryManagementService, Collections.singletonList(functionLibrary), tenantDomain);
} catch (FunctionLibraryManagementException e) {
if (!funLib.getFunctionLibraryName().equals(oldName) && functionLibraryDAO.isFunctionLibraryExists(funLib.getFunctionLibraryName(), tenantDomain)) {
assertEquals(e.getMessage(), "Already a script library available with the name: " + ((FunctionLibrary) functionLibrary).getFunctionLibraryName() + ".");
}
if (!isRegexValidated(funLib.getFunctionLibraryName())) {
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);
}
}
use of org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary in project carbon-identity-framework by wso2.
the class FunctionLibraryManagementServiceTest method listFunctionLibraries.
@Test(dataProvider = "listFunctionLibraryDataProvider")
public void listFunctionLibraries(List<Object> functionLibraries, String tenantDomain) throws Exception {
FunctionLibraryManagementService functionLibraryManagementService = FunctionLibraryManagementServiceImpl.getInstance();
FunctionLibraryDAOImpl functionLibraryDAO = PowerMockito.mock(FunctionLibraryDAOImpl.class);
PowerMockito.whenNew(FunctionLibraryDAOImpl.class).withNoArguments().thenReturn(functionLibraryDAO);
for (Object functionLibrary : functionLibraries) {
when(functionLibraryDAO.isFunctionLibraryExists(((FunctionLibrary) functionLibrary).getFunctionLibraryName(), tenantDomain)).thenReturn(false);
}
List<FunctionLibrary> functionLibraries1 = Arrays.asList(new FunctionLibrary[3]);
int i = 0;
for (Object functionLibrary : functionLibraries) {
functionLibraries1.set(i, (FunctionLibrary) functionLibrary);
i += 1;
}
when(functionLibraryDAO.listFunctionLibraries(SAMPLE_TENANT_DOMAIN)).thenReturn(functionLibraries1);
addFunctionLibraries(functionLibraryManagementService, functionLibraries, tenantDomain);
List<FunctionLibrary> functionLibrariesList = functionLibraryManagementService.listFunctionLibraries(tenantDomain);
assertTrue(functionLibrariesList != null && functionLibrariesList.size() != 0, "Failed to retrieve scopes.");
// Clean after test
deleteFunctionLibraries(functionLibraryManagementService, functionLibraries, tenantDomain);
}
use of org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary in project carbon-identity-framework by wso2.
the class FunctionLibraryDAOImplTest method deleteFunctionLibrary.
@Test(dataProvider = "deleteFunctionLibraryData")
public void deleteFunctionLibrary(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()).thenReturn(connection1);
functionLibraryDAO.deleteFunctionLibrary(((FunctionLibrary) functionLibrary).getFunctionLibraryName(), tenantDomain);
when(IdentityDatabaseUtil.getDBConnection(false)).thenReturn(connection2);
assertNull(functionLibraryDAO.getFunctionLibrary(((FunctionLibrary) functionLibrary).getFunctionLibraryName(), tenantDomain), "Failed to delete the functionLibrary by name.");
}
}
use of org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary in project carbon-identity-framework by wso2.
the class FunctionLibraryDAOImplTest method createFunctionLibrary.
@Test(dataProvider = "createFunctionLibraryDataProvider")
public void createFunctionLibrary(Object functionLibrary, String tenantDomain) {
try (Connection connection1 = DAOUtils.getConnection(DB_NAME);
Connection connection2 = DAOUtils.getConnection(DB_NAME);
Connection connection3 = DAOUtils.getConnection(DB_NAME)) {
FunctionLibraryDAO functionLibraryDAO = new FunctionLibraryDAOImpl();
FunctionLibrary functionLibrary1 = new FunctionLibrary();
functionLibrary1.setFunctionLibraryName("sample1");
functionLibrary1.setDescription("sample1");
functionLibrary1.setFunctionLibraryScript("samplefunction1");
try (Connection connection = DAOUtils.getConnection(DB_NAME)) {
when(IdentityDatabaseUtil.getDBConnection()).thenReturn(connection);
functionLibraryDAO.createFunctionLibrary(functionLibrary1, tenantDomain);
} catch (FunctionLibraryManagementException e) {
log.error("FunctionLibraryManagementException");
} catch (SQLException e) {
log.error("SQLException");
}
when(IdentityDatabaseUtil.getDBConnection()).thenReturn(connection1);
functionLibraryDAO.createFunctionLibrary((FunctionLibrary) functionLibrary, tenantDomain);
when(IdentityDatabaseUtil.getDBConnection(false)).thenReturn(connection2);
assertEquals(((FunctionLibrary) functionLibrary).getFunctionLibraryName(), functionLibraryDAO.getFunctionLibrary(((FunctionLibrary) functionLibrary).getFunctionLibraryName(), tenantDomain).getFunctionLibraryName());
// Clean after test
when(IdentityDatabaseUtil.getDBConnection()).thenReturn(connection3);
functionLibraryDAO.deleteFunctionLibrary(((FunctionLibrary) functionLibrary).getFunctionLibraryName(), tenantDomain);
} catch (SQLException e) {
log.error("SQLException");
} catch (FunctionLibraryManagementException e) {
assertEquals(e.getMessage(), "Error while creating the script library: " + ((FunctionLibrary) functionLibrary).getFunctionLibraryName() + ".");
}
}
Aggregations