use of org.wso2.carbon.apimgt.impl.dao.ScopesDAO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testIsGlobalPolicyKeyTemplateExists.
@Test
public void testIsGlobalPolicyKeyTemplateExists() throws APIManagementException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
GlobalPolicy globalPolicy = Mockito.mock(GlobalPolicy.class);
Mockito.when(apimgtDAO.isKeyTemplatesExist(globalPolicy)).thenReturn(true);
assertTrue(apiProvider.isGlobalPolicyKeyTemplateExists(globalPolicy));
}
use of org.wso2.carbon.apimgt.impl.dao.ScopesDAO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetSecurityAuditAttributesFromGlobalConfig.
/**
* This method tests the retrieval of API Security Audit Properties from the Global Config
* (i.e. deployment.toml)
* @throws APIManagementException
*/
@Test
public void testGetSecurityAuditAttributesFromGlobalConfig() throws APIManagementException {
// Instantiate required variables
String username = "admin";
String apiToken = "2780f0ca-3423-435f-0e9f-a634e0do65915";
String collectionId = "8750f8ca-34f9-4baf-8b9f-c6854ed06534";
String global = "true";
// Mock retrieving the tenant domain
PowerMockito.mockStatic(MultitenantUtils.class);
Mockito.when(MultitenantUtils.getTenantDomain(username)).thenReturn("carbon.super");
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
// Create a mock APIManagerConfiguration Object for retrieving properties from the deployment.toml
APIManagerConfiguration apiManagerConfiguration = PowerMockito.mock(APIManagerConfiguration.class);
ServiceReferenceHolder serviceReferenceHolder = PowerMockito.mock(ServiceReferenceHolder.class);
APIManagerConfigurationService apiManagerConfigurationService = PowerMockito.mock(APIManagerConfigurationService.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
// Mock the properties read from the deployment.toml
Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.API_SECURITY_AUDIT_API_TOKEN)).thenReturn(apiToken);
Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.API_SECURITY_AUDIT_CID)).thenReturn(collectionId);
Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.API_SECURITY_AUDIT_GLOBAL)).thenReturn(global);
// Pass the mocked properties into the getSecurityAuditAttributesFromConfig method
JSONObject jsonObject = apiProvider.getSecurityAuditAttributesFromConfig(username);
// Compare the properties from the returned object and the mocked ones.
Assert.assertEquals(jsonObject.get(APIConstants.SECURITY_AUDIT_API_TOKEN), apiToken);
Assert.assertEquals(jsonObject.get(APIConstants.SECURITY_AUDIT_COLLECTION_ID), collectionId);
}
use of org.wso2.carbon.apimgt.impl.dao.ScopesDAO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetCustomInSequences.
@Test
public void testGetCustomInSequences() throws Exception {
APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.1");
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
mockSequences(APIConstants.API_CUSTOM_INSEQUENCE_LOCATION, APIConstants.API_CUSTOM_SEQUENCE_TYPE_IN, apiId);
List<String> sequenceList = apiProvider.getCustomInSequences(apiId);
Assert.assertNotNull(sequenceList);
Assert.assertEquals(2, sequenceList.size());
Assert.assertTrue(sequenceList.contains("fault-seq"));
Assert.assertTrue(sequenceList.contains("custom-fault-seq"));
// OMException when building OMElement
PowerMockito.when(APIUtil.buildOMElement(any(InputStream.class))).thenThrow(new OMException());
apiProvider.getCustomInSequences(apiId);
// org.wso2.carbon.registry.api.RegistryException
ServiceReferenceHolder sh = PowerMockito.mock(ServiceReferenceHolder.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(sh);
RegistryService registryService = Mockito.mock(RegistryService.class);
PowerMockito.when(sh.getRegistryService()).thenReturn(registryService);
UserRegistry registry = Mockito.mock(UserRegistry.class);
PowerMockito.when(registryService.getGovernanceSystemRegistry(Matchers.anyInt())).thenReturn(registry);
Mockito.when(registry.resourceExists(APIConstants.API_CUSTOM_INSEQUENCE_LOCATION)).thenThrow(org.wso2.carbon.registry.api.RegistryException.class);
String msg = "Issue is in getting custom InSequences from the Registry";
try {
apiProvider.getCustomInSequences(apiId);
} catch (APIManagementException e) {
Assert.assertEquals(msg, e.getMessage());
}
// Registry Exception
PowerMockito.when(registryService.getGovernanceSystemRegistry(Matchers.anyInt())).thenThrow(RegistryException.class);
try {
apiProvider.getCustomInSequences(apiId);
} catch (APIManagementException e) {
Assert.assertEquals(msg, e.getMessage());
}
}
use of org.wso2.carbon.apimgt.impl.dao.ScopesDAO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetAPIsByProvider.
@Test
public void testGetAPIsByProvider() throws RegistryException, UserStoreException, APIManagementException {
String providerId = "admin";
API api1 = new API(new APIIdentifier("admin", "API1", "1.0.0"));
API api2 = new API(new APIIdentifier("admin", "API2", "1.0.0"));
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
prepareForGetAPIsByProvider(artifactManager, apiProvider, providerId, api1, api2);
List<API> apiResponse = apiProvider.getAPIsByProvider(providerId);
Assert.assertEquals(2, apiResponse.size());
Assert.assertEquals("API1", apiResponse.get(0).getId().getApiName());
Mockito.when(apiProvider.registry.getAspectActions(Matchers.anyString(), Matchers.anyString())).thenThrow(RegistryException.class);
try {
apiProvider.getAPIsByProvider(providerId);
} catch (APIManagementException e) {
Assert.assertEquals("Failed to get APIs for provider : " + providerId, e.getMessage());
}
}
use of org.wso2.carbon.apimgt.impl.dao.ScopesDAO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetApplicationPolicy.
@Test
public void testGetApplicationPolicy() throws APIManagementException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
PowerMockito.when(APIUtil.getTenantId("testUser")).thenReturn(1111);
ApplicationPolicy applicationPolicy = Mockito.mock(ApplicationPolicy.class);
Mockito.when(apimgtDAO.getApplicationPolicy("testPolicy", 1111)).thenReturn(applicationPolicy);
assertNotNull(apiProvider.getApplicationPolicy("testUser", "testPolicy"));
}
Aggregations