-
Notifications
You must be signed in to change notification settings - Fork 544
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for SAMLSSOPersistenceManagerFactory
- Loading branch information
Showing
3 changed files
with
62 additions
and
1 deletion.
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
60 changes: 60 additions & 0 deletions
60
...src/test/java/org/wso2/carbon/identity/core/dao/SAMLSSOPersistenceManagerFactoryTest.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,60 @@ | ||
package org.wso2.carbon.identity.core.dao; | ||
|
||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
import static org.testng.Assert.assertTrue; | ||
|
||
public class SAMLSSOPersistenceManagerFactoryTest { | ||
|
||
private SAMLSSOPersistenceManagerFactory factory; | ||
|
||
@BeforeMethod | ||
public void setUp() { | ||
|
||
factory = new SAMLSSOPersistenceManagerFactory(); | ||
|
||
} | ||
|
||
@AfterMethod | ||
public void tearDown() throws Exception { | ||
|
||
setPrivateStaticField(SAMLSSOPersistenceManagerFactory.class, "SAML_STORAGE_TYPE", ""); | ||
factory = null; | ||
} | ||
|
||
@Test | ||
public void testBuildSSOServiceProviderManagerWithDefaultStorage() throws Exception { | ||
|
||
setPrivateStaticField(SAMLSSOPersistenceManagerFactory.class, "SAML_STORAGE_TYPE", "database"); | ||
SAMLSSOServiceProviderDAO samlSSOServiceProviderDAO = factory.buildSSOServiceProviderManager(); | ||
assertTrue(samlSSOServiceProviderDAO instanceof JDBCSAMLSSOServiceProviderDAOImpl); | ||
} | ||
|
||
@Test | ||
public void testBuildSSOServiceProviderManagerWithRegistryStorage() throws Exception { | ||
|
||
setPrivateStaticField(SAMLSSOPersistenceManagerFactory.class, "SAML_STORAGE_TYPE", "registry"); | ||
SAMLSSOServiceProviderDAO samlSSOServiceProviderDAO = factory.buildSSOServiceProviderManager(); | ||
assertTrue(samlSSOServiceProviderDAO instanceof RegistrySAMLSSOServiceProviderDAOImpl); | ||
} | ||
|
||
@Test | ||
public void testBuildSSOServiceProviderManagerWithHybridStorage() throws Exception { | ||
|
||
setPrivateStaticField(SAMLSSOPersistenceManagerFactory.class, "SAML_STORAGE_TYPE", "hybrid"); | ||
SAMLSSOServiceProviderDAO samlSSOServiceProviderDAO = factory.buildSSOServiceProviderManager(); | ||
assertTrue(samlSSOServiceProviderDAO instanceof JDBCSAMLSSOServiceProviderDAOImpl); | ||
} | ||
|
||
private void setPrivateStaticField(Class<?> clazz, String fieldName, Object newValue) | ||
throws NoSuchFieldException, IllegalAccessException { | ||
|
||
Field field = clazz.getDeclaredField(fieldName); | ||
field.setAccessible(true); | ||
field.set(null, newValue); | ||
} | ||
} |
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