use of org.wso2.carbon.apimgt.api.model.APIPublisher in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUpdateAPIWithStatusUnchangedWhenContextExists.
@Test(description = "Test UpdateAPI with Status unchanged but context exist", expectedExceptions = APIManagementException.class)
public void testUpdateAPIWithStatusUnchangedWhenContextExists() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
API.APIBuilder api = SampleTestObjectCreator.createDefaultAPI();
String uuid = api.getId();
APIGateway gateway = Mockito.mock(APIGateway.class);
IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
Policy apiPolicy = new APIPolicy(APIMgtConstants.DEFAULT_API_POLICY);
apiPolicy.setUuid(UUID.randomUUID().toString());
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.api, APIMgtConstants.DEFAULT_API_POLICY)).thenReturn(apiPolicy);
APIPublisherImpl apiPublisher = getApiPublisherImpl(identityProvider, apiDAO, apiLifecycleManager, gatewaySourceGenerator, gateway, policyDAO);
Mockito.when(apiDAO.getApiSwaggerDefinition(api.getId())).thenReturn(SampleTestObjectCreator.apiDefinition);
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api.build());
Mockito.when(apiDAO.isAPIContextExists("testContext")).thenReturn(true);
Mockito.when(identityProvider.getRoleId(ADMIN_ROLE)).thenReturn(ADMIN_ROLE_ID);
Mockito.when(identityProvider.getRoleId(DEVELOPER_ROLE)).thenReturn(DEVELOPER_ROLE_ID);
apiPublisher.updateAPI(api.context("testContext"));
}
use of org.wso2.carbon.apimgt.api.model.APIPublisher in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testGetDedicatedGateway.
@Test(description = "Get dedicated gateway")
public void testGetDedicatedGateway() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
DedicatedGateway dedicatedGateway = new DedicatedGateway();
dedicatedGateway.setEnabled(true);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
Mockito.when(apiDAO.getDedicatedGateway(Mockito.anyString())).thenReturn(dedicatedGateway);
DedicatedGateway result = apiPublisher.getDedicatedGateway(Mockito.anyString());
Assert.assertTrue(result.isEnabled());
}
use of org.wso2.carbon.apimgt.api.model.APIPublisher in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testDeleteApiWithZeroSubscriptionsLifeCycleException.
@Test(description = "Error occurred while disassociating the API with Lifecycle when deleting the API", expectedExceptions = APIManagementException.class)
public void testDeleteApiWithZeroSubscriptionsLifeCycleException() throws APIManagementException, LifecycleException, SQLException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
API api = SampleTestObjectCreator.createDefaultAPI().build();
String uuid = api.getId();
String lifecycleId = api.getLifecycleInstanceId();
Mockito.when(apiSubscriptionDAO.getSubscriptionCountByAPI(uuid)).thenReturn(0L);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(identityProvider, apiDAO, apiSubscriptionDAO, apiLifecycleManager);
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
Mockito.when(identityProvider.getRoleName(SampleTestObjectCreator.DEVELOPER_ROLE_ID)).thenReturn(DEVELOPER_ROLE);
Mockito.when(apiDAO.getApiSwaggerDefinition(api.getId())).thenReturn(SampleTestObjectCreator.apiDefinition);
Mockito.when(identityProvider.getRoleName(SampleTestObjectCreator.ADMIN_ROLE_ID)).thenReturn(ADMIN_ROLE);
Mockito.doThrow(new LifecycleException("Error occurred while Disassociating the API with Lifecycle id " + uuid)).when(apiLifecycleManager).removeLifecycle(lifecycleId);
apiPublisher.deleteAPI(uuid);
}
use of org.wso2.carbon.apimgt.api.model.APIPublisher in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method getLabelsByTypeException.
@Test(description = "get labels by type Exception", expectedExceptions = Exception.class)
public void getLabelsByTypeException() throws Exception {
LabelDAO labelDao = Mockito.mock(LabelDAO.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(labelDao);
Mockito.when(labelDao.getLabelsByType("GATEWAY")).thenThrow(new LabelException("Error occurred while " + "retrieving labels"));
apiPublisher.getLabelsByType("GATEWAY");
}
use of org.wso2.carbon.apimgt.api.model.APIPublisher in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testCheckIfAPIExistWhileGettingJDBCConnectionFailure.
@Test(description = "Check if api exist with invalid uuid", expectedExceptions = { APIMgtDAOException.class, APIManagementException.class })
public void testCheckIfAPIExistWhileGettingJDBCConnectionFailure() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
Mockito.when(apiDAO.isAPIExists("bbbbb")).thenThrow(new APIMgtDAOException(""));
apiPublisher.isAPIExists("bbbbb");
}
Aggregations