Search in sources :

Example 96 with APIMgtAdminServiceImpl

use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.

the class PoliciesApiServiceImplTest method policiesThrottlingAdvancedGetTest.

@Test
public void policiesThrottlingAdvancedGetTest() throws APIManagementException, NotFoundException {
    PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    APIPolicy policy1 = new APIPolicy("samplePolicy1");
    APIPolicy policy2 = new APIPolicy("samplePolicy2");
    List<APIPolicy> policies = new ArrayList<>();
    policies.add(policy1);
    policies.add(policy2);
    Mockito.doReturn(policies).doThrow(new IllegalArgumentException()).when(adminService).getApiPolicies();
    Response response = policiesApiService.policiesThrottlingAdvancedGet(null, null, getRequest());
    Assert.assertEquals(response.getStatus(), 200);
}
Also used : Response(javax.ws.rs.core.Response) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) PoliciesApiServiceImpl(org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl) ArrayList(java.util.ArrayList) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 97 with APIMgtAdminServiceImpl

use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.

the class PoliciesApiServiceImplTest method policiesThrottlingApplicationPostTest.

@Test
public void policiesThrottlingApplicationPostTest() throws APIManagementException, NotFoundException {
    printTestMethodName();
    PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
    ApplicationThrottlePolicyDTO dto = new ApplicationThrottlePolicyDTO();
    String uuid = UUID.randomUUID().toString();
    dto.setId(uuid);
    dto.setPolicyName("SamplePolicy");
    dto.setDisplayName("DisplayName");
    dto.setDescription("Policy Description");
    dto.setIsDeployed(true);
    ApplicationPolicy policy = ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyDTOToModel(dto);
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.mockStatic(ApplicationThrottlePolicyMappingUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    Mockito.doReturn(uuid).doThrow(new IllegalArgumentException()).when(adminService).addApplicationPolicy(policy);
    Mockito.doReturn(policy).doThrow(new IllegalArgumentException()).when(adminService).getApplicationPolicyByUuid(uuid);
    PowerMockito.when(ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyToDTO(policy)).thenReturn(dto);
    PowerMockito.when(ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyDTOToModel(dto)).thenReturn(policy);
    Response response = policiesApiService.policiesThrottlingApplicationPost(dto, getRequest());
    Assert.assertEquals(201, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) PoliciesApiServiceImpl(org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) ApplicationThrottlePolicyDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ApplicationThrottlePolicyDTO) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 98 with APIMgtAdminServiceImpl

use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.

the class PoliciesApiServiceImplTest method policiesThrottlingSubscriptionGetTest.

@Test
public void policiesThrottlingSubscriptionGetTest() throws APIManagementException, NotFoundException {
    printTestMethodName();
    PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
    List<SubscriptionPolicy> policies = new ArrayList<>();
    policies.add(new SubscriptionPolicy("Policy1"));
    policies.add(new SubscriptionPolicy("Policy2"));
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    Mockito.doReturn(policies).doThrow(new IllegalArgumentException()).when(adminService).getSubscriptionPolicies();
    Response response = policiesApiService.policiesThrottlingSubscriptionGet(null, null, getRequest());
    Assert.assertEquals(response.getStatus(), 200);
}
Also used : Response(javax.ws.rs.core.Response) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) PoliciesApiServiceImpl(org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl) ArrayList(java.util.ArrayList) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 99 with APIMgtAdminServiceImpl

use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.

the class LabelsApiServiceImplTest method testLabelsGetWithoutLabelId.

@Test
public void testLabelsGetWithoutLabelId() throws Exception {
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    List<Label> labels = new ArrayList<>();
    Label label1 = new Label.Builder().id("1").name("label1").type("GATEWAY").build();
    Label label2 = new Label.Builder().id("2").name("label2").type("STORE").build();
    labels.add(label1);
    labels.add(label2);
    LabelsApiServiceImpl labelService = new LabelsApiServiceImpl();
    Mockito.when(labelService.labelsGet(null, null, getRequest())).thenReturn(Response.status(Response.Status.OK).entity(LabelMappingUtil.fromLabelArrayToListDTO(labels)).build());
    Response response = labelService.labelsGet(null, null, getRequest());
    Assert.assertEquals(response.getEntity(), LabelMappingUtil.fromLabelArrayToListDTO(labels));
}
Also used : Response(javax.ws.rs.core.Response) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) Label(org.wso2.carbon.apimgt.core.models.Label) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 100 with APIMgtAdminServiceImpl

use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.

the class LabelsApiServiceImplTest method testLabelsLabelIdDelete.

@Test
public void testLabelsLabelIdDelete() throws Exception {
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    LabelsApiServiceImpl labelService = new LabelsApiServiceImpl();
    Mockito.doNothing().when(labelService.labelsLabelIdDelete("1", getRequest()));
    Response response = labelService.labelsLabelIdDelete("1", getRequest());
    Assert.assertEquals(response.getStatus(), Response.Status.OK);
}
Also used : Response(javax.ws.rs.core.Response) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)67 Response (javax.ws.rs.core.Response)65 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)65 Test (org.junit.Test)59 Test (org.testng.annotations.Test)58 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)46 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)33 ArrayList (java.util.ArrayList)28 PoliciesApiServiceImpl (org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl)20 APIManagerFactory (org.wso2.carbon.apimgt.core.impl.APIManagerFactory)17 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)14 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)13 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)11 CustomPolicy (org.wso2.carbon.apimgt.core.models.policy.CustomPolicy)11 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)11 BlockConditions (org.wso2.carbon.apimgt.core.models.BlockConditions)10 Label (org.wso2.carbon.apimgt.core.models.Label)10 ThreatProtectionPolicy (org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy)9 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)6 LabelDAO (org.wso2.carbon.apimgt.core.dao.LabelDAO)6