diff --git a/pom.xml b/pom.xml index 91ac8a9..5ec8225 100644 --- a/pom.xml +++ b/pom.xml @@ -18,21 +18,6 @@ 11 - - - org.springframework.boot - spring-boot-starter-security - - - org.thymeleaf.extras - thymeleaf-extras-springsecurity5 - - - org.springframework.security - spring-security-test - test - - org.springframework.boot spring-boot-starter-thymeleaf diff --git a/src/main/java/osm/surveyor/task/HomeController.java b/src/main/java/osm/surveyor/task/HomeController.java new file mode 100644 index 0000000..063d5bb --- /dev/null +++ b/src/main/java/osm/surveyor/task/HomeController.java @@ -0,0 +1,13 @@ +package osm.surveyor.task; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class HomeController { + + @GetMapping("/") + public String index() { + return "cities"; + } +} diff --git a/src/main/java/osm/surveyor/task/city/CitymeshController.java b/src/main/java/osm/surveyor/task/city/CitymeshController.java index 9c701aa..ed61e5a 100644 --- a/src/main/java/osm/surveyor/task/city/CitymeshController.java +++ b/src/main/java/osm/surveyor/task/city/CitymeshController.java @@ -2,13 +2,10 @@ import java.util.List; -import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.security.core.userdetails.UserDetails; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestParam; import lombok.RequiredArgsConstructor; import osm.surveyor.task.city.model.City; @@ -29,14 +26,4 @@ return "meshes"; } - @GetMapping("/usertask") - public String userTask(@AuthenticationPrincipal UserDetails user, Model model, - @RequestParam(name="user") String username) - { - List meshes = meshRepository.serchByUser(username); - model.addAttribute("username", username); - model.addAttribute("meshes", meshes); - return "meshlist"; - } - } diff --git a/src/main/java/osm/surveyor/task/city/TaskController.java b/src/main/java/osm/surveyor/task/city/TaskController.java index 69281e3..d44a599 100644 --- a/src/main/java/osm/surveyor/task/city/TaskController.java +++ b/src/main/java/osm/surveyor/task/city/TaskController.java @@ -9,8 +9,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; -import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.security.core.userdetails.UserDetails; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; @@ -45,17 +43,10 @@ * @return */ @GetMapping("/tasks") - public String showList(@AuthenticationPrincipal UserDetails user, Model model, + public String showList(Model model, @RequestParam(name="citycode") String citycode, @RequestParam(name="meshcode") String meshcode) { - // ログイン名を取得 - String loginName = ""; - if (user != null) { - loginName = user.getUsername(); - } - model.addAttribute("username", loginName); - City city = cityRepository.getById(citycode); model.addAttribute("citycode", citycode); model.addAttribute("cityname", city.getCityname()); @@ -80,8 +71,7 @@ * @return */ @GetMapping("/task/add") - public String addTask(@AuthenticationPrincipal UserDetails user, - Model model, + public String addTask(Model model, @RequestParam(name="op") String op, @RequestParam(name="citycode") String citycode, @RequestParam(name="meshcode") String meshcode) @@ -92,7 +82,7 @@ if (op.equals(Operation.RESERVE.toString())) { model.addAttribute("command", "編集者登録"); operation = Operation.RESERVE; - nextStatus = Status.EDITING; + nextStatus = Status.RESERVED; } else if (op.equals(Operation.CANCEL.toString())) { model.addAttribute("command", "編集取消"); @@ -111,13 +101,6 @@ nextStatus = Status.ACCEPTING; } - // ログイン名を取得 - String loginName = ""; - if (user != null) { - loginName = user.getUsername(); - } - model.addAttribute("username", loginName); - City city = cityRepository.getById(citycode); model.addAttribute("citycode", citycode); model.addAttribute("cityname", city.getCityname()); @@ -145,7 +128,7 @@ task.setMeshcode(meshcode); task.setMesh(mesh); task.setStatus(nextStatus); - task.setUsername(loginName); + task.setUsername(""); task.setOperation(operation); model.addAttribute("task", task); return next; @@ -153,15 +136,14 @@ } @PostMapping("/task/process") - public String process(@AuthenticationPrincipal UserDetails user, - @Validated @ModelAttribute TaskEntity task, + public String process(@Validated @ModelAttribute TaskEntity task, BindingResult result) { if (result.hasErrors()) { // エラーがある場合 return nextPage(task); } - service.add(task, user); + service.add(task); return "redirect:/tasks?citycode="+ task.getCitycode() +"&meshcode="+ task.getMeshcode(); } diff --git a/src/main/java/osm/surveyor/task/city/TaskService.java b/src/main/java/osm/surveyor/task/city/TaskService.java index 295ed94..422683a 100644 --- a/src/main/java/osm/surveyor/task/city/TaskService.java +++ b/src/main/java/osm/surveyor/task/city/TaskService.java @@ -1,7 +1,6 @@ package osm.surveyor.task.city; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.core.userdetails.UserDetails; import org.springframework.stereotype.Service; import osm.surveyor.task.city.model.Citymesh; @@ -26,9 +25,9 @@ @Autowired CitymeshRepository meshRepository; - public void add(TaskEntity task, UserDetails user) { + public void add(TaskEntity task) { if (task.getOperation() == Operation.RESERVE) { - task.setStatus(Status.EDITING); + task.setStatus(Status.RESERVED); } else if (task.getOperation() == Operation.CANCEL) { task.setStatus(Status.ACCEPTING); @@ -64,7 +63,7 @@ throw e; } if (task.getOperation() == Operation.CANCEL) { - if (ctask.getStatus() != Status.EDITING) { + if (ctask.getStatus() != Status.RESERVED) { NotAcceptableException e = new NotAcceptableException("タスクが'編集中'ではないため'編集取消'できませんでした : "+ task.getOperation()); e.setTask(task); throw e; @@ -73,6 +72,18 @@ else if (task.getOperation() == Operation.OK) { // タスク予約していなくてもインポートできる // 他のマッパーが予約していてもインポート可能 + String username = task.getUsername(); + if (username == null) { + TaskException e = new TaskException("編集者が入力されていません"); + e.setTask(task); + throw e; + } + else if (username.isEmpty()) { + TaskException e = new TaskException("編集者が入力されていません"); + e.setTask(task); + throw e; + } + String changeset = task.getChangeSet(); if (changeset == null) { TaskException e = new TaskException("変更セットNoが入力されていません"); @@ -96,6 +107,18 @@ } } else if (task.getOperation() == Operation.NG) { + String username = task.getUsername(); + if (username == null) { + TaskException e = new TaskException("編集者が入力されていません"); + e.setTask(task); + throw e; + } + else if (username.isEmpty()) { + TaskException e = new TaskException("編集者が入力されていません"); + e.setTask(task); + throw e; + } + String comment = task.getComment(); if (comment == null || comment.isEmpty()) { TaskException e = new TaskException("コメントが入力されていません"); diff --git a/src/main/java/osm/surveyor/task/city/model/Status.java b/src/main/java/osm/surveyor/task/city/model/Status.java index 8dae868..07e274a 100644 --- a/src/main/java/osm/surveyor/task/city/model/Status.java +++ b/src/main/java/osm/surveyor/task/city/model/Status.java @@ -3,8 +3,8 @@ public enum Status { PREPARATION, // 1: preparation 準備中 "X" ACCEPTING, // 2: Accepting 受付中 "1" - EDITING, // 4: 編集待ち "2" RESERVED, // 3: Reserved 予約済み "3" + EDITING, // 4: 編集中 "2" NG, // 5: 検証(NG) "0" OK // 6: 完了 "4" } diff --git a/src/main/java/osm/surveyor/task/user/config/SecurityConfig.java b/src/main/java/osm/surveyor/task/user/config/SecurityConfig.java deleted file mode 100644 index 7d501fa..0000000 --- a/src/main/java/osm/surveyor/task/user/config/SecurityConfig.java +++ /dev/null @@ -1,78 +0,0 @@ -package osm.surveyor.task.user.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.builders.WebSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.security.web.util.matcher.AntPathRequestMatcher; - -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor -@Configuration -@EnableWebSecurity -public class SecurityConfig extends WebSecurityConfigurerAdapter { - private final UserDetailsService userDetailsService; - - @Bean - public PasswordEncoder passwordEncoder() { - return new BCryptPasswordEncoder(); - } - - @Override - public void configure(WebSecurity web) throws Exception { - // セキュリティ設定を、無視(ignoring)するパスを指定します - // 通常、cssやjs、imgなどの静的リソースを指定します - web.ignoring().antMatchers( - "/favicon.ico", - "/custom/**", - "/pref/**", - "/js/**", - "/css/**", - "/img/**", - "/data/**", - "/webjars/**", - "/howto", - "/h2-console/**" - ); - } - - @Override - protected void configure(HttpSecurity http) throws Exception { - http.authorizeHttpRequests() - // 「/login」と「/error」をアクセス可能にします - .antMatchers("/login", "/error", "/register").permitAll() - .anyRequest().authenticated() - .and() - .formLogin() - // ログイン時のURLを指定 - .loginPage("/login") - // 認証後にリダイレクトする場所を指定 - .defaultSuccessUrl("/city") - .and() - // ログアウトの設定 - .logout() - // ログアウト時のURLを指定 - .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) - .and() - // Remember-Meの認証を許可します - // これを設定すると、ブラウザを閉じて、 - // 再度開いた場合でも「ログインしたまま」にできます - .rememberMe(); - } - - /** - * ユーザ名「admin」と「user」を用意します - * パスワードは両方とも「password」です - */ - @Override - protected void configure(AuthenticationManagerBuilder auth) throws Exception { - auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder()); - } -} diff --git a/src/main/java/osm/surveyor/task/user/controller/SecurityController.java b/src/main/java/osm/surveyor/task/user/controller/SecurityController.java deleted file mode 100644 index bfcd35f..0000000 --- a/src/main/java/osm/surveyor/task/user/controller/SecurityController.java +++ /dev/null @@ -1,70 +0,0 @@ -package osm.surveyor.task.user.controller; - -import org.springframework.security.core.Authentication; -import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.validation.BindingResult; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PostMapping; - -import lombok.RequiredArgsConstructor; -import osm.surveyor.task.user.model.SiteUser; -import osm.surveyor.task.user.repository.SiteUserRepository; -import osm.surveyor.task.util.Role; - -@RequiredArgsConstructor -@Controller -public class SecurityController { - - private final SiteUserRepository userRepository; - private final PasswordEncoder passwordEncoder; - - @GetMapping("/login") - public String success() { - return "login"; - } - - @GetMapping("/") - public String showList(Authentication loginUser, Model model) { - if (loginUser == null) { - model.addAttribute("username", ""); - model.addAttribute("role", ""); - } - else { - model.addAttribute("username", loginUser.getName()); - model.addAttribute("role", loginUser.getAuthorities()); - } - return "redirect:/city"; - } - - @GetMapping("/admin/list") - public String showAdminList(Model model) { - model.addAttribute("users", userRepository.findAll()); - return "list"; - } - - @GetMapping("/register") - public String register(@ModelAttribute("user") SiteUser user) { - return "register"; - } - - @PostMapping("/register") - public String process(@Validated @ModelAttribute("user") SiteUser user, BindingResult result) { - if (result.hasErrors()) { - return "register"; - } - - user.setPassword(passwordEncoder.encode(user.getPassword())); - if (user.isAdmin()) { - user.setRole(Role.ADMIN.name()); - } else { - user.setRole(Role.USER.name()); - } - userRepository.save(user); - - return "redirect:/login?register"; - } -} diff --git a/src/main/java/osm/surveyor/task/user/model/SiteUser.java b/src/main/java/osm/surveyor/task/user/model/SiteUser.java deleted file mode 100644 index f7b0905..0000000 --- a/src/main/java/osm/surveyor/task/user/model/SiteUser.java +++ /dev/null @@ -1,37 +0,0 @@ -package osm.surveyor.task.user.model; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.validation.constraints.Email; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.Size; - -import lombok.Getter; -import lombok.Setter; -import osm.surveyor.task.user.validator.UniqueLogin; - -@Getter -@Setter -@Entity -public class SiteUser { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @Size(min = 2, max = 20) - @UniqueLogin - private String username; - - @Size(min = 4, max = 255) - private String password; - - @NotBlank - @Email - private String email; - - private boolean admin; - private String role; - private boolean active = true; -} diff --git a/src/main/java/osm/surveyor/task/user/repository/SiteUserRepository.java b/src/main/java/osm/surveyor/task/user/repository/SiteUserRepository.java deleted file mode 100644 index 83ee8b4..0000000 --- a/src/main/java/osm/surveyor/task/user/repository/SiteUserRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package osm.surveyor.task.user.repository; - -import org.springframework.data.jpa.repository.JpaRepository; - -import osm.surveyor.task.user.model.SiteUser; - -public interface SiteUserRepository extends JpaRepository { - SiteUser findByUsername(String username); - boolean existsByUsername(String username); -} diff --git a/src/main/java/osm/surveyor/task/user/service/UserDetailsServiceImpl.java b/src/main/java/osm/surveyor/task/user/service/UserDetailsServiceImpl.java deleted file mode 100644 index 91bac3c..0000000 --- a/src/main/java/osm/surveyor/task/user/service/UserDetailsServiceImpl.java +++ /dev/null @@ -1,39 +0,0 @@ -package osm.surveyor.task.user.service; - -import java.util.HashSet; - -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.core.userdetails.User; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.core.userdetails.UsernameNotFoundException; -import org.springframework.stereotype.Service; - - -import lombok.RequiredArgsConstructor; -import osm.surveyor.task.user.model.SiteUser; -import osm.surveyor.task.user.repository.SiteUserRepository; - -@RequiredArgsConstructor -@Service -public class UserDetailsServiceImpl implements UserDetailsService { - - private final SiteUserRepository userRepository; - - @Override - public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { - var user = userRepository.findByUsername(username); - if (user == null) { - throw new UsernameNotFoundException(username + " not found"); - } - return createUserDetails(user); - } - - public User createUserDetails(SiteUser user) { - var grantedAuthorities = new HashSet(); - grantedAuthorities.add(new SimpleGrantedAuthority("ROLE_" + user.getRole())); - - return new User(user.getUsername(), user.getPassword(), grantedAuthorities); - } -} diff --git a/src/main/java/osm/surveyor/task/user/validator/UniqueLogin.java b/src/main/java/osm/surveyor/task/user/validator/UniqueLogin.java deleted file mode 100644 index 3c05159..0000000 --- a/src/main/java/osm/surveyor/task/user/validator/UniqueLogin.java +++ /dev/null @@ -1,18 +0,0 @@ -package osm.surveyor.task.user.validator; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import javax.validation.Constraint; -import javax.validation.Payload; - -@Target({ElementType.METHOD, ElementType.FIELD}) -@Retention(RetentionPolicy.RUNTIME) -@Constraint(validatedBy = UniqueLoginValidator.class) -public @interface UniqueLogin { - String message() default "このユーザ名は既に登録されています"; - Class>[] groups() default{}; - Class extends Payload>[] payload() default{}; -} diff --git a/src/main/java/osm/surveyor/task/user/validator/UniqueLoginValidator.java b/src/main/java/osm/surveyor/task/user/validator/UniqueLoginValidator.java deleted file mode 100644 index 4cf6aa5..0000000 --- a/src/main/java/osm/surveyor/task/user/validator/UniqueLoginValidator.java +++ /dev/null @@ -1,27 +0,0 @@ -package osm.surveyor.task.user.validator; - -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; - -import org.springframework.beans.factory.annotation.Autowired; - -import osm.surveyor.task.user.repository.SiteUserRepository; - -public class UniqueLoginValidator implements ConstraintValidator { - - private final SiteUserRepository userRepository; - - public UniqueLoginValidator() { - this.userRepository = null; - } - - @Autowired - public UniqueLoginValidator(SiteUserRepository userRepository) { - this.userRepository = userRepository; - } - - @Override - public boolean isValid(String value, ConstraintValidatorContext context) { - return userRepository == null || userRepository.findByUsername(value) == null; - } -} diff --git a/src/main/resources/templates/form.html b/src/main/resources/templates/form.html deleted file mode 100644 index 0f27483..0000000 --- a/src/main/resources/templates/form.html +++ /dev/null @@ -1,71 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - マッパー登録 - - - - - citycode - - - - - - - cityname - - - - - - - folder - - - - - - - - - 保存 - - - - - - - - - - - - - diff --git a/src/main/resources/templates/fragments/sidebar.html b/src/main/resources/templates/fragments/sidebar.html index 5752b84..7f27a81 100644 --- a/src/main/resources/templates/fragments/sidebar.html +++ b/src/main/resources/templates/fragments/sidebar.html @@ -31,30 +31,12 @@ - - - ログイン - - - - - - ログアウト - - - BLDGデータリスト - - - マッパーリスト - - - 管理 diff --git a/src/main/resources/templates/login.html b/src/main/resources/templates/login.html deleted file mode 100644 index 84e9d31..0000000 --- a/src/main/resources/templates/login.html +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - - - - - - - - - - ログイン - - - - - - - - - - - - - - - - - - ログインしたままにする - - - - ログイン - - - - - - 新規登録はこちら - - - - - - - - - - - diff --git a/src/main/resources/templates/register.html b/src/main/resources/templates/register.html deleted file mode 100644 index d0dbd70..0000000 --- a/src/main/resources/templates/register.html +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - - - - - - - - - - - - マッパー登録 - - - - - - 必須 - マッパー名 - - - - - - - - - 必須 - パスワード - - - - - - - - - 必須 - メールアドレス - - - - - - - - - - 管理者(Admin)として登録する - - - - - 登録 - - - - - - - - - - - diff --git a/src/main/resources/templates/task.html b/src/main/resources/templates/task.html index 7059e14..5937ca9 100644 --- a/src/main/resources/templates/task.html +++ b/src/main/resources/templates/task.html @@ -92,13 +92,22 @@ - + 必須 + 編集者 + + + + + + + + コメント diff --git a/src/main/resources/templates/task_done.html b/src/main/resources/templates/task_done.html index 136d999..28cb520 100644 --- a/src/main/resources/templates/task_done.html +++ b/src/main/resources/templates/task_done.html @@ -87,13 +87,22 @@ - 必須 + 編集者 + + + + + + + + + 必須 変更セットNo diff --git a/src/main/resources/templates/user.html b/src/main/resources/templates/user.html deleted file mode 100644 index b9afdb4..0000000 --- a/src/main/resources/templates/user.html +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - ログイン情報 - - - - - - - マッパー名 - マッパー権限 - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/test/java/osm/surveyor/task/user/controller/SecurityControllerTest.java b/src/test/java/osm/surveyor/task/user/controller/SecurityControllerTest.java deleted file mode 100644 index 52f60c9..0000000 --- a/src/test/java/osm/surveyor/task/user/controller/SecurityControllerTest.java +++ /dev/null @@ -1,85 +0,0 @@ -package osm.surveyor.task.user.controller; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; - -import javax.transaction.Transactional; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.security.test.context.support.WithMockUser; -import org.springframework.test.web.servlet.MockMvc; - -import osm.surveyor.task.user.model.SiteUser; -import osm.surveyor.task.util.Role; - -@SpringBootTest -@AutoConfigureMockMvc -@Transactional -class SecurityControllerTest { - - @Autowired - MockMvc mockMvc; - - @Test - @DisplayName("登録エラーがある時、エラー表示することを期待します") - void whenThereIsRegistrationError_expectToSeeErrors() throws Exception { - mockMvc - // リクエストを実行します - .perform( - // HTTPのPOSTリクエストを使用します - post("/register") - // 入力の属性を設定します - .flashAttr("user", new SiteUser()) - // CSRFトークンを自動挿入します - .with(csrf()) - ) - // エラーがあることを検証します - .andExpect(model().hasErrors()) - // 指定したHTMLを表示しているか検証します - .andExpect(view().name("register")); - } - - @Test - @DisplayName("管理者ユーザとして登録する時、成功することを期待します") - void whenRegisteringAsAdminUser_expectToSucceed() throws Exception { - var user = new SiteUser(); - user.setUsername("管理者ユーザ"); - user.setPassword("password"); - user.setEmail("admin@example.com"); - user.setAdmin(true); - user.setRole(Role.ADMIN.name()); - - mockMvc.perform(post("/register") - .flashAttr("user", user).with(csrf())) - // エラーがないことを検証します - .andExpect(model().hasNoErrors()) - // 指定したURLに、リダイレクトすることを検証します - .andExpect(redirectedUrl("/login?register")) - // ステータスコードが、Found(302)であることを検証します - .andExpect(status().isFound()); - } - - @Test - @DisplayName("管理者ユーザでログイン時、ユーザ一覧を表示することを期待します") - @WithMockUser(username="admin", roles="ADMIN") - void whenLoggedInAsAdminUser_expectToSeeListOfUsers() throws Exception { - mockMvc.perform(get("/admin/list")) - // ステータスコードが、OK(200)であることを検証します - .andExpect(status().isOk()) - // HTMLの表示内容に、指定した文字列を含んでいるか検証します - .andExpect(content().string(containsString("マッパーリスト"))) - .andExpect(view().name("list")); - } - -} diff --git a/src/test/java/osm/surveyor/task/user/service/UserDetailsServiceImplTest.java b/src/test/java/osm/surveyor/task/user/service/UserDetailsServiceImplTest.java deleted file mode 100644 index 03712c0..0000000 --- a/src/test/java/osm/surveyor/task/user/service/UserDetailsServiceImplTest.java +++ /dev/null @@ -1,73 +0,0 @@ -package osm.surveyor.task.user.service; - -import static org.junit.jupiter.api.Assertions.*; - -import javax.transaction.Transactional; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.security.core.userdetails.UsernameNotFoundException; - -import osm.surveyor.task.user.model.SiteUser; -import osm.surveyor.task.util.Role; - -import osm.surveyor.task.user.repository.SiteUserRepository; - -@SpringBootTest -@Transactional -class UserDetailsServiceImplTest { - - @Autowired - SiteUserRepository repository; - - @Autowired - UserDetailsServiceImpl service; - - @BeforeAll - static void setUpBeforeClass() throws Exception { - } - - @AfterAll - static void tearDownAfterClass() throws Exception { - } - - @BeforeEach - void setUp() throws Exception { - } - - @AfterEach - void tearDown() throws Exception { - } - - @Test - @DisplayName("ユーザ名が存在する時、ユーザ詳細を取得することを期待します") - void test() { - // Arrange(準備する) - var user = new SiteUser(); - user.setUsername("Harada"); - user.setPassword("password"); - user.setEmail("harada@example.com"); - user.setRole(Role.USER.name()); - repository.save(user); - - // Act(実行する) - var actual = service.loadUserByUsername("Harada"); - - // Assert(検証する) - assertEquals(user.getUsername(), actual.getUsername()); - } - - @Test - @DisplayName("ユーザ名が存在しない時、例外をスローします") - void whenUsernameDoesNotExist_throwException() { - // Act & Assert - assertThrows(UsernameNotFoundException.class, - () -> service.loadUserByUsername("Takeda")); - } -}