use of org.wso2.carbon.user.core.common.User in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdDocumentsDocumentIdContentPostAPIManagementException.
@Test
public void testApisApiIdDocumentsDocumentIdContentPostAPIManagementException() throws Exception {
String inlineContent = "INLINE CONTENT";
printTestMethodName();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
String api1Id = UUID.randomUUID().toString();
String documentId = UUID.randomUUID().toString();
Mockito.doThrow(new APIManagementException("Error Occurred", ExceptionCodes.DOCUMENT_CONTENT_NOT_FOUND)).when(apiPublisher).getDocumentationSummary(documentId);
Response response = apisApiService.apisApiIdDocumentsDocumentIdContentPost(api1Id, documentId, null, null, null, null, null, getRequest());
assertEquals(response.getStatus(), 404);
assertTrue(response.getEntity().toString().contains("Document content not found"));
}
use of org.wso2.carbon.user.core.common.User in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdDedicatedGatewayPutForInvalidAPI.
@Test
public void testApisApiIdDedicatedGatewayPutForInvalidAPI() 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.doReturn(false).when(apiPublisher).isAPIExists(apiId);
Response response = apisApiService.apisApiIdDedicatedGatewayPut(apiId, new DedicatedGatewayDTO(), null, null, getRequest());
assertEquals(ExceptionCodes.API_NOT_FOUND.getHttpStatusCode(), response.getStatus());
assertTrue(response.getEntity().toString().contains(ExceptionCodes.API_NOT_FOUND.getErrorMessage()));
}
use of org.wso2.carbon.user.core.common.User in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisHeadNoWord.
@Test
public void testApisHeadNoWord() throws Exception {
printTestMethodName();
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).checkIfAPIContextExists("testContext");
Response response = apisApiService.apisHead("", null, getRequest());
assertEquals(response.getStatus(), 400);
}
use of org.wso2.carbon.user.core.common.User in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdPut.
@Test
public void testApisApiIdPut() 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.when(apiPublisher.getApiSwaggerDefinition(apiId)).thenReturn(SampleTestObjectCreator.apiDefinition);
API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI();
API api = apiBuilder.id(apiId).build();
APIDTO apidto = MappingUtil.toAPIDto(api);
Mockito.doReturn(api).doThrow(new IllegalArgumentException()).when(apiPublisher).getAPIbyUUID(apiId);
Mockito.doNothing().doThrow(new IllegalArgumentException()).when(apiPublisher).updateAPI(apiBuilder);
Response response = apisApiService.apisApiIdPut(apiId, apidto, null, null, getRequest());
assertEquals(response.getStatus(), 200);
assertTrue(response.getEntity().toString().contains(api.getId()));
assertTrue(response.getEntity().toString().contains(api.getName()));
}
use of org.wso2.carbon.user.core.common.User in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdLifecycleHistoryGetAPINotExist.
@Test
public void testApisApiIdLifecycleHistoryGetAPINotExist() 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.doReturn(false).doThrow(new IllegalArgumentException()).when(apiPublisher).isAPIExists(apiId);
Response response = apisApiService.apisApiIdLifecycleHistoryGet(apiId, null, null, getRequest());
assertEquals(response.getStatus(), 404);
assertTrue(response.getEntity().toString().contains("API not found"));
}
Aggregations