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);
}
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);
}
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);
}
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());
}
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);
}
Aggregations