Java Code Examples for org.wso2.carbon.apimgt.api.model.API#getCorsConfiguration()
The following examples show how to use
org.wso2.carbon.apimgt.api.model.API#getCorsConfiguration() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 4 votes |
@Test public void testGetAPIInformation() throws Exception { GovernanceArtifact artifact = Mockito.mock(GovernanceArtifact.class); Registry registry = Mockito.mock(Registry.class); Resource resource = Mockito.mock(Resource.class); API expectedAPI = getUniqueAPI(); String artifactPath = ""; PowerMockito.mockStatic(GovernanceUtils.class); Mockito.when(GovernanceUtils.getArtifactPath(registry, expectedAPI.getUUID())).thenReturn(artifactPath); Mockito.when(registry.get(artifactPath)).thenReturn(resource); Mockito.when(resource.getLastModified()).thenReturn(expectedAPI.getLastUpdated()); DateFormat df = new SimpleDateFormat("E MMM dd HH:mm:ss zzz yyyy", Locale.US); Date createdTime = df.parse(expectedAPI.getCreatedTime()); Mockito.when(resource.getCreatedTime()).thenReturn(createdTime); ServiceReferenceHolderMockCreator holderMockCreator = new ServiceReferenceHolderMockCreator(1); APIManagerConfiguration apimConfiguration = holderMockCreator.getConfigurationServiceMockCreator(). getConfigurationMockCreator().getMock(); CORSConfiguration corsConfiguration = expectedAPI.getCorsConfiguration(); Mockito.when(apimConfiguration.getFirstProperty(APIConstants.CORS_CONFIGURATION_ACCESS_CTL_ALLOW_HEADERS)). thenReturn(corsConfiguration.getAccessControlAllowHeaders().toString()); Mockito.when(apimConfiguration.getFirstProperty(APIConstants.CORS_CONFIGURATION_ACCESS_CTL_ALLOW_METHODS)). thenReturn(corsConfiguration.getAccessControlAllowMethods().toString()); Mockito.when(apimConfiguration.getFirstProperty(APIConstants.CORS_CONFIGURATION_ACCESS_CTL_ALLOW_ORIGIN)). thenReturn(corsConfiguration.getAccessControlAllowOrigins().toString()); Mockito.when(artifact.getAttribute(APIConstants.API_OVERVIEW_PROVIDER)). thenReturn(expectedAPI.getId().getProviderName()); Mockito.when(artifact.getAttribute(APIConstants.API_OVERVIEW_NAME)). thenReturn(expectedAPI.getId().getApiName()); Mockito.when(artifact.getAttribute(APIConstants.API_OVERVIEW_VERSION)). thenReturn(expectedAPI.getId().getVersion()); Mockito.when(artifact.getId()).thenReturn(expectedAPI.getUUID()); API api = APIUtil.getAPIInformation(artifact, registry); Assert.assertEquals(expectedAPI.getId(), api.getId()); Assert.assertEquals(expectedAPI.getUUID(), api.getUUID()); Mockito.verify(artifact, Mockito.atLeastOnce()).getAttribute(APIConstants.API_OVERVIEW_PROVIDER); Mockito.verify(artifact, Mockito.atLeastOnce()).getAttribute(APIConstants.API_OVERVIEW_NAME); Mockito.verify(artifact, Mockito.atLeastOnce()).getAttribute(APIConstants.API_OVERVIEW_VERSION); Mockito.verify(artifact, Mockito.atLeastOnce()).getAttribute(APIConstants.API_OVERVIEW_THUMBNAIL_URL); Mockito.verify(artifact, Mockito.atLeastOnce()).getLifecycleState(); Mockito.verify(artifact, Mockito.atLeastOnce()).getAttribute(APIConstants.API_OVERVIEW_CONTEXT); Mockito.verify(artifact, Mockito.atLeastOnce()).getAttribute(APIConstants.API_OVERVIEW_VISIBILITY); Mockito.verify(artifact, Mockito.atLeastOnce()).getAttribute(APIConstants.API_OVERVIEW_VISIBLE_ROLES); Mockito.verify(artifact, Mockito.atLeastOnce()).getAttribute(APIConstants.API_OVERVIEW_VISIBLE_TENANTS); Mockito.verify(artifact, Mockito.atLeastOnce()).getAttribute(APIConstants.API_OVERVIEW_TRANSPORTS); Mockito.verify(artifact, Mockito.atLeastOnce()).getAttribute(APIConstants.API_OVERVIEW_INSEQUENCE); Mockito.verify(artifact, Mockito.atLeastOnce()).getAttribute(APIConstants.API_OVERVIEW_OUTSEQUENCE); Mockito.verify(artifact, Mockito.atLeastOnce()).getAttribute(APIConstants.API_OVERVIEW_FAULTSEQUENCE); Mockito.verify(artifact, Mockito.atLeastOnce()).getAttribute(APIConstants.API_OVERVIEW_DESCRIPTION); Mockito.verify(artifact, Mockito.atLeastOnce()).getAttribute(APIConstants.API_OVERVIEW_REDIRECT_URL); Mockito.verify(artifact, Mockito.atLeastOnce()).getAttribute(APIConstants.API_OVERVIEW_BUSS_OWNER); Mockito.verify(artifact, Mockito.atLeastOnce()).getAttribute(APIConstants.API_OVERVIEW_OWNER); Mockito.verify(artifact, Mockito.atLeastOnce()).getAttribute(APIConstants.API_OVERVIEW_ADVERTISE_ONLY); Mockito.verify(artifact, Mockito.atLeastOnce()).getAttribute(APIConstants.API_OVERVIEW_ENVIRONMENTS); }
Example 2
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 4 votes |
@Test public void testGetAPI() throws Exception { API expectedAPI = getUniqueAPI(); final String provider = expectedAPI.getId().getProviderName(); final String tenantDomain = org.wso2.carbon.utils.multitenancy.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME; final int tenantId = -1234; GovernanceArtifact artifact = Mockito.mock(GovernanceArtifact.class); Registry registry = Mockito.mock(Registry.class); ApiMgtDAO apiMgtDAO = Mockito.mock(ApiMgtDAO.class); Resource resource = Mockito.mock(Resource.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); RealmService realmService = Mockito.mock(RealmService.class); TenantManager tenantManager = Mockito.mock(TenantManager.class); APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class); APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class); ThrottleProperties throttleProperties = Mockito.mock(ThrottleProperties.class); SubscriptionPolicy policy = Mockito.mock(SubscriptionPolicy.class); SubscriptionPolicy[] policies = new SubscriptionPolicy[]{policy}; QuotaPolicy quotaPolicy = Mockito.mock(QuotaPolicy.class); RequestCountLimit limit = Mockito.mock(RequestCountLimit.class); PowerMockito.mockStatic(ApiMgtDAO.class); PowerMockito.mockStatic(MultitenantUtils.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); Mockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO); Mockito.when(apiMgtDAO.getAPIID(Mockito.any(APIIdentifier.class), eq((Connection) null))).thenReturn(123); Mockito.when(artifact.getId()).thenReturn(""); Mockito.when(artifact.getAttribute(APIConstants.API_OVERVIEW_PROVIDER)).thenReturn(provider); Mockito.when(MultitenantUtils.getTenantDomain(provider)). thenReturn(tenantDomain); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService); Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager); Mockito.when(tenantManager.getTenantId(tenantDomain)).thenReturn(tenantId); String artifactPath = ""; PowerMockito.mockStatic(GovernanceUtils.class); Mockito.when(GovernanceUtils.getArtifactPath(registry, "")).thenReturn(artifactPath); Mockito.when(registry.get(artifactPath)).thenReturn(resource); Mockito.when(resource.getLastModified()).thenReturn(expectedAPI.getLastUpdated()); Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService); Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration); Mockito.when(apiManagerConfiguration.getThrottleProperties()).thenReturn(throttleProperties); Mockito.when(throttleProperties.isEnabled()).thenReturn(true); Mockito.when(apiMgtDAO.getSubscriptionPolicies(tenantId)).thenReturn(policies); Mockito.when(policy.getPolicyName()).thenReturn("policy"); Mockito.when(policy.getDefaultQuotaPolicy()).thenReturn(quotaPolicy); Mockito.when(quotaPolicy.getLimit()).thenReturn(limit); Mockito.when(registry.getTags(artifactPath)).thenReturn(getTagsFromSet(expectedAPI.getTags())); HashMap<String, String> urlPatterns = getURLTemplatePattern(expectedAPI.getUriTemplates()); Mockito.when(apiMgtDAO.getURITemplatesPerAPIAsString(Mockito.any(APIIdentifier.class))).thenReturn(urlPatterns); CORSConfiguration corsConfiguration = expectedAPI.getCorsConfiguration(); Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.CORS_CONFIGURATION_ACCESS_CTL_ALLOW_HEADERS)). thenReturn(corsConfiguration.getAccessControlAllowHeaders().toString()); Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.CORS_CONFIGURATION_ACCESS_CTL_ALLOW_METHODS)). thenReturn(corsConfiguration.getAccessControlAllowMethods().toString()); Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.CORS_CONFIGURATION_ACCESS_CTL_ALLOW_ORIGIN)). thenReturn(corsConfiguration.getAccessControlAllowOrigins().toString()); API api = APIUtil.getAPI(artifact, registry); Assert.assertNotNull(api); }
Example 3
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 4 votes |
@Test public void testGetAPIForPublishing() throws Exception { API expectedAPI = getUniqueAPI(); final String provider = expectedAPI.getId().getProviderName(); final String tenantDomain = org.wso2.carbon.utils.multitenancy.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME; final int tenantId = -1234; GovernanceArtifact artifact = Mockito.mock(GovernanceArtifact.class); Registry registry = Mockito.mock(Registry.class); ApiMgtDAO apiMgtDAO = Mockito.mock(ApiMgtDAO.class); Resource resource = Mockito.mock(Resource.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); RealmService realmService = Mockito.mock(RealmService.class); TenantManager tenantManager = Mockito.mock(TenantManager.class); APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class); APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class); ThrottleProperties throttleProperties = Mockito.mock(ThrottleProperties.class); SubscriptionPolicy policy = Mockito.mock(SubscriptionPolicy.class); SubscriptionPolicy[] policies = new SubscriptionPolicy[]{policy}; QuotaPolicy quotaPolicy = Mockito.mock(QuotaPolicy.class); RequestCountLimit limit = Mockito.mock(RequestCountLimit.class); PowerMockito.mockStatic(ApiMgtDAO.class); PowerMockito.mockStatic(GovernanceUtils.class); PowerMockito.mockStatic(MultitenantUtils.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); Mockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO); Mockito.when(apiMgtDAO.getAPIID(Mockito.any(APIIdentifier.class), eq((Connection) null))).thenReturn(123); Mockito.when(artifact.getId()).thenReturn(""); Mockito.when(artifact.getAttribute(APIConstants.API_OVERVIEW_PROVIDER)).thenReturn(provider); Mockito.when(artifact.getAttribute(APIConstants.API_OVERVIEW_CACHE_TIMEOUT)).thenReturn("15"); Mockito.when(MultitenantUtils.getTenantDomain(provider)).thenReturn(tenantDomain); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService); Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager); Mockito.when(tenantManager.getTenantId(tenantDomain)).thenReturn(tenantId); String artifactPath = ""; Mockito.when(GovernanceUtils.getArtifactPath(registry, "")).thenReturn(artifactPath); Mockito.when(registry.get(artifactPath)).thenReturn(resource); Mockito.when(resource.getLastModified()).thenReturn(expectedAPI.getLastUpdated()); Mockito.when(resource.getCreatedTime()).thenReturn(expectedAPI.getLastUpdated()); Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService); Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration); Mockito.when(apiManagerConfiguration.getThrottleProperties()).thenReturn(throttleProperties); Mockito.when(throttleProperties.isEnabled()).thenReturn(true); Mockito.when(apiMgtDAO.getSubscriptionPolicies(tenantId)).thenReturn(policies); Mockito.when(policy.getPolicyName()).thenReturn("policy"); Mockito.when(policy.getDefaultQuotaPolicy()).thenReturn(quotaPolicy); Mockito.when(quotaPolicy.getLimit()).thenReturn(limit); Mockito.when(registry.getTags(artifactPath)).thenReturn(getTagsFromSet(expectedAPI.getTags())); HashMap<String, String> urlPatterns = getURLTemplatePattern(expectedAPI.getUriTemplates()); Mockito.when(apiMgtDAO.getURITemplatesPerAPIAsString(Mockito.any(APIIdentifier.class))).thenReturn(urlPatterns); CORSConfiguration corsConfiguration = expectedAPI.getCorsConfiguration(); Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.CORS_CONFIGURATION_ACCESS_CTL_ALLOW_HEADERS)). thenReturn(corsConfiguration.getAccessControlAllowHeaders().toString()); Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.CORS_CONFIGURATION_ACCESS_CTL_ALLOW_METHODS)). thenReturn(corsConfiguration.getAccessControlAllowMethods().toString()); Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.CORS_CONFIGURATION_ACCESS_CTL_ALLOW_ORIGIN)). thenReturn(corsConfiguration.getAccessControlAllowOrigins().toString()); Mockito.when(artifact.getAttribute(APIConstants.API_OVERVIEW_ENDPOINT_CONFIG)) .thenReturn("{\"production_endpoints\":{\"url\":\"http://www.mocky.io/v2/5b21fe0f2e00002a00e313fe\"," + "\"config\":null,\"template_not_supported\":false}," + "\"sandbox_endpoints\":{\"url\":\"http://www.mocky.io/v2/5b21fe0f2e00002a00e313fe\"," + "\"config\":null,\"template_not_supported\":false},\"endpoint_type\":\"http\"}"); API api = APIUtil.getAPIForPublishing(artifact, registry); Assert.assertNotNull(api); Set<String> testEnvironmentList = new HashSet<String>(); testEnvironmentList.add("PRODUCTION"); testEnvironmentList.add("SANDBOX"); Assert.assertThat(SetUtils.isEqualSet(api.getEnvironmentList(), testEnvironmentList), is(true)); }
Example 4
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 4 votes |
@Test public void testGetAPIWithGovernanceArtifact() throws Exception { System.setProperty("carbon.home", APIUtilTest.class.getResource("/").getFile()); try { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants .SUPER_TENANT_DOMAIN_NAME); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID); API expectedAPI = getUniqueAPI(); final String provider = expectedAPI.getId().getProviderName(); final String tenantDomain = org.wso2.carbon.utils.multitenancy.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME; final int tenantId = -1234; System.setProperty("carbon.home", ""); File siteConfFile = new File(Thread.currentThread().getContextClassLoader(). getResource("tenant-conf.json").getFile()); String tenantConfValue = FileUtils.readFileToString(siteConfFile); GovernanceArtifact artifact = Mockito.mock(GovernanceArtifact.class); Registry registry = Mockito.mock(Registry.class); ApiMgtDAO apiMgtDAO = Mockito.mock(ApiMgtDAO.class); Resource resource = Mockito.mock(Resource.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); RealmService realmService = Mockito.mock(RealmService.class); TenantManager tenantManager = Mockito.mock(TenantManager.class); APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class); APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class); ThrottleProperties throttleProperties = Mockito.mock(ThrottleProperties.class); SubscriptionPolicy policy = Mockito.mock(SubscriptionPolicy.class); SubscriptionPolicy[] policies = new SubscriptionPolicy[] {policy}; QuotaPolicy quotaPolicy = Mockito.mock(QuotaPolicy.class); RequestCountLimit limit = Mockito.mock(RequestCountLimit.class); PrivilegedCarbonContext carbonContext = Mockito.mock(PrivilegedCarbonContext.class); RegistryService registryService = Mockito.mock(RegistryService.class); UserRegistry userRegistry = Mockito.mock(UserRegistry.class); PowerMockito.mockStatic(ApiMgtDAO.class); PowerMockito.mockStatic(GovernanceUtils.class); PowerMockito.mockStatic(MultitenantUtils.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); Mockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO); Mockito.when(apiMgtDAO.getAPIID(Mockito.any(APIIdentifier.class), eq((Connection) null))).thenReturn(123); Mockito.when(apiMgtDAO.getPolicyNames(PolicyConstants.POLICY_LEVEL_SUB, provider)).thenReturn(new String[] {"Unlimited"}); Mockito.when(artifact.getId()).thenReturn(""); Mockito.when(artifact.getAttribute(APIConstants.API_OVERVIEW_PROVIDER)).thenReturn(provider); Mockito.when(artifact.getAttribute(APIConstants.API_OVERVIEW_CACHE_TIMEOUT)).thenReturn("15"); Mockito.when(artifact.getAttribute(APIConstants.API_OVERVIEW_TIER)).thenReturn("Unlimited"); Mockito.when(MultitenantUtils.getTenantDomain(provider)).thenReturn(tenantDomain); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService); Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager); Mockito.when(tenantManager.getTenantId(tenantDomain)).thenReturn(tenantId); Mockito.when(registryService.getConfigSystemRegistry(tenantId)).thenReturn(userRegistry); Mockito.when(userRegistry.resourceExists(APIConstants.API_TENANT_CONF_LOCATION)).thenReturn(true); Mockito.when(userRegistry.get(APIConstants.API_TENANT_CONF_LOCATION)).thenReturn(resource); String artifactPath = ""; Mockito.when(GovernanceUtils.getArtifactPath(registry, "")).thenReturn(artifactPath); Mockito.when(registry.get(artifactPath)).thenReturn(resource); Mockito.when(resource.getLastModified()).thenReturn(expectedAPI.getLastUpdated()); Mockito.when(resource.getCreatedTime()).thenReturn(expectedAPI.getLastUpdated()); Mockito.when(resource.getContent()).thenReturn(tenantConfValue.getBytes()); Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService); Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration); Mockito.when(apiManagerConfiguration.getThrottleProperties()).thenReturn(throttleProperties); Mockito.when(throttleProperties.isEnabled()).thenReturn(true); Mockito.when(apiMgtDAO.getSubscriptionPolicies(tenantId)).thenReturn(policies); Mockito.when(policy.getDefaultQuotaPolicy()).thenReturn(quotaPolicy); Mockito.when(quotaPolicy.getLimit()).thenReturn(limit); Mockito.when(registry.getTags(artifactPath)).thenReturn(getTagsFromSet(expectedAPI.getTags())); ArrayList<URITemplate> urlList = getURLTemplateList(expectedAPI.getUriTemplates()); Mockito.when(apiMgtDAO.getAllURITemplates(Mockito.anyString(), Mockito.anyString())).thenReturn(urlList); CORSConfiguration corsConfiguration = expectedAPI.getCorsConfiguration(); Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.CORS_CONFIGURATION_ACCESS_CTL_ALLOW_HEADERS)). thenReturn(corsConfiguration.getAccessControlAllowHeaders().toString()); Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.CORS_CONFIGURATION_ACCESS_CTL_ALLOW_METHODS)). thenReturn(corsConfiguration.getAccessControlAllowMethods().toString()); Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.CORS_CONFIGURATION_ACCESS_CTL_ALLOW_ORIGIN)). thenReturn(corsConfiguration.getAccessControlAllowOrigins().toString()); API api = APIUtil.getAPI(artifact); Assert.assertNotNull(api); }finally { PrivilegedCarbonContext.endTenantFlow(); } }
Example 5
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 4 votes |
@Test public void testGetAPIWithGovernanceArtifactAdvancedThrottlingDisabled() throws Exception { System.setProperty("carbon.home", APIUtilTest.class.getResource("/").getFile()); try { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants .SUPER_TENANT_DOMAIN_NAME); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID); API expectedAPI = getUniqueAPI(); final String provider = expectedAPI.getId().getProviderName(); final String tenantDomain = org.wso2.carbon.utils.multitenancy.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME; final int tenantId = -1234; System.setProperty("carbon.home", ""); File siteConfFile = new File(Thread.currentThread().getContextClassLoader(). getResource("tenant-conf.json").getFile()); String tenantConfValue = FileUtils.readFileToString(siteConfFile); GovernanceArtifact artifact = Mockito.mock(GovernanceArtifact.class); Registry registry = Mockito.mock(Registry.class); ApiMgtDAO apiMgtDAO = Mockito.mock(ApiMgtDAO.class); Resource resource = Mockito.mock(Resource.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); RealmService realmService = Mockito.mock(RealmService.class); TenantManager tenantManager = Mockito.mock(TenantManager.class); APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class); APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class); ThrottleProperties throttleProperties = Mockito.mock(ThrottleProperties.class); SubscriptionPolicy policy = Mockito.mock(SubscriptionPolicy.class); SubscriptionPolicy[] policies = new SubscriptionPolicy[]{policy}; QuotaPolicy quotaPolicy = Mockito.mock(QuotaPolicy.class); RequestCountLimit limit = Mockito.mock(RequestCountLimit.class); RegistryService registryService = Mockito.mock(RegistryService.class); UserRegistry userRegistry = Mockito.mock(UserRegistry.class); PowerMockito.mockStatic(ApiMgtDAO.class); PowerMockito.mockStatic(GovernanceUtils.class); PowerMockito.mockStatic(MultitenantUtils.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); Mockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO); Mockito.when(apiMgtDAO.getAPIID(Mockito.any(APIIdentifier.class), eq((Connection) null))).thenReturn(123); Mockito.when(apiMgtDAO.getPolicyNames(PolicyConstants.POLICY_LEVEL_SUB, provider)).thenReturn(new String[]{"Unlimited"}); Mockito.when(artifact.getId()).thenReturn(""); Mockito.when(artifact.getAttribute(APIConstants.API_OVERVIEW_PROVIDER)).thenReturn(provider); Mockito.when(artifact.getAttribute(APIConstants.API_OVERVIEW_CACHE_TIMEOUT)).thenReturn("15"); Mockito.when(artifact.getAttribute(APIConstants.API_OVERVIEW_TIER)).thenReturn("Unlimited"); Mockito.when(MultitenantUtils.getTenantDomain(provider)).thenReturn(tenantDomain); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService); Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager); Mockito.when(tenantManager.getTenantId(tenantDomain)).thenReturn(tenantId); Mockito.when(registryService.getConfigSystemRegistry(tenantId)).thenReturn(userRegistry); Mockito.when(userRegistry.resourceExists(APIConstants.API_TENANT_CONF_LOCATION)).thenReturn(true); Mockito.when(userRegistry.get(APIConstants.API_TENANT_CONF_LOCATION)).thenReturn(resource); String artifactPath = ""; Mockito.when(GovernanceUtils.getArtifactPath(registry, "")).thenReturn(artifactPath); Mockito.when(registry.get(artifactPath)).thenReturn(resource); Mockito.when(resource.getLastModified()).thenReturn(expectedAPI.getLastUpdated()); Mockito.when(resource.getCreatedTime()).thenReturn(expectedAPI.getLastUpdated()); Mockito.when(resource.getContent()).thenReturn(tenantConfValue.getBytes()); Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService); Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration); Mockito.when(apiManagerConfiguration.getThrottleProperties()).thenReturn(throttleProperties); Mockito.when(throttleProperties.isEnabled()).thenReturn(false); Mockito.when(apiMgtDAO.getSubscriptionPolicies(tenantId)).thenReturn(policies); Mockito.when(policy.getDefaultQuotaPolicy()).thenReturn(quotaPolicy); Mockito.when(quotaPolicy.getLimit()).thenReturn(limit); Mockito.when(registry.getTags(artifactPath)).thenReturn(getTagsFromSet(expectedAPI.getTags())); ArrayList<URITemplate> urlList = getURLTemplateList(expectedAPI.getUriTemplates()); Mockito.when(apiMgtDAO.getAllURITemplates(Mockito.anyString(), Mockito.anyString())).thenReturn(urlList); CORSConfiguration corsConfiguration = expectedAPI.getCorsConfiguration(); Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.CORS_CONFIGURATION_ACCESS_CTL_ALLOW_HEADERS)). thenReturn(corsConfiguration.getAccessControlAllowHeaders().toString()); Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.CORS_CONFIGURATION_ACCESS_CTL_ALLOW_METHODS)). thenReturn(corsConfiguration.getAccessControlAllowMethods().toString()); Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.CORS_CONFIGURATION_ACCESS_CTL_ALLOW_ORIGIN)). thenReturn(corsConfiguration.getAccessControlAllowOrigins().toString()); API api = APIUtil.getAPI(artifact); Assert.assertNotNull(api); }finally { PrivilegedCarbonContext.endTenantFlow(); } }