use of org.wso2.carbon.apimgt.core.exception.APIRatingException in project carbon-apimgt by wso2.
the class APIStoreImpl method addRating.
@Override
public String addRating(String apiId, Rating rating) throws APIRatingException, APIMgtResourceNotFoundException {
try {
validateMaxMinRatingValue(rating.getRating());
failIfApiNotExists(apiId);
String generatedUuid = UUID.randomUUID().toString();
rating.setUuid(generatedUuid);
getApiDAO().addRating(apiId, rating);
return rating.getUuid();
} catch (APIMgtDAOException e) {
String errorMsg = "Error occurred while adding 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 ApisApiServiceImplTestCase method testApisApiIdRatingsGetErrorCase.
@Test
public void testApisApiIdRatingsGetErrorCase() 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 getRatingForApiFromUser.
@Override
public Rating getRatingForApiFromUser(String apiId, String userId) throws APIRatingException, APIMgtResourceNotFoundException {
try {
failIfApiNotExists(apiId);
Rating userRatingForApi = getApiDAO().getUserRatingForApiFromUser(apiId, userId);
return userRatingForApi;
} catch (APIMgtDAOException e) {
String errorMsg = "Error occurred while retrieving ratings for user " + userId + " for api " + apiId;
log.error(errorMsg, e);
throw new APIRatingException(errorMsg, e, e.getErrorHandler());
}
}
Aggregations