Search in sources :

Example 31 with FunctionLibrary

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);
}
Also used : FunctionLibrary(org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary) FunctionLibraryDAO(org.wso2.carbon.identity.functions.library.mgt.dao.FunctionLibraryDAO) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PowerMockIdentityBaseTest(org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)

Example 32 with FunctionLibrary

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);
    }
}
Also used : Connection(java.sql.Connection) FunctionLibrary(org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary) FunctionLibraryDAO(org.wso2.carbon.identity.functions.library.mgt.dao.FunctionLibraryDAO) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PowerMockIdentityBaseTest(org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)

Example 33 with FunctionLibrary

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 } };
}
Also used : FunctionLibrary(org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary) DataProvider(org.testng.annotations.DataProvider)

Example 34 with FunctionLibrary

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

Example 35 with FunctionLibrary

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);
}
Also used : FunctionLibraryDAOImpl(org.wso2.carbon.identity.functions.library.mgt.dao.impl.FunctionLibraryDAOImpl) FunctionLibraryDAO(org.wso2.carbon.identity.functions.library.mgt.dao.FunctionLibraryDAO)

Aggregations

FunctionLibrary (org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary)31 Test (org.testng.annotations.Test)19 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)15 PowerMockIdentityBaseTest (org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)15 DataProvider (org.testng.annotations.DataProvider)13 FunctionLibraryManagementException (org.wso2.carbon.identity.functions.library.mgt.exception.FunctionLibraryManagementException)11 FunctionLibraryDAO (org.wso2.carbon.identity.functions.library.mgt.dao.FunctionLibraryDAO)10 Connection (java.sql.Connection)9 FunctionLibraryDAOImpl (org.wso2.carbon.identity.functions.library.mgt.dao.impl.FunctionLibraryDAOImpl)9 SQLException (java.sql.SQLException)5 AxisFault (org.apache.axis2.AxisFault)5 FunctionLibrary (org.wso2.carbon.identity.functions.library.mgt.model.xsd.FunctionLibrary)5 IOException (java.io.IOException)4 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)4 PreparedStatement (java.sql.PreparedStatement)3 IdentityRuntimeException (org.wso2.carbon.identity.base.IdentityRuntimeException)3 File (java.io.File)2 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1