build: test crud

This commit is contained in:
CaptainB 2023-05-23 17:50:11 +08:00
parent f13c1c87b2
commit 0f90e2f31c
4 changed files with 13 additions and 10 deletions

View File

@ -1,7 +1,12 @@
package io.metersphere.sdk.mapper; package io.metersphere.sdk.mapper;
import io.metersphere.sdk.dto.UserDTO; import io.metersphere.sdk.dto.UserDTO;
import io.metersphere.system.domain.User;
import java.util.List;
public interface UserMapper { public interface UserMapper {
UserDTO selectById(String id); UserDTO selectById(String id);
List<User> findAll();
} }

View File

@ -8,4 +8,9 @@
LEFT JOIN user_extend ON user.id = user_extend.id LEFT JOIN user_extend ON user.id = user_extend.id
WHERE user.id = #{id} WHERE user.id = #{id}
</select> </select>
<select id="findAll" resultType="io.metersphere.system.domain.User">
SELECT *
FROM user
</select>
</mapper> </mapper>

View File

@ -6,8 +6,6 @@ import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.system.domain.User; import io.metersphere.system.domain.User;
import io.metersphere.system.domain.UserExtend; import io.metersphere.system.domain.UserExtend;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections4.IterableUtils;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jdbc.core.JdbcAggregateTemplate; import org.springframework.data.jdbc.core.JdbcAggregateTemplate;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -41,9 +39,6 @@ public class UserService {
} }
public List<User> list() { public List<User> list() {
return userMapper.findAll();
PageRequest pageable = PageRequest.of(2, 5);
Iterable<User> users = jdbcAggregateTemplate.findAll(User.class, pageable);
return IterableUtils.toList(users);
} }
} }

View File

@ -1,7 +1,7 @@
package io.metersphere.system.controller; package io.metersphere.system.controller;
import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.dto.UserDTO; import io.metersphere.sdk.dto.UserDTO;
import io.metersphere.sdk.util.JSON;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Order;
@ -13,7 +13,6 @@ import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@ -30,8 +29,7 @@ public class UserControllerTests {
mockMvc.perform(MockMvcRequestBuilders.get("/user/list-all")) mockMvc.perform(MockMvcRequestBuilders.get("/user/list-all"))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(content().contentType(MediaType.APPLICATION_JSON))
// .andExpect(jsonPath("$.person.name").value("Jason")) .andExpect(jsonPath("$.data[0].name").value("admin"));
.andDo(print());
} }
@Test @Test