use of org.wso2.carbon.apimgt.keymgt.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class ThrottlingPolicyTemplateBuilderTest method setUp.
@Before
public void setUp() {
System.setProperty("carbon.home", ThrottlingPolicyTemplateBuilderTest.class.getResource("/").getFile());
templateBuilder = new ThrottlePolicyTemplateBuilder();
PowerMockito.mockStatic(ServiceReferenceHolder.class);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.VELOCITY_LOGGER)).thenReturn("not-defined");
Mockito.when(serviceReferenceHolder.getAPIMConfiguration()).thenReturn(apiManagerConfiguration);
}
use of org.wso2.carbon.apimgt.keymgt.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.keymgt.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.keymgt.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.keymgt.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class AbstractAPIManagerTestCase method testGetPoliciesIncludeUnlimitedThrottletier.
@Test
public void testGetPoliciesIncludeUnlimitedThrottletier() throws APIManagementException, org.wso2.carbon.user.api.UserStoreException, RegistryException, XMLStreamException {
SubscriptionPolicy[] policies3 = { new SubscriptionPolicy("policy4"), new SubscriptionPolicy("policy5"), new SubscriptionPolicy("policy6") };
PowerMockito.mockStatic(APIUtil.class);
BDDMockito.when(APIUtil.getTenantId(Mockito.anyString())).thenReturn(-1234);
PowerMockito.when(APIUtil.replaceSystemProperty(Mockito.anyString())).thenAnswer((Answer<String>) invocation -> {
Object[] args = invocation.getArguments();
return (String) args[0];
});
AbstractAPIManager abstractAPIManager = new AbstractAPIManagerWrapper(apiMgtDAO);
Mockito.when(apiMgtDAO.getSubscriptionPolicies(Mockito.anyInt())).thenReturn(policies3);
ServiceReferenceHolder sh = mockRegistryAndUserRealm(-1234);
APIManagerConfigurationService amConfigService = Mockito.mock(APIManagerConfigurationService.class);
APIManagerConfiguration amConfig = Mockito.mock(APIManagerConfiguration.class);
ThrottleProperties throttleProperties = Mockito.mock(ThrottleProperties.class, Mockito.RETURNS_MOCKS);
PowerMockito.when(sh.getAPIManagerConfigurationService()).thenReturn(amConfigService);
PowerMockito.when(amConfigService.getAPIManagerConfiguration()).thenReturn(amConfig);
PowerMockito.when(amConfig.getThrottleProperties()).thenReturn(throttleProperties);
PowerMockito.when(throttleProperties.isEnableUnlimitedTier()).thenReturn(true);
Assert.assertEquals(3, abstractAPIManager.getPolicies(API_PROVIDER, PolicyConstants.POLICY_LEVEL_SUB).length);
}
Aggregations