Search in sources :

Example 6 with APIMgtAdminServiceImpl

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

the class WorkflowsApiServiceImplTestCase method testWorkflowsGetWithoutType.

@Test
public void testWorkflowsGetWithoutType() throws Exception {
    printTestMethodName();
    WorkflowsApiServiceImpl workflowsApiService = new WorkflowsApiServiceImpl();
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    List<Workflow> workflowList = new ArrayList<>();
    Mockito.doReturn(workflowList).doThrow(new IllegalArgumentException()).when(adminService).retrieveUncompletedWorkflows();
    Response response = workflowsApiService.workflowsGet(null, null, null, getRequest());
    assertEquals(200, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) ArrayList(java.util.ArrayList) ApplicationCreationWorkflow(org.wso2.carbon.apimgt.core.workflow.ApplicationCreationWorkflow) Workflow(org.wso2.carbon.apimgt.core.workflow.Workflow) APIStateChangeWorkflow(org.wso2.carbon.apimgt.core.workflow.APIStateChangeWorkflow) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with APIMgtAdminServiceImpl

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

the class LabelsApiServiceImplTest method testLabelsPost.

@Test
public void testLabelsPost() throws Exception {
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    Label label1 = new Label.Builder().id("1").name("label1").type("GATEWAY").build();
    LabelsApiServiceImpl labelService = new LabelsApiServiceImpl();
    Mockito.when(labelService.labelsPost(LabelMappingUtil.fromLabelToDTO(label1), "application/json", getRequest())).thenReturn(Response.status(Response.Status.CREATED).entity(LabelMappingUtil.fromLabelToDTO(label1)).build());
    Response response = labelService.labelsPost(LabelMappingUtil.fromLabelToDTO(label1), "application/json", getRequest());
    Assert.assertEquals(response.getStatus(), Response.Status.CREATED);
}
Also used : Response(javax.ws.rs.core.Response) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) Label(org.wso2.carbon.apimgt.core.models.Label) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 8 with APIMgtAdminServiceImpl

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

the class LabelsApiServiceImplTest method testLabelsLabelIdPut.

@Test
public void testLabelsLabelIdPut() 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.labelsLabelIdPut("1", LabelMappingUtil.fromLabelToDTO(label1), "application/Json", getRequest())).thenReturn(Response.status(Response.Status.OK).entity(LabelMappingUtil.fromLabelArrayToListDTO(labels)).build());
    Response response = labelService.labelsLabelIdPut("1", LabelMappingUtil.fromLabelToDTO(label1), "application/Json", 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 9 with APIMgtAdminServiceImpl

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

the class LabelsApiServiceImplTest method testLabelsDelete.

@Test
public void testLabelsDelete() 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)

Example 10 with APIMgtAdminServiceImpl

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

the class EndpointsApiServiceImplTestCase method endpointsGetTest.

@Test
public void endpointsGetTest() throws Exception {
    APIMgtAdminServiceImpl apiMgtAdminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(apiMgtAdminService);
    Endpoint endpointOne = SampleTestObjectCreator.createUniqueEndpoint();
    Endpoint endpointTwo = SampleTestObjectCreator.createUniqueEndpoint();
    Endpoint endpointThree = SampleTestObjectCreator.createUniqueEndpoint();
    List<Endpoint> endpointList = new ArrayList<>();
    endpointList.add(endpointOne);
    endpointList.add(endpointTwo);
    endpointList.add(endpointThree);
    Mockito.when(apiMgtAdminService.getAllEndpoints()).thenReturn(endpointList);
    EndpointsApiServiceImpl endpointsApiService = new EndpointsApiServiceImpl();
    Response response = endpointsApiService.endpointsGet(null, null, getRequest());
    Assert.assertEquals(response.getStatus(), 200);
    Assert.assertEquals(((EndpointListDTO) response.getEntity()).getList().size(), 3);
}
Also used : Response(javax.ws.rs.core.Response) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) ArrayList(java.util.ArrayList) EndpointListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.EndpointListDTO) Test(org.junit.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