use of org.wso2.carbon.apimgt.api.APIProvider in project carbon-apimgt by wso2.
the class APIProviderImplTest method testDeleteBlockCondition.
@Test
public void testDeleteBlockCondition() throws APIManagementException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
BlockConditionsDTO blockConditionsDTO = new BlockConditionsDTO();
Mockito.when(apimgtDAO.getBlockCondition(1111)).thenReturn(blockConditionsDTO);
Mockito.when(apimgtDAO.deleteBlockCondition(1111)).thenReturn(false, true);
// deleteState false
assertFalse(apiProvider.deleteBlockCondition(1111));
// deleteState true
assertTrue(apiProvider.deleteBlockCondition(1111));
}
use of org.wso2.carbon.apimgt.api.APIProvider in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetCustomFaultSequences.
@Test
public void testGetCustomFaultSequences() throws Exception {
APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.1");
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
mockSequences(APIConstants.API_CUSTOM_FAULTSEQUENCE_LOCATION, APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT, apiId);
List<String> sequenceList = apiProvider.getCustomFaultSequences(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.getCustomFaultSequences(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_FAULTSEQUENCE_LOCATION)).thenThrow(org.wso2.carbon.registry.api.RegistryException.class);
String msg = "Error while processing the " + APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT + " sequences of " + apiId + " in the registry";
try {
apiProvider.getCustomFaultSequences(apiId);
} catch (APIManagementException e) {
Assert.assertEquals(msg, e.getMessage());
}
// Registry Exception
PowerMockito.when(registryService.getGovernanceSystemRegistry(Matchers.anyInt())).thenThrow(RegistryException.class);
try {
apiProvider.getCustomFaultSequences(apiId);
} catch (APIManagementException e) {
Assert.assertEquals("Error while retrieving registry for tenant -1", e.getMessage());
}
}
use of org.wso2.carbon.apimgt.api.APIProvider in project carbon-apimgt by wso2.
the class APIProviderImplTest method testSearchAPIs.
@Test
public void testSearchAPIs() throws APIManagementException, RegistryException {
// APIs of the provider
API api1 = new API(new APIIdentifier("admin", "API1", "1.0.1"));
api1.setContext("api1context");
api1.setStatus(APIConstants.PUBLISHED);
api1.setDescription("API 1 Desciption");
Set<URITemplate> uriTemplates = new HashSet<URITemplate>();
URITemplate uriTemplate1 = new URITemplate();
uriTemplate1.setHTTPVerb("POST");
uriTemplate1.setAuthType("Application");
uriTemplate1.setUriTemplate("/add");
uriTemplate1.setThrottlingTier("Gold");
uriTemplates.add(uriTemplate1);
api1.setUriTemplates(uriTemplates);
API api2 = new API(new APIIdentifier("admin", "API2", "1.0.0"));
api2.setContext("api2context");
api2.setStatus(APIConstants.CREATED);
api2.setDescription("API 2 Desciption");
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
prepareForGetAPIsByProvider(artifactManager, apiProvider, "admin", api1, api2);
// Search by Name matching both APIs
List<API> foundApiList0 = apiProvider.searchAPIs("API", "Name", "admin");
Assert.assertNotNull(foundApiList0);
Assert.assertEquals(2, foundApiList0.size());
// Search by exact name
List<API> foundApiList1 = apiProvider.searchAPIs("API1", "Name", "admin");
Assert.assertNotNull(foundApiList1);
Assert.assertEquals(1, foundApiList1.size());
// Search by exact provider
List<API> foundApiList2 = apiProvider.searchAPIs("admin", "Provider", "admin");
Assert.assertNotNull(foundApiList2);
Assert.assertEquals(2, foundApiList2.size());
// Search by exact version
List<API> foundApiList3 = apiProvider.searchAPIs("1.0.0", "Version", "admin");
Assert.assertNotNull(foundApiList3);
Assert.assertEquals(1, foundApiList3.size());
// Search by exact context
List<API> foundApiList4 = apiProvider.searchAPIs("api1context", "Context", "admin");
Assert.assertNotNull(foundApiList4);
Assert.assertEquals(1, foundApiList4.size());
// Search by exact context
List<API> foundApiList5 = apiProvider.searchAPIs("api2context", "Context", "admin");
Assert.assertNotNull(foundApiList5);
Assert.assertEquals(1, foundApiList5.size());
// Search by wrong context
List<API> foundApiList6 = apiProvider.searchAPIs("test", "Context", "admin");
Assert.assertNotNull(foundApiList6);
Assert.assertEquals(0, foundApiList6.size());
// Search by status
List<API> foundApiList7 = apiProvider.searchAPIs("Published", "Status", "admin");
Assert.assertNotNull(foundApiList7);
Assert.assertEquals(1, foundApiList7.size());
// Search by Description
List<API> foundApiList8 = apiProvider.searchAPIs("API 1 Desciption", "Description", "admin");
Assert.assertNotNull(foundApiList8);
Assert.assertEquals(1, foundApiList8.size());
// Search by Description
List<API> foundApiList9 = apiProvider.searchAPIs("API", "Description", "admin");
Assert.assertNotNull(foundApiList9);
Assert.assertEquals(2, foundApiList9.size());
}
use of org.wso2.carbon.apimgt.api.APIProvider in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetAPIPolicy.
@Test
public void testGetAPIPolicy() throws APIManagementException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
PowerMockito.when(APIUtil.getTenantId("testUser")).thenReturn(1111);
APIPolicy apiPolicy = Mockito.mock(APIPolicy.class);
Mockito.when(apimgtDAO.getAPIPolicy("testPolicy", 1111)).thenReturn(apiPolicy);
assertNotNull(apiProvider.getAPIPolicy("testUser", "testPolicy"));
}
use of org.wso2.carbon.apimgt.api.APIProvider in project carbon-apimgt by wso2.
the class APIProviderImplTest method testDeleteBlockConditionByUUID.
@Test
public void testDeleteBlockConditionByUUID() throws APIManagementException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
BlockConditionsDTO blockConditionsDTO = new BlockConditionsDTO();
blockConditionsDTO.setConditionType("testType");
blockConditionsDTO.setConditionValue("USER");
blockConditionsDTO.setConditionId(1111);
Mockito.when(apimgtDAO.getBlockConditionByUUID("testId")).thenReturn(blockConditionsDTO);
Mockito.when(apimgtDAO.deleteBlockCondition(1111)).thenReturn(false, true);
PowerMockito.mockStatic(MultitenantUtils.class);
PowerMockito.when(MultitenantUtils.getTenantAwareUsername("User")).thenReturn("testValue");
// deleteState false
assertFalse(apiProvider.deleteBlockConditionByUUID("testId"));
// deleteState true
assertTrue(apiProvider.deleteBlockConditionByUUID("testId"));
}
Aggregations