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"));
}
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);
}
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());
}
Aggregations