Search in sources :

Example 6 with Favorite

use of com.ctrip.framework.apollo.portal.entity.po.Favorite in project apollo by ctripcorp.

the class FavoriteServiceTest method testSearchByAppIdAndUserId.

@Test
@Sql(scripts = "/sql/favorites/favorites.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testSearchByAppIdAndUserId() {
    List<Favorite> favorites = favoriteService.search(testUser, "test0621-04", new PageRequest(0, 10));
    Assert.assertEquals(1, favorites.size());
}
Also used : Favorite(com.ctrip.framework.apollo.portal.entity.po.Favorite) PageRequest(org.springframework.data.domain.PageRequest) AbstractIntegrationTest(com.ctrip.framework.apollo.portal.AbstractIntegrationTest) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 7 with Favorite

use of com.ctrip.framework.apollo.portal.entity.po.Favorite in project apollo by ctripcorp.

the class FavoriteServiceTest method testAdjustFavorite.

@Test
@Sql(scripts = "/sql/favorites/favorites.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testAdjustFavorite() {
    long toAdjustFavoriteId = 20;
    favoriteService.adjustFavoriteToFirst(toAdjustFavoriteId);
    List<Favorite> favorites = favoriteService.search(testUser, null, PageRequest.of(0, 10));
    Favorite firstFavorite = favorites.get(0);
    Favorite secondFavorite = favorites.get(1);
    Assert.assertEquals(toAdjustFavoriteId, firstFavorite.getId());
    Assert.assertEquals(firstFavorite.getPosition() + 1, secondFavorite.getPosition());
}
Also used : Favorite(com.ctrip.framework.apollo.portal.entity.po.Favorite) AbstractIntegrationTest(com.ctrip.framework.apollo.portal.AbstractIntegrationTest) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 8 with Favorite

use of com.ctrip.framework.apollo.portal.entity.po.Favorite in project apollo by ctripcorp.

the class FavoriteServiceTest method testAddNormalFavorite.

@Test
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testAddNormalFavorite() {
    String testApp = "testApp";
    Favorite favorite = instanceOfFavorite(testUser, testApp);
    favoriteService.addFavorite(favorite);
    List<Favorite> createdFavorites = favoriteService.search(testUser, testApp, PageRequest.of(0, 10));
    Assert.assertEquals(1, createdFavorites.size());
    Assert.assertEquals(FavoriteService.POSITION_DEFAULT, createdFavorites.get(0).getPosition());
    Assert.assertEquals(testUser, createdFavorites.get(0).getUserId());
    Assert.assertEquals(testApp, createdFavorites.get(0).getAppId());
}
Also used : Favorite(com.ctrip.framework.apollo.portal.entity.po.Favorite) AbstractIntegrationTest(com.ctrip.framework.apollo.portal.AbstractIntegrationTest) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 9 with Favorite

use of com.ctrip.framework.apollo.portal.entity.po.Favorite in project apollo by ctripcorp.

the class FavoriteServiceTest method testAddFavoriteErrorUser.

@Test(expected = BadRequestException.class)
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testAddFavoriteErrorUser() {
    String testApp = "testApp";
    Favorite favorite = instanceOfFavorite("errorUser", testApp);
    favoriteService.addFavorite(favorite);
}
Also used : Favorite(com.ctrip.framework.apollo.portal.entity.po.Favorite) AbstractIntegrationTest(com.ctrip.framework.apollo.portal.AbstractIntegrationTest) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 10 with Favorite

use of com.ctrip.framework.apollo.portal.entity.po.Favorite in project apollo by ctripcorp.

the class FavoriteService method adjustFavoriteToFirst.

public void adjustFavoriteToFirst(long favoriteId) {
    Favorite favorite = favoriteRepository.findById(favoriteId).orElse(null);
    checkUserOperatePermission(favorite);
    String userId = favorite.getUserId();
    Favorite firstFavorite = favoriteRepository.findFirstByUserIdOrderByPositionAscDataChangeCreatedTimeAsc(userId);
    long minPosition = firstFavorite.getPosition();
    favorite.setPosition(minPosition - 1);
    favoriteRepository.save(favorite);
}
Also used : Favorite(com.ctrip.framework.apollo.portal.entity.po.Favorite)

Aggregations

Favorite (com.ctrip.framework.apollo.portal.entity.po.Favorite)10 AbstractIntegrationTest (com.ctrip.framework.apollo.portal.AbstractIntegrationTest)6 Test (org.junit.Test)6 Sql (org.springframework.test.context.jdbc.Sql)6 PageRequest (org.springframework.data.domain.PageRequest)3 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)1 UserInfo (com.ctrip.framework.apollo.portal.entity.bo.UserInfo)1