use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetAPIsByStatus.
@Test(description = "Test getting APIs by status")
public void testGetAPIsByStatus() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(apiDAO);
adminService.getAPIsByStatus(new ArrayList<>(), APIStatus.CREATED.getStatus());
Mockito.verify(apiDAO, Mockito.times(1)).getAPIsByStatus(new ArrayList<>(), APIStatus.CREATED.getStatus());
// When gateway labels are null
try {
adminService.getAPIsByStatus(null, APIStatus.CREATED.getStatus());
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Gateway labels cannot be null");
}
// When status is null
try {
adminService.getAPIsByStatus(new ArrayList<>(), null);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Status cannot be null");
}
// Error path
// APIMgtDAOException
Mockito.when(apiDAO.getAPIsByStatus(new ArrayList<>(), APIStatus.CREATED.getStatus())).thenThrow(APIMgtDAOException.class);
try {
adminService.getAPIsByStatus(new ArrayList<>(), APIStatus.CREATED.getStatus());
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Error occurred while getting the API list in given states");
}
}
use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testAddApplicationPolicy.
@Test(description = "Test add application policy")
public void testAddApplicationPolicy() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
ApplicationPolicy policy = SampleTestObjectCreator.createDefaultApplicationPolicy();
adminService.addApplicationPolicy(policy);
Mockito.verify(policyDAO, Mockito.times(1)).addApplicationPolicy(policy);
// Error path
Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).addApplicationPolicy(policy);
try {
adminService.addApplicationPolicy(policy);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't add Application for uuid: " + policy.getUuid());
}
}
use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testUpdateBlockConditionStateByUUID.
@Test(description = "Test updating block condition state by uuid")
public void testUpdateBlockConditionStateByUUID() 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);
Mockito.when(policyDAO.updateBlockConditionStateByUUID(blockConditions.getUuid(), true)).thenReturn(true);
Boolean statusTrue = adminService.updateBlockConditionStateByUUID(blockConditions.getUuid(), true);
Assert.assertTrue(statusTrue);
// Error path
// Failure updating
Mockito.when(policyDAO.updateBlockConditionStateByUUID(blockConditions.getUuid(), true)).thenReturn(false);
Boolean statusFalse = adminService.updateBlockConditionStateByUUID(blockConditions.getUuid(), true);
Assert.assertFalse(statusFalse);
// Error path
// APIMgtDAOException
Mockito.when(policyDAO.updateBlockConditionStateByUUID(blockConditions.getUuid(), true)).thenThrow(APIMgtDAOException.class);
try {
adminService.updateBlockConditionStateByUUID(blockConditions.getUuid(), true);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't update block condition with UUID: " + blockConditions.getUuid() + ", state: " + true);
}
}
use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetPolicy.
@Test(description = "Get policy by level and name")
public void testGetPolicy() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
Policy policy = Mockito.mock(Policy.class);
Mockito.when(policyDAO.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, POLICY_NAME)).thenReturn(policy);
adminService.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, POLICY_NAME);
Mockito.verify(policyDAO, Mockito.times(1)).getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, POLICY_NAME);
// Error path
Mockito.when(policyDAO.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, POLICY_NAME)).thenThrow(APIMgtDAOException.class);
try {
adminService.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, POLICY_NAME);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't retrieve Throttle Policy with level: " + APIMgtAdminService.PolicyLevel.application.name() + ", name: " + POLICY_NAME);
}
}
use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testUpdateSubscriptionPolicy.
@Test(description = "Test update subscription policy")
public void testUpdateSubscriptionPolicy() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
SubscriptionPolicy subscriptionPolicy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
adminService.updateSubscriptionPolicy(subscriptionPolicy);
Mockito.verify(policyDAO, Mockito.times(1)).updateSubscriptionPolicy(subscriptionPolicy);
// Error path
Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).updateSubscriptionPolicy(subscriptionPolicy);
try {
adminService.updateSubscriptionPolicy(subscriptionPolicy);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't update Subscription policy for uuid: " + subscriptionPolicy.getUuid());
}
}
Aggregations