@Test public void testGeneratePrimaryKey() throws Exception { final String id = "id"; User user = (User) ParameterUtil.generatePrimaryKey(new User(), id); Assert.assertEquals(id, user.getId()); }
@Test public void testExtractPrimaryKey() throws Exception { final String id = "id"; User user = new User(); user.setId(id); Serializable privaryKey = ParameterUtil.extractPrimaryKey(user); Assert.assertEquals(privaryKey, id); }
/** for insert new user */ private User insertUser(String username, String password, int age, int gender) { User user = new User(username, password, gender); user.setAge(age); int rows = userMapper.insertUser(user); assertTrue("Insert User does not success!", rows == 1); assertNotNull(user.getId()); return user; }
@Test @Transactional public void testDelete() throws Exception { User user = this.insertUser("makersoft-vertical", "makersoft-vertical", 18, User.SEX_MALE); assertNotNull("Insert User does not success!", user); int rows = userMapper.deleteById(user.getId()); assertTrue("Delete User does not success!", rows == 1); user = userMapper.getById(user.getId()); assertNull(user); }
@Test @Transactional public void testUpdate() throws Exception { User user = this.insertUser("makersoft-vertical", "makersoft-vertical", 18, User.SEX_MALE); assertNotNull("Insert User does not success!", user); user.setUsername("fengkuok"); user.setPassword("password"); int rows = userMapper.updateById(user); assertTrue("Update User does not success!", rows == 1); User fengkuok = userMapper.getById(user.getId()); assertTrue("Update User does not success!", user.equals(fengkuok)); }
@Test @SuppressWarnings("unchecked") public void testObject() throws Exception { User user = new User(); user.setId("id"); user.setUsername("makersoft"); user.setPassword("password"); user.setAge(20); Object obj = ParameterUtil.resolve(user, shardId); Assert.assertTrue(obj instanceof Map); Map<String, Object> map = (Map<String, Object>) obj; Assert.assertEquals(PREFIX_VALUE, map.get(PREFIX)); Assert.assertEquals(SUFFIX_VALUE, map.get(SUFFIX)); Assert.assertEquals(user.getId(), map.get("id")); Assert.assertEquals(user.getUsername(), map.get("username")); Assert.assertEquals(user.getPassword(), map.get("password")); Assert.assertEquals(user.getAge(), map.get("age")); }