Search in sources :

Example 86 with ServiceReferenceHolder

use of org.wso2.carbon.apimgt.persistence.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.

the class APIKeyValidatorTestCase method setup.

@Before
public void setup() {
    System.setProperty("carbon.home", "jhkjn");
    PowerMockito.mockStatic(PrivilegedCarbonContext.class);
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    PowerMockito.mockStatic(CarbonConstants.class);
    PowerMockito.mockStatic(ServerConfiguration.class);
    PowerMockito.mockStatic(APIUtil.class);
    PowerMockito.mockStatic(CarbonContext.class);
    PowerMockito.mockStatic(Util.class);
    PowerMockito.mockStatic(Caching.class);
    PowerMockito.when(Util.getTenantDomain()).thenReturn("carbon.super");
    serverConfiguration = Mockito.mock(ServerConfiguration.class);
    ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    PowerMockito.when(ServerConfiguration.getInstance()).thenReturn(serverConfiguration);
    PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
    Mockito.when(serviceReferenceHolder.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
    PowerMockito.mockStatic(APISecurityUtils.class);
    privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class);
    PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext);
    Cache cache = Mockito.mock(Cache.class);
    PowerMockito.when(APIUtil.getCache(APIConstants.API_MANAGER_CACHE_MANAGER, APIConstants.GATEWAY_TOKEN_CACHE_NAME, defaultCacheTimeout, defaultCacheTimeout)).thenReturn(cache);
    Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.GATEWAY_TOKEN_CACHE_ENABLED)).thenReturn("true");
    Mockito.when(serverConfiguration.getFirstProperty(APIConstants.DEFAULT_CACHE_TIMEOUT)).thenReturn("900");
    CacheManager cacheManager = Mockito.mock(CacheManager.class);
    PowerMockito.when(Caching.getCacheManager(APIConstants.API_MANAGER_CACHE_MANAGER)).thenReturn(cacheManager);
    Mockito.when(cacheManager.getCache(Mockito.anyString())).thenReturn(cache);
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.gateway.internal.ServiceReferenceHolder) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) ServerConfiguration(org.wso2.carbon.base.ServerConfiguration) CacheManager(javax.cache.CacheManager) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) Cache(javax.cache.Cache) Before(org.junit.Before)

Example 87 with ServiceReferenceHolder

use of org.wso2.carbon.apimgt.persistence.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.

the class APIKeyValidatorTestCase method testGetVerbInfoDTOFromAPIData.

/*
     * Test method for getVerbInfoDTOFromAPIData()
     * */
@Test
public void testGetVerbInfoDTOFromAPIData() throws Exception {
    String context = "/";
    String apiVersion = "1.0";
    String requestPath = "/menu";
    String httpMethod = "GET";
    VerbInfoDTO verbDTO = getDefaultVerbInfoDTO();
    verbDTO.setRequestKey("//1.0/:https");
    APIKeyValidator apiKeyValidator = createAPIKeyValidator(true, getDefaultURITemplates("/menu", "GET"), verbDTO);
    // If isAPIResourceValidationEnabled==true
    apiKeyValidator.setGatewayAPIResourceValidationEnabled(true);
    PowerMockito.mockStatic(Cache.class);
    Cache cache = Mockito.mock(Cache.class);
    PowerMockito.mockStatic(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder.class);
    PowerMockito.mockStatic(APIManagerConfigurationService.class);
    PowerMockito.mockStatic(CacheProvider.class);
    org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder.class);
    final APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
    PowerMockito.when(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
    PowerMockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
    PowerMockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
    CacheProvider cacheProvider = Mockito.mock(CacheProvider.class);
    PowerMockito.when(cacheProvider.getDefaultCacheTimeout()).thenReturn((long) 900);
    Mockito.when(CacheProvider.getResourceCache()).thenReturn(cache);
    VerbInfoDTO verbInfoDTO1 = new VerbInfoDTO();
    verbInfoDTO1.setHttpVerb("get");
    Mockito.when(APIUtil.getAPIInfoDTOCacheKey("", "1.0")).thenReturn("abc");
    Mockito.when((VerbInfoDTO) CacheProvider.getResourceCache().get("abc")).thenReturn(verbInfoDTO1);
    MessageContext messageContext = Mockito.mock(MessageContext.class);
    VerbInfoDTO verbInfoDTOFromAPIData = apiKeyValidator.getVerbInfoDTOFromAPIData(messageContext, context, apiVersion, requestPath, httpMethod);
    Assert.assertEquals("", verbDTO, verbInfoDTOFromAPIData);
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) APIManagerConfigurationService(org.wso2.carbon.apimgt.impl.APIManagerConfigurationService) VerbInfoDTO(org.wso2.carbon.apimgt.impl.dto.VerbInfoDTO) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) CacheProvider(org.wso2.carbon.apimgt.impl.caching.CacheProvider) Cache(javax.cache.Cache) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 88 with ServiceReferenceHolder

use of org.wso2.carbon.apimgt.persistence.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.

the class CORSRequestHandlerTestCase method setup.

@Before
public void setup() {
    PowerMockito.mockStatic(APIUtil.class);
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    PowerMockito.when(APIUtil.getAllowedMethods()).thenReturn("GET,PUT,POST,DELETE,PATCH,OPTIONS");
    PowerMockito.when(APIUtil.isAllowCredentials()).thenReturn(false);
    PowerMockito.when(APIUtil.getAllowedOrigins()).thenReturn("*");
    PowerMockito.when(APIUtil.getAllowedHeaders()).thenReturn("authorization,Access-Control-Allow-Origin,Content-Type,SOAPAction");
    ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
    PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    Mockito.when(serviceReferenceHolder.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.gateway.internal.ServiceReferenceHolder) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) Before(org.junit.Before)

Example 89 with ServiceReferenceHolder

use of org.wso2.carbon.apimgt.persistence.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.

the class ServiceReferenceHolderTestCase method testServiceReferenceHolder.

@Test
public void testServiceReferenceHolder() {
    ServiceReferenceHolder serviceReferenceHolder = ServiceReferenceHolder.getInstance();
    Assert.assertTrue(serviceReferenceHolder instanceof ServiceReferenceHolder);
    serviceReferenceHolder.getThrottleDataHolder();
    ThrottleDataHolder throttleDataHolder = Mockito.mock(ThrottleDataHolder.class);
    serviceReferenceHolder.setThrottleDataHolder(throttleDataHolder);
    ConfigurationContextService cfgCtxService = Mockito.mock(ConfigurationContextService.class);
    serviceReferenceHolder.setConfigurationContextService(cfgCtxService);
    cfgCtxService = serviceReferenceHolder.getConfigurationContextService();
    Assert.assertNotNull(cfgCtxService);
    APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
    serviceReferenceHolder.setAPIManagerConfigurationService(apiManagerConfigurationService);
    apiManagerConfigurationService = serviceReferenceHolder.getApiManagerConfigurationService();
    Assert.assertNotNull(apiManagerConfigurationService);
    Assert.assertNull(serviceReferenceHolder.getAPIManagerConfiguration());
    Assert.assertNull(serviceReferenceHolder.getServerConfigurationContext());
    ThrottleProperties throttleProperties = Mockito.mock(ThrottleProperties.class);
    serviceReferenceHolder.setThrottleProperties(throttleProperties);
    Assert.assertNotNull(serviceReferenceHolder.getThrottleProperties());
}
Also used : ThrottleDataHolder(org.wso2.carbon.apimgt.gateway.throttling.ThrottleDataHolder) APIManagerConfigurationService(org.wso2.carbon.apimgt.impl.APIManagerConfigurationService) ConfigurationContextService(org.wso2.carbon.utils.ConfigurationContextService) ThrottleProperties(org.wso2.carbon.apimgt.impl.dto.ThrottleProperties) Test(org.junit.Test)

Example 90 with ServiceReferenceHolder

use of org.wso2.carbon.apimgt.persistence.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.

the class WebsocketUtilTestCase method setup.

@Before
public void setup() {
    System.setProperty("carbon.home", "jhkjn");
    PowerMockito.mockStatic(MultitenantUtils.class);
    PowerMockito.mockStatic(PrivilegedCarbonContext.class);
    PrivilegedCarbonContext privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class);
    PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext);
    Mockito.when(privilegedCarbonContext.getTenantDomain()).thenReturn("abc.com");
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
    PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    Mockito.when(serviceReferenceHolder.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
    Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.API_KEY_VALIDATOR_URL)).thenReturn(apiKeyValidationURL);
    Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.GATEWAY_TOKEN_CACHE_ENABLED)).thenReturn("true");
    Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.REMOVE_OAUTH_HEADERS_FROM_MESSAGE)).thenReturn("true");
    cacheManager = Mockito.mock(CacheManager.class);
    PowerMockito.mockStatic(Caching.class);
    PowerMockito.when(Caching.getCacheManager(APIConstants.API_MANAGER_CACHE_MANAGER)).thenReturn(cacheManager);
    gwKeyCache = Mockito.mock(Cache.class);
    gwTokenCache = Mockito.mock(Cache.class);
    Mockito.when(cacheManager.getCache(APIConstants.GATEWAY_KEY_CACHE_NAME)).thenReturn(gwKeyCache);
    Mockito.when(cacheManager.getCache(APIConstants.GATEWAY_TOKEN_CACHE_NAME)).thenReturn(gwTokenCache);
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.gateway.internal.ServiceReferenceHolder) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) CacheManager(javax.cache.CacheManager) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) Cache(javax.cache.Cache) Before(org.junit.Before)

Aggregations

ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)109 Test (org.junit.Test)105 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)102 RegistryService (org.wso2.carbon.registry.core.service.RegistryService)64 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)63 RealmService (org.wso2.carbon.user.core.service.RealmService)53 TenantManager (org.wso2.carbon.user.core.tenant.TenantManager)49 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)47 Resource (org.wso2.carbon.registry.core.Resource)40 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)38 APIManagerConfigurationService (org.wso2.carbon.apimgt.impl.APIManagerConfigurationService)30 InputStream (java.io.InputStream)29 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)28 Before (org.junit.Before)27 API (org.wso2.carbon.apimgt.api.model.API)24 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)23 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)22 HashMap (java.util.HashMap)21 Organization (org.wso2.carbon.apimgt.persistence.dto.Organization)21 QName (javax.xml.namespace.QName)19