forked from wso2/carbon-identity-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1191c5b
commit ea2b2b1
Showing
5 changed files
with
314 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 165 additions & 0 deletions
165
...carbon/identity/application/common/model/test/dao/AuthenticatorManagementDAOImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.wso2.carbon.identity.application.common.model.test.dao; | ||
|
||
import org.testng.Assert; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
import org.wso2.carbon.identity.application.common.dao.impl.AuthenticatorManagementDAOImpl; | ||
import org.wso2.carbon.identity.application.common.exception.AuthenticatorMgtException; | ||
import org.wso2.carbon.identity.application.common.model.Property; | ||
import org.wso2.carbon.identity.application.common.model.UserDefinedLocalAuthenticatorConfig; | ||
import org.wso2.carbon.identity.base.AuthenticatorPropertyConstants; | ||
import org.wso2.carbon.identity.common.testng.WithCarbonHome; | ||
import org.wso2.carbon.identity.common.testng.WithH2Database; | ||
import org.wso2.carbon.identity.common.testng.WithRealmService; | ||
import org.wso2.carbon.identity.core.internal.IdentityCoreServiceDataHolder; | ||
|
||
import static org.junit.Assert.assertThrows; | ||
import static org.wso2.carbon.identity.application.common.model.test.util.UserDefinedLocalAuthenticatorDataUtil.createUserDefinedAuthenticatorConfig; | ||
import static org.wso2.carbon.identity.application.common.model.test.util.UserDefinedLocalAuthenticatorDataUtil.createUserDefinedAuthenticatorConfigForSQLException; | ||
import static org.wso2.carbon.identity.application.common.util.AuthenticatorMgtExceptionBuilder.AuthenticatorMgtError.ERROR_WHILE_ADDING_AUTHENTICATOR; | ||
|
||
@WithH2Database(files = {"dbscripts/h2.sql"}) | ||
@WithCarbonHome | ||
@WithRealmService(injectToSingletons = {IdentityCoreServiceDataHolder.class}) | ||
public class AuthenticatorManagementDAOImplTest { | ||
|
||
private final int tenantId = -1234; | ||
|
||
private UserDefinedLocalAuthenticatorConfig authenticatorConfig1; | ||
private UserDefinedLocalAuthenticatorConfig authenticatorConfig2; | ||
private UserDefinedLocalAuthenticatorConfig authenticatorConfigForException; | ||
private UserDefinedLocalAuthenticatorConfig nonExistAuthenticatorConfig; | ||
|
||
private static final String AUTHENTICATOR1_NAME = "auth1"; | ||
private static final String AUTHENTICATOR2_NAME = "auth2"; | ||
private static final String AUTHENTICATOR_CONFIG_FOR_EXCEPTION_NAME = "exception_auth"; | ||
private static final String NON_EXIST_AUTHENTICATOR_NAME = "non_exist_auth"; | ||
|
||
private final AuthenticatorManagementDAOImpl authenticatorManagementDAO = new AuthenticatorManagementDAOImpl(); | ||
|
||
@BeforeClass | ||
public void setUpClass() { | ||
|
||
authenticatorConfig1 = createUserDefinedAuthenticatorConfig(AUTHENTICATOR1_NAME, | ||
AuthenticatorPropertyConstants.AuthenticationType.IDENTIFICATION); | ||
authenticatorConfig2 = createUserDefinedAuthenticatorConfig(AUTHENTICATOR2_NAME, | ||
AuthenticatorPropertyConstants.AuthenticationType.VERIFICATION); | ||
nonExistAuthenticatorConfig = createUserDefinedAuthenticatorConfig(NON_EXIST_AUTHENTICATOR_NAME, | ||
AuthenticatorPropertyConstants.AuthenticationType.IDENTIFICATION); | ||
authenticatorConfigForException = createUserDefinedAuthenticatorConfigForSQLException( | ||
AUTHENTICATOR_CONFIG_FOR_EXCEPTION_NAME, | ||
AuthenticatorPropertyConstants.AuthenticationType.IDENTIFICATION); | ||
|
||
} | ||
|
||
@DataProvider(name = "authenticatorConfig") | ||
public Object[][] authenticatorConfig() { | ||
|
||
return new Object[][]{ | ||
{authenticatorConfig1}, | ||
{authenticatorConfig2} | ||
}; | ||
} | ||
|
||
@Test(dataProvider = "authenticatorConfig") | ||
public void testAddUserDefinedLocalAuthenticator(UserDefinedLocalAuthenticatorConfig config) | ||
throws AuthenticatorMgtException { | ||
|
||
UserDefinedLocalAuthenticatorConfig createdAuthenticator = authenticatorManagementDAO | ||
.addUserDefinedLocalAuthenticator(config, tenantId); | ||
Assert.assertNotNull(createdAuthenticator); | ||
} | ||
|
||
@Test | ||
public void testAddUserDefinedLocalAuthenticatorWithSQLException() { | ||
|
||
AuthenticatorMgtException exception = assertThrows(AuthenticatorMgtException.class, () -> | ||
authenticatorManagementDAO.addUserDefinedLocalAuthenticator(authenticatorConfigForException, tenantId)); | ||
Assert.assertEquals(exception.getErrorCode(), ERROR_WHILE_ADDING_AUTHENTICATOR.getCode()); | ||
} | ||
|
||
@Test | ||
public void testAddUserDefinedLocalAuthenticatorWithOutActionProperty() { | ||
|
||
authenticatorConfigForException.setProperties(new Property[0]); | ||
AuthenticatorMgtException exception = assertThrows(AuthenticatorMgtException.class, () -> | ||
authenticatorManagementDAO.addUserDefinedLocalAuthenticator(authenticatorConfigForException, tenantId)); | ||
Assert.assertEquals(exception.getErrorCode(), ERROR_WHILE_ADDING_AUTHENTICATOR.getCode()); | ||
} | ||
|
||
/* | ||
@Test | ||
public void testUpdateUserDefinedLocalAuthenticator() throws AuthenticatorMgtException { | ||
authenticatorManagementDAO.updateUserDefinedLocalAuthenticator(authenticatorConfig1, tenantId); | ||
} | ||
@Test | ||
public void testUpdateUserDefinedLocalAuthenticatorForException() throws AuthenticatorMgtException { | ||
authenticatorManagementDAO.updateUserDefinedLocalAuthenticator(authenticatorConfigForException, tenantId); | ||
} | ||
@Test | ||
public void testDeleteUserDefinedLocalAuthenticator() throws AuthenticatorMgtException { | ||
authenticatorManagementDAO.deleteUserDefinedLocalAuthenticator(AUTHENTICATOR1_NAME, tenantId); | ||
} | ||
@Test | ||
public void testDeleteUserDefinedLocalAuthenticatorForException() throws AuthenticatorMgtException { | ||
authenticatorManagementDAO.deleteUserDefinedLocalAuthenticator(AUTHENTICATOR_CONFIG_FOR_EXCEPTION_NAME, | ||
tenantId); | ||
} | ||
@Test(dataProvider = "authenticatorConfig") | ||
public void testDeleteUserDefinedLocalAuthenticatorForException(UserDefinedLocalAuthenticatorConfig config) | ||
throws AuthenticatorMgtException { | ||
authenticatorManagementDAO.deleteUserDefinedLocalAuthenticator(config.getName(), config, tenantId); | ||
} | ||
*/ | ||
|
||
@Test(dataProvider = "authenticatorConfig") | ||
public void testGetUserDefinedLocalAuthenticator(UserDefinedLocalAuthenticatorConfig config) | ||
throws AuthenticatorMgtException { | ||
|
||
UserDefinedLocalAuthenticatorConfig retrievedConfig = authenticatorManagementDAO | ||
.getUserDefinedLocalAuthenticator(config.getName(), tenantId); | ||
Assert.assertNotNull(retrievedConfig); | ||
Assert.assertEquals(retrievedConfig.getName(), config.getName()); | ||
} | ||
|
||
@Test | ||
public void testGetUserDefinedLocalAuthenticatorForException() throws AuthenticatorMgtException { | ||
|
||
authenticatorManagementDAO.getUserDefinedLocalAuthenticator(AUTHENTICATOR_CONFIG_FOR_EXCEPTION_NAME, tenantId); | ||
} | ||
|
||
@Test | ||
public void testGetUserDefinedLocalAuthenticatorForNonExist() throws AuthenticatorMgtException { | ||
|
||
Assert.assertNull(authenticatorManagementDAO.getUserDefinedLocalAuthenticator( | ||
NON_EXIST_AUTHENTICATOR_NAME, tenantId)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.