Search in sources :

Example 6 with RatingDTO

use of org.wso2.carbon.apimgt.rest.api.store.dto.RatingDTO in project carbon-apimgt by wso2.

the class RatingMappingUtil method fromRatingToDTO.

/**
 * Converts an Rating object into corresponding REST API RatingDTO object
 *
 * @param rating Comment object
 * @return a new RatingDTO object corresponding to given Rating object
 */
public static RatingDTO fromRatingToDTO(Rating rating) {
    RatingDTO ratingDTO = new RatingDTO();
    ratingDTO.setRatingId(rating.getUuid());
    ratingDTO.setRating(rating.getRating());
    ratingDTO.setUsername(rating.getUsername());
    return ratingDTO;
}
Also used : RatingDTO(org.wso2.carbon.apimgt.rest.api.store.dto.RatingDTO)

Example 7 with RatingDTO

use of org.wso2.carbon.apimgt.rest.api.store.dto.RatingDTO in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method testApisApiIdUserRatingPut.

@Test
public void testApisApiIdUserRatingPut() 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);
    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);
    Rating ratingNow = new Rating();
    ratingNow.setApiId(apiId);
    ratingNow.setRating(3);
    ratingNow.setUsername(USER);
    ratingNow.setUuid(rateId);
    ratingNow.setCreatedUser(USER);
    ratingNow.setCreatedTime(LocalDateTime.now().minusHours(2));
    ratingNow.setLastUpdatedUser(USER);
    ratingNow.setLastUpdatedTime(LocalDateTime.now());
    Mockito.when(apiStore.getRatingForApiFromUser(apiId, USER)).thenReturn(ratingNow);
    Mockito.doNothing().doThrow(new IllegalArgumentException()).when(apiStore).updateRating(apiId, ratingNow.getUuid(), rating);
    Mockito.when(apiStore.getRatingByUUID(apiId, ratingNow.getUuid())).thenReturn(ratingNow);
    Response response = apisApiService.apisApiIdUserRatingPut(apiId, ratingDTO, request);
    Assert.assertEquals(200, response.getStatus());
}
Also used : 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 8 with RatingDTO

use of org.wso2.carbon.apimgt.rest.api.store.dto.RatingDTO in project carbon-apimgt by wso2.

the class RatingMappingUtil method fromDTOToRating.

/**
 * Converts a RatingDTO to a Rating
 *
 * @param username username of the invoked user
 * @param apiId UUID of the api
 * @param body request payload
 * @return a new rating object
 */
public static Rating fromDTOToRating(String username, String apiId, RatingDTO body) {
    Rating rating = new Rating();
    rating.setApiId(apiId);
    rating.setRating(body.getRating());
    rating.setUsername(username);
    return rating;
}
Also used : Rating(org.wso2.carbon.apimgt.core.models.Rating)

Aggregations

RatingDTO (org.wso2.carbon.apimgt.rest.api.store.dto.RatingDTO)7 Rating (org.wso2.carbon.apimgt.core.models.Rating)6 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)5 HashMap (java.util.HashMap)3 Map (java.util.Map)3 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)3 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)3 Response (javax.ws.rs.core.Response)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 RatingListDTO (org.wso2.carbon.apimgt.rest.api.store.dto.RatingListDTO)2 Request (org.wso2.msf4j.Request)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 DecimalFormat (java.text.DecimalFormat)1 APIRatingException (org.wso2.carbon.apimgt.core.exception.APIRatingException)1 ErrorHandler (org.wso2.carbon.apimgt.core.exception.ErrorHandler)1