Search in sources :

Example 1 with RegistryContext

use of org.wso2.carbon.registry.core.config.RegistryContext in project carbon-apimgt by wso2.

the class APIProviderImplTest method testGetProvider.

@Test
public void testGetProvider() throws APIManagementException, RegistryException {
    APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
    Mockito.when(APIUtil.getMountedPath((RegistryContext) Mockito.anyObject(), Mockito.anyString())).thenReturn("testPath");
    UserRegistry userReg = Mockito.mock(UserRegistry.class);
    Resource resource = Mockito.mock(Resource.class);
    Mockito.when(apiProvider.registry.get("testPath/providers/testProvider")).thenReturn(resource);
    Mockito.when(resource.getUUID()).thenReturn("testID");
    PowerMockito.when(APIUtil.getArtifactManager(userReg, APIConstants.API_KEY)).thenReturn(artifactManager);
    GenericArtifact providerArtifact = Mockito.mock(GenericArtifact.class);
    Mockito.when(artifactManager.getGenericArtifact("testID")).thenReturn(providerArtifact);
    Provider provider = Mockito.mock(Provider.class);
    Mockito.when(APIUtil.getProvider(providerArtifact)).thenReturn(provider);
    Assert.assertNotNull(apiProvider.getProvider("testProvider"));
}
Also used : GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) Resource(org.wso2.carbon.registry.core.Resource) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) Provider(org.wso2.carbon.apimgt.api.model.Provider) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with RegistryContext

use of org.wso2.carbon.registry.core.config.RegistryContext in project carbon-apimgt by wso2.

the class RegistryCacheInvalidationServiceTestCase method setup.

@Before
public void setup() throws Exception {
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
    Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
    Mockito.when(tenantManager.getTenantId(tenantDomain)).thenReturn(6543);
    Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
    Mockito.when(registryService.getGovernanceSystemRegistry(6543)).thenReturn(userRegistry);
    PowerMockito.mockStatic(RegistryUtils.class);
    Mockito.when(userRegistry.getRegistryContext()).thenReturn(registryContext);
    System.setProperty(CARBON_HOME, "");
    PrivilegedCarbonContext privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class);
    PowerMockito.mockStatic(PrivilegedCarbonContext.class);
    PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext);
}
Also used : PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) Before(org.junit.Before)

Example 3 with RegistryContext

use of org.wso2.carbon.registry.core.config.RegistryContext in project carbon-apimgt by wso2.

the class AbstractAPIManagerTestCase method testConstructor.

@Test
public void testConstructor() throws Exception {
    ServiceReferenceHolderMockCreator holderMockCreator = new ServiceReferenceHolderMockCreator(1);
    ServiceReferenceHolderMockCreator.initContextService();
    holderMockCreator.initRegistryServiceMockCreator(false, new Object());
    RegistryAuthorizationManager registryAuthorizationManager = Mockito.mock(RegistryAuthorizationManager.class);
    Mockito.doThrow(UserStoreException.class).doNothing().when(registryAuthorizationManager).authorizeRole(Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
    PowerMockito.whenNew(RegistryAuthorizationManager.class).withAnyArguments().thenReturn(registryAuthorizationManager);
    PowerMockito.mockStatic(RegistryUtils.class);
    PowerMockito.when(RegistryUtils.getAbsolutePath((RegistryContext) Mockito.any(), Mockito.anyString())).thenReturn("/test");
    try {
        new AbstractAPIManager(null) {

            @Override
            public String getGraphqlSchema(APIIdentifier apiId) throws APIManagementException {
                return null;
            }

            @Override
            public API getLightweightAPIByUUID(String uuid, String organization) throws APIManagementException {
                return null;
            }

            @Override
            public Map<String, Object> searchPaginatedAPIs(String searchQuery, String organization, int start, int end, String sortBy, String sortOrder) throws APIManagementException {
                return null;
            }

            @Override
            public Map<String, Object> searchPaginatedContent(String searchQuery, String tenantDomain, int start, int end) throws APIManagementException {
                return null;
            }
        };
        Assert.fail("User store exception not thrown for error scenario");
    } catch (APIManagementException e) {
        Assert.assertTrue(e.getMessage().contains("Error while setting the permissions"));
    }
    PowerMockito.mockStatic(APIUtil.class);
    PowerMockito.doNothing().when(APIUtil.class, "loadTenantRegistry", Mockito.anyInt());
    PowerMockito.mockStatic(MultitenantUtils.class);
    PowerMockito.when(MultitenantUtils.getTenantDomain(Mockito.anyString())).thenReturn(SAMPLE_TENANT_DOMAIN_1);
    String userName = "admin";
    Mockito.verify(holderMockCreator.getRegistryServiceMockCreator().getMock().getConfigSystemRegistry(Mockito.anyInt()), Mockito.atLeastOnce());
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) RegistryAuthorizationManager(org.wso2.carbon.registry.core.jdbc.realm.RegistryAuthorizationManager) UserStoreException(org.wso2.carbon.user.core.UserStoreException) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Before (org.junit.Before)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)1 Provider (org.wso2.carbon.apimgt.api.model.Provider)1 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)1 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)1 Resource (org.wso2.carbon.registry.core.Resource)1 RegistryAuthorizationManager (org.wso2.carbon.registry.core.jdbc.realm.RegistryAuthorizationManager)1 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)1 UserStoreException (org.wso2.carbon.user.core.UserStoreException)1