use of org.wso2.carbon.registry.core.exceptions.RegistryException in project carbon-apimgt by wso2.
the class CustomAPIIndexerTest method testIndexDocumentForNewAPI.
/**
* This method checks the indexer's behaviour for new APIs which does not have the relevant properties.
*
* @throws RegistryException Registry Exception.
* @throws APIManagementException API Management Exception.
*/
@Test
public void testIndexDocumentForNewAPI() throws APIManagementException, RegistryException {
Resource resource = new ResourceImpl();
PowerMockito.mockStatic(APIUtil.class);
GenericArtifactManager artifactManager = Mockito.mock(GenericArtifactManager.class);
PowerMockito.when(APIUtil.getArtifactManager((UserRegistry) (Mockito.anyObject()), Mockito.anyString())).thenReturn(artifactManager);
GenericArtifact genericArtifact = Mockito.mock(GenericArtifact.class);
Mockito.when(artifactManager.getGenericArtifact(Mockito.anyString())).thenReturn(genericArtifact);
Mockito.when(genericArtifact.getAttribute(APIConstants.API_OVERVIEW_VISIBILITY)).thenReturn("public");
PowerMockito.when(APIUtil.getAPI(genericArtifact, userRegistry)).thenReturn(Mockito.mock(API.class));
resource.setProperty(APIConstants.ACCESS_CONTROL, APIConstants.NO_ACCESS_CONTROL);
resource.setProperty(APIConstants.PUBLISHER_ROLES, APIConstants.NULL_USER_ROLE_LIST);
resource.setProperty(APIConstants.STORE_VIEW_ROLES, APIConstants.NULL_USER_ROLE_LIST);
Mockito.doReturn(resource).when(userRegistry).get(Mockito.anyString());
indexer.getIndexedDocument(file2Index);
Assert.assertNull(APIConstants.CUSTOM_API_INDEXER_PROPERTY + " property was set for the API which does not " + "require migration", resource.getProperty(APIConstants.CUSTOM_API_INDEXER_PROPERTY));
}
use of org.wso2.carbon.registry.core.exceptions.RegistryException 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.exceptions.RegistryException in project carbon-apimgt by wso2.
the class TestUtils method mockAPIMConfiguration.
public static void mockAPIMConfiguration() throws RegistryException, UserStoreException, XMLStreamException {
ServiceReferenceHolder sh = mockRegistryAndUserRealm(-1234);
APIManagerConfigurationService amConfigService = Mockito.mock(APIManagerConfigurationService.class);
APIManagerConfiguration amConfig = Mockito.mock(APIManagerConfiguration.class);
PowerMockito.when(sh.getAPIManagerConfigurationService()).thenReturn(amConfigService);
PowerMockito.when(amConfigService.getAPIManagerConfiguration()).thenReturn(amConfig);
Map<String, Environment> apiGatewayEnvironments = new HashMap<String, Environment>();
Environment env1 = new Environment();
env1.setApiGatewayEndpoint("https://abc.com, http://abc.com");
apiGatewayEnvironments.put("PROD", env1);
// Mocking some commonly used configs
PowerMockito.when(amConfig.getApiGatewayEnvironments()).thenReturn(apiGatewayEnvironments);
PowerMockito.when(amConfig.getFirstProperty(APIConstants.API_GATEWAY_TYPE)).thenReturn(APIConstants.API_GATEWAY_TYPE_SYNAPSE);
PowerMockito.when(amConfig.getFirstProperty(APIConstants.API_PUBLISHER_ENABLE_API_DOC_VISIBILITY_LEVELS)).thenReturn("true", "false");
ThrottleProperties throttleProperties = new ThrottleProperties();
PowerMockito.when(amConfig.getThrottleProperties()).thenReturn(throttleProperties);
}
use of org.wso2.carbon.registry.core.exceptions.RegistryException 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.exceptions.RegistryException 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);
}
}
Aggregations