use of org.wso2.carbon.apimgt.core.exception.APIManagementException in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testCreateNewAPIVersionAndGetAPIByUuidFailure.
@Test(description = "Create new API version with APIID and new API lifecycle add get failed", expectedExceptions = { APIMgtDAOException.class, APIManagementException.class })
public void testCreateNewAPIVersionAndGetAPIByUuidFailure() 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);
Mockito.when(apiDAO.getAPI("yyyyy")).thenThrow(new APIMgtDAOException(""));
apiPublisher.createNewAPIVersion("yyyyy", "2.0.0");
}
use of org.wso2.carbon.apimgt.core.exception.APIManagementException in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testAddApiDefinitionErrorGettingSwaggerResource.
@Test(description = "Response not 200 when getting swagger resource from url when adding api from swagger resource", expectedExceptions = APIManagementException.class)
public void testAddApiDefinitionErrorGettingSwaggerResource() throws APIManagementException, LifecycleException, IOException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
HttpURLConnection httpURLConnection = Mockito.mock(HttpURLConnection.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
Mockito.when(apiLifecycleManager.addLifecycle(APIMgtConstants.API_LIFECYCLE, USER)).thenReturn(new LifecycleState());
APIGateway gateway = Mockito.mock(APIGateway.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiLifecycleManager, gateway);
Mockito.when(httpURLConnection.getResponseCode()).thenReturn(400);
apiPublisher.addApiFromDefinition(httpURLConnection);
Mockito.verify(apiLifecycleManager, Mockito.times(0)).addLifecycle(APIMgtConstants.API_LIFECYCLE, USER);
}
use of org.wso2.carbon.apimgt.core.exception.APIManagementException in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUpdateDescription.
@Test(description = "Test add api with production endpoint")
public void testUpdateDescription() throws APIManagementException {
/**
* this test method verify the API Add with correct API object get invoked correctly
*/
Map<String, Endpoint> endpointMap = SampleTestObjectCreator.getMockEndpointMap();
API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI().id(UUID.randomUUID().toString()).endpoint(endpointMap);
apiBuilder.apiPermission("");
apiBuilder.permissionMap(null);
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
Mockito.when(apiDAO.getAPI(apiBuilder.getId())).thenReturn(apiBuilder.build());
GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
APIGateway gateway = Mockito.mock(APIGateway.class);
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.api, APIMgtConstants.DEFAULT_API_POLICY)).thenReturn(new APIPolicy(APIMgtConstants.DEFAULT_API_POLICY));
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, GOLD_TIER)).thenReturn(new SubscriptionPolicy(GOLD_TIER));
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, SILVER_TIER)).thenReturn(new SubscriptionPolicy(SILVER_TIER));
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, BRONZE_TIER)).thenReturn(new SubscriptionPolicy(BRONZE_TIER));
APIPublisherImpl apiPublisher = getApiPublisherImpl(identityProvider, apiDAO, apiLifecycleManager, gatewaySourceGenerator, gateway, policyDAO);
Mockito.when(apiDAO.getEndpoint(endpointMap.get(APIMgtConstants.PRODUCTION_ENDPOINT).getId())).thenReturn(endpointMap.get(APIMgtConstants.PRODUCTION_ENDPOINT));
Mockito.when(apiDAO.getEndpoint(endpointMap.get(APIMgtConstants.SANDBOX_ENDPOINT).getId())).thenReturn(endpointMap.get(APIMgtConstants.SANDBOX_ENDPOINT));
Mockito.when(apiDAO.getEndpointByName(endpointMap.get(APIMgtConstants.PRODUCTION_ENDPOINT).getName())).thenReturn(endpointMap.get(APIMgtConstants.PRODUCTION_ENDPOINT));
Mockito.when(apiDAO.getEndpointByName(endpointMap.get(APIMgtConstants.SANDBOX_ENDPOINT).getName())).thenReturn(endpointMap.get(APIMgtConstants.SANDBOX_ENDPOINT));
Mockito.when(apiDAO.getApiSwaggerDefinition(apiBuilder.getId())).thenReturn(SampleTestObjectCreator.apiDefinition);
apiBuilder.description("aaaaaa");
apiPublisher.updateAPI(apiBuilder);
Mockito.verify(apiDAO, Mockito.times(1)).updateAPI(apiBuilder.getId(), apiBuilder.build());
}
use of org.wso2.carbon.apimgt.core.exception.APIManagementException in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testAddEndpointException.
@Test(description = "Exception when adding endpoint")
public void testAddEndpointException() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
APIGateway gateway = Mockito.mock(APIGateway.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, gatewaySourceGenerator, gateway);
Endpoint endpointToAdd = new Endpoint.Builder(SampleTestObjectCreator.createMockEndpoint()).build();
Mockito.when(apiDAO.getEndpointByName(endpointToAdd.getName())).thenReturn(null);
Mockito.doThrow(APIMgtDAOException.class).when(apiDAO).addEndpoint(Mockito.any());
try {
apiPublisher.addEndpoint(endpointToAdd);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Failed to add Endpoint : " + endpointToAdd.getName());
}
}
use of org.wso2.carbon.apimgt.core.exception.APIManagementException in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUpdateDedicatedGatewayWhenDedicatedGatewayIsDisabledAndAPIHasOwnGateway.
@Test(description = "Update dedicated gateway when dedicated gateway is disabled and api has own gateway")
public void testUpdateDedicatedGatewayWhenDedicatedGatewayIsDisabledAndAPIHasOwnGateway() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
API api = SampleTestObjectCreator.createDefaultAPI().hasOwnGateway(true).build();
String uuid = api.getId();
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
Mockito.when(identityProvider.getRoleName(SampleTestObjectCreator.DEVELOPER_ROLE_ID)).thenReturn(DEVELOPER_ROLE);
Mockito.when(identityProvider.getRoleName(SampleTestObjectCreator.ADMIN_ROLE_ID)).thenReturn(ADMIN_ROLE);
Mockito.when(apiDAO.getApiSwaggerDefinition(api.getId())).thenReturn(SampleTestObjectCreator.apiDefinition);
APIPublisherImpl apiPublisher = getApiPublisherImpl(identityProvider, apiDAO, labelDAO, gatewaySourceGenerator);
DedicatedGateway dedicatedGateway = SampleTestObjectCreator.createDedicatedGateway(uuid, false, api.getCreatedBy());
apiPublisher.updateDedicatedGateway(dedicatedGateway);
Mockito.verify(apiDAO, Mockito.times(1)).updateDedicatedGateway(Mockito.any(), Mockito.anyList());
}
Aggregations