use of org.wso2.carbon.registry.core.session.UserRegistry in project carbon-apimgt by wso2.
the class CustomAPIIndexerTest method init.
@Before
public void init() throws RegistryException {
PowerMockito.mockStatic(GovernanceUtils.class);
PowerMockito.mockStatic(IndexingManager.class);
IndexingManager indexingManager = Mockito.mock(IndexingManager.class);
PowerMockito.when(IndexingManager.getInstance()).thenReturn(indexingManager);
userRegistry = Mockito.mock(UserRegistry.class);
Mockito.doReturn(userRegistry).when(indexingManager).getRegistry(Mockito.anyInt());
Mockito.doReturn(true).when(userRegistry).resourceExists(Mockito.anyString());
PowerMockito.when(GovernanceUtils.getGovernanceSystemRegistry(userRegistry)).thenReturn(userRegistry);
String path = RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH + "/api";
file2Index = new AsyncIndexer.File2Index("".getBytes(), null, path, -1234, "");
indexer = new CustomAPIIndexer();
}
use of org.wso2.carbon.registry.core.session.UserRegistry in project carbon-apimgt by wso2.
the class AbstractAPIManagerTestCase method testGetSwaggerDefinitionTimeStamps.
@Test
public void testGetSwaggerDefinitionTimeStamps() throws Exception {
APIIdentifier identifier = getAPIIdentifier(SAMPLE_API_NAME, API_PROVIDER, SAMPLE_API_VERSION);
UserRegistry registry = Mockito.mock(UserRegistry.class);
Mockito.when(tenantManager.getTenantId(Mockito.anyString())).thenThrow(UserStoreException.class).thenReturn(-1234);
PowerMockito.mockStatic(OASParserUtil.class);
Mockito.when(registryService.getGovernanceUserRegistry(Mockito.anyString(), Mockito.anyInt())).thenThrow(RegistryException.class).thenReturn(registry);
AbstractAPIManager abstractAPIManager = new AbstractAPIManagerWrapper(null, registryService, registry, tenantManager);
Assert.assertNull(abstractAPIManager.getSwaggerDefinitionTimeStamps(identifier));
Assert.assertNull(abstractAPIManager.getSwaggerDefinitionTimeStamps(identifier));
abstractAPIManager.tenantDomain = SAMPLE_TENANT_DOMAIN_1;
Map<String, String> result = new HashMap<String, String>();
result.put("swagger1", "scopes:apim_create,resources:{get:/*}");
result.put("swagger2", "scopes:apim_view,resources:{get:/menu}");
// Mockito.when(apiDefinitionFromOpenAPISpec.getAPIOpenAPIDefinitionTimeStamps((APIIdentifier) Mockito.any(),
// (org.wso2.carbon.registry.api.Registry) Mockito.any())).thenReturn(result);
// Assert.assertEquals(abstractAPIManager.getSwaggerDefinitionTimeStamps(identifier).size(),2);
// abstractAPIManager.tenantDomain = SAMPLE_TENANT_DOMAIN;
// result.put("swagger3","");
// Assert.assertEquals(abstractAPIManager.getSwaggerDefinitionTimeStamps(identifier).size(),3);
}
use of org.wso2.carbon.registry.core.session.UserRegistry in project carbon-apimgt by wso2.
the class GatewayUtils method getRegistry.
/**
* Get the config system registry for tenants
*
* @param tenantDomain - The tenant domain
* @return - A UserRegistry instance for the tenant
* @throws APIManagementException
*/
public static UserRegistry getRegistry(String tenantDomain) throws APIManagementException {
PrivilegedCarbonContext.startTenantFlow();
if (tenantDomain != null && StringUtils.isNotEmpty(tenantDomain)) {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
} else {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true);
}
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
UserRegistry registry;
try {
registry = RegistryServiceHolder.getInstance().getRegistryService().getConfigSystemRegistry(tenantId);
} catch (RegistryException e) {
String msg = "Failed to get registry instance for the tenant : " + tenantDomain + e.getMessage();
throw new APIManagementException(msg, e);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
return registry;
}
use of org.wso2.carbon.registry.core.session.UserRegistry in project carbon-apimgt by wso2.
the class APIManagerComponent method addDefinedSequencesToRegistry.
private void addDefinedSequencesToRegistry() throws APIManagementException {
try {
RegistryService registryService = ServiceReferenceHolder.getInstance().getRegistryService();
UserRegistry registry = registryService.getGovernanceSystemRegistry();
// Add all custom in,out and fault sequences to registry
APIUtil.addDefinedAllSequencesToRegistry(registry, APIConstants.API_CUSTOM_SEQUENCE_TYPE_IN);
APIUtil.addDefinedAllSequencesToRegistry(registry, APIConstants.API_CUSTOM_SEQUENCE_TYPE_OUT);
APIUtil.addDefinedAllSequencesToRegistry(registry, APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT);
} catch (RegistryException e) {
throw new APIManagementException("Error while saving defined sequences to the registry ", e);
}
}
use of org.wso2.carbon.registry.core.session.UserRegistry in project carbon-apimgt by wso2.
the class APIUtilTierTest method testGetAllTiers.
@Test
public void testGetAllTiers() throws APIManagementException, RegistryException {
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
APIManagerConfigurationService amConfigService = Mockito.mock(APIManagerConfigurationService.class);
APIManagerConfiguration amConfig = Mockito.mock(APIManagerConfiguration.class);
ApiMgtDAO apiMgtDAO = Mockito.mock(ApiMgtDAO.class);
ThrottleProperties throttleProperties = Mockito.mock(ThrottleProperties.class);
RegistryService registryService = Mockito.mock(RegistryService.class);
UserRegistry userRegistry = Mockito.mock(UserRegistry.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
PowerMockito.mockStatic(ApiMgtDAO.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
PowerMockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO);
Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(amConfigService);
Mockito.when(amConfigService.getAPIManagerConfiguration()).thenReturn(amConfig);
Mockito.when(amConfig.getThrottleProperties()).thenReturn(throttleProperties);
Mockito.when(throttleProperties.isEnableUnlimitedTier()).thenReturn(true);
Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
Mockito.when(registryService.getGovernanceSystemRegistry()).thenReturn(userRegistry);
SubscriptionPolicy[] policies = new SubscriptionPolicy[3];
policies[0] = TestUtils.getUniqueSubscriptionPolicyWithBandwidthLimit();
policies[1] = TestUtils.getUniqueSubscriptionPolicyWithRequestCountLimit();
policies[2] = TestUtils.getUniqueSubscriptionPolicyWithBandwidthLimit();
Mockito.when(apiMgtDAO.getSubscriptionPolicies(Mockito.anyInt())).thenReturn(policies);
// IsEnabled true scenario
Assert.assertEquals(3, APIUtil.getAllTiers().size());
}
Aggregations