Search in sources :

Example 6 with FunctionLibraryManagementService

use of org.wso2.carbon.identity.functions.library.mgt.FunctionLibraryManagementService 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);
    }
}
Also used : FunctionLibraryDAOImpl(org.wso2.carbon.identity.functions.library.mgt.dao.impl.FunctionLibraryDAOImpl) FunctionLibraryManagementException(org.wso2.carbon.identity.functions.library.mgt.exception.FunctionLibraryManagementException) Test(org.testng.annotations.Test) PowerMockIdentityBaseTest(org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with FunctionLibraryManagementService

use of org.wso2.carbon.identity.functions.library.mgt.FunctionLibraryManagementService 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);
    }
}
Also used : FunctionLibraryDAOImpl(org.wso2.carbon.identity.functions.library.mgt.dao.impl.FunctionLibraryDAOImpl) FunctionLibraryManagementException(org.wso2.carbon.identity.functions.library.mgt.exception.FunctionLibraryManagementException) Test(org.testng.annotations.Test) PowerMockIdentityBaseTest(org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 8 with FunctionLibraryManagementService

use of org.wso2.carbon.identity.functions.library.mgt.FunctionLibraryManagementService 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);
    }
}
Also used : FunctionLibraryDAOImpl(org.wso2.carbon.identity.functions.library.mgt.dao.impl.FunctionLibraryDAOImpl) FunctionLibraryManagementException(org.wso2.carbon.identity.functions.library.mgt.exception.FunctionLibraryManagementException) FunctionLibraryManagementException(org.wso2.carbon.identity.functions.library.mgt.exception.FunctionLibraryManagementException) Test(org.testng.annotations.Test) PowerMockIdentityBaseTest(org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 9 with FunctionLibraryManagementService

use of org.wso2.carbon.identity.functions.library.mgt.FunctionLibraryManagementService in project identity-api-server by wso2.

the class ScriptLibraryMgtOSGIService method createInstance.

protected FunctionLibraryManagementService createInstance() throws Exception {
    if (this.functionLibraryManagementService == null) {
        FunctionLibraryManagementService taskOperationService = (FunctionLibraryManagementService) PrivilegedCarbonContext.getThreadLocalCarbonContext().getOSGiService(FunctionLibraryManagementService.class, (Hashtable) null);
        if (taskOperationService == null) {
            throw new Exception("Unable to retrieve Function Library Management Service.");
        }
        this.functionLibraryManagementService = taskOperationService;
    }
    return this.functionLibraryManagementService;
}
Also used : Hashtable(java.util.Hashtable) FunctionLibraryManagementService(org.wso2.carbon.identity.functions.library.mgt.FunctionLibraryManagementService)

Aggregations

PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 Test (org.testng.annotations.Test)7 FunctionLibraryDAOImpl (org.wso2.carbon.identity.functions.library.mgt.dao.impl.FunctionLibraryDAOImpl)7 PowerMockIdentityBaseTest (org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)7 FunctionLibraryManagementException (org.wso2.carbon.identity.functions.library.mgt.exception.FunctionLibraryManagementException)6 FunctionLibrary (org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary)4 FunctionLibraryManagementService (org.wso2.carbon.identity.functions.library.mgt.FunctionLibraryManagementService)2 Hashtable (java.util.Hashtable)1