Search in sources :

Example 6 with APIRatingException

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());
    }
}
Also used : APIRatingException(org.wso2.carbon.apimgt.core.exception.APIRatingException) APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)

Example 7 with APIRatingException

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());
}
Also used : APIRatingException(org.wso2.carbon.apimgt.core.exception.APIRatingException) Response(javax.ws.rs.core.Response) Request(org.wso2.msf4j.Request) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with APIRatingException

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());
    }
}
Also used : APIRatingException(org.wso2.carbon.apimgt.core.exception.APIRatingException) APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) Rating(org.wso2.carbon.apimgt.core.models.Rating)

Aggregations

APIRatingException (org.wso2.carbon.apimgt.core.exception.APIRatingException)8 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)5 Rating (org.wso2.carbon.apimgt.core.models.Rating)4 Response (javax.ws.rs.core.Response)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)3 Request (org.wso2.msf4j.Request)3 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException)1 RatingDTO (org.wso2.carbon.apimgt.rest.api.store.dto.RatingDTO)1