Search in sources :

Example 81 with ServiceReferenceHolder

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

the class RestAPIStoreUtilsTest method testIsUserOwnerOfApplicationlowerCase.

@Test
public void testIsUserOwnerOfApplicationlowerCase() {
    String username = "William Black";
    String lowerCaseUsername = "william black";
    PowerMockito.mockStatic(RestApiCommonUtil.class);
    Mockito.when(RestApiCommonUtil.getLoggedInUsername()).thenReturn(username);
    PowerMockito.mockStatic(Application.class);
    Application mockApplication = Mockito.mock(Application.class);
    Subscriber subscriber = Mockito.mock(Subscriber.class);
    Mockito.when(mockApplication.getSubscriber()).thenReturn(subscriber);
    Mockito.when(subscriber.getName()).thenReturn(lowerCaseUsername);
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
    Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
    APIManagerConfiguration configuration = Mockito.mock(APIManagerConfiguration.class);
    Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(configuration);
    Mockito.when(configuration.getFirstProperty(APIConstants.API_STORE_FORCE_CI_COMPARISIONS)).thenReturn("true");
    Assert.assertEquals(true, RestAPIStoreUtils.isUserOwnerOfApplication(mockApplication));
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) APIManagerConfigurationService(org.wso2.carbon.apimgt.impl.APIManagerConfigurationService) Subscriber(org.wso2.carbon.apimgt.api.model.Subscriber) Application(org.wso2.carbon.apimgt.api.model.Application) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 82 with ServiceReferenceHolder

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

the class ServiceReferenceHolderTestCase method testGetAvailableFeaturesForException.

@Test
public void testGetAvailableFeaturesForException() throws ConfigurationException {
    ServiceReferenceHolder instance = ServiceReferenceHolder.getInstance();
    ConfigProvider configProvider = Mockito.mock(ConfigProvider.class);
    instance.setConfigProvider(configProvider);
    Mockito.when(configProvider.getConfigurationObject(Mockito.anyString())).thenThrow(ConfigurationException.class);
    Map<String, Feature> featureList = instance.getAvailableFeatures();
    Assert.assertNotNull(featureList);
}
Also used : ConfigProvider(org.wso2.carbon.config.provider.ConfigProvider) Feature(org.wso2.carbon.apimgt.rest.api.configurations.models.Feature) Test(org.testng.annotations.Test)

Example 83 with ServiceReferenceHolder

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

the class ServiceReferenceHolderTestCase method testGetAvailableFeatures.

@Test
public void testGetAvailableFeatures() throws ConfigurationException {
    // //Happy Path
    ServiceReferenceHolder instance = ServiceReferenceHolder.getInstance();
    ConfigProvider configProvider = Mockito.mock(ConfigProvider.class);
    instance.setConfigProvider(configProvider);
    Map configs = new HashMap<>();
    configs.put(ConfigurationAPIConstants.ENABLED, true);
    Mockito.when(configProvider.getConfigurationObject(Mockito.anyString())).thenReturn(configs);
    Map<String, Feature> featureList = instance.getAvailableFeatures();
    Assert.assertNotNull(featureList);
}
Also used : ConfigProvider(org.wso2.carbon.config.provider.ConfigProvider) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) Feature(org.wso2.carbon.apimgt.rest.api.configurations.models.Feature) Test(org.testng.annotations.Test)

Example 84 with ServiceReferenceHolder

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

the class ServiceReferenceHolderTestCase method testGetAPIMAppConfiguration.

@Test
public void testGetAPIMAppConfiguration() throws ConfigurationException {
    // // Happy Path
    ServiceReferenceHolder instance = ServiceReferenceHolder.getInstance();
    ConfigProvider configProvider = Mockito.mock(ConfigProvider.class);
    instance.setConfigProvider(configProvider);
    APIMAppConfigurations expectedConfigs = new APIMAppConfigurations();
    expectedConfigs.setApimBaseUrl("https://localhost:9443/");
    Mockito.when(configProvider.getConfigurationObject(Mockito.any(Class.class))).thenReturn(expectedConfigs);
    APIMAppConfigurations actualConfigs = instance.getAPIMAppConfiguration();
    Assert.assertNotNull(actualConfigs);
    Assert.assertEquals(expectedConfigs.getApimBaseUrl(), actualConfigs.getApimBaseUrl());
    // // Error path
    // // ConfigurationException
    Mockito.when(configProvider.getConfigurationObject(Mockito.any(Class.class))).thenThrow(ConfigurationException.class);
    actualConfigs = instance.getAPIMAppConfiguration();
    Assert.assertNotNull(actualConfigs);
    // // config provider is null
    instance.setConfigProvider(null);
    actualConfigs = instance.getAPIMAppConfiguration();
    Assert.assertNotNull(actualConfigs);
}
Also used : ConfigProvider(org.wso2.carbon.config.provider.ConfigProvider) APIMAppConfigurations(org.wso2.carbon.apimgt.rest.api.authenticator.configuration.models.APIMAppConfigurations) Test(org.junit.Test)

Example 85 with ServiceReferenceHolder

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

the class APIMgtGatewayJWTGeneratorImplTest method testJWTGeneratorClaimConfig.

@Test
public void testJWTGeneratorClaimConfig() {
    APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
    APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
    ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
    Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
    ExtendedJWTConfigurationDto jwtConfigurationDto = Mockito.mock(ExtendedJWTConfigurationDto.class);
    Mockito.when(apiManagerConfiguration.getJwtConfigurationDto()).thenReturn(jwtConfigurationDto);
    String defaultDialectUri = "http://wso2.org/claims";
    // default dialect if not changed
    AbstractAPIMgtGatewayJWTGenerator generator = new APIMgtGatewayJWTGeneratorImpl();
    // Set jwtConfigurationDto
    generator.setJWTConfigurationDto(jwtConfigurationDto);
    Assert.assertEquals(generator.getDialectURI(), ClaimsRetriever.DEFAULT_DIALECT_URI);
    // Test dialect after changing it through config
    String claimDialect = "http://test.com";
    Mockito.when(jwtConfigurationDto.getConsumerDialectUri()).thenReturn(claimDialect);
    generator = new APIMgtGatewayJWTGeneratorImpl();
    generator.setJWTConfigurationDto(jwtConfigurationDto);
    Assert.assertEquals(generator.getDialectURI(), claimDialect);
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) ExtendedJWTConfigurationDto(org.wso2.carbon.apimgt.impl.dto.ExtendedJWTConfigurationDto) APIMgtGatewayJWTGeneratorImpl(org.wso2.carbon.apimgt.common.gateway.jwtgenerator.APIMgtGatewayJWTGeneratorImpl) APIManagerConfigurationService(org.wso2.carbon.apimgt.impl.APIManagerConfigurationService) AbstractAPIMgtGatewayJWTGenerator(org.wso2.carbon.apimgt.common.gateway.jwtgenerator.AbstractAPIMgtGatewayJWTGenerator) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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