Search in sources :

Example 91 with APIMgtAdminServiceImpl

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

the class WorkflowsApiServiceImplTestCase method testWorkflowsGetException.

@Test
public void testWorkflowsGetException() throws Exception {
    printTestMethodName();
    WorkflowsApiServiceImpl workflowsApiService = new WorkflowsApiServiceImpl();
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    String message = "Error while retrieving workflow information";
    Mockito.doThrow(new APIManagementException(message, ExceptionCodes.APIMGT_DAO_EXCEPTION)).when(adminService).retrieveUncompletedWorkflows();
    Response response = workflowsApiService.workflowsGet(null, null, null, getRequest());
    assertEquals(500, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 92 with APIMgtAdminServiceImpl

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

the class WorkflowsApiServiceImplTestCase method testWorkflowsWorkflowReferenceIdGetForInvalidReference.

@Test
public void testWorkflowsWorkflowReferenceIdGetForInvalidReference() throws Exception {
    printTestMethodName();
    WorkflowsApiServiceImpl workflowsApiService = new WorkflowsApiServiceImpl();
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    String workflowRefId = UUID.randomUUID().toString();
    String message = "Workflow not found for : " + workflowRefId;
    Mockito.doThrow(new APIMgtDAOException(message, ExceptionCodes.WORKFLOW_NOT_FOUND)).when(adminService).retrieveWorkflow(workflowRefId);
    Response response = workflowsApiService.workflowsWorkflowReferenceIdGet(workflowRefId, getRequest());
    assertEquals(404, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 93 with APIMgtAdminServiceImpl

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

the class WorkflowsApiServiceImplTestCase method testWorkflowsWorkflowReferenceIdPutException.

@Test
public void testWorkflowsWorkflowReferenceIdPutException() throws Exception {
    printTestMethodName();
    WorkflowsApiServiceImpl workflowsApiService = new WorkflowsApiServiceImpl();
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    String workflowRefId = UUID.randomUUID().toString();
    String message = "Error while retrieving workflow entry for :" + workflowRefId;
    Mockito.doThrow(new APIManagementException(message, ExceptionCodes.APIMGT_DAO_EXCEPTION)).when(adminService).retrieveWorkflow(workflowRefId);
    WorkflowRequestDTO workflowRequestDTO = new WorkflowRequestDTO();
    workflowRequestDTO.setDescription("Test Desc");
    workflowRequestDTO.setStatus(WorkflowRequestDTO.StatusEnum.APPROVED);
    Response response = workflowsApiService.workflowsWorkflowReferenceIdPut(workflowRefId, workflowRequestDTO, getRequest());
    assertEquals(500, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) WorkflowRequestDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.WorkflowRequestDTO) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 94 with APIMgtAdminServiceImpl

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

the class WorkflowsApiServiceImplTestCase method testWorkflowsWorkflowReferenceIdGet.

@Test
public void testWorkflowsWorkflowReferenceIdGet() throws Exception {
    printTestMethodName();
    WorkflowsApiServiceImpl workflowsApiService = new WorkflowsApiServiceImpl();
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    String workflowRefId = UUID.randomUUID().toString();
    WorkflowRequestDTO workflowRequestDTO = new WorkflowRequestDTO();
    workflowRequestDTO.setDescription("Test Desc");
    workflowRequestDTO.setStatus(WorkflowRequestDTO.StatusEnum.APPROVED);
    Workflow workflow = new ApplicationCreationWorkflow(null, null, null);
    workflow.setStatus(WorkflowStatus.APPROVED);
    LocalDateTime date1 = LocalDateTime.now();
    workflow.setCreatedTime(date1);
    workflow.setWorkflowDescription("Description 1");
    workflow.setWorkflowType(WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION);
    String ref1 = UUID.randomUUID().toString();
    workflow.setExternalWorkflowReference(ref1);
    Mockito.doReturn(workflow).doThrow(new IllegalArgumentException()).when(adminService).retrieveWorkflow(workflowRefId);
    Response response = workflowsApiService.workflowsWorkflowReferenceIdGet(workflowRefId, getRequest());
    assertEquals(200, response.getStatus());
}
Also used : LocalDateTime(java.time.LocalDateTime) Response(javax.ws.rs.core.Response) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) WorkflowRequestDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.WorkflowRequestDTO) ApplicationCreationWorkflow(org.wso2.carbon.apimgt.core.workflow.ApplicationCreationWorkflow) Workflow(org.wso2.carbon.apimgt.core.workflow.Workflow) APIStateChangeWorkflow(org.wso2.carbon.apimgt.core.workflow.APIStateChangeWorkflow) ApplicationCreationWorkflow(org.wso2.carbon.apimgt.core.workflow.ApplicationCreationWorkflow) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 95 with APIMgtAdminServiceImpl

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

the class BlacklistApiServiceImplTest method blacklistConditionIdDeleteTest.

@Test
public void blacklistConditionIdDeleteTest() throws NotFoundException, APIManagementException {
    printTestMethodName();
    BlacklistApiServiceImpl blacklistApiService = new BlacklistApiServiceImpl();
    String uuid = UUID.randomUUID().toString();
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    Mockito.doReturn(true).doThrow(new IllegalArgumentException()).when(adminService).deleteBlockConditionByUuid(uuid);
    Response response = blacklistApiService.blacklistConditionIdDelete(uuid, null, null, getRequest());
    Assert.assertEquals(response.getStatus(), 200);
}
Also used : Response(javax.ws.rs.core.Response) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) BlacklistApiServiceImpl(org.wso2.carbon.apimgt.rest.api.admin.impl.BlacklistApiServiceImpl) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

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