Search in sources :

Example 11 with ServerConfiguration

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);
}
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 12 with ServerConfiguration

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;
    }
}
Also used : ServerConfiguration(org.wso2.carbon.base.ServerConfiguration)

Example 13 with ServerConfiguration

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);
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) APIManagerConfigurationServiceImpl(org.wso2.carbon.apimgt.impl.APIManagerConfigurationServiceImpl) ServerConfiguration(org.wso2.carbon.base.ServerConfiguration) SubscriptionDataStore(org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore) Application(org.wso2.carbon.apimgt.keymgt.model.entity.Application) SubscriptionDataHolder(org.wso2.carbon.apimgt.keymgt.SubscriptionDataHolder) Before(org.junit.Before)

Example 14 with ServerConfiguration

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));
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) APIManagerConfigurationServiceImpl(org.wso2.carbon.apimgt.impl.APIManagerConfigurationServiceImpl) ServerConfiguration(org.wso2.carbon.base.ServerConfiguration) Before(org.junit.Before)

Example 15 with ServerConfiguration

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;
    }
}
Also used : ServerConfiguration(org.wso2.carbon.base.ServerConfiguration) OAuthServerConfiguration(org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration)

Aggregations

ServerConfiguration (org.wso2.carbon.base.ServerConfiguration)13 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)4 Before (org.junit.Before)3 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)3 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)3 APIManagerConfigurationServiceImpl (org.wso2.carbon.apimgt.impl.APIManagerConfigurationServiceImpl)3 IOException (java.io.IOException)2 Cache (javax.cache.Cache)2 SimpleQueryCriteria (org.wso2.carbon.humantask.core.dao.SimpleQueryCriteria)2 SdkClientException (com.amazonaws.SdkClientException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 UnknownHostException (java.net.UnknownHostException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CertificateException (java.security.cert.CertificateException)1