Search in sources :

Example 41 with RegistryException

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));
}
Also used : GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) ResourceImpl(org.wso2.carbon.registry.core.ResourceImpl) GenericArtifactManager(org.wso2.carbon.governance.api.generic.GenericArtifactManager) Resource(org.wso2.carbon.registry.core.Resource) API(org.wso2.carbon.apimgt.api.model.API) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 42 with RegistryException

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();
}
Also used : IndexingManager(org.wso2.carbon.registry.indexing.IndexingManager) AsyncIndexer(org.wso2.carbon.registry.indexing.AsyncIndexer) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) Before(org.junit.Before)

Example 43 with RegistryException

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);
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) HashMap(java.util.HashMap) Environment(org.wso2.carbon.apimgt.api.model.Environment) ThrottleProperties(org.wso2.carbon.apimgt.impl.dto.ThrottleProperties)

Example 44 with RegistryException

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;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Example 45 with RegistryException

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);
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) RegistryService(org.wso2.carbon.registry.core.service.RegistryService) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Aggregations

RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)235 Resource (org.wso2.carbon.registry.core.Resource)196 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)167 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)145 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)104 Registry (org.wso2.carbon.registry.core.Registry)95 Test (org.junit.Test)81 GenericArtifactManager (org.wso2.carbon.governance.api.generic.GenericArtifactManager)81 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)75 APIProductResource (org.wso2.carbon.apimgt.api.model.APIProductResource)70 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)67 APIPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException)61 UserStoreException (org.wso2.carbon.user.api.UserStoreException)60 API (org.wso2.carbon.apimgt.api.model.API)58 IOException (java.io.IOException)57 ArrayList (java.util.ArrayList)55 QName (javax.xml.namespace.QName)42 APIResource (org.wso2.carbon.apimgt.api.doc.model.APIResource)40 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)40 GovernanceException (org.wso2.carbon.governance.api.exception.GovernanceException)40