use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetEndpointGatewayConfig.
@Test(description = "Test getting the endpoint gateway configuration")
public void testGetEndpointGatewayConfig() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(apiDAO);
Endpoint endpoint = SampleTestObjectCreator.createMockEndpoint();
Mockito.when(apiDAO.getEndpointConfig(endpoint.getId())).thenReturn(endpoint.getEndpointConfig());
String endpointConfigReturned = adminService.getEndpointGatewayConfig(endpoint.getId());
Assert.assertEquals(endpointConfigReturned, endpoint.getEndpointConfig());
// Error path
Mockito.when(apiDAO.getEndpointConfig(endpoint.getId())).thenThrow(APIMgtDAOException.class);
try {
adminService.getEndpointGatewayConfig(endpoint.getId());
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Error occurred while getting the Endpoint Configuration");
}
}
use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testAddBlockCondition.
@Test(description = "Test adding block condition")
public void testAddBlockCondition() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
BlockConditions blockConditions = SampleTestObjectCreator.createDefaultBlockCondition(BLOCK_CONDITION_TYPE);
String uuid = adminService.addBlockCondition(blockConditions);
Assert.assertNotNull(uuid);
// Error path
Mockito.when(policyDAO.addBlockConditions(blockConditions)).thenThrow(APIMgtDAOException.class);
try {
adminService.addBlockCondition(blockConditions);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't add block condition with condition type: " + blockConditions.getConditionType() + ", condition value: " + blockConditions.getConditionValue());
}
}
use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetAllResourcesForApi.
@Test(description = "Test getting all resources for API")
public void testGetAllResourcesForApi() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(apiDAO);
adminService.getAllResourcesForApi(API_CONTEXT, API_VERSION);
Mockito.verify(apiDAO, Mockito.times(1)).getResourcesOfApi(API_CONTEXT, API_VERSION);
// Error path
Mockito.when(apiDAO.getResourcesOfApi(API_CONTEXT, API_VERSION)).thenThrow(APIMgtDAOException.class);
try {
adminService.getAllResourcesForApi(API_CONTEXT, API_VERSION);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't retrieve resources for Api Name: " + API_CONTEXT);
}
}
use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testRegisterGatewayLabelsException.
@Test(description = "Exception when registering gateway labels", expectedExceptions = APIManagementException.class)
public void testRegisterGatewayLabelsException() throws APIManagementException {
LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
List<Label> labels = new ArrayList<>();
Label label = SampleTestObjectCreator.createLabel("testLabel1", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
labels.add(label);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(labelDAO);
Mockito.doThrow(new APIMgtDAOException("Error occurred while adding label information")).when(labelDAO).addLabels(labels);
adminService.registerGatewayLabels(labels, "false");
}
use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetApiPolicyByUuid.
@Test(description = "Test getting API policy by UUID")
public void testGetApiPolicyByUuid() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
APIPolicy apiPolicy = SampleTestObjectCreator.createDefaultAPIPolicy();
Mockito.when(policyDAO.getApiPolicyByUuid(apiPolicy.getUuid())).thenReturn(apiPolicy);
adminService.getApiPolicyByUuid(apiPolicy.getUuid());
Mockito.verify(policyDAO, Mockito.times(1)).getApiPolicyByUuid(apiPolicy.getUuid());
// Error path
Mockito.when(policyDAO.getApiPolicyByUuid(apiPolicy.getUuid())).thenThrow(APIMgtDAOException.class);
try {
adminService.getApiPolicyByUuid(apiPolicy.getUuid());
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't retrieve API policy with id: " + apiPolicy.getUuid());
}
}
Aggregations