use of org.wso2.carbon.apimgt.impl.APIManagerConfigurationService 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.APIManagerConfigurationService in project carbon-apimgt by wso2.
the class UserSignUpWSWorkflowExecutorTest method init.
@Before
public void init() throws Exception {
ServiceReferenceHolder serviceReferenceHolder = TestUtils.getServiceReferenceHolder();
ConfigurationContextService configurationContextService = Mockito.mock(ConfigurationContextService.class);
ConfigurationContext configurationContext = Mockito.mock(ConfigurationContext.class);
RealmService realmService = Mockito.mock(RealmService.class);
UserRealm userRealm = Mockito.mock(UserRealm.class);
userStoreManager = Mockito.mock(UserStoreManager.class);
TenantManager tenantManager = Mockito.mock(TenantManager.class);
apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
serviceClient = Mockito.mock(ServiceClient.class);
APIManagerConfigurationService apiManagerConfigurationService = new APIManagerConfigurationServiceImpl(apiManagerConfiguration);
PowerMockito.mockStatic(SelfSignUpUtil.class);
PowerMockito.mockStatic(CarbonUtils.class);
PowerMockito.mockStatic(APIUtil.class);
PowerMockito.when(APIUtil.isAnalyticsEnabled()).thenReturn(true);
PowerMockito.doNothing().when(CarbonUtils.class, "setBasicAccessSecurityHeaders", Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.any());
PowerMockito.when(serviceReferenceHolder.getContextService()).thenReturn(configurationContextService);
PowerMockito.when(configurationContextService.getClientConfigContext()).thenReturn(configurationContext);
PowerMockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
PowerMockito.whenNew(ServiceClient.class).withAnyArguments().thenReturn(serviceClient);
Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
Mockito.when(tenantManager.getTenantId(tenantDomain)).thenReturn(tenantID);
Mockito.when(tenantManager.getTenantId(tenantDomain)).thenReturn(tenantID);
Mockito.when(realmService.getTenantUserRealm(tenantID)).thenReturn(userRealm);
Mockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
apiMgtDAO = TestUtils.getApiMgtDAO();
userSignUpWSWorkflowExecutor = new UserSignUpWSWorkflowExecutor();
workflowDTO = new WorkflowDTO();
workflowDTO.setCallbackUrl(callBackURL);
workflowDTO.setTenantDomain(tenantDomain);
workflowDTO.setExternalWorkflowReference(externalWFReference);
workflowDTO.setWorkflowReference(testUsername + "@carbon.super");
}
Aggregations