use of org.wso2.carbon.apimgt.api.model.APIStore in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdCommentsCommentIdPut.
@Test
public void testApisApiIdCommentsCommentIdPut() throws APIManagementException, NotFoundException {
printTestMethodName();
String apiId = UUID.randomUUID().toString();
String commentId = UUID.randomUUID().toString();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Request request = getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
CommentDTO commentDTO = new CommentDTO();
commentDTO.setApiId(apiId);
commentDTO.setCommentText("comment text");
commentDTO.setCreatedBy("creater");
commentDTO.setLastUpdatedBy("updater");
Comment comment = new Comment();
comment.setCommentedUser("commentedUser");
comment.setCommentText("this is a comment");
comment.setCreatedUser("createdUser");
comment.setUpdatedUser("updatedUser");
comment.setCreatedTime(LocalDateTime.now().minusHours(1));
comment.setUpdatedTime(LocalDateTime.now());
Mockito.doNothing().doThrow(new IllegalArgumentException()).when(apiStore).updateComment(comment, commentId, apiId, USER);
Mockito.when(apiStore.getCommentByUUID(commentId, apiId)).thenReturn(comment);
Response response = apisApiService.apisApiIdCommentsCommentIdPut(commentId, apiId, commentDTO, null, null, request);
Assert.assertEquals(200, response.getStatus());
}
use of org.wso2.carbon.apimgt.api.model.APIStore in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdRatingsRatingIdGetErrorCase.
@Test
public void testApisApiIdRatingsRatingIdGetErrorCase() throws APIManagementException, NotFoundException {
printTestMethodName();
String apiId = UUID.randomUUID().toString();
String rateId = UUID.randomUUID().toString();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Request request = getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
Mockito.doThrow(new APIRatingException("Error occurred", ExceptionCodes.RATING_NOT_FOUND)).when(apiStore).getRatingForApiFromUser(apiId, USER);
Response response = apisApiService.apisApiIdRatingsGet(apiId, 10, 0, request);
Assert.assertEquals(404, response.getStatus());
}
use of org.wso2.carbon.apimgt.api.model.APIStore in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdDocumentsDocumentIdContentGetErrorCase.
@Test
public void testApisApiIdDocumentsDocumentIdContentGetErrorCase() throws APIManagementException, NotFoundException {
printTestMethodName();
String apiId = UUID.randomUUID().toString();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Request request = getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
String documentIdFile = UUID.randomUUID().toString();
String documentIdInline = UUID.randomUUID().toString();
Mockito.doThrow(new APIManagementException("Error Occurred", ExceptionCodes.DOCUMENT_CONTENT_NOT_FOUND)).when(apiStore).getDocumentationContent(documentIdFile);
Mockito.doThrow(new APIManagementException("Error Occurred", ExceptionCodes.DOCUMENT_CONTENT_NOT_FOUND)).when(apiStore).getDocumentationContent(documentIdInline);
Response responseFile = apisApiService.apisApiIdDocumentsDocumentIdContentGet(apiId, documentIdFile, null, null, request);
Response responseInline = apisApiService.apisApiIdDocumentsDocumentIdContentGet(apiId, documentIdInline, null, null, request);
Assert.assertEquals(404, responseFile.getStatus());
Assert.assertEquals(404, responseInline.getStatus());
}
use of org.wso2.carbon.apimgt.api.model.APIStore in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdDocumentsGetErrorCase.
@Test
public void testApisApiIdDocumentsGetErrorCase() throws APIManagementException, NotFoundException {
printTestMethodName();
String apiId = UUID.randomUUID().toString();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Request request = getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
Mockito.doThrow(new APIManagementException("Error Occurred", ExceptionCodes.DOCUMENT_NOT_FOUND)).when(apiStore).getAllDocumentation(apiId, 0, 10);
Response response = apisApiService.apisApiIdDocumentsGet(apiId, 10, 0, null, request);
Assert.assertEquals(404, response.getStatus());
}
use of org.wso2.carbon.apimgt.api.model.APIStore in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdWsdlGetArchive.
@Test
public void testApisApiIdWsdlGetArchive() throws Exception {
printTestMethodName();
final String uuid = "11112222-3333-4444-5555-666677778888";
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Request request = getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
Mockito.doReturn(true).when(apiStore).isWSDLExists(uuid);
Mockito.doReturn(true).when(apiStore).isWSDLArchiveExists(uuid);
WSDLArchiveInfo archiveInfo = new WSDLArchiveInfo(WSDL_ZIP_LOCATION, WSDL_ZIP);
Mockito.doReturn(archiveInfo).when(apiStore).getAPIWSDLArchive(uuid, "Sample");
Response response = apisApiService.apisApiIdWsdlGet(uuid, "Sample", null, null, request);
Assert.assertEquals(response.getStatus(), 200);
Assert.assertTrue(response.getEntity() instanceof File);
}
Aggregations