use of org.wso2.carbon.identity.template.mgt.util.TestUtils.mockDataSource 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);
}
}
use of org.wso2.carbon.identity.template.mgt.util.TestUtils.mockDataSource 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);
}
}
use of org.wso2.carbon.identity.template.mgt.util.TestUtils.mockDataSource 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.
}
}
use of org.wso2.carbon.identity.template.mgt.util.TestUtils.mockDataSource 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));
}
}
use of org.wso2.carbon.identity.template.mgt.util.TestUtils.mockDataSource in project carbon-identity-framework by wso2.
the class UserFunctionalityManagerDAOImplTest method testGetFunctionalityLockStatus.
@Test(dataProvider = "TestFunctionalityData")
public void testGetFunctionalityLockStatus(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(), isFunctionalityLocked);
Assert.assertEquals(userFunctionalityManagerDAO.getFunctionalityLockStatus(userId, tenantId, functionalityIdentifier).getUnlockTime(), functionalityUnlockTime);
Assert.assertEquals(userFunctionalityManagerDAO.getFunctionalityLockStatus(userId, tenantId, functionalityIdentifier).getLockReasonCode(), functionalityLockReasonCode);
Assert.assertEquals(userFunctionalityManagerDAO.getFunctionalityLockStatus(userId, tenantId, functionalityIdentifier).getLockReason(), functionalityLockReason);
} catch (SQLException e) {
// Mock behaviour. Hence ignored.
} catch (UserFunctionalityManagementServerException e) {
assertEquals(e.getMessage(), String.format("Error occurred while retrieving functionality lock status from DB for " + "functionality id: %s, user Id: %s and tenant Id: %d.", functionalityIdentifier, userId, tenantId));
}
}
Aggregations