Search in sources :

Example 51 with User

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

the class ImportApiServiceImplTestCase method testImportApisPutError.

@Test
public void testImportApisPutError() throws Exception {
    printTestMethodName();
    ClassLoader classLoader = getClass().getClassLoader();
    File file = new File(classLoader.getResource("swagger.json").getFile());
    FileInputStream fis = null;
    fis = new FileInputStream(file);
    ImportApiServiceImpl importApiService = new ImportApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    Response response = importApiService.importApisPut(fis, null, null, getRequest());
    assertEquals(response.getStatus(), 500);
    assertTrue(response.getEntity().toString().contains("Error while importing the given APIs"));
}
Also used : Response(javax.ws.rs.core.Response) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 52 with User

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

the class LabelsApiServiceImplTestCase method getRequest.

// Sample request to be used by tests
private Request getRequest() throws Exception {
    HTTPCarbonMessage carbonMessage = Mockito.mock(HTTPCarbonMessage.class);
    Mockito.when(carbonMessage.getProperty("LOGGED_IN_USER")).thenReturn(USER);
    Request request = new Request(carbonMessage);
    return request;
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) Request(org.wso2.msf4j.Request)

Example 53 with User

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

the class LabelsApiServiceImplTestCase method testLabelsGetException.

@Test
public void testLabelsGetException() throws Exception {
    printTestMethodName();
    LabelsApiServiceImpl labelsApiService = new LabelsApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    Mockito.doThrow(new LabelException("Error occurred", ExceptionCodes.LABEL_EXCEPTION)).when(apiPublisher).getAllLabels();
    Response response = labelsApiService.labelsGet(null, null, null, null, getRequest());
    assertEquals(response.getStatus(), 500);
    assertTrue(response.getEntity().toString().contains("Label Error"));
}
Also used : Response(javax.ws.rs.core.Response) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) LabelException(org.wso2.carbon.apimgt.core.exception.LabelException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 54 with User

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

the class ApisApiServiceImplTestCase method testApisApiIdThumbnailGetException.

@Test
public void testApisApiIdThumbnailGetException() 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();
    Mockito.doThrow(new APIManagementException("Error occurred", ExceptionCodes.API_TYPE_INVALID)).when(apiPublisher).getThumbnailImage(apiId);
    Response response = apisApiService.apisApiIdThumbnailGet(apiId, null, null, 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) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 55 with User

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

the class ApisApiServiceImplTestCase method testApisApiIdThumbnailPostException.

@Test
public void testApisApiIdThumbnailPostException() 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();
    FileInfo fileDetail = new FileInfo();
    fileDetail.setFileName("test.png");
    Mockito.doThrow(new APIManagementException("Error occurred", ExceptionCodes.API_TYPE_INVALID)).when(apiPublisher).saveThumbnailImage(apiId, null, fileDetail.getFileName());
    Response response = apisApiService.apisApiIdThumbnailPost(apiId, null, fileDetail, null, null, 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) FileInfo(org.wso2.msf4j.formparam.FileInfo) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) 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