/*
 * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * WSO2 Inc. 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.common.testng.realm;

import org.osgi.framework.BundleContext;
import org.wso2.carbon.user.api.Tenant;
import org.wso2.carbon.user.core.UserStoreException;
import org.wso2.carbon.user.core.tenant.TenantManager;

/**
 * Simple In memory tenant manager for mocking.
 */
public class InMemoryTenantManager implements TenantManager {

    private static final String UNIVERSAL_TENANT = "Universe";
    private static final int UNIVERSAL_TENANT_ID = Short.MAX_VALUE;
    private Tenant universalTenant;

    public InMemoryTenantManager() {
        universalTenant = new Tenant();
        universalTenant.setId(UNIVERSAL_TENANT_ID);
        universalTenant.setDomain(UNIVERSAL_TENANT);
    }

    @Override
    public int addTenant(Tenant tenant) throws org.wso2.carbon.user.api.UserStoreException {
        return 0;
    }

    @Override
    public void updateTenant(Tenant tenant) throws org.wso2.carbon.user.api.UserStoreException {

    }

    @Override
    public Tenant getTenant(int i) throws org.wso2.carbon.user.api.UserStoreException {
        return new Tenant();
    }

    @Override
    public Tenant[] getAllTenants() throws org.wso2.carbon.user.api.UserStoreException {
        return new Tenant[] { universalTenant };
    }

    @Override
    public Tenant[] getAllTenantsForTenantDomainStr(String s) throws org.wso2.carbon.user.api.UserStoreException {
        return new Tenant[] { universalTenant };
    }

    @Override
    public String getDomain(int i) throws org.wso2.carbon.user.api.UserStoreException {
        return UNIVERSAL_TENANT;
    }

    @Override
    public int getTenantId(String s) throws org.wso2.carbon.user.api.UserStoreException {
        return UNIVERSAL_TENANT_ID;
    }

    @Override
    public void activateTenant(int i) throws org.wso2.carbon.user.api.UserStoreException {

    }

    @Override
    public void deactivateTenant(int i) throws org.wso2.carbon.user.api.UserStoreException {

    }

    @Override
    public boolean isTenantActive(int i) throws org.wso2.carbon.user.api.UserStoreException {
        return false;
    }

    @Override
    public void deleteTenant(int i) throws org.wso2.carbon.user.api.UserStoreException {

    }

    @Override
    public void deleteTenant(int i, boolean b) throws org.wso2.carbon.user.api.UserStoreException {

    }

    @Override
    public String getSuperTenantDomain() throws UserStoreException {
        return null;
    }

    @Override
    public void setBundleContext(BundleContext bundleContext) {

    }

    @Override
    public void initializeExistingPartitions() {

    }
}

@@ -761,16 +761,66 @@
 ontext;%0A
+import org.wso2.carbon.base.MultitenantConstants;%0A
 import o
@@ -1095,156 +1095,16 @@
 ate 
-static final String UNIVERSAL_TENANT = %22Universe%22;%0A    private static final int UNIVERSAL_TENANT_ID = Short.MAX_VALUE;%0A    private Tenant universalT
+Tenant t
 enan
@@ -1148,34 +1148,25 @@
 ) %7B%0A        
-universalT
+t
 enant = new 
@@ -1179,34 +1179,25 @@
 ();%0A        
-universalT
+t
 enant.setId(
@@ -1196,25 +1196,42 @@
 t.setId(
-UNIVERSAL
+MultitenantConstants.SUPER
 _TENANT_
@@ -1243,26 +1243,17 @@
         
-universalT
+t
 enant.se
@@ -1260,32 +1260,61 @@
 tDomain(
-UNIVERSAL_TENANT
+MultitenantConstants.SUPER_TENANT_DOMAIN_NAME
 );%0A    %7D
@@ -1834,35 +1834,23 @@
 Tenant%5B%5D
- %7B universalT
+%7Bt
 enant
- 
 %7D;%0A    %7D
@@ -2011,27 +2011,15 @@
 nt%5B%5D
- %7B universalT
+%7Bt
 enant
- 
 %7D;%0A 
@@ -2141,32 +2141,61 @@
  return 
-UNIVERSAL_TENANT
+MultitenantConstants.SUPER_TENANT_DOMAIN_NAME
 ;%0A    %7D%0A
@@ -2318,17 +2318,34 @@
 urn 
-UNIVERSAL
+MultitenantConstants.SUPER
 _TEN

Refactor test util InMemoryTenantManager (#1162)