use of org.wso2.carbon.apimgt.api.APIProvider 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.api.APIProvider 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.apimgt.api.APIProvider in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetSecurityAuditAttributesFromTenantConfig.
/**
* This method tests the retrieval of API Security Audit Properties from the Tenant Config
* (i.e. tenant-conf.json)
* @throws RegistryException
* @throws APIManagementException
*/
@Test
public void testGetSecurityAuditAttributesFromTenantConfig() throws RegistryException, APIManagementException {
// Instantiating required variables
final int tenantId = -1234;
String apiToken = "1234f0ca-9879-112f-0e8f-a098e0do12456";
String collectionId = "467f8ca-40f8-4baf-8b0f-c6854ed04653";
boolean overrideGlobal = true;
// Sample JSONObject for mocking
JSONObject jsonObject = new JSONObject();
jsonObject.put("apiToken", apiToken);
jsonObject.put("collectionId", collectionId);
jsonObject.put("overrideGlobal", overrideGlobal);
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
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);
Mockito.when(registryService.getConfigSystemRegistry(tenantId)).thenReturn(userRegistry);
PowerMockito.mockStatic(APIUtil.class);
Mockito.when(APIUtil.getSecurityAuditAttributesFromRegistry(superTenantDomain)).thenReturn(jsonObject);
// Pass the mock values to the method call
JSONObject jsonObject1 = apiProvider.getSecurityAuditAttributesFromConfig("admin");
// Compare the API Token and Collection ID returned from the method call
Assert.assertEquals(jsonObject1.get(APIConstants.SECURITY_AUDIT_API_TOKEN), apiToken);
Assert.assertEquals(jsonObject1.get(APIConstants.SECURITY_AUDIT_COLLECTION_ID), collectionId);
}
use of org.wso2.carbon.apimgt.api.APIProvider in project carbon-apimgt by wso2.
the class APIProviderImplTest method testUpdateAPIsInExternalAPIStores.
@Test
public void testUpdateAPIsInExternalAPIStores() throws APIManagementException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.1");
API api = new API(apiId);
api.setContext("/test");
api.setStatus(APIConstants.CREATED);
api.setUuid(UUID.randomUUID().toString());
APIPublisher publisher = Mockito.mock(APIPublisher.class);
Set<APIStore> apiStores = new HashSet<APIStore>();
APIStore apiStore = new APIStore();
apiStore.setDisplayName("testName");
apiStore.setName("testStoreName");
apiStore.setPublisher(publisher);
apiStore.setEndpoint("testEndpoint");
apiStore.setType("testType");
apiStores.add(apiStore);
APIStore apiStore1 = new APIStore();
apiStore1.setDisplayName("testName1");
apiStore1.setName("testStoreName1");
apiStore1.setEndpoint("testEndpoint");
apiStore1.setType("testType");
apiStore1.setPublisher(publisher);
apiStores.add(apiStore1);
PowerMockito.when(APIUtil.getExternalStores(-1)).thenReturn(apiStores);
PowerMockito.when(APIUtil.isAPIsPublishToExternalAPIStores(-1)).thenReturn(true);
Mockito.when(apimgtDAO.getExternalAPIStoresDetails(api.getUuid())).thenReturn(apiStores);
Mockito.when(publisher.isAPIAvailable(api, apiStore)).thenReturn(true);
Mockito.when(publisher.isAPIAvailable(api, apiStore1)).thenReturn(true);
Mockito.when(APIUtil.getExternalAPIStore(apiStore.getName(), -1)).thenReturn(apiStore);
Mockito.when(APIUtil.getExternalAPIStore(apiStore1.getName(), -1)).thenReturn(apiStore1);
Assert.assertTrue(apiProvider.updateAPIsInExternalAPIStores(api, apiStores, true));
}
use of org.wso2.carbon.apimgt.api.APIProvider in project carbon-apimgt by wso2.
the class APIProviderImplTest method testUpdateBlockConditionByUUID.
@Test
public void testUpdateBlockConditionByUUID() throws APIManagementException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
Mockito.when(apimgtDAO.updateBlockConditionStateByUUID("testID", "testState")).thenReturn(false, true);
BlockConditionsDTO blockConditionsDTO = new BlockConditionsDTO();
blockConditionsDTO.setConditionType("testType");
blockConditionsDTO.setConditionValue("USER");
Mockito.when(apimgtDAO.getBlockConditionByUUID("testState")).thenReturn(blockConditionsDTO);
// updateState false
assertFalse(apiProvider.updateBlockConditionByUUID("testID", "testState"));
// updateState true
assertTrue(apiProvider.updateBlockConditionByUUID("testID", "testState"));
}
Aggregations