Search in sources :

Example 46 with User

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

the class EnvironmentsApiServiceImplTestCase 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 47 with User

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

the class ExportApiServiceImplTestCase method testExportApisGetNotFound.

@Test
public void testExportApisGetNotFound() throws Exception {
    printTestMethodName();
    ExportApiServiceImpl exportApiService = new ExportApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    Response response = exportApiService.exportApisGet("", null, null, getRequest());
    assertEquals(response.getStatus(), 404);
}
Also used : Response(javax.ws.rs.core.Response) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 48 with User

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

the class ExternalResourcesApiServiceImplTestCase 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 49 with User

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

the class ExternalResourcesApiServiceImplTestCase method testExternalResourcesServicesGet.

@Test
public void testExternalResourcesServicesGet() throws Exception {
    printTestMethodName();
    ExternalResourcesApiServiceImpl externalResourcesApiService = new ExternalResourcesApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    Endpoint endpoint1 = SampleTestObjectCreator.createMockEndpoint();
    Endpoint endpoint2 = SampleTestObjectCreator.createMockEndpoint();
    List<Endpoint> endpointList = new ArrayList<>();
    endpointList.add(endpoint1);
    endpointList.add(endpoint2);
    Mockito.doReturn(endpointList).doThrow(new IllegalArgumentException()).when(apiPublisher).discoverServiceEndpoints();
    Response response = externalResourcesApiService.externalResourcesServicesGet(null, null, getRequest());
    Assert.assertEquals(response.getStatus(), 200);
    Assert.assertTrue(response.getEntity().toString().contains(endpoint1.getId()));
    Assert.assertTrue(response.getEntity().toString().contains(endpoint2.getId()));
}
Also used : Response(javax.ws.rs.core.Response) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) ArrayList(java.util.ArrayList) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 50 with User

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

the class ImportApiServiceImplTestCase method testImportApisPostError.

@Test
public void testImportApisPostError() 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.importApisPost(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)

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