diff --git a/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/dao/SAMLSSOPersistenceManagerFactory.java b/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/dao/SAMLSSOPersistenceManagerFactory.java index 34effcf88fef..98005528149e 100644 --- a/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/dao/SAMLSSOPersistenceManagerFactory.java +++ b/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/dao/SAMLSSOPersistenceManagerFactory.java @@ -10,7 +10,7 @@ public class SAMLSSOPersistenceManagerFactory { private static final Log LOG = LogFactory.getLog(SAMLSSOPersistenceManagerFactory.class); - private static final String SAML_STORAGE_TYPE = IdentityUtil.getProperty(SAML_STORAGE_CONFIG); + private static String SAML_STORAGE_TYPE = IdentityUtil.getProperty(SAML_STORAGE_CONFIG); private static final String HYBRID = "hybrid"; private static final String REGISTRY = "registry"; diff --git a/components/identity-core/org.wso2.carbon.identity.core/src/test/java/org/wso2/carbon/identity/core/dao/SAMLSSOPersistenceManagerFactoryTest.java b/components/identity-core/org.wso2.carbon.identity.core/src/test/java/org/wso2/carbon/identity/core/dao/SAMLSSOPersistenceManagerFactoryTest.java new file mode 100644 index 000000000000..846ebcf47c70 --- /dev/null +++ b/components/identity-core/org.wso2.carbon.identity.core/src/test/java/org/wso2/carbon/identity/core/dao/SAMLSSOPersistenceManagerFactoryTest.java @@ -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); + } +} \ No newline at end of file diff --git a/components/identity-core/org.wso2.carbon.identity.core/src/test/resources/testng.xml b/components/identity-core/org.wso2.carbon.identity.core/src/test/resources/testng.xml index 515455319c13..d00128b48616 100644 --- a/components/identity-core/org.wso2.carbon.identity.core/src/test/resources/testng.xml +++ b/components/identity-core/org.wso2.carbon.identity.core/src/test/resources/testng.xml @@ -31,6 +31,7 @@ +