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