Search in sources :

Example 91 with User

use of org.wso2.broker.core.security.authentication.user.User in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method testApisHeadNameMatch.

@Test
public void testApisHeadNameMatch() throws Exception {
    printTestMethodName();
    String word = "name:testName";
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    Mockito.doReturn(true).doThrow(new IllegalArgumentException()).when(apiPublisher).checkIfAPINameExists("testName");
    Response response = apisApiService.apisHead(word, null, getRequest());
    assertEquals(response.getStatus(), 200);
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Response(javax.ws.rs.core.Response) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 92 with User

use of org.wso2.broker.core.security.authentication.user.User in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method testApisPostException.

@Test
public void testApisPostException() throws Exception {
    printTestMethodName();
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    String apiId = UUID.randomUUID().toString();
    API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI();
    API api = apiBuilder.id(apiId).build();
    APIDTO apidto = MappingUtil.toAPIDto(api);
    Mockito.doReturn(apiId).doThrow(new IllegalArgumentException()).when(apiPublisher).addAPI(apiBuilder);
    Mockito.doThrow(new APIManagementException("Error occurred", ExceptionCodes.API_TYPE_INVALID)).when(apiPublisher).getAPIbyUUID(apiId);
    Response response = apisApiService.apisPost(apidto, getRequest());
    assertEquals(response.getStatus(), 400);
    assertTrue(response.getEntity().toString().contains("API Type specified is invalid"));
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Response(javax.ws.rs.core.Response) APIDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.APIDTO) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) API(org.wso2.carbon.apimgt.core.models.API) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 93 with User

use of org.wso2.broker.core.security.authentication.user.User in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method testApisApiIdDocumentsDocumentIdGet.

@Test
public void testApisApiIdDocumentsDocumentIdGet() throws Exception {
    printTestMethodName();
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    String documentId = UUID.randomUUID().toString();
    String apiId = UUID.randomUUID().toString();
    DocumentInfo documentInfo = SampleTestObjectCreator.createDefaultDocumentationInfo().build();
    Mockito.doReturn(documentInfo).doThrow(new IllegalArgumentException()).when(apiPublisher).getDocumentationSummary(documentId);
    Response response = apisApiService.apisApiIdDocumentsDocumentIdGet(apiId, documentId, null, null, getRequest());
    assertEquals(response.getStatus(), 200);
    assertTrue(response.getEntity().toString().contains("Summary of Calculator Documentation"));
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Response(javax.ws.rs.core.Response) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 94 with User

use of org.wso2.broker.core.security.authentication.user.User in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method testApisApiIdDocumentsDocumentIdPutException.

@Test
public void testApisApiIdDocumentsDocumentIdPutException() throws Exception {
    printTestMethodName();
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    DocumentInfo documentInfo1 = SampleTestObjectCreator.createDefaultDocumentationInfo().build();
    DocumentInfo documentInfo2 = SampleTestObjectCreator.createDefaultDocumentationInfo().id(documentInfo1.getId()).summary("My new summary").build();
    DocumentDTO documentDTO = MappingUtil.toDocumentDTO(documentInfo2);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    String documentId = UUID.randomUUID().toString();
    String apiId = UUID.randomUUID().toString();
    Mockito.doReturn(documentInfo1).doReturn(documentInfo2).doThrow(new IllegalArgumentException()).when(apiPublisher).getDocumentationSummary(documentId);
    Mockito.doThrow(new APIManagementException("Error occurred", ExceptionCodes.INVALID_DOCUMENT_CONTENT_DATA)).when(apiPublisher).updateDocumentation(apiId, documentInfo1);
    Response response = apisApiService.apisApiIdDocumentsDocumentIdPut(apiId, documentId, documentDTO, null, null, getRequest());
    assertEquals(response.getStatus(), 400);
    assertTrue(response.getEntity().toString().contains("Invalid document content data provided"));
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Response(javax.ws.rs.core.Response) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) DocumentDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.DocumentDTO) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 95 with User

use of org.wso2.broker.core.security.authentication.user.User in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method testApisApiIdDocumentsGet.

@Test
public void testApisApiIdDocumentsGet() throws Exception {
    printTestMethodName();
    Integer offset = 0;
    Integer limit = 10;
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    String apiId = UUID.randomUUID().toString();
    List<DocumentInfo> documentInfos = new ArrayList<>();
    documentInfos.add(SampleTestObjectCreator.createDefaultDocumentationInfo().name("NewName1").build());
    documentInfos.add(SampleTestObjectCreator.createDefaultDocumentationInfo().name("NewName2").build());
    Mockito.doReturn(documentInfos).doThrow(new IllegalArgumentException()).when(apiPublisher).getAllDocumentation(apiId, offset, limit);
    Response response = apisApiService.apisApiIdDocumentsGet(apiId, 10, 0, null, getRequest());
    assertEquals(response.getStatus(), 200);
    assertTrue(response.getEntity().toString().contains("NewName1"));
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Response(javax.ws.rs.core.Response) ArrayList(java.util.ArrayList) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)225 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)223 Response (javax.ws.rs.core.Response)215 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)130 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)114 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)112 Request (org.wso2.msf4j.Request)105 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)98 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)88 Test (org.testng.annotations.Test)74 API (org.wso2.carbon.apimgt.core.models.API)73 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)65 ArrayList (java.util.ArrayList)55 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)44 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)41 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)37 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)35 HashMap (java.util.HashMap)34 LifecycleState (org.wso2.carbon.lcm.core.impl.LifecycleState)28 DocumentInfo (org.wso2.carbon.apimgt.core.models.DocumentInfo)26