use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetApiPolicies.
@Test(description = "Test getting all API Policies")
public void testGetApiPolicies() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
adminService.getApiPolicies();
Mockito.verify(policyDAO, Mockito.times(1)).getApiPolicies();
// Error path
Mockito.when(policyDAO.getApiPolicies()).thenThrow(APIMgtDAOException.class);
try {
adminService.getApiPolicies();
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't retrieve API policies");
}
}
use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetSubscriptionPolicy.
@Test(description = "Test getting Subscription policy")
public void testGetSubscriptionPolicy() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
SubscriptionPolicy subscriptionPolicy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
Mockito.when(policyDAO.getSubscriptionPolicy(subscriptionPolicy.getPolicyName())).thenReturn(subscriptionPolicy);
adminService.getSubscriptionPolicy(subscriptionPolicy.getPolicyName());
Mockito.verify(policyDAO, Mockito.times(1)).getSubscriptionPolicy(subscriptionPolicy.getPolicyName());
// Error path
Mockito.when(policyDAO.getSubscriptionPolicy(subscriptionPolicy.getPolicyName())).thenThrow(APIMgtDAOException.class);
try {
adminService.getSubscriptionPolicy(subscriptionPolicy.getPolicyName());
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't retrieve Subscription policy with name: " + subscriptionPolicy.getPolicyName());
}
}
use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetBlockConditionByUUID.
@Test(description = "Test getting block condition by uuid")
public void testGetBlockConditionByUUID() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
BlockConditions blockConditions = SampleTestObjectCreator.createDefaultBlockCondition(BLOCK_CONDITION_TYPE);
Mockito.when(policyDAO.getBlockConditionByUUID(blockConditions.getUuid())).thenReturn(blockConditions);
BlockConditions blockConditionsReturned = adminService.getBlockConditionByUUID(blockConditions.getUuid());
Assert.assertEquals(blockConditionsReturned, blockConditions);
// Error path
Mockito.when(policyDAO.getBlockConditionByUUID(blockConditions.getUuid())).thenThrow(APIMgtDAOException.class);
try {
adminService.getBlockConditionByUUID(blockConditions.getUuid());
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't get block condition by UUID: " + blockConditions.getUuid());
}
}
use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testDeleteLabel.
@Test(description = "Delete a label")
public void testDeleteLabel() throws APIManagementException {
LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(labelDAO);
Label label = SampleTestObjectCreator.createLabel("Public", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
String labelId = label.getId();
adminService.deleteLabel(labelId);
Mockito.verify(labelDAO, Mockito.times(1)).deleteLabel(labelId);
}
use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testRegisterGatewayLabelsWhenOverwriteLabelsNull.
@Test(description = "Register gateway labels when overwriteLabels value is null")
public void testRegisterGatewayLabelsWhenOverwriteLabelsNull() throws APIManagementException {
LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
List<Label> labels = new ArrayList<>();
Label label1 = SampleTestObjectCreator.createLabel("testLabel1", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
labels.add(label1);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(labelDAO);
adminService.registerGatewayLabels(labels, null);
Mockito.verify(labelDAO, Mockito.times(1)).addLabels(labels);
}
Aggregations