use of org.wso2.carbon.apimgt.impl.APIManagerConfiguration in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetSecurityAuditAttributesFromAllConfigs.
/**
* This method tests the retrieval of API Security Audit Properties when both the tenant and global
* configs contain values
* @throws APIManagementException
* @throws RegistryException
*/
@Test
public void testGetSecurityAuditAttributesFromAllConfigs() throws APIManagementException, RegistryException {
// Mock values from global config
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);
// Mock values from tenant config
final int tenantId = -1234;
String apiToken1 = "1234f0ca-9879-112f-0e8f-a098e0do12456";
String collectionId1 = "467f8ca-40f8-4baf-8b0f-c6854ed04653";
boolean overrideGlobal = true;
// Sample JSONObject for mocking
JSONObject jsonObject = new JSONObject();
jsonObject.put("apiToken", apiToken1);
jsonObject.put("collectionId", collectionId1);
jsonObject.put("overrideGlobal", overrideGlobal);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
RegistryService registryService = Mockito.mock(RegistryService.class);
UserRegistry userRegistry = Mockito.mock(UserRegistry.class);
Resource resource = Mockito.mock(Resource.class);
Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
PowerMockito.mockStatic(APIUtil.class);
Mockito.when(APIUtil.getSecurityAuditAttributesFromRegistry(superTenantDomain)).thenReturn(jsonObject);
// Test the object to be returned when overrideGlobal is true
JSONObject jsonObject1 = apiProvider.getSecurityAuditAttributesFromConfig("admin");
Assert.assertEquals(jsonObject1.get(APIConstants.SECURITY_AUDIT_API_TOKEN), apiToken1);
Assert.assertEquals(jsonObject1.get(APIConstants.SECURITY_AUDIT_COLLECTION_ID), collectionId1);
// Test the object to be returned when overrideGlobal is false
jsonObject.put("overrideGlobal", false);
JSONObject jsonObject2 = apiProvider.getSecurityAuditAttributesFromConfig("admin");
Assert.assertEquals(jsonObject2.get(APIConstants.SECURITY_AUDIT_API_TOKEN), apiToken);
Assert.assertEquals(jsonObject2.get(APIConstants.SECURITY_AUDIT_COLLECTION_ID), collectionId);
}
use of org.wso2.carbon.apimgt.impl.APIManagerConfiguration in project carbon-apimgt by wso2.
the class APIProviderImplTest method prepareForChangeLifeCycleStatus.
/**
* This method can be used when invoking changeLifeCycleStatus()
*/
private void prepareForChangeLifeCycleStatus(APIProviderImplWrapper apiProvider, ApiMgtDAO apimgtDAO, APIIdentifier apiId, GenericArtifact apiArtifact) throws GovernanceException, APIManagementException, FaultGatewaysException, WorkflowException, XMLStreamException {
Mockito.when(APIUtil.getAPIArtifact(apiId, apiProvider.registry)).thenReturn(apiArtifact);
Mockito.when(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_PROVIDER)).thenReturn("admin");
Mockito.when(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_NAME)).thenReturn("API1");
Mockito.when(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_VERSION)).thenReturn("1.0.0");
Mockito.when(apiArtifact.getLifecycleState()).thenReturn("CREATED");
Mockito.when(apimgtDAO.getAPIID(apiUUID)).thenReturn(1);
// Workflow has not started, this will trigger the executor
WorkflowDTO wfDTO1 = Mockito.mock(WorkflowDTO.class);
Mockito.when(wfDTO1.getStatus()).thenReturn(null);
WorkflowDTO wfDTO2 = Mockito.mock(WorkflowDTO.class);
Mockito.when(wfDTO2.getStatus()).thenReturn(WorkflowStatus.APPROVED);
Mockito.when(apimgtDAO.retrieveWorkflowFromInternalReference("1", WorkflowConstants.WF_TYPE_AM_API_STATE)).thenReturn(wfDTO1, wfDTO2);
ServiceReferenceHolder sh = TestUtils.getServiceReferenceHolder();
APIManagerConfigurationService amConfigService = Mockito.mock(APIManagerConfigurationService.class);
APIManagerConfiguration amConfig = Mockito.mock(APIManagerConfiguration.class);
PowerMockito.when(sh.getAPIManagerConfigurationService()).thenReturn(amConfigService);
PowerMockito.when(amConfigService.getAPIManagerConfiguration()).thenReturn(amConfig);
WorkflowProperties workflowProperties = Mockito.mock(WorkflowProperties.class);
Mockito.when(workflowProperties.getWorkflowCallbackAPI()).thenReturn("");
Mockito.when(amConfig.getWorkflowProperties()).thenReturn(workflowProperties);
WorkflowExecutorFactory wfe = PowerMockito.mock(WorkflowExecutorFactory.class);
Mockito.when(WorkflowExecutorFactory.getInstance()).thenReturn(wfe);
WorkflowExecutor apiStateWFExecutor = new APIStateChangeSimpleWorkflowExecutor();
Mockito.when(wfe.getWorkflowExecutor(WorkflowConstants.WF_TYPE_AM_API_STATE)).thenReturn(apiStateWFExecutor);
Mockito.when(APIUtil.isAnalyticsEnabled()).thenReturn(false);
}
use of org.wso2.carbon.apimgt.impl.APIManagerConfiguration in project carbon-apimgt by wso2.
the class APIProviderImplTest method testIsSynapseGateway.
@Test
public void testIsSynapseGateway() throws APIManagementException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
ServiceReferenceHolder sh = PowerMockito.mock(ServiceReferenceHolder.class);
APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(sh);
Mockito.when(sh.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
Mockito.when(apiManagerConfiguration.getFirstProperty(Mockito.anyString())).thenReturn("synapse");
assertTrue(apiProvider.isSynapseGateway());
}
use of org.wso2.carbon.apimgt.impl.APIManagerConfiguration in project carbon-apimgt by wso2.
the class APIClientGenerationManagerWrapper method getAPIManagerConfiguration.
@Override
protected APIManagerConfiguration getAPIManagerConfiguration() {
APIManagerConfiguration apiManagerConfiguration = new APIManagerConfiguration();
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("amConfig.xml").getFile());
try {
apiManagerConfiguration.load(file.getPath().toString());
} catch (APIManagementException e) {
log.error("Error while reading configs from file api-manager.xml", e);
}
return apiManagerConfiguration;
}
use of org.wso2.carbon.apimgt.impl.APIManagerConfiguration in project carbon-apimgt by wso2.
the class ThrottlingPolicyTemplateBuilderTest method setUp.
@Before
public void setUp() {
System.setProperty("carbon.home", ThrottlingPolicyTemplateBuilderTest.class.getResource("/").getFile());
templateBuilder = new ThrottlePolicyTemplateBuilder();
PowerMockito.mockStatic(ServiceReferenceHolder.class);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.VELOCITY_LOGGER)).thenReturn("not-defined");
Mockito.when(serviceReferenceHolder.getAPIMConfiguration()).thenReturn(apiManagerConfiguration);
}
Aggregations