use of org.wso2.carbon.apimgt.api.APIManagementException in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testGetSubscribersOfProviderException.
@Test(description = "Exception when getting subscriptions for a provider's APIs", expectedExceptions = APIManagementException.class)
public void testGetSubscribersOfProviderException() throws APIManagementException {
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiSubscriptionDAO);
Mockito.when(apiSubscriptionDAO.getAPISubscriptionsForUser(1, 2, USER)).thenThrow(new APIMgtDAOException("Unable to fetch subscriptions APIs of provider " + USER));
apiPublisher.getSubscribersOfProvider(1, 2, USER);
}
use of org.wso2.carbon.apimgt.api.APIManagementException in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUploadDocumentationFileException.
@Test(description = "Exception when uploading Documentation File", expectedExceptions = APIManagementException.class)
public void testUploadDocumentationFileException() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
Mockito.doThrow(new APIMgtDAOException("Unable to add documentation with file")).when(apiDAO).addDocumentFileContent(DOC_ID, null, "text/plain", USER);
apiPublisher.uploadDocumentationFile(DOC_ID, null, "text/plain");
}
use of org.wso2.carbon.apimgt.api.APIManagementException in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testGetLifeCycleEvents.
@Test(description = "Get lifecycle events list of an API")
public void testGetLifeCycleEvents() throws APIManagementException, LifecycleException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
APIGateway gateway = Mockito.mock(APIGateway.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiLifecycleManager, gateway);
API api = SampleTestObjectCreator.createDefaultAPI().build();
String uuid = api.getId();
String lifecycleId = api.getLifecycleInstanceId();
List<LifecycleHistoryBean> lifecycleHistoryBeanList = new ArrayList<>();
LifecycleHistoryBean bean = new LifecycleHistoryBean();
bean.setPreviousState(APIStatus.CREATED.getStatus());
bean.setPostState(APIStatus.DEPRECATED.getStatus());
bean.setUser(USER);
lifecycleHistoryBeanList.add(bean);
Mockito.when(apiDAO.getAPISummary(uuid)).thenReturn(api);
Mockito.doReturn(lifecycleHistoryBeanList).when(apiLifecycleManager).getLifecycleHistory(lifecycleId);
apiPublisher.getLifeCycleEvents(uuid);
}
use of org.wso2.carbon.apimgt.api.APIManagementException in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testRemoveDocumentationInfoException.
@Test(description = "Exception when removing Documentation Info", expectedExceptions = APIManagementException.class)
public void testRemoveDocumentationInfoException() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
Mockito.doThrow(new APIMgtDAOException("Unable to add documentation with file")).when(apiDAO).deleteDocument(DOC_ID);
apiPublisher.removeDocumentation(DOC_ID);
}
use of org.wso2.carbon.apimgt.api.APIManagementException in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testAddExistingScopeToApi2.
@Test(description = "Add existing Scope to API")
public void testAddExistingScopeToApi2() throws APIManagementException, IOException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
API api = SampleTestObjectCreator.createDefaultAPI().build();
String uuid = api.getId();
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
APIGateway gateway = Mockito.mock(APIGateway.class);
IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
KeyManager keyManager = Mockito.mock(KeyManager.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(identityProvider, apiDAO, gatewaySourceGenerator, gateway, keyManager);
String oldSwagger = IOUtils.toString(new FileInputStream("src" + File.separator + "test" + File.separator + "resources" + File.separator + "swagger" + File.separator + "swaggerWithAuthorization" + ".yaml"));
Scope scope = new Scope("api_delete", "api_delete");
Mockito.when(apiDAO.getApiSwaggerDefinition(uuid)).thenReturn(oldSwagger);
Mockito.when(keyManager.registerScope(scope)).thenReturn(false);
try {
apiPublisher.addScopeToTheApi(api.getId(), scope);
Assert.fail();
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Scope already registered");
}
}
Aggregations