Search in sources :

Example 1 with APIRatingException

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

Example 2 with APIRatingException

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());
}
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 3 with APIRatingException

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

Example 4 with APIRatingException

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;
}
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) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException)

Example 5 with APIRatingException

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());
    }
}
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