diff --git a/components/org.wso2.carbon.identity.organization.config.service/pom.xml b/components/org.wso2.carbon.identity.organization.config.service/pom.xml
index 26b533a14..7b377ce8d 100644
--- a/components/org.wso2.carbon.identity.organization.config.service/pom.xml
+++ b/components/org.wso2.carbon.identity.organization.config.service/pom.xml
@@ -45,6 +45,21 @@
org.wso2.carbon.identity.organization.management.core
org.wso2.carbon.identity.organization.management.service
+
+ org.testng
+ testng
+ test
+
+
+ org.mockito
+ mockito-inline
+ test
+
+
+ com.h2database
+ h2
+ test
+
diff --git a/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/OrganizationConfigManager.java b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/OrganizationConfigManager.java
index 1056790dc..88d2f27bb 100644
--- a/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/OrganizationConfigManager.java
+++ b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/OrganizationConfigManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
+ * Copyright (c) 2023-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
@@ -20,6 +20,7 @@
import org.wso2.carbon.identity.organization.config.service.exception.OrganizationConfigException;
import org.wso2.carbon.identity.organization.config.service.model.DiscoveryConfig;
+import org.wso2.carbon.identity.organization.management.service.exception.NotImplementedException;
/**
* Interface for organization configuration management.
@@ -35,6 +36,19 @@ public interface OrganizationConfigManager {
*/
void addDiscoveryConfiguration(DiscoveryConfig discoveryConfig) throws OrganizationConfigException;
+ /**
+ * Update the discovery configuration of the primary organization.
+ *
+ * @param discoveryConfig The discovery configuration.
+ * @throws OrganizationConfigException The exception thrown when an error occurs while updating the discovery
+ * configuration.
+ */
+ default void updateDiscoveryConfiguration(DiscoveryConfig discoveryConfig) throws OrganizationConfigException {
+
+ throw new NotImplementedException("updateDiscoveryConfiguration method is not implemented in " +
+ this.getClass().getName());
+ }
+
/**
* Fetch the discovery configuration of the primary organization.
*
diff --git a/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/OrganizationConfigManagerImpl.java b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/OrganizationConfigManagerImpl.java
index 6ddd75597..e1ced4f66 100644
--- a/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/OrganizationConfigManagerImpl.java
+++ b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/OrganizationConfigManagerImpl.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
+ * Copyright (c) 2023-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
@@ -38,6 +38,8 @@
import java.util.stream.Collectors;
import static org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_RESOURCE_DOES_NOT_EXISTS;
+import static org.wso2.carbon.identity.organization.config.service.constant.OrganizationConfigConstants.EMAIL_DOMAIN_BASED_SELF_SIGNUP_ENABLE;
+import static org.wso2.carbon.identity.organization.config.service.constant.OrganizationConfigConstants.EMAIL_DOMAIN_ENABLE;
import static org.wso2.carbon.identity.organization.config.service.constant.OrganizationConfigConstants.ErrorMessages.ERROR_CODE_DISCOVERY_CONFIG_CONFLICT;
import static org.wso2.carbon.identity.organization.config.service.constant.OrganizationConfigConstants.ErrorMessages.ERROR_CODE_DISCOVERY_CONFIG_NOT_EXIST;
import static org.wso2.carbon.identity.organization.config.service.constant.OrganizationConfigConstants.ErrorMessages.ERROR_CODE_DISCOVERY_CONFIG_UPDATE_NOT_ALLOWED;
@@ -45,6 +47,7 @@
import static org.wso2.carbon.identity.organization.config.service.constant.OrganizationConfigConstants.ErrorMessages.ERROR_CODE_ERROR_DELETING_DISCOVERY_CONFIG;
import static org.wso2.carbon.identity.organization.config.service.constant.OrganizationConfigConstants.ErrorMessages.ERROR_CODE_ERROR_RETRIEVING_DISCOVERY_CONFIG;
import static org.wso2.carbon.identity.organization.config.service.constant.OrganizationConfigConstants.ErrorMessages.ERROR_CODE_INVALID_DISCOVERY_ATTRIBUTE;
+import static org.wso2.carbon.identity.organization.config.service.constant.OrganizationConfigConstants.ErrorMessages.ERROR_CODE_INVALID_DISCOVERY_ATTRIBUTE_VALUES;
import static org.wso2.carbon.identity.organization.config.service.constant.OrganizationConfigConstants.RESOURCE_NAME;
import static org.wso2.carbon.identity.organization.config.service.constant.OrganizationConfigConstants.RESOURCE_TYPE_NAME;
import static org.wso2.carbon.identity.organization.config.service.constant.OrganizationConfigConstants.SUPPORTED_DISCOVERY_ATTRIBUTE_KEYS;
@@ -75,6 +78,25 @@ public void addDiscoveryConfiguration(DiscoveryConfig discoveryConfig) throws Or
}
}
+ @Override
+ public void updateDiscoveryConfiguration(DiscoveryConfig discoveryConfig) throws OrganizationConfigException {
+
+ try {
+ if (!isDiscoveryConfigChangeAllowed()) {
+ throw handleClientException(ERROR_CODE_DISCOVERY_CONFIG_UPDATE_NOT_ALLOWED);
+ }
+ Optional resourceOptional = getDiscoveryResource();
+ Resource resource = buildResourceFromValidationConfig(discoveryConfig);
+ if (!resourceOptional.isPresent()) {
+ getConfigurationManager().addResource(RESOURCE_TYPE_NAME, resource);
+ } else {
+ getConfigurationManager().replaceResource(RESOURCE_TYPE_NAME, resource);
+ }
+ } catch (ConfigurationManagementException | OrganizationManagementServerException e) {
+ throw handleServerException(ERROR_CODE_ERROR_ADDING_DISCOVERY_CONFIG, e, getOrganizationId());
+ }
+ }
+
@Override
public DiscoveryConfig getDiscoveryConfiguration() throws OrganizationConfigException {
@@ -158,6 +180,12 @@ private Resource buildResourceFromValidationConfig(DiscoveryConfig discoveryConf
}
configAttributes.put(key, property.getValue());
}
+
+ if (Boolean.parseBoolean(configAttributes.get(EMAIL_DOMAIN_BASED_SELF_SIGNUP_ENABLE)) &&
+ !Boolean.parseBoolean(configAttributes.get(EMAIL_DOMAIN_ENABLE))) {
+ throw handleClientException(ERROR_CODE_INVALID_DISCOVERY_ATTRIBUTE_VALUES);
+ }
+
List resourceAttributes = configAttributes.entrySet().stream()
.filter(attribute -> attribute.getValue() != null && !"null".equals(attribute.getValue()))
.map(attribute -> new Attribute(attribute.getKey(), attribute.getValue()))
diff --git a/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/constant/OrganizationConfigConstants.java b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/constant/OrganizationConfigConstants.java
index bbf64eff2..550f082d2 100644
--- a/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/constant/OrganizationConfigConstants.java
+++ b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/constant/OrganizationConfigConstants.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
+ * Copyright (c) 2023-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
@@ -18,7 +18,6 @@
package org.wso2.carbon.identity.organization.config.service.constant;
-import java.util.Collections;
import java.util.List;
/**
@@ -28,8 +27,10 @@ public class OrganizationConfigConstants {
public static final String RESOURCE_TYPE_NAME = "ORGANIZATION_CONFIGURATION";
public static final String RESOURCE_NAME = "OrganizationDiscovery";
+ public static final String EMAIL_DOMAIN_ENABLE = "emailDomain.enable";
+ public static final String EMAIL_DOMAIN_BASED_SELF_SIGNUP_ENABLE = "emailDomainBasedSelfSignup.enable";
public static final List SUPPORTED_DISCOVERY_ATTRIBUTE_KEYS =
- Collections.singletonList("emailDomain.enable");
+ List.of(EMAIL_DOMAIN_ENABLE, EMAIL_DOMAIN_BASED_SELF_SIGNUP_ENABLE);
private static final String ORGANIZATION_CONFIGURATION_ERROR_CODE_PREFIX = "OCM-";
/**
@@ -47,6 +48,8 @@ public enum ErrorMessages {
"The organization discovery configuration is already for available for the organization with id: %s."),
ERROR_CODE_INVALID_DISCOVERY_ATTRIBUTE("60004", "Invalid organization discovery attribute.",
"The organization discovery attribute with key: %s is not supported."),
+ ERROR_CODE_INVALID_DISCOVERY_ATTRIBUTE_VALUES("60005", "Invalid organization discovery attribute " +
+ "values.", "Provided organization discovery attribute value combination is not supported."),
// Server errors.
ERROR_CODE_ERROR_ADDING_DISCOVERY_CONFIG("65001", "Unable to add the organization discovery " +
diff --git a/components/org.wso2.carbon.identity.organization.config.service/src/test/java/org/wso2/carbon/identity/organization/config/service/OrganizationConfigManagerImplTest.java b/components/org.wso2.carbon.identity.organization.config.service/src/test/java/org/wso2/carbon/identity/organization/config/service/OrganizationConfigManagerImplTest.java
new file mode 100644
index 000000000..0b0fecc60
--- /dev/null
+++ b/components/org.wso2.carbon.identity.organization.config.service/src/test/java/org/wso2/carbon/identity/organization/config/service/OrganizationConfigManagerImplTest.java
@@ -0,0 +1,207 @@
+/*
+ * 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.organization.config.service;
+
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.MockitoAnnotations;
+import org.testng.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import org.wso2.carbon.base.CarbonBaseConstants;
+import org.wso2.carbon.context.PrivilegedCarbonContext;
+import org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager;
+import org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManagerImpl;
+import org.wso2.carbon.identity.configuration.mgt.core.dao.ConfigurationDAO;
+import org.wso2.carbon.identity.configuration.mgt.core.dao.impl.ConfigurationDAOImpl;
+import org.wso2.carbon.identity.configuration.mgt.core.internal.ConfigurationManagerComponentDataHolder;
+import org.wso2.carbon.identity.configuration.mgt.core.model.ConfigurationManagerConfigurationHolder;
+import org.wso2.carbon.identity.core.util.IdentityDatabaseUtil;
+import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
+import org.wso2.carbon.identity.organization.config.service.exception.OrganizationConfigClientException;
+import org.wso2.carbon.identity.organization.config.service.internal.OrganizationConfigServiceHolder;
+import org.wso2.carbon.identity.organization.config.service.model.ConfigProperty;
+import org.wso2.carbon.identity.organization.config.service.model.DiscoveryConfig;
+import org.wso2.carbon.identity.organization.config.service.util.TestUtils;
+import org.wso2.carbon.identity.organization.management.service.OrganizationManager;
+
+import java.nio.file.Paths;
+import java.sql.Connection;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.sql.DataSource;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+/**
+ * Unit tests for OrganizationConfigManagerImpl class.
+ */
+public class OrganizationConfigManagerImplTest {
+
+ @Mock
+ private OrganizationManager organizationManager;
+ private final OrganizationConfigManagerImpl organizationConfigManagerImpl = new OrganizationConfigManagerImpl();
+ private AutoCloseable mocks;
+ MockedStatic identityTenantUtil;
+ MockedStatic identityDatabaseUtil;
+ MockedStatic privilegedCarbonContext;
+ private static final int SUPER_TENANT_ID = -1234;
+ private static final String SUPER_TENANT_DOMAIN_NAME = "carbon.super";
+ private static final String EMAIL_DOMAIN_ENABLE = "emailDomain.enable";
+ private static final String EMAIL_DOMAIN_BASED_SELF_SIGNUP_ENABLE = "emailDomainBasedSelfSignup.enable";
+ private static final String TRUE = "true";
+ private static final String FALSE = "false";
+
+ @BeforeClass
+ public void setUp() throws Exception {
+
+ mocks = MockitoAnnotations.openMocks(this);
+
+ TestUtils.initiateH2Base();
+ setUpCarbonHome();
+ mockCarbonContextForSuperTenant();
+
+ DataSource dataSource = mock(DataSource.class);
+ identityTenantUtil = mockStatic(IdentityTenantUtil.class);
+ identityDatabaseUtil = mockStatic(IdentityDatabaseUtil.class);
+ identityDatabaseUtil.when(IdentityDatabaseUtil::getDataSource).thenReturn(dataSource);
+
+ // Mocking the connection close method to avoid closing the connection before needed.
+ Connection connection = spy(TestUtils.getConnection());
+ doNothing().when(connection).close();
+ when(dataSource.getConnection()).thenReturn(connection);
+
+ ConfigurationManager configurationManager = setUpConfigurationManager(identityTenantUtil);
+ OrganizationConfigServiceHolder.getInstance().setOrganizationManager(organizationManager);
+ when(organizationManager.isPrimaryOrganization(anyString())).thenReturn(true);
+ OrganizationConfigServiceHolder.getInstance().setConfigurationManager(configurationManager);
+ }
+
+ @Test(priority = 1)
+ public void testAddDiscoveryConfiguration() throws Exception {
+
+ List configProperties = new ArrayList<>();
+ configProperties.add(new ConfigProperty(EMAIL_DOMAIN_ENABLE, TRUE));
+ DiscoveryConfig discoveryConfig = new DiscoveryConfig(configProperties);
+
+ organizationConfigManagerImpl.addDiscoveryConfiguration(discoveryConfig);
+ List returnedConfigProperties =
+ organizationConfigManagerImpl.getDiscoveryConfiguration().getConfigProperties();
+
+ Assert.assertEquals(returnedConfigProperties.size(), 1);
+ Assert.assertEquals(returnedConfigProperties.get(0).getKey(), EMAIL_DOMAIN_ENABLE);
+ Assert.assertEquals(returnedConfigProperties.get(0).getValue(), TRUE);
+ }
+
+ @Test(priority = 2)
+ public void testUpdateDiscoveryConfiguration() throws Exception {
+
+ List configProperties = new ArrayList<>();
+ configProperties.add(new ConfigProperty(EMAIL_DOMAIN_ENABLE, TRUE));
+ configProperties.add(new ConfigProperty(EMAIL_DOMAIN_BASED_SELF_SIGNUP_ENABLE, TRUE));
+ DiscoveryConfig discoveryConfig = new DiscoveryConfig(configProperties);
+
+ organizationConfigManagerImpl.updateDiscoveryConfiguration(discoveryConfig);
+ List returnedConfigProperties =
+ organizationConfigManagerImpl.getDiscoveryConfiguration().getConfigProperties();
+
+ Assert.assertEquals(returnedConfigProperties.size(), 2);
+ Assert.assertEquals(returnedConfigProperties.get(0).getKey(), EMAIL_DOMAIN_ENABLE);
+ Assert.assertEquals(returnedConfigProperties.get(0).getValue(), TRUE);
+ Assert.assertEquals(returnedConfigProperties.get(1).getKey(), EMAIL_DOMAIN_BASED_SELF_SIGNUP_ENABLE);
+ Assert.assertEquals(returnedConfigProperties.get(1).getValue(), TRUE);
+ }
+
+ @Test(priority = 3)
+ public void testUpdateDiscoveryConfigurationInvalidConfig() throws Exception {
+
+ try {
+ List configProperties = new ArrayList<>();
+ configProperties.add(new ConfigProperty(EMAIL_DOMAIN_ENABLE, FALSE));
+ configProperties.add(new ConfigProperty(EMAIL_DOMAIN_BASED_SELF_SIGNUP_ENABLE, TRUE));
+ DiscoveryConfig discoveryConfig = new DiscoveryConfig(configProperties);
+
+ organizationConfigManagerImpl.updateDiscoveryConfiguration(discoveryConfig);
+ Assert.fail("Expected OrganizationConfigClientException was not thrown.");
+ } catch (OrganizationConfigClientException e) {
+ Assert.assertEquals(e.getMessage(), "Invalid organization discovery attribute values.");
+ }
+ }
+
+ @Test(priority = 4)
+ public void testDeleteDiscoveryConfiguration() throws Exception {
+
+ try {
+ organizationConfigManagerImpl.deleteDiscoveryConfiguration();
+ organizationConfigManagerImpl.getDiscoveryConfiguration();
+ Assert.fail("Expected OrganizationConfigClientException was not thrown.");
+ } catch (OrganizationConfigClientException e) {
+ Assert.assertEquals(e.getMessage(), "No organization discovery configuration found.");
+ }
+ }
+
+ @AfterClass
+ public void tearDown() throws Exception {
+
+ TestUtils.closeH2Base();
+ mocks.close();
+ identityDatabaseUtil.close();
+ identityTenantUtil.close();
+ privilegedCarbonContext.close();
+ }
+
+ private static ConfigurationManager setUpConfigurationManager(MockedStatic identityTenantUtil) {
+
+ ConfigurationManagerComponentDataHolder.setUseCreatedTime(true);
+ ConfigurationManagerConfigurationHolder configurationHolder = new ConfigurationManagerConfigurationHolder();
+ ConfigurationDAO configurationDAO = new ConfigurationDAOImpl();
+ configurationHolder.setConfigurationDAOS(Collections.singletonList(configurationDAO));
+ identityTenantUtil.when(() -> IdentityTenantUtil.getTenantDomain(any(Integer.class)))
+ .thenReturn(SUPER_TENANT_DOMAIN_NAME);
+ return new ConfigurationManagerImpl(configurationHolder);
+ }
+
+ private void mockCarbonContextForSuperTenant() {
+
+ privilegedCarbonContext = mockStatic(PrivilegedCarbonContext.class);
+ PrivilegedCarbonContext mockPrivilegedCarbonContext = mock(PrivilegedCarbonContext.class);
+
+ privilegedCarbonContext.when(
+ PrivilegedCarbonContext::getThreadLocalCarbonContext).thenReturn(mockPrivilegedCarbonContext);
+ when(mockPrivilegedCarbonContext.getTenantDomain()).thenReturn(SUPER_TENANT_DOMAIN_NAME);
+ when(mockPrivilegedCarbonContext.getTenantId()).thenReturn(SUPER_TENANT_ID);
+ when(mockPrivilegedCarbonContext.getUsername()).thenReturn("admin");
+ }
+
+ private static void setUpCarbonHome() {
+
+ String carbonHome = Paths.get(System.getProperty("user.dir"), "target", "test-classes").toString();
+ System.setProperty(CarbonBaseConstants.CARBON_HOME, carbonHome);
+ }
+
+}
diff --git a/components/org.wso2.carbon.identity.organization.config.service/src/test/java/org/wso2/carbon/identity/organization/config/service/util/TestUtils.java b/components/org.wso2.carbon.identity.organization.config.service/src/test/java/org/wso2/carbon/identity/organization/config/service/util/TestUtils.java
new file mode 100644
index 000000000..d4e86d6e0
--- /dev/null
+++ b/components/org.wso2.carbon.identity.organization.config.service/src/test/java/org/wso2/carbon/identity/organization/config/service/util/TestUtils.java
@@ -0,0 +1,78 @@
+/*
+ * 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.organization.config.service.util;
+
+import org.apache.commons.dbcp.BasicDataSource;
+import org.apache.commons.lang.StringUtils;
+
+import java.nio.file.Paths;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Test utils class for OrganizationConfigManagerImpl tests.
+ */
+public class TestUtils {
+
+ public static final String DB_NAME = "testOrgDiscoveryConfig_db";
+ public static final String H2_SCRIPT_NAME = "h2.sql";
+ public static Map dataSourceMap = new HashMap<>();
+
+ public static String getFilePath(String fileName) {
+
+ if (StringUtils.isNotBlank(fileName)) {
+ return Paths.get(System.getProperty("user.dir"), "src", "test", "resources", "dbscripts",
+ fileName).toString();
+ }
+ throw new IllegalArgumentException("DB Script file name cannot be empty.");
+ }
+
+ public static Connection getConnection() throws SQLException {
+
+ if (dataSourceMap.get(DB_NAME) != null) {
+ return dataSourceMap.get(DB_NAME).getConnection();
+ }
+ throw new RuntimeException("No data source initiated for database: " + DB_NAME);
+ }
+
+ public static void initiateH2Base() throws Exception {
+
+ BasicDataSource dataSource = new BasicDataSource();
+ dataSource.setDriverClassName("org.h2.Driver");
+ dataSource.setUsername("username");
+ dataSource.setPassword("password");
+ dataSource.setUrl("jdbc:h2:mem:test" + DB_NAME);
+ dataSource.setTestOnBorrow(true);
+ dataSource.setValidationQuery("select 1");
+ try (Connection connection = dataSource.getConnection()) {
+ connection.createStatement().executeUpdate("RUNSCRIPT FROM '" + getFilePath(H2_SCRIPT_NAME) + "'");
+ }
+ dataSourceMap.put(DB_NAME, dataSource);
+ }
+
+ public static void closeH2Base() throws Exception {
+
+ BasicDataSource dataSource = dataSourceMap.remove(DB_NAME);
+ if (dataSource != null) {
+ dataSource.close();
+ }
+ }
+}
diff --git a/components/org.wso2.carbon.identity.organization.config.service/src/test/resources/dbscripts/h2.sql b/components/org.wso2.carbon.identity.organization.config.service/src/test/resources/dbscripts/h2.sql
new file mode 100644
index 000000000..4b5ba16c9
--- /dev/null
+++ b/components/org.wso2.carbon.identity.organization.config.service/src/test/resources/dbscripts/h2.sql
@@ -0,0 +1,47 @@
+CREATE TABLE IF NOT EXISTS IDN_CONFIG_TYPE (
+ ID VARCHAR(255) NOT NULL,
+ NAME VARCHAR(255) NOT NULL,
+ DESCRIPTION VARCHAR(1023) NULL,
+ PRIMARY KEY (ID),
+ CONSTRAINT TYPE_NAME_CONSTRAINT UNIQUE (NAME)
+);
+
+CREATE TABLE IF NOT EXISTS IDN_CONFIG_RESOURCE (
+ ID VARCHAR(255) NOT NULL,
+ TENANT_ID INT NOT NULL,
+ NAME VARCHAR(255) NOT NULL,
+ CREATED_TIME TIMESTAMP NOT NULL,
+ LAST_MODIFIED TIMESTAMP NOT NULL,
+ HAS_FILE BOOLEAN NOT NULL,
+ HAS_ATTRIBUTE BOOLEAN NOT NULL,
+ TYPE_ID VARCHAR(255) NOT NULL,
+ UNIQUE (NAME, TENANT_ID, TYPE_ID),
+ PRIMARY KEY (ID)
+);
+
+ALTER TABLE IDN_CONFIG_RESOURCE
+ ADD CONSTRAINT TYPE_ID_FOREIGN_CONSTRAINT FOREIGN KEY (TYPE_ID) REFERENCES IDN_CONFIG_TYPE (ID) ON DELETE CASCADE ON UPDATE CASCADE;
+
+CREATE TABLE IF NOT EXISTS IDN_CONFIG_ATTRIBUTE (
+ ID VARCHAR(255) NOT NULL,
+ RESOURCE_ID VARCHAR(255) NOT NULL,
+ ATTR_KEY VARCHAR(1023) NOT NULL,
+ ATTR_VALUE VARCHAR(1023) NULL,
+ PRIMARY KEY (ID),
+ UNIQUE (RESOURCE_ID, ATTR_KEY, ATTR_VALUE)
+);
+ALTER TABLE IDN_CONFIG_ATTRIBUTE
+ ADD CONSTRAINT RESOURCE_ID_ATTRIBUTE_FOREIGN_CONSTRAINT FOREIGN KEY (RESOURCE_ID) REFERENCES IDN_CONFIG_RESOURCE (ID) ON DELETE CASCADE ON UPDATE CASCADE;
+
+CREATE TABLE IF NOT EXISTS IDN_CONFIG_FILE (
+ ID VARCHAR(255) NOT NULL,
+ `VALUE` BLOB NULL,
+ NAME VARCHAR (255) NULL,
+ RESOURCE_ID VARCHAR(255) NOT NULL,
+ PRIMARY KEY (ID)
+);
+ALTER TABLE IDN_CONFIG_FILE
+ ADD CONSTRAINT RESOURCE_ID_FILE_FOREIGN_CONSTRAINT FOREIGN KEY (RESOURCE_ID) REFERENCES IDN_CONFIG_RESOURCE (ID) ON DELETE CASCADE ON UPDATE CASCADE;
+
+INSERT INTO IDN_CONFIG_TYPE (ID, NAME, DESCRIPTION) VALUES
+('132b0ee6-43e0-462d-8b4b-15b68109d71d', 'ORGANIZATION_CONFIGURATION', 'A resource type to keep the organization configurations.');
diff --git a/components/org.wso2.carbon.identity.organization.config.service/src/test/resources/testng.xml b/components/org.wso2.carbon.identity.organization.config.service/src/test/resources/testng.xml
new file mode 100644
index 000000000..0fffae7fc
--- /dev/null
+++ b/components/org.wso2.carbon.identity.organization.config.service/src/test/resources/testng.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+