Search in sources :

Example 1 with TestUtils.getConnection

use of org.wso2.carbon.identity.user.functionality.mgt.util.TestUtils.getConnection in project carbon-identity-framework by wso2.

the class ConfigurationManagerTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    initiateH2Base();
    String carbonHome = Paths.get(System.getProperty("user.dir"), "target", "test-classes").toString();
    System.setProperty(CarbonBaseConstants.CARBON_HOME, carbonHome);
    System.setProperty(CarbonBaseConstants.CARBON_CONFIG_DIR_PATH, Paths.get(carbonHome, "conf").toString());
    DataSource dataSource = mock(DataSource.class);
    mockStatic(IdentityDatabaseUtil.class);
    when(IdentityDatabaseUtil.getDataSource()).thenReturn(dataSource);
    connection = TestUtils.getConnection();
    Connection spyConnection = spyConnection(connection);
    when(dataSource.getConnection()).thenReturn(spyConnection);
    prepareConfigs();
    ConfigurationManagerComponentDataHolder.getInstance().setConfigurationManagementEnabled(true);
}
Also used : Connection(java.sql.Connection) TestUtils.spyConnection(org.wso2.carbon.identity.configuration.mgt.core.util.TestUtils.spyConnection) DataSource(javax.sql.DataSource) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with TestUtils.getConnection

use of org.wso2.carbon.identity.user.functionality.mgt.util.TestUtils.getConnection in project carbon-identity-framework by wso2.

the class UserFunctionalityManagerImplTest method testLockFunctionalityForUser.

@Test(dataProvider = "LockFunctionalityForUserData")
public void testLockFunctionalityForUser(String functionalityIdentifier, String userId, int tenantId, boolean expected) {
    DataSource dataSource = mock(DataSource.class);
    TestUtils.mockDataSource(dataSource);
    long functionalityUnlockTime = System.currentTimeMillis() + 300000;
    String functionalityLockReasonCode = "Lock code";
    String functionalityLockReason = "Lock Reason 2";
    try {
        try (Connection connection = TestUtils.getConnection()) {
            Connection spyConnection = TestUtils.spyConnection(connection);
            when(dataSource.getConnection()).thenReturn(spyConnection);
            try {
                mockIsUserStoreManager(userId);
                userFunctionalityManager.lock(userId, tenantId, functionalityIdentifier, functionalityUnlockTime, functionalityLockReasonCode, functionalityLockReason);
                assertEquals(userFunctionalityManager.getLockStatus(userId, tenantId, functionalityIdentifier).getLockStatus(), expected);
                assertEquals(userFunctionalityManager.getLockStatus(userId, tenantId, functionalityIdentifier).getLockReason(), functionalityLockReason);
            } catch (UserFunctionalityManagementException e) {
                log.error(String.format("Error while selecting functionality: %s", functionalityIdentifier), e);
            } catch (UserStoreException e) {
                log.error("Error while checking userid in userstore", e);
            }
        }
    } catch (SQLException e) {
        log.error("SQL Exception", e);
    }
}
Also used : UserFunctionalityManagementException(org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) UserStoreException(org.wso2.carbon.user.api.UserStoreException) DataSource(javax.sql.DataSource) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with TestUtils.getConnection

use of org.wso2.carbon.identity.user.functionality.mgt.util.TestUtils.getConnection in project carbon-identity-framework by wso2.

the class UserFunctionalityManagerImplTest method testUnlockFunctionalityForUser.

@Test(dataProvider = "UnlockFunctionalityForUserData")
public void testUnlockFunctionalityForUser(String functionalityIdentifier, String userId, int tenantId, boolean isFunctionalityLocked) {
    DataSource dataSource = mock(DataSource.class);
    TestUtils.mockDataSource(dataSource);
    try {
        try (Connection connection = TestUtils.getConnection()) {
            Connection spyConnection = TestUtils.spyConnection(connection);
            when(dataSource.getConnection()).thenReturn(spyConnection);
            try {
                mockIsUserStoreManager(userId);
                assertEquals(userFunctionalityManager.getLockStatus(userId, tenantId, functionalityIdentifier).getLockStatus(), isFunctionalityLocked);
                userFunctionalityManager.unlock(userId, tenantId, functionalityIdentifier);
                assertEquals(userFunctionalityManager.getLockStatus(userId, tenantId, functionalityIdentifier).getLockStatus(), false);
            } catch (UserFunctionalityManagementException e) {
                log.error(String.format("Error while selecting functionality: %s", functionalityIdentifier), e);
            } catch (UserStoreException e) {
                log.error("Error while checking userid in userstore", e);
            }
        }
    } catch (SQLException e) {
        log.error("SQL Exception", e);
    }
}
Also used : UserFunctionalityManagementException(org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) UserStoreException(org.wso2.carbon.user.api.UserStoreException) DataSource(javax.sql.DataSource) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with TestUtils.getConnection

use of org.wso2.carbon.identity.user.functionality.mgt.util.TestUtils.getConnection in project carbon-identity-framework by wso2.

the class UserFunctionalityManagerDAOImplTest method testDeleteFunctionality.

@Test
public void testDeleteFunctionality() {
    DataSource dataSource = mock(DataSource.class);
    TestUtils.mockDataSource(dataSource);
    try (Connection connection = TestUtils.getConnection()) {
        Connection spyConnection = TestUtils.spyConnection(connection);
        when(dataSource.getConnection()).thenReturn(spyConnection);
        FunctionalityLockStatus functionalityLockStatus = new FunctionalityLockStatus(false, 0, null, null);
        try {
            userFunctionalityManagerDAO.addFunctionalityLock("userId", 1, "functionalityIdentifier1", functionalityLockStatus);
            userFunctionalityManagerDAO.deleteMappingForUser("userId", 1, "functionalityIdentifier1");
            userFunctionalityManagerDAO.deleteMappingForUser("userId", 2, "functionalityIdentifier2");
            assertNull(userFunctionalityManagerDAO.getFunctionalityLockStatus("userId", 1, "functionalityIdentifier1"));
        } catch (UserFunctionalityManagementServerException e) {
            log.error("FunctionalityManagementServer Exception", e);
        }
    } catch (SQLException e) {
    // Mock behaviour. Hence ignored.
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) FunctionalityLockStatus(org.wso2.carbon.identity.user.functionality.mgt.model.FunctionalityLockStatus) UserFunctionalityManagementServerException(org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementServerException) DataSource(javax.sql.DataSource) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with TestUtils.getConnection

use of org.wso2.carbon.identity.user.functionality.mgt.util.TestUtils.getConnection in project carbon-identity-framework by wso2.

the class UserFunctionalityManagerDAOImplTest method testAddFunctionality.

@Test(dataProvider = "TestFunctionalityData")
public void testAddFunctionality(String functionalityIdentifier, String userId, int tenantId, boolean isFunctionalityLocked, int functionalityUnlockTime, String functionalityLockReasonCode, String functionalityLockReason) {
    DataSource dataSource = mock(DataSource.class);
    TestUtils.mockDataSource(dataSource);
    try (Connection connection = TestUtils.getConnection()) {
        Connection spyConnection = TestUtils.spyConnection(connection);
        when(dataSource.getConnection()).thenReturn(spyConnection);
        FunctionalityLockStatus functionalityLockStatus = new FunctionalityLockStatus(isFunctionalityLocked, functionalityUnlockTime, functionalityLockReasonCode, functionalityLockReason);
        try {
            userFunctionalityManagerDAO.addFunctionalityLock(userId, tenantId, functionalityIdentifier, functionalityLockStatus);
        } catch (UserFunctionalityManagementServerException e) {
            log.error(String.format("Error while adding functionality: %s", functionalityIdentifier), e);
        }
        Assert.assertEquals(userFunctionalityManagerDAO.getFunctionalityLockStatus(userId, tenantId, functionalityIdentifier).getLockStatus(), functionalityLockStatus.getLockStatus());
        Assert.assertEquals(userFunctionalityManagerDAO.getFunctionalityLockStatus(userId, tenantId, functionalityIdentifier).getUnlockTime(), functionalityLockStatus.getUnlockTime());
        Assert.assertEquals(userFunctionalityManagerDAO.getFunctionalityLockStatus(userId, tenantId, functionalityIdentifier).getLockReason(), functionalityLockStatus.getLockReason());
        Assert.assertEquals(userFunctionalityManagerDAO.getFunctionalityLockStatus(userId, tenantId, functionalityIdentifier).getLockReasonCode(), functionalityLockStatus.getLockReasonCode());
    } catch (SQLException e) {
    // Mock behaviour. Hence ignored.
    } catch (UserFunctionalityManagementServerException e) {
        assertEquals(e.getMessage(), String.format("Error occurred while adding the functionality: %s, for user: %s, for tenant" + " id: %d, having the parameters, functionality lock status: %b, functionality " + "unlock time: %d, functionality lock reason code: %s, functionality lock reason: " + "%s.", functionalityIdentifier, userId, tenantId, isFunctionalityLocked, functionalityUnlockTime, functionalityLockReasonCode, functionalityLockReason));
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) FunctionalityLockStatus(org.wso2.carbon.identity.user.functionality.mgt.model.FunctionalityLockStatus) UserFunctionalityManagementServerException(org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementServerException) DataSource(javax.sql.DataSource) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Connection (java.sql.Connection)15 DataSource (javax.sql.DataSource)15 SQLException (java.sql.SQLException)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 Test (org.testng.annotations.Test)12 UserFunctionalityManagementServerException (org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementServerException)7 FunctionalityLockStatus (org.wso2.carbon.identity.user.functionality.mgt.model.FunctionalityLockStatus)7 UserFunctionalityManagementException (org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementException)6 UserStoreException (org.wso2.carbon.user.api.UserStoreException)6 BeforeMethod (org.testng.annotations.BeforeMethod)3 BeforeClass (org.testng.annotations.BeforeClass)2 ScopeClaimMappingDAOImpl (org.wso2.carbon.identity.openidconnect.dao.ScopeClaimMappingDAOImpl)2 CryptoUtil (org.wso2.carbon.core.util.CryptoUtil)1 TestUtils.spyConnection (org.wso2.carbon.identity.configuration.mgt.core.util.TestUtils.spyConnection)1 OpenIDConnectClaimFilterImpl (org.wso2.carbon.identity.openidconnect.OpenIDConnectClaimFilterImpl)1 RequestObjectService (org.wso2.carbon.identity.openidconnect.RequestObjectService)1 RequestedClaim (org.wso2.carbon.identity.openidconnect.model.RequestedClaim)1 TestUtils.spyConnection (org.wso2.carbon.identity.secret.mgt.core.util.TestUtils.spyConnection)1