bugfix for OptimisticLockerInterceptor
@@ -26,29 +26,51 @@ public class OptimisticLockerInterceptorJUnitTest extends UserTestBase{
@Test
public void testUpdateWithoutVersionControl(){
- User user = userService.selectById(11);
+ User user = userService.selectById(11);//if cacheEnabled=true, this object will be cached
Assert.assertEquals(1, user.getAge().intValue());
- user.setVersion(null);
- user.setAge(2);
- userService.updateById(user);
+ User updateUser = new User();
+ updateUser.setId(user.getId());
+ updateUser.setAge(2);
+ userService.updateById(updateUser);
+
user = userService.selectById(11);
Assert.assertEquals(2, user.getAge().intValue());
Assert.assertEquals(1, user.getVersion().intValue());
+
+ User user2 = userService.selectById(12);
+ updateUser = new User();
+ updateUser.setAge(99);
+ updateUser.setPrice(new BigDecimal("9.99"));
+ userService.updateById(updateUser);
+ user2 = userService.selectById(12);
+ Assert.assertEquals(1, user2.getVersion().intValue());//test if version is cached in plugin [OK]
}
@Test
public void testUpdateWithVersionControl(){
long userId = 12;
User user = userService.selectById(userId);
- Assert.assertEquals(2, user.getAge().intValue());
- user.setAge(3);
- userService.updateById(user);
+ Assert.assertEquals(1, user.getVersion().intValue());
+ User updateUser = new User();
+ updateUser.setId(userId);
+ updateUser.setAge(3);
+ updateUser.setVersion(user.getVersion());
+ userService.updateById(updateUser);
+ user = userService.selectById(userId);
+
+ Assert.assertEquals(3, user.getAge().intValue());
+ Assert.assertEquals(2, user.getVersion().intValue());
+
User where = new User();
where.setId(userId);
+// updateUser = new User();
+// updateUser.setId(userId);
+// updateUser.setAge(3);
+// updateUser.setVersion(user.getVersion());
userService.update(user, new EntityWrapper<User>(where));
user = userService.selectById(userId);
Assert.assertEquals(3, user.getAge().intValue());
- Assert.assertEquals(2, user.getVersion().intValue());
+ Assert.assertEquals(3, user.getVersion().intValue());
}
}
