Skip to content

Commit

Permalink
Add unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisara-Welmilla committed Jan 27, 2025
1 parent 86b4aae commit e4ca996
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.mockito.MockedStatic;
import org.mockito.testng.MockitoTestNGListener;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Listeners;
Expand Down Expand Up @@ -124,18 +125,54 @@ public void testGetAllAuthenticatorsWithAuthActionTypeEnabledAndNotNullUserDefin
}

@Test
public void testGetAllAuthenticatorsWithAuthActionTypeEnabledAndNullUserDefinedAuthenticatorService() {
public void testGetAllAuthenticatorsWithAuthenticationActionTypeDisabled() {

FrameworkServiceDataHolder.getInstance().setUserDefinedAuthenticatorService(null);
setAuthenticatorActionEnableStatus(true);
setAuthenticatorActionEnableStatus(false);
List<ApplicationAuthenticator> result = applicationAuthenticatorService.getAllAuthenticators(TENANT_DOMAIN);
assertEquals(1, result.size());
}

@Test
public void testGetAllAuthenticatorsWithAuthenticationActionTypeDisabled() {
public void testGetAuthenticatorByNameWithAuthActionTypeEnabledAndNotNullUserDefinedAuthenticatorService() {

setAuthenticatorActionEnableStatus(true);
Assert.assertNotNull(applicationAuthenticatorService.getApplicationAuthenticatorByName(
SYSTEM_DEFINED_AUTHENTICATOR_NAME, TENANT_DOMAIN));
Assert.assertNotNull(applicationAuthenticatorService.getApplicationAuthenticatorByName(
USER_DEFINED_FEDERATED_AUTHENTICATOR_NAME, TENANT_DOMAIN));
Assert.assertNotNull(applicationAuthenticatorService.getApplicationAuthenticatorByName(
USER_DEFINED_LOCAL_AUTHENTICATOR_NAME, TENANT_DOMAIN));
}

@Test
public void testGetAuthenticatorByNameWithAuthenticationActionTypeDisabled() {

setAuthenticatorActionEnableStatus(false);
Assert.assertNotNull(applicationAuthenticatorService.getApplicationAuthenticatorByName(
SYSTEM_DEFINED_AUTHENTICATOR_NAME, TENANT_DOMAIN));
Assert.assertNull(applicationAuthenticatorService.getApplicationAuthenticatorByName(
USER_DEFINED_FEDERATED_AUTHENTICATOR_NAME, TENANT_DOMAIN));
Assert.assertNull(applicationAuthenticatorService.getApplicationAuthenticatorByName(
USER_DEFINED_LOCAL_AUTHENTICATOR_NAME, TENANT_DOMAIN));
}

@Test
public void testGetAllAuthenticatorsWithAuthActionTypeEnabledAndNullUserDefinedAuthenticatorService() {

FrameworkServiceDataHolder.getInstance().setUserDefinedAuthenticatorService(null);
Assert.assertNotNull(applicationAuthenticatorService.getApplicationAuthenticatorByName(
SYSTEM_DEFINED_AUTHENTICATOR_NAME, TENANT_DOMAIN));
Assert.assertNull(applicationAuthenticatorService.getApplicationAuthenticatorByName(
USER_DEFINED_FEDERATED_AUTHENTICATOR_NAME, TENANT_DOMAIN));
Assert.assertNull(applicationAuthenticatorService.getApplicationAuthenticatorByName(
USER_DEFINED_LOCAL_AUTHENTICATOR_NAME, TENANT_DOMAIN));
}

@Test
public void testGetAuthenticatorByNameWithAuthActionTypeEnabledAndNullUserDefinedAuthenticatorService() {

FrameworkServiceDataHolder.getInstance().setUserDefinedAuthenticatorService(null);
setAuthenticatorActionEnableStatus(true);
List<ApplicationAuthenticator> result = applicationAuthenticatorService.getAllAuthenticators(TENANT_DOMAIN);
assertEquals(1, result.size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.mockito.Mock;
import org.mockito.MockedStatic;
import org.mockito.testng.MockitoTestNGListener;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Listeners;
Expand Down Expand Up @@ -1138,6 +1139,18 @@ public void testGetEffectiveIdpGroupClaimUriLegacyBehaviourWithNoCustomClaimMapp
assertEquals(result, "rolesClaimInDialect");
}
}

@Test
public void getAppAuthenticatorByNameExistingAuthenticator() {

Assert.assertNotNull(FrameworkUtils.getAppAuthenticatorByName("BasicAuthenticator"));
}

@Test
public void getAppAuthenticatorByNameNonExistingAuthenticator() {

Assert.assertNull(FrameworkUtils.getAppAuthenticatorByName("NonExistAuthenticator"));
}

private void removeAllSystemDefinedAuthenticators() {

Expand Down

0 comments on commit e4ca996

Please sign in to comment.