From 77e735e5256a5ce763aff70ec70f9c3dcf29c9de Mon Sep 17 00:00:00 2001 From: Nirothipan Date: Thu, 12 Oct 2017 17:41:58 +0530 Subject: [PATCH] making required changes --- .../publisher/APIPublisherUtilTest.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtilTest.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtilTest.java index 8a93773257..e84cdb6f08 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtilTest.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtilTest.java @@ -55,20 +55,24 @@ public class APIPublisherUtilTest extends BaseAPIPublisherTest { } @Test(description = "test buildAPIConfig method and ensures an APIConfig is created") - private void buildApiConfigAsNonAdminUser() throws UserStoreException, RegistryException { - PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername("test"); - setUserRealm(); - ServletContext servletContext = new MockServletContext(); - APIResourceConfiguration apiDef = new APIResourceConfiguration(); - List resources = new ArrayList<>(); - apiDef.setResources(resources); - APIConfig apiConfig = buildApiConfig(servletContext, apiDef); - Assert.assertNotNull(apiConfig, "API configuration is null."); + private void buildApiConfigTest() throws UserStoreException, RegistryException { + try { + startTenantFlowAsTestTenant(); + setUserRealm(); + ServletContext servletContext = new MockServletContext(); + APIResourceConfiguration apiDef = new APIResourceConfiguration(); + List resources = new ArrayList<>(); + apiDef.setResources(resources); + APIConfig apiConfig = buildApiConfig(servletContext, apiDef); + Assert.assertNotNull(apiConfig, "API configuration is null."); + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } } @Test(description = "test buildAPIConfig method as SuperTenant and ensures" + " an APIConfig is created") - private void buildApiConfigAsAdminUser() throws UserStoreException { + private void buildApiConfigAsSuperTenat() throws UserStoreException { ServletContext servletContext = new MockServletContext(); APIResourceConfiguration apiDef = new APIResourceConfiguration(); List resources = new ArrayList<>(); @@ -113,4 +117,10 @@ public class APIPublisherUtilTest extends BaseAPIPublisherTest { UserRealm userRealm = new InMemoryRealmService().getUserRealm(configuration); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUserRealm(userRealm); } + + private void startTenantFlowAsTestTenant() { + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID, true); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain("test"); + } }