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