use of org.wso2.carbon.base.ServerConfiguration 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.base.ServerConfiguration in project carbon-apimgt by wso2.
the class APIMSiddhiExtensionsComponent method getPortOffset.
private static int getPortOffset() {
ServerConfiguration carbonConfig = CarbonUtils.getServerConfiguration();
String portOffset = System.getProperty(PORT_OFFSET_SYSTEM_VAR, carbonConfig.getFirstProperty(PORT_OFFSET_CONFIG));
try {
if ((portOffset != null)) {
return Integer.parseInt(portOffset.trim());
} else {
return 0;
}
} catch (NumberFormatException e) {
log.error("Invalid Port Offset: " + portOffset + ". Default value 0 will be used.", e);
return 0;
}
}
use of org.wso2.carbon.base.ServerConfiguration in project carbon-apimgt by wso2.
the class TokenGenTest method setUp.
@Before
public void setUp() throws Exception {
PowerMockito.mockStatic(CarbonUtils.class);
PowerMockito.mockStatic(SubscriptionDataHolder.class);
ServerConfiguration serverConfiguration = Mockito.mock(ServerConfiguration.class);
Mockito.when(serverConfiguration.getFirstProperty(APIConstants.PORT_OFFSET_CONFIG)).thenReturn("2");
PowerMockito.when(CarbonUtils.getServerConfiguration()).thenReturn(serverConfiguration);
String dbConfigPath = System.getProperty("APIManagerDBConfigurationPath");
APIManagerConfiguration config = new APIManagerConfiguration();
config.load(dbConfigPath);
ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService(new APIManagerConfigurationServiceImpl(config));
SubscriptionDataStore subscriptionDataStore = Mockito.mock(SubscriptionDataStore.class);
SubscriptionDataHolder subscriptionDataHolder = Mockito.mock(SubscriptionDataHolder.class);
PowerMockito.when(SubscriptionDataHolder.getInstance()).thenReturn(subscriptionDataHolder);
PowerMockito.when(SubscriptionDataHolder.getInstance().getTenantSubscriptionStore(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)).thenReturn(subscriptionDataStore);
Application application = new Application();
application.setId(1);
application.setName("app2");
application.setUUID(UUID.randomUUID().toString());
application.addAttribute("abc", "cde");
Mockito.when(subscriptionDataStore.getApplicationById(1)).thenReturn(application);
}
use of org.wso2.carbon.base.ServerConfiguration in project carbon-apimgt by wso2.
the class JWTSignatureAlgTestCase method setUp.
@Before
public void setUp() throws Exception {
PowerMockito.mockStatic(CarbonUtils.class);
ServerConfiguration serverConfiguration = Mockito.mock(ServerConfiguration.class);
Mockito.when(serverConfiguration.getFirstProperty(APIConstants.PORT_OFFSET_CONFIG)).thenReturn("2");
PowerMockito.when(CarbonUtils.getServerConfiguration()).thenReturn(serverConfiguration);
String dbConfigPath = System.getProperty("APIManagerDBConfigurationPath");
APIManagerConfiguration config = new APIManagerConfiguration();
config.load(dbConfigPath);
ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService(new APIManagerConfigurationServiceImpl(config));
}
use of org.wso2.carbon.base.ServerConfiguration in project carbon-apimgt by wso2.
the class APIUtil method getPortOffset.
public static int getPortOffset() {
ServerConfiguration carbonConfig = CarbonUtils.getServerConfiguration();
String portOffset = System.getProperty(APIConstants.PORT_OFFSET_SYSTEM_VAR, carbonConfig.getFirstProperty(APIConstants.PORT_OFFSET_CONFIG));
try {
if ((portOffset != null)) {
return Integer.parseInt(portOffset.trim());
} else {
return 0;
}
} catch (NumberFormatException e) {
log.error("Invalid Port Offset: " + portOffset + ". Default value 0 will be used.", e);
return 0;
}
}
Aggregations