Search in sources :

Example 71 with APIGateway

use of org.wso2.carbon.apimgt.core.api.APIGateway in project carbon-apimgt by wso2.

the class APIMgtAdminServiceImplTestCase method testAddPolicy.

@Test(description = "Add policy")
public void testAddPolicy() throws APIManagementException {
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    APIGateway apiGateway = Mockito.mock(APIGateway.class);
    APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
    APIPolicy policy = SampleTestObjectCreator.createDefaultAPIPolicy();
    adminService.addApiPolicy(policy);
    Mockito.verify(policyDAO, Mockito.times(1)).addApiPolicy(policy);
    // Error path
    Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).addApiPolicy(policy);
    try {
        adminService.addApiPolicy(policy);
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Couldn't add API policy for uuid: " + policy.getUuid());
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Example 72 with APIGateway

use of org.wso2.carbon.apimgt.core.api.APIGateway in project carbon-apimgt by wso2.

the class APIMgtAdminServiceImplTestCase method testAddPolicyWhenPolicyIdNull.

@Test(description = "Add policy when policy id is null")
public void testAddPolicyWhenPolicyIdNull() throws APIManagementException {
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    APIGateway apiGateway = Mockito.mock(APIGateway.class);
    APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
    APIPolicy policy = SampleTestObjectCreator.createDefaultAPIPolicy();
    policy.setUuid(null);
    adminService.addApiPolicy(policy);
    Mockito.verify(policyDAO, Mockito.times(1)).addApiPolicy(policy);
}
Also used : APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Example 73 with APIGateway

use of org.wso2.carbon.apimgt.core.api.APIGateway in project carbon-apimgt by wso2.

the class APIMgtAdminServiceImplTestCase method testAddApplicationPolicyWhenPolicyIdNull.

@Test(description = "Test add application policy when the policy ID is null")
public void testAddApplicationPolicyWhenPolicyIdNull() throws APIManagementException {
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    APIGateway apiGateway = Mockito.mock(APIGateway.class);
    APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
    ApplicationPolicy policy = SampleTestObjectCreator.createDefaultApplicationPolicy();
    policy.setUuid(null);
    adminService.addApplicationPolicy(policy);
    Mockito.verify(policyDAO, Mockito.times(1)).addApplicationPolicy(policy);
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Example 74 with APIGateway

use of org.wso2.carbon.apimgt.core.api.APIGateway in project carbon-apimgt by wso2.

the class APIMgtAdminServiceImplTestCase method testAddSubscriptionPolicyWhenPolicyIdNull.

@Test(description = "Test add subscription policy when the policy ID is null")
public void testAddSubscriptionPolicyWhenPolicyIdNull() throws APIManagementException {
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    APIGateway apiGateway = Mockito.mock(APIGateway.class);
    APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
    SubscriptionPolicy policy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
    policy.setUuid(null);
    adminService.addSubscriptionPolicy(policy);
    Mockito.verify(policyDAO, Mockito.times(1)).addSubscriptionPolicy(policy);
}
Also used : SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Example 75 with APIGateway

use of org.wso2.carbon.apimgt.core.api.APIGateway in project carbon-apimgt by wso2.

the class APIMgtAdminServiceImplTestCase method testUpdateApiPolicy.

@Test(description = "Test update API policy")
public void testUpdateApiPolicy() throws APIManagementException {
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    APIGateway apiGateway = Mockito.mock(APIGateway.class);
    APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
    APIPolicy apiPolicy = SampleTestObjectCreator.createDefaultAPIPolicy();
    adminService.updateApiPolicy(apiPolicy);
    Mockito.verify(policyDAO, Mockito.times(1)).updateApiPolicy(apiPolicy);
    // Error path
    Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).updateApiPolicy(apiPolicy);
    try {
        adminService.updateApiPolicy(apiPolicy);
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Couldn't update API policy for uuid: " + apiPolicy.getUuid());
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Aggregations

APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)135 Test (org.testng.annotations.Test)129 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)100 API (org.wso2.carbon.apimgt.core.models.API)87 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)73 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)59 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)55 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)48 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)38 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)35 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)32 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)31 WorkflowDAO (org.wso2.carbon.apimgt.core.dao.WorkflowDAO)29 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)28 LifecycleState (org.wso2.carbon.lcm.core.impl.LifecycleState)28 LabelDAO (org.wso2.carbon.apimgt.core.dao.LabelDAO)26 HashMap (java.util.HashMap)22 APISubscriptionDAO (org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO)22 BeforeTest (org.testng.annotations.BeforeTest)19 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)19