use of org.wso2.carbon.apimgt.core.exception.APIRatingException in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdUserRatingPutErrorCase.
@Test
public void testApisApiIdUserRatingPutErrorCase() 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 Occured", ExceptionCodes.RATING_NOT_FOUND)).when(apiStore).getRatingForApiFromUser(apiId, USER);
Rating rating = new Rating();
rating.setApiId(apiId);
rating.setRating(5);
rating.setUsername(USER);
rating.setUuid(rateId);
rating.setCreatedUser(USER);
rating.setCreatedTime(LocalDateTime.now().minusHours(2));
rating.setLastUpdatedUser(USER);
rating.setLastUpdatedTime(LocalDateTime.now());
RatingDTO ratingDTO = RatingMappingUtil.fromRatingToDTO(rating);
Response response = apisApiService.apisApiIdUserRatingPut(apiId, ratingDTO, request);
Assert.assertEquals(404, response.getStatus());
}
use of org.wso2.carbon.apimgt.core.exception.APIRatingException 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.core.exception.APIRatingException in project carbon-apimgt by wso2.
the class APIStoreImpl method updateRating.
@Override
public void updateRating(String apiId, String ratingId, Rating ratingFromPayload) throws APIRatingException, APIMgtResourceNotFoundException {
try {
validateMaxMinRatingValue(ratingFromPayload.getRating());
failIfApiNotExists(apiId);
getApiDAO().updateRating(apiId, ratingId, ratingFromPayload);
} catch (APIMgtDAOException e) {
String errorMsg = "Error occurred while updating rating for user " + getUsername() + " for api " + apiId;
log.error(errorMsg, e);
throw new APIRatingException(errorMsg, e, e.getErrorHandler());
}
}
use of org.wso2.carbon.apimgt.core.exception.APIRatingException in project carbon-apimgt by wso2.
the class APIStoreImpl method getRatingByUUID.
@Override
public Rating getRatingByUUID(String apiId, String ratingId) throws APIRatingException, APIMgtResourceNotFoundException {
Rating rating;
try {
failIfApiNotExists(apiId);
rating = getApiDAO().getRatingByUUID(apiId, ratingId);
if (rating == null) {
String errorMsg = "Couldn't find rating with rating id - " + ratingId + " for api_id " + apiId;
log.error(errorMsg);
throw new APIMgtResourceNotFoundException(errorMsg, ExceptionCodes.RATING_NOT_FOUND);
}
} catch (APIMgtDAOException e) {
String errorMsg = "Error occurred while retrieving rating for rating id " + ratingId + " for api_id " + apiId;
log.error(errorMsg, e);
throw new APIRatingException(errorMsg, e, e.getErrorHandler());
}
return rating;
}
use of org.wso2.carbon.apimgt.core.exception.APIRatingException in project carbon-apimgt by wso2.
the class APIStoreImpl method getRatingsListForApi.
@Override
public List<Rating> getRatingsListForApi(String apiId) throws APIRatingException, APIMgtResourceNotFoundException {
try {
failIfApiNotExists(apiId);
List<Rating> ratingsListForApi = getApiDAO().getRatingsListForApi(apiId);
return ratingsListForApi;
} catch (APIMgtDAOException e) {
String errorMsg = "Error occurred while retrieving ratings list for api_id " + apiId;
log.error(errorMsg, e);
throw new APIRatingException(errorMsg, e, e.getErrorHandler());
}
}
Aggregations