├── .gitignore ├── README.md ├── manifest.yml ├── pom.xml └── src ├── main ├── java │ └── jsug │ │ ├── App.java │ │ ├── AppConfig.java │ │ ├── SecurityConfig.java │ │ ├── app │ │ ├── account │ │ │ ├── AccountController.java │ │ │ └── AccountForm.java │ │ ├── cart │ │ │ ├── CartController.java │ │ │ └── CartForm.java │ │ ├── goods │ │ │ ├── AddToCartForm.java │ │ │ └── GoodsController.java │ │ ├── login │ │ │ └── LoginController.java │ │ └── order │ │ │ └── OrderController.java │ │ ├── domain │ │ ├── model │ │ │ ├── Account.java │ │ │ ├── Cart.java │ │ │ ├── Category.java │ │ │ ├── Goods.java │ │ │ ├── Order.java │ │ │ ├── OrderLine.java │ │ │ └── OrderLines.java │ │ ├── repository │ │ │ ├── SqlFinder.java │ │ │ ├── account │ │ │ │ └── AccountRepository.java │ │ │ ├── category │ │ │ │ └── CategoryRepository.java │ │ │ ├── goods │ │ │ │ └── GoodsRepository.java │ │ │ └── order │ │ │ │ └── OrderRepository.java │ │ ├── service │ │ │ ├── account │ │ │ │ └── AccountService.java │ │ │ ├── category │ │ │ │ └── CategoryService.java │ │ │ ├── goods │ │ │ │ ├── GoodsNotFoundException.java │ │ │ │ └── GoodsService.java │ │ │ ├── order │ │ │ │ ├── EmptyCartOrderException.java │ │ │ │ ├── InvalidCartOrderException.java │ │ │ │ └── OrderService.java │ │ │ └── userdetails │ │ │ │ ├── ShopUserDetails.java │ │ │ │ └── ShopUserDetailsService.java │ │ └── validation │ │ │ ├── Confirm.java │ │ │ ├── ConfirmValidator.java │ │ │ ├── UnusedEmail.java │ │ │ └── UnusedEmailValidator.java │ │ └── infra │ │ ├── cart │ │ └── CachingCart.java │ │ └── logging │ │ └── HandlerExceptionResolverLoggingAspect.java └── resources │ ├── application-cloud.properties │ ├── application.properties │ ├── db │ └── migration │ │ ├── V1__create-schema.sql │ │ └── V2__initial-data.sql │ ├── log4jdbc.log4j2.properties │ ├── messages.properties │ ├── sql │ ├── account │ │ ├── countByEmail.sql │ │ ├── create.sql │ │ └── findOne.sql │ ├── category │ │ └── findAll.sql │ ├── goods │ │ ├── countByCategoryId.sql │ │ ├── findByCategoryId.sql │ │ └── findOne.sql │ ├── order │ │ └── create.sql │ └── orderLine │ │ └── create.sql │ ├── static │ ├── css │ │ └── wro.css │ ├── fonts │ │ ├── montserrat-webfont.eot │ │ ├── montserrat-webfont.svg │ │ ├── montserrat-webfont.ttf │ │ ├── montserrat-webfont.woff │ │ ├── varela_round-webfont.eot │ │ ├── varela_round-webfont.svg │ │ ├── varela_round-webfont.ttf │ │ └── varela_round-webfont.woff │ └── images │ │ ├── 404-icon.png │ │ ├── homepage-bg.jpg │ │ ├── platform-bg.png │ │ ├── platform-spring-xd.png │ │ ├── spring-logo-xd-mobile.png │ │ └── spring-logo-xd.png │ └── templates │ ├── account │ ├── createFinish.html │ └── createForm.html │ ├── cart │ └── viewCart.html │ ├── error.html │ ├── goods │ ├── notFound.html │ └── showGoods.html │ ├── login │ └── loginForm.html │ └── order │ ├── confirm.html │ ├── error.html │ └── finish.html └── test ├── java └── jsug │ └── domain │ ├── TestConfig.java │ ├── model │ └── CartTest.java │ ├── repository │ ├── account │ │ └── AccountRepositoryTest.java │ ├── category │ │ └── CategoryRepositoryTest.java │ ├── goods │ │ └── GoodsRepositoryTest.java │ └── order │ │ └── OrderRepositoryTest.java │ └── service │ ├── account │ └── AccountServiceTest.java │ ├── goods │ └── GoodsServiceTest.java │ ├── order │ └── OrderServiceTest.java │ └── userdetails │ └── ShopUserDetailsServiceTest.java └── resources ├── logback.xml └── sql ├── drop-tables.sql ├── insert-accounts.sql ├── insert-category.sql ├── insert-goods.sql └── insert-orders.sql /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | target 3 | *.iml -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | mvn clean package 2 | 3 | ### Deploy to Pivotal Web Services 4 | 5 | cf create-service cleardb spark shop-db 6 | cf create-service rediscloud 30mb shop-redis 7 | cf push 8 | 9 | 10 | ### Deploy to Pivotal Cloud Foundry 11 | 12 | cf create-service p-mysql 100mb-dev shop-db 13 | cf create-service p-redis shared-vm shop-redis 14 | cf push 15 | -------------------------------------------------------------------------------- /manifest.yml: -------------------------------------------------------------------------------- 1 | --- 2 | applications: 3 | - name: jsug-shop 4 | memory: 1G 5 | random-route: true 6 | path: target/jsug-shop-1.0-SNAPSHOT.jar 7 | services: 8 | - shop-db 9 | - shop-redis -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | jsug 7 | jsug-shop 8 | 1.0-SNAPSHOT 9 | jar 10 | 11 | JSUG Shop 12 | 13 | 14 | org.springframework.boot 15 | spring-boot-starter-parent 16 | 1.3.3.RELEASE 17 | 18 | 19 | 20 | UTF-8 21 | jsug.App 22 | 1.8 23 | 1.16.4 24 | 1.16 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-aop 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-thymeleaf 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-starter-jdbc 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-starter-security 47 | 48 | 49 | org.springframework.data 50 | spring-data-commons 51 | 52 | 53 | org.springframework.session 54 | spring-session 55 | 56 | 57 | org.springframework.boot 58 | spring-boot-starter-redis 59 | 60 | 61 | org.springframework.boot 62 | spring-boot-starter-actuator 63 | 64 | 65 | org.flywaydb 66 | flyway-core 67 | 68 | 69 | com.h2database 70 | h2 71 | 72 | 73 | org.projectlombok 74 | lombok 75 | ${lombok.version} 76 | provided 77 | 78 | 79 | org.bgee.log4jdbc-log4j2 80 | log4jdbc-log4j2-jdbc4.1 81 | ${log4jdbc.log4j2.version} 82 | 83 | 84 | 85 | org.springframework.boot 86 | spring-boot-starter-test 87 | test 88 | 89 | 90 | 91 | 92 | 93 | org.springframework.boot 94 | spring-boot-maven-plugin 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /src/main/java/jsug/App.java: -------------------------------------------------------------------------------- 1 | package jsug; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class App { 8 | public static void main(String[] args) { 9 | SpringApplication.run(App.class, args); 10 | } 11 | } -------------------------------------------------------------------------------- /src/main/java/jsug/AppConfig.java: -------------------------------------------------------------------------------- 1 | package jsug; 2 | 3 | import jsug.domain.model.Cart; 4 | import jsug.infra.cart.CachingCart; 5 | import net.sf.log4jdbc.sql.jdbcapi.DataSourceSpy; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; 8 | import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; 9 | import org.springframework.boot.context.properties.ConfigurationProperties; 10 | import org.springframework.cache.annotation.EnableCaching; 11 | import org.springframework.context.annotation.*; 12 | import org.springframework.web.context.WebApplicationContext; 13 | 14 | import javax.sql.DataSource; 15 | 16 | @Configuration 17 | @EnableCaching 18 | public class AppConfig { 19 | @Autowired 20 | DataSourceProperties dataSourceProperties; 21 | DataSource dataSource; 22 | 23 | @Bean(destroyMethod = "close") 24 | @ConfigurationProperties(prefix = DataSourceProperties.PREFIX) 25 | DataSource realDataSource() { 26 | DataSourceBuilder factory = DataSourceBuilder 27 | .create(this.dataSourceProperties.getClassLoader()) 28 | .url(this.dataSourceProperties.getUrl()) 29 | .username(this.dataSourceProperties.getUsername()) 30 | .password(this.dataSourceProperties.getPassword()); 31 | this.dataSource = factory.build(); 32 | return this.dataSource; 33 | } 34 | 35 | @Primary 36 | @Bean 37 | DataSource dataSource() { 38 | return new DataSourceSpy(this.dataSource); 39 | } 40 | 41 | @Bean 42 | @Scope(value = WebApplicationContext.SCOPE_SESSION, proxyMode = ScopedProxyMode.TARGET_CLASS) 43 | Cart cart() { 44 | return new CachingCart(); 45 | } 46 | } -------------------------------------------------------------------------------- /src/main/java/jsug/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package jsug; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 7 | import org.springframework.security.config.annotation.authentication.configurers.GlobalAuthenticationConfigurerAdapter; 8 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 9 | import org.springframework.security.config.annotation.web.builders.WebSecurity; 10 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 11 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 12 | import org.springframework.security.core.userdetails.UserDetailsService; 13 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 14 | import org.springframework.security.crypto.password.PasswordEncoder; 15 | 16 | @Configuration 17 | @EnableWebSecurity 18 | public class SecurityConfig extends WebSecurityConfigurerAdapter { 19 | 20 | @Override 21 | public void configure(WebSecurity web) throws Exception { 22 | web.ignoring().antMatchers("/favicon.ico", "/css/**", "/js/**", "/images/**", "/fonts/**", "/shutdown" /* for Demo */); 23 | } 24 | 25 | @Override 26 | protected void configure(HttpSecurity http) throws Exception { 27 | http.authorizeRequests() 28 | .antMatchers("/loginForm").permitAll() 29 | .antMatchers("/account/**").permitAll() 30 | .anyRequest().authenticated(); 31 | http.formLogin() 32 | .loginProcessingUrl("/login") 33 | .loginPage("/loginForm") 34 | .failureUrl("/loginForm?error") 35 | .defaultSuccessUrl("/", true) 36 | .usernameParameter("username") 37 | .passwordParameter("password"); 38 | http.logout() 39 | .logoutUrl("/logout**") 40 | .logoutSuccessUrl("/loginForm"); 41 | } 42 | 43 | @Configuration 44 | static class AuthenticationConfiguration extends GlobalAuthenticationConfigurerAdapter { 45 | @Autowired 46 | UserDetailsService userDetailsService; 47 | 48 | @Bean 49 | PasswordEncoder passwordEncoder() { 50 | return new BCryptPasswordEncoder(); 51 | } 52 | 53 | @Override 54 | public void init(AuthenticationManagerBuilder auth) throws Exception { 55 | auth.userDetailsService(userDetailsService) 56 | .passwordEncoder(passwordEncoder()); 57 | } 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/jsug/app/account/AccountController.java: -------------------------------------------------------------------------------- 1 | package jsug.app.account; 2 | 3 | import jsug.domain.model.Account; 4 | import jsug.domain.service.account.AccountService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.validation.BindingResult; 8 | import org.springframework.validation.annotation.Validated; 9 | import org.springframework.web.bind.annotation.ModelAttribute; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RequestMethod; 12 | import org.springframework.web.servlet.mvc.support.RedirectAttributes; 13 | 14 | @Controller 15 | @RequestMapping("account") 16 | public class AccountController { 17 | @Autowired 18 | AccountService accountService; 19 | 20 | @ModelAttribute 21 | AccountForm setupForm() { 22 | return new AccountForm(); 23 | } 24 | 25 | @RequestMapping(value = "create", params = "form", method = RequestMethod.GET) 26 | String createForm() { 27 | return "account/createForm"; 28 | } 29 | 30 | @RequestMapping(value = "create", method = RequestMethod.POST) 31 | String create(@Validated AccountForm form, BindingResult bindingResult, 32 | RedirectAttributes attributes) { 33 | if (bindingResult.hasErrors()) { 34 | return "account/createForm"; 35 | } 36 | Account account = Account.builder() 37 | .name(form.getName()) 38 | .email(form.getEmail()) 39 | .birthDay(form.getBirthDay()) 40 | .zip(form.getZip()) 41 | .address(form.getAddress()) 42 | .build(); 43 | accountService.register(account, form.getPassword()); 44 | attributes.addFlashAttribute(account); 45 | return "redirect:/account/create?finish"; 46 | } 47 | 48 | @RequestMapping(value = "create", params = "finish", method = RequestMethod.GET) 49 | String createFinish() { 50 | return "account/createFinish"; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/jsug/app/account/AccountForm.java: -------------------------------------------------------------------------------- 1 | package jsug.app.account; 2 | 3 | import jsug.domain.validation.Confirm; 4 | import jsug.domain.validation.UnusedEmail; 5 | import lombok.Data; 6 | import org.hibernate.validator.constraints.Email; 7 | import org.springframework.format.annotation.DateTimeFormat; 8 | 9 | import javax.validation.constraints.NotNull; 10 | import javax.validation.constraints.Pattern; 11 | import javax.validation.constraints.Size; 12 | import java.io.Serializable; 13 | import java.time.LocalDate; 14 | 15 | @Data 16 | @Confirm(field = "password") 17 | public class AccountForm implements Serializable { 18 | @Email 19 | @Size(min = 1, max = 100) 20 | @NotNull 21 | @UnusedEmail 22 | private String email; 23 | @Size(min = 6) 24 | @NotNull 25 | private String password; 26 | @NotNull 27 | private String confirmPassword; 28 | @Size(min = 1, max = 40) 29 | @NotNull 30 | private String name; 31 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) 32 | @NotNull 33 | private LocalDate birthDay; 34 | @NotNull 35 | @Pattern(regexp = "[0-9]{7}") 36 | private String zip; 37 | @Size(min = 1, max = 100) 38 | @NotNull 39 | private String address; 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/jsug/app/cart/CartController.java: -------------------------------------------------------------------------------- 1 | package jsug.app.cart; 2 | 3 | import jsug.domain.model.Cart; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.ui.Model; 7 | import org.springframework.validation.BindingResult; 8 | import org.springframework.validation.annotation.Validated; 9 | import org.springframework.web.bind.annotation.ModelAttribute; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RequestMethod; 12 | 13 | @Controller 14 | @RequestMapping("cart") 15 | public class CartController { 16 | @Autowired 17 | Cart cart; 18 | 19 | @ModelAttribute 20 | CartForm setUpForm() { 21 | return new CartForm(); 22 | } 23 | 24 | @RequestMapping(method = RequestMethod.GET) 25 | String viewCart(Model model) { 26 | model.addAttribute("orderLines", cart.getOrderLines()); 27 | return "cart/viewCart"; 28 | } 29 | 30 | @RequestMapping(method = RequestMethod.POST) 31 | String removeFromCart(@Validated CartForm cartForm, BindingResult bindingResult, Model model) { 32 | if (bindingResult.hasErrors()) { 33 | model.addAttribute("error", "商品がチェックされていません"); 34 | return viewCart(model); 35 | } 36 | cart.remove(cartForm.getLineNo()); 37 | return "redirect:/cart"; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/jsug/app/cart/CartForm.java: -------------------------------------------------------------------------------- 1 | package jsug.app.cart; 2 | 3 | import lombok.Data; 4 | import org.hibernate.validator.constraints.NotEmpty; 5 | 6 | import javax.validation.constraints.NotNull; 7 | import java.io.Serializable; 8 | import java.util.Set; 9 | 10 | @Data 11 | public class CartForm implements Serializable { 12 | @NotEmpty 13 | @NotNull 14 | private Set lineNo; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/jsug/app/goods/AddToCartForm.java: -------------------------------------------------------------------------------- 1 | package jsug.app.goods; 2 | 3 | import lombok.Data; 4 | 5 | import javax.validation.constraints.Max; 6 | import javax.validation.constraints.Min; 7 | import javax.validation.constraints.NotNull; 8 | import java.util.UUID; 9 | 10 | @Data 11 | public class AddToCartForm { 12 | @NotNull 13 | private UUID goodsId; 14 | @Min(1) 15 | @Max(50) 16 | private int quantity; 17 | private int categoryId; 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/jsug/app/goods/GoodsController.java: -------------------------------------------------------------------------------- 1 | package jsug.app.goods; 2 | 3 | import jsug.domain.model.Cart; 4 | import jsug.domain.model.Category; 5 | import jsug.domain.model.Goods; 6 | import jsug.domain.model.OrderLine; 7 | import jsug.domain.service.category.CategoryService; 8 | import jsug.domain.service.goods.GoodsNotFoundException; 9 | import jsug.domain.service.goods.GoodsService; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.data.domain.Page; 12 | import org.springframework.data.domain.Pageable; 13 | import org.springframework.data.web.PageableDefault; 14 | import org.springframework.http.HttpStatus; 15 | import org.springframework.stereotype.Controller; 16 | import org.springframework.ui.Model; 17 | import org.springframework.validation.BindingResult; 18 | import org.springframework.validation.annotation.Validated; 19 | import org.springframework.web.bind.annotation.*; 20 | 21 | import java.util.List; 22 | 23 | @Controller 24 | public class GoodsController { 25 | 26 | @Autowired 27 | GoodsService goodsService; 28 | @Autowired 29 | CategoryService categoryService; 30 | @Autowired 31 | Cart cart; 32 | 33 | @ModelAttribute("categories") 34 | List getCategories() { 35 | return categoryService.findAll(); 36 | } 37 | 38 | @ModelAttribute 39 | AddToCartForm addToCartForm() { 40 | return new AddToCartForm(); 41 | } 42 | 43 | @RequestMapping(value = "/") 44 | String showGoods(@RequestParam(defaultValue = "1") Integer categoryId, 45 | @PageableDefault Pageable pageable, Model model) { 46 | Page page = goodsService.findByCategoryId(categoryId, pageable); 47 | model.addAttribute("page", page); 48 | model.addAttribute("categoryId", categoryId); 49 | return "goods/showGoods"; 50 | } 51 | 52 | @RequestMapping(value = "/addToCart", method = RequestMethod.POST) 53 | String addToCart(@Validated AddToCartForm form, BindingResult result, 54 | @PageableDefault Pageable pageable, Model model) { 55 | if (result.hasErrors()) { 56 | return showGoods(form.getCategoryId(), pageable, model); 57 | } 58 | Goods goods = goodsService.findOne(form.getGoodsId()); 59 | cart.add(OrderLine.builder() 60 | .goods(goods) 61 | .quantity(form.getQuantity()) 62 | .build()); 63 | return "redirect:/cart"; 64 | } 65 | 66 | @ExceptionHandler(GoodsNotFoundException.class) 67 | @ResponseStatus(HttpStatus.NOT_FOUND) 68 | String handleGoodsNotFoundException() { 69 | return "goods/notFound"; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/jsug/app/login/LoginController.java: -------------------------------------------------------------------------------- 1 | package jsug.app.login; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | @Controller 7 | public class LoginController { 8 | @RequestMapping("loginForm") 9 | String loginForm() { 10 | return "login/loginForm"; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/jsug/app/order/OrderController.java: -------------------------------------------------------------------------------- 1 | package jsug.app.order; 2 | 3 | import jsug.domain.model.Cart; 4 | import jsug.domain.model.Order; 5 | import jsug.domain.service.order.EmptyCartOrderException; 6 | import jsug.domain.service.order.InvalidCartOrderException; 7 | import jsug.domain.service.order.OrderService; 8 | import jsug.domain.service.userdetails.ShopUserDetails; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.http.HttpStatus; 11 | import org.springframework.security.core.annotation.AuthenticationPrincipal; 12 | import org.springframework.stereotype.Controller; 13 | import org.springframework.ui.Model; 14 | import org.springframework.web.bind.annotation.*; 15 | import org.springframework.web.servlet.ModelAndView; 16 | import org.springframework.web.servlet.mvc.support.RedirectAttributes; 17 | 18 | @Controller 19 | @RequestMapping("order") 20 | public class OrderController { 21 | @Autowired 22 | OrderService orderService; 23 | @Autowired 24 | Cart cart; 25 | 26 | @RequestMapping(method = RequestMethod.GET, params = "confirm") 27 | String confirm(@AuthenticationPrincipal ShopUserDetails userDetails, Model model) { 28 | model.addAttribute("orderLines", cart.getOrderLines()); 29 | if (cart.isEmpty()) { 30 | model.addAttribute("error", "買い物カゴが空です"); 31 | return "cart/viewCart"; 32 | } 33 | model.addAttribute("account", userDetails.getAccount()); 34 | model.addAttribute("signature", orderService.calcSignature(cart)); 35 | return "order/confirm"; 36 | } 37 | 38 | @RequestMapping(method = RequestMethod.POST) 39 | String order(@AuthenticationPrincipal ShopUserDetails userDetails, 40 | @RequestParam String signature, RedirectAttributes attributes) { 41 | Order order = orderService.purchase(userDetails.getAccount(), cart, signature); 42 | attributes.addFlashAttribute(order); 43 | return "redirect:/order?finish"; 44 | } 45 | 46 | @RequestMapping(method = RequestMethod.GET, params = "finish") 47 | String finish() { 48 | return "order/finish"; 49 | } 50 | 51 | @ExceptionHandler({EmptyCartOrderException.class, InvalidCartOrderException.class}) 52 | @ResponseStatus(HttpStatus.CONFLICT) 53 | ModelAndView handleOrderException(RuntimeException e) { 54 | return new ModelAndView("order/error") 55 | .addObject("error", e.getMessage()); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/jsug/domain/model/Account.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.model; 2 | 3 | import lombok.Builder; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | import java.time.LocalDate; 8 | 9 | @Data 10 | @Builder 11 | public class Account implements Serializable { 12 | private String email; 13 | private String password; 14 | private String name; 15 | private LocalDate birthDay; 16 | private String zip; 17 | private String address; 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/jsug/domain/model/Cart.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | import java.util.Iterator; 8 | import java.util.Objects; 9 | import java.util.Optional; 10 | import java.util.Set; 11 | 12 | @Data 13 | @AllArgsConstructor 14 | public class Cart implements Serializable { 15 | private final OrderLines orderLines; 16 | 17 | public Cart() { 18 | this(new OrderLines()); 19 | } 20 | 21 | public Cart add(OrderLine orderLine) { 22 | // 対象の商品が既に買い物カゴに入っているか確認 23 | Optional opt = orderLines.stream().filter(x -> 24 | Objects.equals(x.getGoods().getGoodsId(), orderLine.getGoods().getGoodsId())) 25 | .findFirst(); 26 | if (opt.isPresent()) { 27 | // 入っていたら数量を増やす 28 | OrderLine line = opt.get(); 29 | line.setQuantity(line.getQuantity() + orderLine.getQuantity()); 30 | } else { 31 | orderLines.list.add(orderLine); 32 | } 33 | return this; 34 | } 35 | 36 | public Cart clear() { 37 | orderLines.list.clear(); 38 | return this; 39 | } 40 | 41 | public Cart remove(Set lineNo) { 42 | Iterator iterator = getOrderLines().getList().iterator(); 43 | for (int i = 0; iterator.hasNext(); i++) { 44 | iterator.next(); 45 | if (lineNo.contains(i)) { 46 | iterator.remove(); 47 | } 48 | } 49 | return this; 50 | } 51 | 52 | public boolean isEmpty() { 53 | return orderLines.list.isEmpty(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/jsug/domain/model/Category.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.model; 2 | 3 | import lombok.Builder; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | 8 | @Data 9 | @Builder 10 | public class Category implements Serializable { 11 | private int categoryId; 12 | private String categoryName; 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/jsug/domain/model/Goods.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.model; 2 | 3 | import lombok.Builder; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | import java.util.UUID; 8 | 9 | @Data 10 | @Builder 11 | public class Goods implements Serializable { 12 | private UUID goodsId; 13 | private String goodsName; 14 | private String description; 15 | private Category category; 16 | private int price; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/jsug/domain/model/Order.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.model; 2 | 3 | import lombok.Builder; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | import java.time.LocalDate; 8 | import java.util.UUID; 9 | 10 | @Data 11 | @Builder 12 | public class Order implements Serializable { 13 | private UUID orderId; 14 | private String email; 15 | private OrderLines orderLines; 16 | private LocalDate orderDate; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/jsug/domain/model/OrderLine.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.model; 2 | 3 | import lombok.Builder; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | import java.util.UUID; 8 | 9 | @Data 10 | @Builder 11 | public class OrderLine implements Serializable { 12 | private Goods goods; 13 | private int quantity; 14 | private UUID orderId; 15 | private int lineNo; 16 | 17 | public long getSubtotal() { 18 | return quantity * goods.getPrice(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/jsug/domain/model/OrderLines.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | import java.util.UUID; 10 | import java.util.stream.Stream; 11 | 12 | @Data 13 | @AllArgsConstructor 14 | public class OrderLines implements Serializable { 15 | final List list; 16 | 17 | public OrderLines() { 18 | this(new ArrayList<>()); 19 | } 20 | 21 | public OrderLines orderId(UUID orderId) { 22 | int i = 0; 23 | for (OrderLine orderLine : list) { 24 | orderLine.setLineNo(++i); 25 | orderLine.setOrderId(orderId); 26 | } 27 | return this; 28 | } 29 | 30 | public Stream stream() { 31 | return list.stream(); 32 | } 33 | 34 | public long getTotal() { 35 | return list.stream() 36 | .mapToLong(OrderLine::getSubtotal) 37 | .sum(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/jsug/domain/repository/SqlFinder.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.repository; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.cache.annotation.Cacheable; 5 | import org.springframework.core.io.ClassPathResource; 6 | import org.springframework.core.io.Resource; 7 | import org.springframework.stereotype.Component; 8 | import org.springframework.util.StreamUtils; 9 | 10 | import java.io.IOException; 11 | import java.io.InputStream; 12 | import java.nio.charset.StandardCharsets; 13 | 14 | @Component 15 | @Slf4j 16 | public class SqlFinder { 17 | 18 | @Cacheable("sql") 19 | public String get(String path) { 20 | Resource resource = new ClassPathResource(path); 21 | log.info("load {}", resource); 22 | try (InputStream stream = resource.getInputStream()) { 23 | return StreamUtils.copyToString(stream, StandardCharsets.UTF_8); 24 | } catch (IOException e) { 25 | throw new IllegalArgumentException(path + " is not found!", e); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/jsug/domain/repository/account/AccountRepository.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.repository.account; 2 | 3 | import jsug.domain.model.Account; 4 | import jsug.domain.repository.SqlFinder; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; 7 | import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; 8 | import org.springframework.jdbc.core.namedparam.SqlParameterSource; 9 | import org.springframework.stereotype.Repository; 10 | import org.springframework.transaction.annotation.Transactional; 11 | 12 | import java.sql.Date; 13 | import java.util.Optional; 14 | 15 | @Repository 16 | @Transactional 17 | public class AccountRepository { 18 | @Autowired 19 | NamedParameterJdbcTemplate jdbcTemplate; 20 | @Autowired 21 | SqlFinder sql; 22 | 23 | public int countByEmail(String email) { 24 | SqlParameterSource source = new MapSqlParameterSource() 25 | .addValue("email", email); 26 | return jdbcTemplate.queryForObject(sql.get("sql/account/countByEmail.sql"), 27 | source, Integer.class); 28 | } 29 | 30 | public Optional findOne(String email) { 31 | SqlParameterSource source = new MapSqlParameterSource() 32 | .addValue("email", email); 33 | return jdbcTemplate.query(sql.get("sql/account/findOne.sql"), source, 34 | (rs, i) -> Account.builder() 35 | .email(rs.getString("email")) 36 | .password(rs.getString("password")) 37 | .name(rs.getString("name")) 38 | .birthDay(rs.getDate("birth_day").toLocalDate()) 39 | .address(rs.getString("address")) 40 | .zip(rs.getString("zip")) 41 | .build()) 42 | .stream() 43 | .findFirst(); 44 | } 45 | 46 | public Account create(Account account) { 47 | SqlParameterSource source = new MapSqlParameterSource() 48 | .addValue("email", account.getEmail()) 49 | .addValue("password", account.getPassword()) 50 | .addValue("name", account.getName()) 51 | .addValue("birthDay", Date.valueOf(account.getBirthDay())) 52 | .addValue("zip", account.getZip()) 53 | .addValue("address", account.getAddress()); 54 | jdbcTemplate.update(sql.get("sql/account/create.sql"), source); 55 | return account; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/jsug/domain/repository/category/CategoryRepository.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.repository.category; 2 | 3 | import jsug.domain.model.Category; 4 | import jsug.domain.repository.SqlFinder; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; 7 | import org.springframework.stereotype.Repository; 8 | import org.springframework.transaction.annotation.Transactional; 9 | 10 | import java.util.List; 11 | 12 | @Repository 13 | @Transactional 14 | public class CategoryRepository { 15 | @Autowired 16 | NamedParameterJdbcTemplate jdbcTemplate; 17 | @Autowired 18 | SqlFinder sql; 19 | 20 | public List findAll() { 21 | return jdbcTemplate.query(sql.get("sql/category/findAll.sql"), 22 | (rs, i) -> Category.builder() 23 | .categoryId(rs.getInt("category_id")) 24 | .categoryName(rs.getString("category_name")) 25 | .build()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/jsug/domain/repository/goods/GoodsRepository.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.repository.goods; 2 | 3 | import jsug.domain.model.Category; 4 | import jsug.domain.model.Goods; 5 | import jsug.domain.repository.SqlFinder; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.data.domain.Page; 8 | import org.springframework.data.domain.PageImpl; 9 | import org.springframework.data.domain.Pageable; 10 | import org.springframework.jdbc.core.RowMapper; 11 | import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; 12 | import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; 13 | import org.springframework.jdbc.core.namedparam.SqlParameterSource; 14 | import org.springframework.stereotype.Repository; 15 | import org.springframework.transaction.annotation.Transactional; 16 | 17 | import java.util.List; 18 | import java.util.Optional; 19 | import java.util.UUID; 20 | 21 | @Repository 22 | @Transactional 23 | public class GoodsRepository { 24 | @Autowired 25 | NamedParameterJdbcTemplate jdbcTemplate; 26 | @Autowired 27 | SqlFinder sql; 28 | 29 | RowMapper goodsRowMapper = (rs, i) -> Goods.builder() 30 | .goodsId(UUID.fromString(rs.getString("goods_id"))) 31 | .goodsName(rs.getString("goods_name")) 32 | .category(Category.builder() 33 | .categoryId(rs.getInt("category_id")) 34 | .categoryName(rs.getString("category_name")) 35 | .build()) 36 | .description(rs.getString("description")) 37 | .price(rs.getInt("price")) 38 | .build(); 39 | 40 | public Optional findOne(UUID goodsId) { 41 | SqlParameterSource source = new MapSqlParameterSource() 42 | .addValue("goodsId", goodsId.toString()); 43 | return jdbcTemplate.query(sql.get("sql/goods/findOne.sql"), source, goodsRowMapper) 44 | .stream() 45 | .findFirst(); 46 | } 47 | 48 | public Page findByCategoryId(int categoryId, Pageable pageable) { 49 | SqlParameterSource source = new MapSqlParameterSource() 50 | .addValue("categoryId", categoryId) 51 | .addValue("pageSize", pageable.getPageSize()) 52 | .addValue("offset", pageable.getOffset()); 53 | List content = jdbcTemplate.query(sql.get("sql/goods/findByCategoryId.sql"), source, goodsRowMapper); 54 | long total = countByCategoryId(categoryId); 55 | return new PageImpl<>(content, pageable, total); 56 | } 57 | 58 | public long countByCategoryId(int categoryId) { 59 | SqlParameterSource source = new MapSqlParameterSource() 60 | .addValue("categoryId", categoryId); 61 | return jdbcTemplate.queryForObject(sql.get("sql/goods/countByCategoryId.sql"), source, Long.class); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/jsug/domain/repository/order/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.repository.order; 2 | 3 | import jsug.domain.model.Order; 4 | import jsug.domain.repository.SqlFinder; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; 7 | import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; 8 | import org.springframework.jdbc.core.namedparam.SqlParameterSource; 9 | import org.springframework.stereotype.Repository; 10 | import org.springframework.transaction.annotation.Transactional; 11 | 12 | import java.sql.Date; 13 | import java.util.UUID; 14 | 15 | @Repository 16 | @Transactional 17 | public class OrderRepository { 18 | @Autowired 19 | NamedParameterJdbcTemplate jdbcTemplate; 20 | @Autowired 21 | SqlFinder sql; 22 | 23 | public Order create(Order order) { 24 | UUID orderId = UUID.randomUUID(); 25 | order.setOrderId(orderId); 26 | order.getOrderLines().orderId(orderId); 27 | 28 | SqlParameterSource source = new MapSqlParameterSource() 29 | .addValue("orderId", orderId.toString()) 30 | .addValue("email", order.getEmail()) 31 | .addValue("orderDate", Date.valueOf(order.getOrderDate())); 32 | 33 | jdbcTemplate.update(sql.get("sql/order/create.sql"), source); 34 | jdbcTemplate.batchUpdate(sql.get("sql/orderLine/create.sql"), 35 | order.getOrderLines().stream() 36 | .map(orderLine -> new MapSqlParameterSource() 37 | .addValue("orderId", orderLine.getOrderId().toString()) 38 | .addValue("lineNo", orderLine.getLineNo()) 39 | .addValue("goodsId", orderLine.getGoods().getGoodsId().toString()) 40 | .addValue("quantity", orderLine.getQuantity())) 41 | .toArray(SqlParameterSource[]::new)); 42 | return order; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/jsug/domain/service/account/AccountService.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.service.account; 2 | 3 | import jsug.domain.model.Account; 4 | import jsug.domain.repository.account.AccountRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.security.crypto.password.PasswordEncoder; 7 | import org.springframework.stereotype.Service; 8 | import org.springframework.transaction.annotation.Transactional; 9 | 10 | @Service 11 | @Transactional 12 | public class AccountService { 13 | @Autowired 14 | AccountRepository accountRepository; 15 | @Autowired 16 | PasswordEncoder passwordEncoder; 17 | 18 | @Transactional(readOnly = true) 19 | public boolean isUnusedEmail(String email) { 20 | return accountRepository.countByEmail(email) == 0; 21 | } 22 | 23 | public Account register(Account account, String rawPassword) { 24 | String encodedPassword = passwordEncoder.encode(rawPassword); 25 | account.setPassword(encodedPassword); 26 | return accountRepository.create(account); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/jsug/domain/service/category/CategoryService.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.service.category; 2 | 3 | import jsug.domain.model.Category; 4 | import jsug.domain.repository.category.CategoryRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.cache.annotation.Cacheable; 7 | import org.springframework.stereotype.Service; 8 | import org.springframework.transaction.annotation.Transactional; 9 | 10 | import java.util.List; 11 | 12 | @Service 13 | @Transactional 14 | public class CategoryService { 15 | @Autowired 16 | CategoryRepository categoryRepository; 17 | 18 | @Transactional(readOnly = true) 19 | @Cacheable("category") 20 | public List findAll() { 21 | return categoryRepository.findAll(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/jsug/domain/service/goods/GoodsNotFoundException.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.service.goods; 2 | 3 | 4 | public class GoodsNotFoundException extends RuntimeException { 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/jsug/domain/service/goods/GoodsService.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.service.goods; 2 | 3 | import jsug.domain.model.Goods; 4 | import jsug.domain.repository.goods.GoodsRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.cache.annotation.Cacheable; 7 | import org.springframework.data.domain.Page; 8 | import org.springframework.data.domain.Pageable; 9 | import org.springframework.stereotype.Service; 10 | import org.springframework.transaction.annotation.Transactional; 11 | 12 | import java.util.UUID; 13 | 14 | @Service 15 | @Transactional 16 | public class GoodsService { 17 | @Autowired 18 | GoodsRepository goodsRepository; 19 | 20 | @Transactional(readOnly = true) 21 | @Cacheable("goods") 22 | public Goods findOne(UUID goodsId) { 23 | return goodsRepository.findOne(goodsId) 24 | .orElseThrow(GoodsNotFoundException::new); 25 | } 26 | 27 | @Transactional(readOnly = true) 28 | @Cacheable("goods") 29 | public Page findByCategoryId(int categoryId, Pageable pageable) { 30 | return goodsRepository.findByCategoryId(categoryId, pageable); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/jsug/domain/service/order/EmptyCartOrderException.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.service.order; 2 | 3 | public class EmptyCartOrderException extends RuntimeException { 4 | public EmptyCartOrderException(String message) { 5 | super(message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/jsug/domain/service/order/InvalidCartOrderException.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.service.order; 2 | 3 | public class InvalidCartOrderException extends RuntimeException { 4 | public InvalidCartOrderException(String message) { 5 | super(message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/jsug/domain/service/order/OrderService.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.service.order; 2 | 3 | import jsug.domain.model.Account; 4 | import jsug.domain.model.Cart; 5 | import jsug.domain.model.Order; 6 | import jsug.domain.model.OrderLines; 7 | import jsug.domain.repository.order.OrderRepository; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | import org.springframework.transaction.annotation.Transactional; 11 | import org.springframework.util.SerializationUtils; 12 | 13 | import java.security.MessageDigest; 14 | import java.security.NoSuchAlgorithmException; 15 | import java.time.LocalDate; 16 | import java.util.Base64; 17 | import java.util.Objects; 18 | 19 | @Service 20 | @Transactional 21 | public class OrderService { 22 | @Autowired 23 | OrderRepository orderRepository; 24 | 25 | public String calcSignature(Cart cart) { 26 | byte[] serialized = SerializationUtils.serialize(cart.getOrderLines()); 27 | byte[] signature = null; 28 | try { 29 | MessageDigest messageDigest = MessageDigest.getInstance("MD5"); 30 | signature = messageDigest.digest(serialized); 31 | } catch (NoSuchAlgorithmException ignored) { 32 | } 33 | return Base64.getEncoder().encodeToString(signature); 34 | } 35 | 36 | public Order purchase(Account account, Cart cart, String signature) { 37 | if (cart.isEmpty()) { 38 | throw new EmptyCartOrderException("買い物カゴが空です"); 39 | } 40 | if (!Objects.equals(calcSignature(cart), signature)) { 41 | throw new InvalidCartOrderException("買い物カゴの状態が変わっています"); 42 | } 43 | 44 | // 買い物カゴから削除するため、ディープコピーしておく 45 | OrderLines orderLines = (OrderLines) SerializationUtils.deserialize( 46 | SerializationUtils.serialize(cart.getOrderLines())); 47 | 48 | Order order = Order.builder() 49 | .email(account.getEmail()) 50 | .orderDate(LocalDate.now()) 51 | .orderLines(orderLines) 52 | .build(); 53 | Order ordered = orderRepository.create(order); 54 | cart.clear(); 55 | return ordered; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/jsug/domain/service/userdetails/ShopUserDetails.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.service.userdetails; 2 | 3 | import jsug.domain.model.Account; 4 | import org.springframework.security.core.GrantedAuthority; 5 | import org.springframework.security.core.authority.AuthorityUtils; 6 | import org.springframework.security.core.userdetails.UserDetails; 7 | 8 | import java.util.Collection; 9 | 10 | public class ShopUserDetails implements UserDetails { 11 | private final Account account; 12 | 13 | public ShopUserDetails(Account account) { 14 | this.account = account; 15 | } 16 | 17 | @Override 18 | public Collection getAuthorities() { 19 | return AuthorityUtils.createAuthorityList("DEMO"); 20 | } 21 | 22 | public Account getAccount() { 23 | return account; 24 | } 25 | 26 | @Override 27 | public String getPassword() { 28 | return account.getPassword(); 29 | } 30 | 31 | @Override 32 | public String getUsername() { 33 | return account.getEmail(); 34 | } 35 | 36 | @Override 37 | public boolean isAccountNonExpired() { 38 | return true; 39 | } 40 | 41 | @Override 42 | public boolean isAccountNonLocked() { 43 | return true; 44 | } 45 | 46 | @Override 47 | public boolean isCredentialsNonExpired() { 48 | return true; 49 | } 50 | 51 | @Override 52 | public boolean isEnabled() { 53 | return true; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/jsug/domain/service/userdetails/ShopUserDetailsService.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.service.userdetails; 2 | 3 | import jsug.domain.repository.account.AccountRepository; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.security.core.userdetails.UserDetails; 6 | import org.springframework.security.core.userdetails.UserDetailsService; 7 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 8 | import org.springframework.stereotype.Service; 9 | import org.springframework.transaction.annotation.Transactional; 10 | 11 | @Service 12 | public class ShopUserDetailsService implements UserDetailsService { 13 | @Autowired 14 | AccountRepository accountRepository; 15 | 16 | @Transactional(readOnly = true) 17 | @Override 18 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { 19 | return accountRepository.findOne(username) 20 | .map(ShopUserDetails::new) 21 | .orElseThrow(() -> new UsernameNotFoundException(username + " is not found!")); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/jsug/domain/validation/Confirm.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.validation; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.Target; 6 | import javax.validation.Constraint; 7 | import javax.validation.Payload; 8 | 9 | import static java.lang.annotation.ElementType.ANNOTATION_TYPE; 10 | import static java.lang.annotation.ElementType.TYPE; 11 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 12 | 13 | /** 14 | * http://terasolunaorg.github.io/guideline/5.0.0.RELEASE/ja/ArchitectureInDetail/Validation.html#id15 15 | */ 16 | @Documented 17 | @Constraint(validatedBy = {ConfirmValidator.class}) 18 | @Target({TYPE, ANNOTATION_TYPE}) 19 | @Retention(RUNTIME) 20 | public @interface Confirm { 21 | String message() default "{jsug.domain.validation.Confirm.message}"; 22 | 23 | Class[] groups() default {}; 24 | 25 | Class[] payload() default {}; 26 | 27 | /** 28 | * Field name 29 | */ 30 | String field(); 31 | 32 | @Target({TYPE, ANNOTATION_TYPE}) 33 | @Retention(RUNTIME) 34 | @Documented 35 | public @interface List { 36 | Confirm[] value(); 37 | } 38 | } -------------------------------------------------------------------------------- /src/main/java/jsug/domain/validation/ConfirmValidator.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.validation; 2 | 3 | import javax.validation.ConstraintValidator; 4 | import javax.validation.ConstraintValidatorContext; 5 | 6 | import org.springframework.beans.BeanWrapper; 7 | import org.springframework.beans.BeanWrapperImpl; 8 | import org.springframework.util.StringUtils; 9 | 10 | import java.util.Objects; 11 | 12 | public class ConfirmValidator implements ConstraintValidator { 13 | private String field; 14 | 15 | private String confirmField; 16 | 17 | private String message; 18 | 19 | public void initialize(Confirm constraintAnnotation) { 20 | field = constraintAnnotation.field(); 21 | confirmField = "confirm" + StringUtils.capitalize(field); 22 | message = constraintAnnotation.message(); 23 | } 24 | 25 | public boolean isValid(Object value, ConstraintValidatorContext context) { 26 | BeanWrapper beanWrapper = new BeanWrapperImpl(value); 27 | Object fieldValue = beanWrapper.getPropertyValue(field); 28 | Object confirmFieldValue = beanWrapper.getPropertyValue(confirmField); 29 | if (Objects.equals(fieldValue, confirmFieldValue)) { 30 | return true; 31 | } else { 32 | context.disableDefaultConstraintViolation(); 33 | context.buildConstraintViolationWithTemplate(message) 34 | .addPropertyNode(confirmField).addConstraintViolation(); 35 | return false; 36 | } 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /src/main/java/jsug/domain/validation/UnusedEmail.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.validation; 2 | 3 | 4 | import javax.validation.Constraint; 5 | import javax.validation.Payload; 6 | import java.lang.annotation.Documented; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.Target; 9 | 10 | import static java.lang.annotation.ElementType.*; 11 | import static java.lang.annotation.RetentionPolicy.*; 12 | 13 | /** 14 | * http://terasolunaorg.github.io/guideline/5.0.0.RELEASE/ja/ArchitectureInDetail/Validation.html#id16 15 | */ 16 | @Documented 17 | @Constraint(validatedBy = {UnusedEmailValidator.class}) 18 | @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER}) 19 | @Retention(RUNTIME) 20 | public @interface UnusedEmail { 21 | String message() default "{UnusedEmail.message}"; 22 | 23 | Class[] groups() default {}; 24 | 25 | Class[] payload() default {}; 26 | 27 | @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER}) 28 | @Retention(RUNTIME) 29 | @Documented 30 | public @interface List { 31 | UnusedEmail[] value(); 32 | } 33 | } -------------------------------------------------------------------------------- /src/main/java/jsug/domain/validation/UnusedEmailValidator.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.validation; 2 | 3 | import jsug.domain.service.account.AccountService; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Component; 6 | 7 | import javax.validation.ConstraintValidator; 8 | import javax.validation.ConstraintValidatorContext; 9 | 10 | @Component 11 | public class UnusedEmailValidator implements 12 | ConstraintValidator { 13 | 14 | @Autowired 15 | AccountService accountService; 16 | 17 | @Override 18 | public void initialize(UnusedEmail constraintAnnotation) { 19 | } 20 | 21 | @Override 22 | public boolean isValid(String value, ConstraintValidatorContext context) { 23 | if (value == null) { 24 | return true; 25 | } 26 | return accountService.isUnusedEmail(value); 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /src/main/java/jsug/infra/cart/CachingCart.java: -------------------------------------------------------------------------------- 1 | package jsug.infra.cart; 2 | 3 | import jsug.domain.model.Cart; 4 | import jsug.domain.model.OrderLine; 5 | import jsug.domain.model.OrderLines; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.cache.Cache; 8 | import org.springframework.cache.CacheManager; 9 | import org.springframework.context.ApplicationContext; 10 | import org.springframework.security.core.context.SecurityContextHolder; 11 | import org.springframework.web.context.request.RequestContextHolder; 12 | import org.springframework.web.context.request.ServletRequestAttributes; 13 | import org.springframework.web.servlet.support.RequestContextUtils; 14 | 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | import java.util.Set; 18 | 19 | @Slf4j 20 | public class CachingCart extends Cart { 21 | public CachingCart() { 22 | super(); 23 | loadCache(); 24 | } 25 | 26 | @Override 27 | public OrderLines getOrderLines() { 28 | loadCache(); 29 | return super.getOrderLines(); 30 | } 31 | 32 | @Override 33 | public Cart add(OrderLine orderLine) { 34 | withSyncCache(() -> super.add(orderLine), true); 35 | return this; 36 | } 37 | 38 | @Override 39 | public Cart remove(Set lineNo) { 40 | withSyncCache(() -> super.remove(lineNo), true); 41 | return this; 42 | } 43 | 44 | @Override 45 | public Cart clear() { 46 | withSyncCache(super::clear, true); 47 | return this; 48 | } 49 | 50 | Cache getCache() { 51 | // 本当はCacheManagerをDIしたかったが、 52 | // CacheManagerはSerializableじゃないで、SessionスコープであるCartのフィールドに入れられない 53 | // そのため、リクエストコンテキストから毎度ApplicationContextを取得して、 54 | // CacheManagerを取得している。 55 | ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); 56 | ApplicationContext context = RequestContextUtils.findWebApplicationContext(attributes.getRequest()); 57 | CacheManager cacheManager = context.getBean(CacheManager.class); 58 | Cache cache = cacheManager.getCache("orderLines"); 59 | return cache; 60 | } 61 | 62 | /** 63 | * OrderLinesをキャッシュと同期しながら処理を実行する 64 | * 65 | * @param action 主処理 66 | * @param save 処理後、キャッシュに保存するかどうか 67 | */ 68 | void withSyncCache(Runnable action, boolean save) { 69 | Cache cache = getCache(); 70 | String username = SecurityContextHolder.getContext().getAuthentication().getName(); 71 | OrderLines orderLines = cache.get(username, OrderLines.class); 72 | if (orderLines != null) { 73 | // キャッシュから読み込み 74 | log.debug("load {} -> {}", username, orderLines); 75 | List lines = new ArrayList<>(orderLines.getList()); // copy 76 | super.getOrderLines().getList().clear(); 77 | super.getOrderLines().getList().addAll(lines); 78 | } 79 | // 処理 80 | action.run(); 81 | if (save) { 82 | // キャッシュに保存 83 | if (log.isDebugEnabled()) { 84 | log.debug("save {} -> {}", username, super.getOrderLines()); 85 | } 86 | cache.put(username, super.getOrderLines()); 87 | } 88 | } 89 | 90 | void loadCache() { 91 | withSyncCache(() -> { 92 | }, false); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/jsug/infra/logging/HandlerExceptionResolverLoggingAspect.java: -------------------------------------------------------------------------------- 1 | package jsug.infra.logging; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.aspectj.lang.ProceedingJoinPoint; 5 | import org.aspectj.lang.annotation.Around; 6 | import org.aspectj.lang.annotation.Aspect; 7 | import org.springframework.stereotype.Component; 8 | 9 | import javax.servlet.http.HttpServletRequest; 10 | 11 | @Component 12 | @Aspect 13 | @Slf4j 14 | public class HandlerExceptionResolverLoggingAspect { 15 | @Around("execution(* org.springframework.web.servlet.HandlerExceptionResolver.resolveException(..))") 16 | public Object logException(ProceedingJoinPoint joinPoint) throws Throwable { 17 | Object ret = joinPoint.proceed(); 18 | HttpServletRequest request = (HttpServletRequest) joinPoint.getArgs()[0]; 19 | 20 | if (request.getAttribute("ERROR_LOGGED") == null) { 21 | Object handler = joinPoint.getArgs()[2]; 22 | Exception exception = (Exception) joinPoint.getArgs()[3]; 23 | log.info("Error occurred [url=" + request.getMethod() + " " + request.getRequestURI() + ", handler=" + handler + "]", 24 | exception); 25 | // mark as logged 26 | request.setAttribute("ERROR_LOGGED", true); 27 | } 28 | return ret; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/resources/application-cloud.properties: -------------------------------------------------------------------------------- 1 | spring.redis.port=${vcap.services.shop-redis.credentials.port} 2 | spring.redis.host=${vcap.services.shop-redis.credentials.host} 3 | spring.redis.password=${vcap.services.shop-redis.credentials.password} 4 | 5 | spring.datasource.url=${vcap.services.shop-db.credentials.jdbcUrl} 6 | spring.datasource.username=${vcap.services.shop-db.credentials.username} 7 | spring.datasource.password=${vcap.services.shop-db.credentials.password} 8 | spring.datasource.driver-class-name=org.mariadb.jdbc.Driver 9 | spring.datasource.validation-query=SELECT 1 10 | spring.datasource.test-on-borrow=true 11 | spring.thymeleaf.cache=true 12 | 13 | # for ClearDB spark plan to scale 14 | spring.datasource.max-active=2 15 | spring.datasource.initial-size=0 16 | spring.datasource.max-idle=0 17 | spring.datasource.min-idle=0 18 | # for Demo 19 | endpoints.shutdown.enabled=true 20 | endpoints.env.keys-to-sanitize=.*(password|secret|key|command|credential|url|uri|VCAP_SERVICES).* 21 | endpoints.configprops.keys-to-sanitize=${endpoints.env.keys-to-sanitize} 22 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.thymeleaf.cache=false 2 | spring.main.banner-mode=off 3 | security.basic.enabled=false 4 | logging.level.jdbc=OFF 5 | logging.level.jdbc.sqltiming=DEBUG -------------------------------------------------------------------------------- /src/main/resources/db/migration/V1__create-schema.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE account ( 2 | email VARCHAR(255) PRIMARY KEY, 3 | password VARCHAR(255), 4 | name VARCHAR(128), 5 | birth_day DATE, 6 | zip VARCHAR(32), 7 | address VARCHAR(255) 8 | ); 9 | 10 | CREATE TABLE category ( 11 | category_id INT PRIMARY KEY, 12 | category_name VARCHAR(128) 13 | ); 14 | 15 | CREATE TABLE goods ( 16 | goods_id VARCHAR(36) PRIMARY KEY, 17 | goods_name VARCHAR(255), 18 | description VARCHAR(512), 19 | category_id INT, 20 | price INT, 21 | FOREIGN KEY (category_id) REFERENCES category (category_id) 22 | ); 23 | 24 | CREATE TABLE ordr ( 25 | order_id VARCHAR(36) PRIMARY KEY, 26 | email VARCHAR(255), 27 | order_date DATE 28 | ); 29 | 30 | CREATE TABLE order_line ( 31 | order_id VARCHAR(36), 32 | line_no INT, 33 | goods_id VARCHAR(36), 34 | quantity INT, 35 | PRIMARY KEY (order_id, line_no), 36 | FOREIGN KEY (order_id) REFERENCES ordr (order_id), 37 | FOREIGN KEY (goods_id) REFERENCES goods (goods_id) 38 | ); -------------------------------------------------------------------------------- /src/main/resources/db/migration/V2__initial-data.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO category (category_id, category_name) VALUES (1, '本'); 2 | INSERT INTO category (category_id, category_name) VALUES (2, '音楽'); 3 | INSERT INTO category (category_id, category_name) VALUES (3, '家電'); 4 | INSERT INTO category (category_id, category_name) VALUES (4, 'パソコン'); 5 | 6 | -- 本 7 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 8 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76840', 'こころ', '夏目 漱石の本です', 1, 900); 9 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 10 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76841', '〔雨ニモマケズ〕', '宮沢 賢治の本です', 1, 800); 11 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 12 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76842', '走れメロス', '太宰 治の本です', 1, 880); 13 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 14 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76843', '吾輩は猫である', '夏目 漱石の本です', 1, 900); 15 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 16 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76844', '人間失格', '太宰 治の本です', 1, 880); 17 | 18 | -- 音楽 19 | 20 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 21 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76850', 'ああああ', 'ああああ', 2, 1080); 22 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 23 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76851', 'いいいい', 'いいいい', 2, 1080); 24 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 25 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76852', 'うううう', 'うううう', 2, 1080); 26 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 27 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76853', 'ええええ', 'ええええ', 2, 1080); 28 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 29 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76854', 'おおおお', 'おおおお', 2, 1080); 30 | 31 | -- 家電 32 | 33 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 34 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76860', 'かかかか', 'かかかか', 3, 10800); 35 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 36 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76861', 'きききき', 'きききき', 3, 10800); 37 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 38 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76862', 'くくくく', 'くくくく', 3, 10800); 39 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 40 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76863', 'けけけけ', 'けけけけ', 3, 10800); 41 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 42 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76864', 'ここここ', 'ここここ', 3, 10800); 43 | 44 | -- パソコン 45 | 46 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 47 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76870', 'ささささ', 'ささささ', 4, 108000); 48 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 49 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76871', 'しししし', 'しししし', 4, 108000); 50 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 51 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76872', 'すすすす', 'すすすす', 4, 108000); 52 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 53 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76873', 'せせせせ', 'せせせせ', 4, 108000); 54 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 55 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76874', 'そそそそ', 'そそそそ', 4, 108000); 56 | 57 | -------------------------------------------------------------------------------- /src/main/resources/log4jdbc.log4j2.properties: -------------------------------------------------------------------------------- 1 | log4jdbc.dump.sql.maxlinelength=0 2 | log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator -------------------------------------------------------------------------------- /src/main/resources/messages.properties: -------------------------------------------------------------------------------- 1 | NotNull=入力必須です 2 | Size=長さは{2}以上、{1}以下にしてください 3 | Max={1}以下の値を入力してください 4 | Min={1}以上の値を入力してください 5 | Email=E-mailの形式が不正です 6 | UnusedEmail=既に登録済みです 7 | 8 | Pattern.zip=7桁の整数を入力してください 9 | Confirm.confirmPassword=パスワードとパスワード(確認)が異なります -------------------------------------------------------------------------------- /src/main/resources/sql/account/countByEmail.sql: -------------------------------------------------------------------------------- 1 | SELECT COUNT(*) 2 | FROM account 3 | WHERE email = :email -------------------------------------------------------------------------------- /src/main/resources/sql/account/create.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO 2 | account (email, password, name, birth_day, zip, address) 3 | VALUES (:email, :password, :name, :birthDay, :zip, :address) -------------------------------------------------------------------------------- /src/main/resources/sql/account/findOne.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | email, 3 | password, 4 | name, 5 | birth_day, 6 | zip, 7 | address 8 | FROM account 9 | WHERE email = :email -------------------------------------------------------------------------------- /src/main/resources/sql/category/findAll.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | category_id, 3 | category_name 4 | FROM category 5 | ORDER BY category_id ASC -------------------------------------------------------------------------------- /src/main/resources/sql/goods/countByCategoryId.sql: -------------------------------------------------------------------------------- 1 | SELECT COUNT(*) 2 | FROM goods AS g, category AS c 3 | WHERE 4 | c.category_id = :categoryId 5 | AND 6 | g.category_id = c.category_id 7 | -------------------------------------------------------------------------------- /src/main/resources/sql/goods/findByCategoryId.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | g.goods_id AS goods_id, 3 | g.goods_name AS goods_name, 4 | g.description AS description, 5 | g.price AS price, 6 | c.category_id AS category_id, 7 | c.category_name AS category_name 8 | FROM goods AS g, category AS c 9 | WHERE 10 | c.category_id = :categoryId 11 | AND 12 | g.category_id = c.category_id 13 | ORDER BY g.goods_id ASC 14 | LIMIT 15 | :pageSize 16 | OFFSET 17 | :offset -------------------------------------------------------------------------------- /src/main/resources/sql/goods/findOne.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | g.goods_id AS goods_id, 3 | g.goods_name AS goods_name, 4 | g.description AS description, 5 | g.price AS price, 6 | c.category_id AS category_id, 7 | c.category_name AS category_name 8 | FROM goods AS g, category AS c 9 | WHERE 10 | g.goods_id = :goodsId 11 | AND 12 | g.category_id = c.category_id -------------------------------------------------------------------------------- /src/main/resources/sql/order/create.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO ordr (order_id, email, order_date) VALUES (:orderId, :email, :orderDate) -------------------------------------------------------------------------------- /src/main/resources/sql/orderLine/create.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO order_line (order_id, line_no, goods_id, quantity) VALUES (:orderId, :lineNo, :goodsId, :quantity); -------------------------------------------------------------------------------- /src/main/resources/static/fonts/montserrat-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/making/jsug-shop/be46ce78b9e48dc94144d15627dd6e08fb7eb7d8/src/main/resources/static/fonts/montserrat-webfont.eot -------------------------------------------------------------------------------- /src/main/resources/static/fonts/montserrat-webfont.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 | 863 | 864 | 865 | 866 | 867 | 868 | 869 | 870 | 871 | 872 | 873 | 874 | 875 | 876 | 877 | 878 | 879 | 880 | 881 | 882 | 883 | 884 | 885 | 886 | 887 | 888 | 889 | 890 | 891 | 892 | 893 | 894 | 895 | 896 | 897 | 898 | 899 | 900 | 901 | 902 | 903 | 904 | 905 | 906 | 907 | 908 | 909 | 910 | 911 | 912 | 913 | 914 | 915 | 916 | 917 | 918 | 919 | 920 | 921 | 922 | 923 | 924 | 925 | 926 | 927 | 928 | 929 | 930 | 931 | 932 | 933 | 934 | 935 | 936 | 937 | 938 | 939 | 940 | 941 | 942 | 943 | 944 | 945 | 946 | 947 | 948 | 949 | 950 | 951 | 952 | 953 | 954 | 955 | 956 | 957 | 958 | 959 | 960 | 961 | 962 | 963 | 964 | 965 | 966 | 967 | 968 | 969 | 970 | 971 | 972 | 973 | 974 | 975 | 976 | 977 | 978 | 979 | 980 | 981 | 982 | 983 | 984 | 985 | 986 | 987 | 988 | 989 | 990 | 991 | 992 | 993 | 994 | 995 | 996 | 997 | 998 | 999 | 1000 | 1001 | 1002 | 1003 | 1004 | 1005 | 1006 | 1007 | 1008 | 1009 | 1010 | 1011 | 1012 | 1013 | 1014 | 1015 | 1016 | 1017 | 1018 | 1019 | 1020 | 1021 | 1022 | 1023 | 1024 | 1025 | 1026 | 1027 | 1028 | 1029 | 1030 | 1031 | 1032 | 1033 | 1034 | 1035 | 1036 | 1037 | 1038 | 1039 | 1040 | 1041 | 1042 | 1043 | 1044 | 1045 | 1046 | 1047 | 1048 | 1049 | 1050 | 1051 | 1052 | 1053 | 1054 | 1055 | 1056 | 1057 | 1058 | 1059 | 1060 | 1061 | 1062 | 1063 | 1064 | 1065 | 1066 | 1067 | 1068 | 1069 | 1070 | 1071 | 1072 | 1073 | 1074 | 1075 | 1076 | 1077 | 1078 | 1079 | 1080 | 1081 | 1082 | 1083 | 1084 | 1085 | 1086 | 1087 | 1088 | 1089 | 1090 | 1091 | 1092 | 1093 | 1094 | 1095 | 1096 | 1097 | 1098 | 1099 | 1100 | 1101 | 1102 | 1103 | 1104 | 1105 | 1106 | 1107 | 1108 | 1109 | 1110 | 1111 | 1112 | 1113 | 1114 | 1115 | 1116 | 1117 | 1118 | 1119 | 1120 | 1121 | 1122 | 1123 | 1124 | 1125 | 1126 | 1127 | 1128 | 1129 | 1130 | 1131 | 1132 | 1133 | 1134 | 1135 | 1136 | 1137 | 1138 | 1139 | 1140 | 1141 | 1142 | 1143 | 1144 | 1145 | 1146 | 1147 | 1148 | 1149 | 1150 | 1151 | 1152 | 1153 | 1154 | 1155 | 1156 | 1157 | 1158 | 1159 | 1160 | 1161 | 1162 | 1163 | 1164 | 1165 | 1166 | 1167 | 1168 | 1169 | 1170 | 1171 | 1172 | 1173 | 1174 | 1175 | 1176 | 1177 | 1178 | 1179 | 1180 | 1181 | 1182 | 1183 | 1184 | 1185 | 1186 | 1187 | 1188 | 1189 | 1190 | 1191 | 1192 | 1193 | 1194 | 1195 | 1196 | 1197 | 1198 | 1199 | 1200 | 1201 | 1202 | 1203 | 1204 | 1205 | 1206 | 1207 | 1208 | 1209 | 1210 | 1211 | 1212 | 1213 | 1214 | 1215 | 1216 | 1217 | 1218 | 1219 | 1220 | 1221 | 1222 | 1223 | 1224 | 1225 | 1226 | 1227 | 1228 | 1229 | 1230 | 1231 | 1232 | 1233 | 1234 | 1235 | 1236 | 1237 | 1238 | 1239 | 1240 | 1241 | 1242 | 1243 | 1244 | 1245 | 1246 | 1247 | 1248 | 1249 | 1250 | 1251 | 1252 | 1253 | 1254 | 1255 | 1256 | 1257 | 1258 | 1259 | 1260 | 1261 | 1262 | 1263 | 1264 | 1265 | 1266 | 1267 | 1268 | 1269 | 1270 | 1271 | 1272 | 1273 | 1274 | 1275 | 1276 | 1277 | 1278 | 1279 | 1280 | 1281 | 1282 | 1283 | -------------------------------------------------------------------------------- /src/main/resources/static/fonts/montserrat-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/making/jsug-shop/be46ce78b9e48dc94144d15627dd6e08fb7eb7d8/src/main/resources/static/fonts/montserrat-webfont.ttf -------------------------------------------------------------------------------- /src/main/resources/static/fonts/montserrat-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/making/jsug-shop/be46ce78b9e48dc94144d15627dd6e08fb7eb7d8/src/main/resources/static/fonts/montserrat-webfont.woff -------------------------------------------------------------------------------- /src/main/resources/static/fonts/varela_round-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/making/jsug-shop/be46ce78b9e48dc94144d15627dd6e08fb7eb7d8/src/main/resources/static/fonts/varela_round-webfont.eot -------------------------------------------------------------------------------- /src/main/resources/static/fonts/varela_round-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/making/jsug-shop/be46ce78b9e48dc94144d15627dd6e08fb7eb7d8/src/main/resources/static/fonts/varela_round-webfont.ttf -------------------------------------------------------------------------------- /src/main/resources/static/fonts/varela_round-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/making/jsug-shop/be46ce78b9e48dc94144d15627dd6e08fb7eb7d8/src/main/resources/static/fonts/varela_round-webfont.woff -------------------------------------------------------------------------------- /src/main/resources/static/images/404-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/making/jsug-shop/be46ce78b9e48dc94144d15627dd6e08fb7eb7d8/src/main/resources/static/images/404-icon.png -------------------------------------------------------------------------------- /src/main/resources/static/images/homepage-bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/making/jsug-shop/be46ce78b9e48dc94144d15627dd6e08fb7eb7d8/src/main/resources/static/images/homepage-bg.jpg -------------------------------------------------------------------------------- /src/main/resources/static/images/platform-bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/making/jsug-shop/be46ce78b9e48dc94144d15627dd6e08fb7eb7d8/src/main/resources/static/images/platform-bg.png -------------------------------------------------------------------------------- /src/main/resources/static/images/platform-spring-xd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/making/jsug-shop/be46ce78b9e48dc94144d15627dd6e08fb7eb7d8/src/main/resources/static/images/platform-spring-xd.png -------------------------------------------------------------------------------- /src/main/resources/static/images/spring-logo-xd-mobile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/making/jsug-shop/be46ce78b9e48dc94144d15627dd6e08fb7eb7d8/src/main/resources/static/images/spring-logo-xd-mobile.png -------------------------------------------------------------------------------- /src/main/resources/static/images/spring-logo-xd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/making/jsug-shop/be46ce78b9e48dc94144d15627dd6e08fb7eb7d8/src/main/resources/static/images/spring-logo-xd.png -------------------------------------------------------------------------------- /src/main/resources/templates/account/createFinish.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ユーザー登録 6 | 7 | 8 | 9 | 10 | 24 |
25 | 26 |
27 |

ユーザー登録完了

28 | 29 |

30 | ようこそ ほげさん。
31 | こちらからログインしてください。 32 |

33 |
34 | 35 | -------------------------------------------------------------------------------- /src/main/resources/templates/account/createForm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ユーザー登録 6 | 7 | 8 | 9 | 10 | 24 |
25 | 26 |
27 | 28 |
30 | 31 |

ユーザー登録

32 | 33 |
34 | 35 | 36 |
37 | 38 | error! 40 |
41 |
42 |
43 | 44 | 45 |
46 | 47 | error! 49 |
50 |
51 |
52 | 53 | 54 |
55 | 56 | error! 58 |
59 |
60 |
61 | 62 | 63 |
64 | 66 | error! 68 |
69 |
70 |
71 | 72 | 73 |
74 | 75 | error! 77 |
78 |
79 |
80 | 81 | 82 |
83 | 84 | error! 86 |
87 |
88 |
89 | 90 | 91 |
92 | 93 | error! 95 |
96 |
97 | 98 |
99 |
100 | 101 | -------------------------------------------------------------------------------- /src/main/resources/templates/cart/viewCart.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 買い物カゴ 6 | 7 | 8 | 9 | 10 | 27 |
28 | 29 |
30 |

買い物カゴ内容

31 | 32 |
33 | 買い物カゴが空です 34 |
35 |
36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 |
商品名値段個数合計削除
hoge¥10010¥10,000
56 | 57 | 58 |

合計: 0

59 |
60 |

61 | 買い物に戻る 62 | 注文画面へ 63 |

64 |
65 | 66 | -------------------------------------------------------------------------------- /src/main/resources/templates/error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | エラー 6 | 7 | 8 | 9 | 10 | 27 |
28 | 29 |
30 |
31 | エラーが発生しました。ホームに戻ってやり直してください。 32 |
33 |
34 | 35 | -------------------------------------------------------------------------------- /src/main/resources/templates/goods/notFound.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 商品一覧 6 | 7 | 8 | 9 | 10 | 27 |
28 | 29 |
30 |
31 | 該当の商品が存在しません 32 |
33 |
34 | 35 | -------------------------------------------------------------------------------- /src/main/resources/templates/goods/showGoods.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 商品一覧 6 | 7 | 8 | 9 | 10 | 27 |
28 | 29 |
30 | 31 |
32 | 33 |
34 | 35 |

36 | カテゴリーを選んでください。 37 |

38 | 39 |
40 | 46 | 47 |
48 |
49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 74 | 75 | 76 |
商品名値段説明個数
aa¥100hoge 64 |
65 | 66 | error! 69 | 70 | 71 | 72 |
73 |
77 |
78 | 79 | -------------------------------------------------------------------------------- /src/main/resources/templates/login/loginForm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ログイン 6 | 7 | 8 | 9 | 10 | 24 |
25 | 26 |
27 |

ログインフォーム

28 | 29 |
30 | ユーザー名またはパスワードが正しくありません。 31 |
32 |
33 | 35 | 36 | 37 |
38 |

39 | アカウントをお持ちでない場合はこちらから作成してください。 40 |

41 |
42 | 43 | 44 | -------------------------------------------------------------------------------- /src/main/resources/templates/order/confirm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 注文確認 6 | 7 | 8 | 9 | 10 | 27 |
28 | 29 |
30 |

注文確認

31 | 32 |

33 | この内容で注文しますか? 34 |
35 | カートの内容を変更する 36 |

37 |
38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 |
商品名値段個数合計
hoge¥10010¥10,000
56 |

合計: ¥10,000

57 |
58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 |
名前山田太郎
E-mailyamada@example.com
郵便番号1050011
住所東京都港区芝公園4丁目2−8
76 | 77 |
78 | 79 | 80 |
81 |
82 | 83 | -------------------------------------------------------------------------------- /src/main/resources/templates/order/error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 注文エラー 6 | 7 | 8 | 9 | 10 | 27 |
28 | 29 |
30 |
31 | エラーが発生しましたホームに戻ってやり直してください。 32 |
33 |
34 | 35 | -------------------------------------------------------------------------------- /src/main/resources/templates/order/finish.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 注文完了 6 | 7 | 8 | 9 | 10 | 27 |
28 | 29 |
30 |

注文完了

31 | 32 |

お買い上げありがとうございます。

33 |
34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
注文番号00001
注文日2015-05-31
44 | 45 | 買い物に戻る 46 |
47 | 48 | -------------------------------------------------------------------------------- /src/test/java/jsug/domain/TestConfig.java: -------------------------------------------------------------------------------- 1 | package jsug.domain; 2 | 3 | 4 | import net.sf.log4jdbc.sql.jdbcapi.DataSourceSpy; 5 | import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.ComponentScan; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; 10 | import org.springframework.jdbc.datasource.DataSourceTransactionManager; 11 | import org.springframework.security.crypto.password.NoOpPasswordEncoder; 12 | import org.springframework.security.crypto.password.PasswordEncoder; 13 | import org.springframework.transaction.PlatformTransactionManager; 14 | import org.springframework.transaction.annotation.EnableTransactionManagement; 15 | 16 | import javax.sql.DataSource; 17 | 18 | @Configuration 19 | @EnableTransactionManagement 20 | @ComponentScan({ 21 | "jsug.domain.repository", 22 | "jsug.domain.service"}) 23 | public class TestConfig { 24 | @Bean 25 | DataSource dataSource() { 26 | DataSource dataSource = DataSourceBuilder.create() 27 | .url("jdbc:h2:mem:jsug-shop;DB_CLOSE_ON_EXIT=FALSE") 28 | .build(); 29 | return new DataSourceSpy(dataSource); 30 | } 31 | 32 | @Bean 33 | NamedParameterJdbcTemplate jdbcTemplate() { 34 | return new NamedParameterJdbcTemplate(dataSource()); 35 | } 36 | 37 | @Bean 38 | PlatformTransactionManager transactionManager() { 39 | return new DataSourceTransactionManager(dataSource()); 40 | } 41 | 42 | @Bean 43 | PasswordEncoder passwordEncoder() { 44 | return NoOpPasswordEncoder.getInstance(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/jsug/domain/model/CartTest.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.model; 2 | 3 | import org.junit.Test; 4 | 5 | import java.util.HashSet; 6 | import java.util.Set; 7 | 8 | import static org.hamcrest.CoreMatchers.*; 9 | import static org.junit.Assert.*; 10 | 11 | public class CartTest { 12 | 13 | @Test 14 | public void testRemove() throws Exception { 15 | Cart cart = new Cart(); 16 | OrderLine ol1 = OrderLine.builder().quantity(1).goods(Goods.builder().build()).build(); 17 | OrderLine ol2 = OrderLine.builder().quantity(2).goods(Goods.builder().build()).build(); 18 | OrderLine ol3 = OrderLine.builder().quantity(3).goods(Goods.builder().build()).build(); 19 | OrderLine ol4 = OrderLine.builder().quantity(4).goods(Goods.builder().build()).build(); 20 | cart.add(ol1).add(ol2).add(ol3).add(ol4); 21 | 22 | Set lineNo = new HashSet<>(); 23 | lineNo.add(1); 24 | lineNo.add(2); 25 | 26 | cart.remove(lineNo); 27 | 28 | assertThat(cart, is(new Cart().add(ol1).add(ol4))); 29 | } 30 | } -------------------------------------------------------------------------------- /src/test/java/jsug/domain/repository/account/AccountRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.repository.account; 2 | 3 | import jsug.domain.model.Account; 4 | import jsug.domain.TestConfig; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.test.context.ContextConfiguration; 9 | import org.springframework.test.context.jdbc.Sql; 10 | import org.springframework.test.context.jdbc.SqlConfig; 11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 12 | 13 | import java.time.LocalDate; 14 | import java.util.Optional; 15 | 16 | import static org.hamcrest.CoreMatchers.*; 17 | import static org.junit.Assert.*; 18 | 19 | @RunWith(SpringJUnit4ClassRunner.class) 20 | @ContextConfiguration(classes = TestConfig.class) 21 | @Sql(scripts = { 22 | "/sql/drop-tables.sql", 23 | "/db/migration/V1__create-schema.sql", 24 | "/sql/insert-accounts.sql" 25 | }, config = @SqlConfig(encoding = "UTF-8")) 26 | public class AccountRepositoryTest { 27 | @Autowired 28 | AccountRepository accountRepository; 29 | 30 | @Test 31 | public void testCreateAndFind() throws Exception { 32 | Account account = Account.builder() 33 | .email("foo@example.com") 34 | .password("aaaa") 35 | .name("Taro Yamada") 36 | .birthDay(LocalDate.of(2000, 1, 1)) 37 | .zip("1000000") 38 | .address("Tokyo") 39 | .build(); 40 | Account created = accountRepository.create(account); 41 | Account found = accountRepository.findOne("foo@example.com").get(); 42 | assertThat(found, is(created)); 43 | } 44 | 45 | @Test 46 | public void testCountByEmail() throws Exception { 47 | long count = accountRepository.countByEmail("demo1@example.com"); 48 | assertThat(count, is(1L)); 49 | } 50 | 51 | @Test 52 | public void testCountByEmail_NotFound() throws Exception { 53 | long count = accountRepository.countByEmail("hoge@example.com"); 54 | assertThat(count, is(0L)); 55 | } 56 | 57 | @Test 58 | public void testFindOne() throws Exception { 59 | Optional opt = accountRepository.findOne("demo1@example.com"); 60 | assertThat(opt.isPresent(), is(true)); 61 | Account account = opt.get(); 62 | assertThat(account.getName(), is("山田太郎")); 63 | assertThat(account.getEmail(), is("demo1@example.com")); 64 | assertThat(account.getPassword(), is("demo")); 65 | assertThat(account.getBirthDay(), is(LocalDate.of(2000, 1, 1))); 66 | assertThat(account.getZip(), is("1000000")); 67 | assertThat(account.getAddress(), is("東京都")); 68 | } 69 | 70 | 71 | @Test 72 | public void testFindOne_NotFound() throws Exception { 73 | Optional opt = accountRepository.findOne("hoge@example.com"); 74 | assertThat(opt.isPresent(), is(false)); 75 | } 76 | } -------------------------------------------------------------------------------- /src/test/java/jsug/domain/repository/category/CategoryRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.repository.category; 2 | 3 | import jsug.domain.model.Category; 4 | import jsug.domain.TestConfig; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.test.context.ContextConfiguration; 9 | import org.springframework.test.context.jdbc.Sql; 10 | import org.springframework.test.context.jdbc.SqlConfig; 11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 12 | 13 | import java.util.List; 14 | 15 | import static org.hamcrest.Matchers.*; 16 | import static org.junit.Assert.*; 17 | 18 | 19 | @RunWith(SpringJUnit4ClassRunner.class) 20 | @ContextConfiguration(classes = TestConfig.class) 21 | @Sql(scripts = { 22 | "/sql/drop-tables.sql", 23 | "/db/migration/V1__create-schema.sql", 24 | "/sql/insert-category.sql" 25 | }, config = @SqlConfig(encoding = "UTF-8")) 26 | public class CategoryRepositoryTest { 27 | @Autowired 28 | CategoryRepository categoryRepository; 29 | 30 | @Test 31 | public void testFindAll() throws Exception { 32 | List categories = categoryRepository.findAll(); 33 | assertThat(categories, hasSize(4)); 34 | assertThat(categories.get(0).getCategoryName(), is("本")); 35 | assertThat(categories.get(1).getCategoryName(), is("音楽")); 36 | assertThat(categories.get(2).getCategoryName(), is("家電")); 37 | assertThat(categories.get(3).getCategoryName(), is("パソコン")); 38 | } 39 | } -------------------------------------------------------------------------------- /src/test/java/jsug/domain/repository/goods/GoodsRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.repository.goods; 2 | 3 | import jsug.domain.model.Goods; 4 | import jsug.domain.TestConfig; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.data.domain.Page; 9 | import org.springframework.data.domain.PageRequest; 10 | import org.springframework.test.context.ContextConfiguration; 11 | import org.springframework.test.context.jdbc.Sql; 12 | import org.springframework.test.context.jdbc.SqlConfig; 13 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 14 | 15 | import java.util.Optional; 16 | import java.util.UUID; 17 | 18 | import static org.hamcrest.Matchers.*; 19 | import static org.junit.Assert.*; 20 | 21 | 22 | @RunWith(SpringJUnit4ClassRunner.class) 23 | @ContextConfiguration(classes = TestConfig.class) 24 | @Sql(scripts = { 25 | "/sql/drop-tables.sql", 26 | "/db/migration/V1__create-schema.sql", 27 | "/sql/insert-goods.sql" 28 | }, config = @SqlConfig(encoding = "UTF-8")) 29 | public class GoodsRepositoryTest { 30 | @Autowired 31 | GoodsRepository goodsRepository; 32 | 33 | @Test 34 | public void testFindOne() throws Exception { 35 | Optional opt = goodsRepository.findOne(UUID.fromString("366cf3a4-68c5-4dae-a557-673769f76840")); 36 | assertThat(opt.isPresent(), is(true)); 37 | Goods goods = opt.get(); 38 | assertThat(goods.getGoodsId(), is(UUID.fromString("366cf3a4-68c5-4dae-a557-673769f76840"))); 39 | assertThat(goods.getGoodsName(), is("こころ")); 40 | assertThat(goods.getDescription(), is("夏目 漱石の本です")); 41 | assertThat(goods.getPrice(), is(900)); 42 | assertThat(goods.getCategory().getCategoryName(), is("本")); 43 | } 44 | 45 | @Test 46 | public void testFindOne_notFound() throws Exception { 47 | Optional goods = goodsRepository.findOne(UUID.randomUUID()); 48 | assertThat(goods.isPresent(), is(false)); 49 | } 50 | 51 | @Test 52 | public void testFindByCategoryId_Page0() throws Exception { 53 | Page goods = goodsRepository.findByCategoryId(1, new PageRequest(0, 3)); 54 | assertThat(goods.getTotalElements(), is(5L)); 55 | assertThat(goods.getTotalPages(), is(2)); 56 | assertThat(goods.getNumberOfElements(), is(3)); 57 | assertThat(goods.getContent().get(0).getGoodsName(), is("こころ")); 58 | assertThat(goods.getContent().get(1).getGoodsName(), is("〔雨ニモマケズ〕")); 59 | assertThat(goods.getContent().get(2).getGoodsName(), is("走れメロス")); 60 | } 61 | 62 | @Test 63 | public void testFindByCategoryId_Page1() throws Exception { 64 | Page goods = goodsRepository.findByCategoryId(1, new PageRequest(1, 3)); 65 | assertThat(goods.getTotalElements(), is(5L)); 66 | assertThat(goods.getTotalPages(), is(2)); 67 | assertThat(goods.getNumberOfElements(), is(2)); 68 | assertThat(goods.getContent().get(0).getGoodsName(), is("吾輩は猫である")); 69 | assertThat(goods.getContent().get(1).getGoodsName(), is("人間失格")); 70 | } 71 | } -------------------------------------------------------------------------------- /src/test/java/jsug/domain/repository/order/OrderRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.repository.order; 2 | 3 | import jsug.domain.model.Goods; 4 | import jsug.domain.model.Order; 5 | import jsug.domain.model.OrderLine; 6 | import jsug.domain.model.OrderLines; 7 | import jsug.domain.TestConfig; 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.test.context.ContextConfiguration; 12 | import org.springframework.test.context.jdbc.Sql; 13 | import org.springframework.test.context.jdbc.SqlConfig; 14 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 15 | 16 | import java.time.LocalDate; 17 | import java.util.Arrays; 18 | import java.util.UUID; 19 | 20 | import static org.hamcrest.Matchers.*; 21 | import static org.junit.Assert.*; 22 | 23 | 24 | @RunWith(SpringJUnit4ClassRunner.class) 25 | @ContextConfiguration(classes = TestConfig.class) 26 | @Sql(scripts = { 27 | "/sql/drop-tables.sql", 28 | "/db/migration/V1__create-schema.sql", 29 | "/sql/insert-orders.sql" 30 | }, config = @SqlConfig(encoding = "UTF-8")) 31 | public class OrderRepositoryTest { 32 | @Autowired 33 | OrderRepository orderRepository; 34 | 35 | @Test 36 | public void testCreate() throws Exception { 37 | Goods goods1 = Goods.builder() 38 | .goodsId(UUID.fromString("366cf3a4-68c5-4dae-a557-673769f76840")) 39 | .build(); 40 | Goods goods2 = Goods.builder() 41 | .goodsId(UUID.fromString("366cf3a4-68c5-4dae-a557-673769f76841")) 42 | .build(); 43 | 44 | Order order = Order.builder() 45 | .email("demo1@example.com") 46 | .orderDate(LocalDate.of(2015, 4, 20)) 47 | .orderLines(new OrderLines(Arrays.asList( 48 | OrderLine.builder() 49 | .goods(goods1) 50 | .quantity(2) 51 | .build(), 52 | OrderLine.builder() 53 | .goods(goods2) 54 | .quantity(1) 55 | .build()))) 56 | .build(); 57 | 58 | Order ordered = orderRepository.create(order); 59 | UUID orderId = ordered.getOrderId(); 60 | 61 | assertThat(ordered.getOrderId(), is(notNullValue())); 62 | assertThat(ordered.getEmail(), is("demo1@example.com")); 63 | assertThat(ordered.getOrderDate(), is(LocalDate.of(2015, 4, 20))); 64 | assertThat(ordered.getOrderLines().getList(), hasSize(2)); 65 | assertThat(ordered.getOrderLines().getList().get(0).getGoods().getGoodsId(), is(UUID.fromString("366cf3a4-68c5-4dae-a557-673769f76840"))); 66 | assertThat(ordered.getOrderLines().getList().get(0).getOrderId(), is(orderId)); 67 | assertThat(ordered.getOrderLines().getList().get(1).getGoods().getGoodsId(), is(UUID.fromString("366cf3a4-68c5-4dae-a557-673769f76841"))); 68 | assertThat(ordered.getOrderLines().getList().get(1).getOrderId(), is(orderId)); 69 | } 70 | } -------------------------------------------------------------------------------- /src/test/java/jsug/domain/service/account/AccountServiceTest.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.service.account; 2 | 3 | import jsug.domain.TestConfig; 4 | import jsug.domain.model.Account; 5 | import jsug.domain.repository.account.AccountRepository; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.test.context.ContextConfiguration; 10 | import org.springframework.test.context.jdbc.Sql; 11 | import org.springframework.test.context.jdbc.SqlConfig; 12 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 13 | 14 | import java.time.LocalDate; 15 | 16 | import static org.junit.Assert.*; 17 | import static org.hamcrest.CoreMatchers.*; 18 | 19 | @RunWith(SpringJUnit4ClassRunner.class) 20 | @ContextConfiguration(classes = TestConfig.class) 21 | @Sql(scripts = { 22 | "/sql/drop-tables.sql", 23 | "/db/migration/V1__create-schema.sql", 24 | "/sql/insert-accounts.sql" 25 | }, config = @SqlConfig(encoding = "UTF-8")) 26 | public class AccountServiceTest { 27 | @Autowired 28 | AccountService accountService; 29 | @Autowired 30 | AccountRepository accountRepository; 31 | 32 | @Test 33 | public void testIsUnusedEmail_Used() throws Exception { 34 | assertThat(accountService.isUnusedEmail("demo1@example.com"), is(false)); 35 | } 36 | 37 | @Test 38 | public void testIsUnusedEmail_Unused() throws Exception { 39 | assertThat(accountService.isUnusedEmail("hoge@example.com"), is(true)); 40 | } 41 | 42 | @Test 43 | public void testRegister() throws Exception { 44 | Account account = Account.builder() 45 | .email("foo@example.com") 46 | .name("Taro Yamada") 47 | .birthDay(LocalDate.of(2000, 1, 1)) 48 | .zip("1000000") 49 | .address("Tokyo") 50 | .build(); 51 | Account created = accountService.register(account, "password"); 52 | assertThat(created.getPassword(), is("password")); 53 | Account found = accountRepository.findOne("foo@example.com").get(); 54 | assertThat(found, is(created)); 55 | } 56 | } -------------------------------------------------------------------------------- /src/test/java/jsug/domain/service/goods/GoodsServiceTest.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.service.goods; 2 | 3 | import jsug.domain.TestConfig; 4 | import jsug.domain.model.Goods; 5 | import org.junit.Rule; 6 | import org.junit.Test; 7 | import org.junit.rules.ExpectedException; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.test.context.ContextConfiguration; 11 | import org.springframework.test.context.jdbc.Sql; 12 | import org.springframework.test.context.jdbc.SqlConfig; 13 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 14 | 15 | import java.util.UUID; 16 | 17 | import static org.hamcrest.Matchers.*; 18 | import static org.junit.Assert.*; 19 | 20 | 21 | @RunWith(SpringJUnit4ClassRunner.class) 22 | @ContextConfiguration(classes = TestConfig.class) 23 | @Sql(scripts = { 24 | "/sql/drop-tables.sql", 25 | "/db/migration/V1__create-schema.sql", 26 | "/sql/insert-goods.sql" 27 | }, config = @SqlConfig(encoding = "UTF-8")) 28 | public class GoodsServiceTest { 29 | @Rule 30 | public ExpectedException expectedException = ExpectedException.none(); 31 | @Autowired 32 | GoodsService goodsService; 33 | 34 | @Test 35 | public void testFindOne() throws Exception { 36 | Goods goods = goodsService.findOne(UUID.fromString("366cf3a4-68c5-4dae-a557-673769f76840")); 37 | assertThat(goods.getGoodsId(), is(UUID.fromString("366cf3a4-68c5-4dae-a557-673769f76840"))); 38 | assertThat(goods.getGoodsName(), is("こころ")); 39 | assertThat(goods.getDescription(), is("夏目 漱石の本です")); 40 | assertThat(goods.getPrice(), is(900)); 41 | assertThat(goods.getCategory().getCategoryName(), is("本")); 42 | } 43 | 44 | @Test 45 | public void testFindOne_NotFound() throws Exception { 46 | expectedException.expect(GoodsNotFoundException.class); 47 | goodsService.findOne(UUID.randomUUID()); 48 | } 49 | } -------------------------------------------------------------------------------- /src/test/java/jsug/domain/service/order/OrderServiceTest.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.service.order; 2 | 3 | import jsug.domain.TestConfig; 4 | import jsug.domain.model.*; 5 | import org.junit.Rule; 6 | import org.junit.Test; 7 | import org.junit.rules.ExpectedException; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.test.context.ContextConfiguration; 11 | import org.springframework.test.context.jdbc.Sql; 12 | import org.springframework.test.context.jdbc.SqlConfig; 13 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 14 | 15 | 16 | import java.time.LocalDate; 17 | import java.util.Collections; 18 | import java.util.UUID; 19 | 20 | import static org.hamcrest.Matchers.*; 21 | import static org.junit.Assert.*; 22 | 23 | 24 | @RunWith(SpringJUnit4ClassRunner.class) 25 | @ContextConfiguration(classes = TestConfig.class) 26 | @Sql(scripts = { 27 | "/sql/drop-tables.sql", 28 | "/db/migration/V1__create-schema.sql", 29 | "/sql/insert-orders.sql" 30 | }, config = @SqlConfig(encoding = "UTF-8")) 31 | public class OrderServiceTest { 32 | @Rule 33 | public ExpectedException expectedException = ExpectedException.none(); 34 | @Autowired 35 | OrderService orderService; 36 | 37 | @Test 38 | public void testPurchase() throws Exception { 39 | Cart cart = new Cart(); 40 | OrderLine ol1 = OrderLine.builder() 41 | .quantity(1) 42 | .goods(Goods.builder().goodsId(UUID.fromString("366cf3a4-68c5-4dae-a557-673769f76840")).build()) 43 | .build(); 44 | OrderLine ol2 = OrderLine.builder() 45 | .quantity(2) 46 | .goods(Goods.builder().goodsId(UUID.fromString("366cf3a4-68c5-4dae-a557-673769f76841")).build()) 47 | .build(); 48 | cart.add(ol1).add(ol2); 49 | 50 | Account account = Account.builder().email("demo1@example.com").build(); 51 | String signature = orderService.calcSignature(cart); 52 | 53 | Order ordered = orderService.purchase(account, cart, signature); 54 | 55 | assertThat(cart.isEmpty(), is(true)); 56 | assertThat(ordered.getOrderId(), is(notNullValue())); 57 | assertThat(ordered.getOrderDate(), is(LocalDate.now())); 58 | assertThat(ordered.getEmail(), is("demo1@example.com")); 59 | assertThat(ordered.getOrderLines().getList(), hasSize(2)); 60 | } 61 | 62 | @Test 63 | public void testPurchase_CartIsEmpty() throws Exception { 64 | expectedException.expect(EmptyCartOrderException.class); 65 | expectedException.expect(hasProperty("message", is("買い物カゴが空です"))); 66 | 67 | Cart cart = new Cart(); 68 | 69 | Account account = Account.builder().email("demo1@example.com").build(); 70 | String signature = orderService.calcSignature(cart); 71 | 72 | // change cart 73 | cart.remove(Collections.singleton(0)); 74 | 75 | orderService.purchase(account, cart, signature); 76 | } 77 | 78 | @Test 79 | public void testPurchase_CartHasBeenChanged() throws Exception { 80 | expectedException.expect(InvalidCartOrderException.class); 81 | expectedException.expect(hasProperty("message", is("買い物カゴの状態が変わっています"))); 82 | 83 | Cart cart = new Cart(); 84 | OrderLine ol1 = OrderLine.builder() 85 | .quantity(1) 86 | .goods(Goods.builder().goodsId(UUID.fromString("366cf3a4-68c5-4dae-a557-673769f76840")).build()) 87 | .build(); 88 | OrderLine ol2 = OrderLine.builder() 89 | .quantity(2) 90 | .goods(Goods.builder().goodsId(UUID.fromString("366cf3a4-68c5-4dae-a557-673769f76841")).build()) 91 | .build(); 92 | cart.add(ol1).add(ol2); 93 | 94 | Account account = Account.builder().email("demo1@example.com").build(); 95 | String signature = orderService.calcSignature(cart); 96 | 97 | // change cart 98 | cart.remove(Collections.singleton(0)); 99 | 100 | orderService.purchase(account, cart, signature); 101 | } 102 | } -------------------------------------------------------------------------------- /src/test/java/jsug/domain/service/userdetails/ShopUserDetailsServiceTest.java: -------------------------------------------------------------------------------- 1 | package jsug.domain.service.userdetails; 2 | 3 | import jsug.domain.TestConfig; 4 | import jsug.domain.model.Account; 5 | import org.junit.Rule; 6 | import org.junit.Test; 7 | import org.junit.rules.ExpectedException; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.security.core.authority.AuthorityUtils; 11 | import org.springframework.security.core.userdetails.UserDetails; 12 | import org.springframework.security.core.userdetails.UserDetailsService; 13 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 14 | import org.springframework.test.context.ContextConfiguration; 15 | import org.springframework.test.context.jdbc.Sql; 16 | import org.springframework.test.context.jdbc.SqlConfig; 17 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 18 | 19 | import java.time.LocalDate; 20 | 21 | import static org.junit.Assert.*; 22 | import static org.hamcrest.CoreMatchers.*; 23 | 24 | @RunWith(SpringJUnit4ClassRunner.class) 25 | @ContextConfiguration(classes = TestConfig.class) 26 | @Sql(scripts = { 27 | "/sql/drop-tables.sql", 28 | "/db/migration/V1__create-schema.sql", 29 | "/sql/insert-accounts.sql" 30 | }, config = @SqlConfig(encoding = "UTF-8")) 31 | public class ShopUserDetailsServiceTest { 32 | @Rule 33 | public ExpectedException expectedException = ExpectedException.none(); 34 | @Autowired 35 | UserDetailsService userDetailsService; 36 | 37 | @Test 38 | public void testLoadUserByUsername() throws Exception { 39 | UserDetails userDetails = userDetailsService.loadUserByUsername("demo1@example.com"); 40 | assertThat(userDetails.getUsername(), is("demo1@example.com")); 41 | assertThat(userDetails.getPassword(), is("demo")); 42 | assertThat(userDetails.getAuthorities(), is(AuthorityUtils.createAuthorityList("DEMO"))); 43 | assertThat(userDetails, is(instanceOf(ShopUserDetails.class))); 44 | Account account = ShopUserDetails.class.cast(userDetails).getAccount(); 45 | assertThat(account.getName(), is("山田太郎")); 46 | assertThat(account.getEmail(), is("demo1@example.com")); 47 | assertThat(account.getPassword(), is("demo")); 48 | assertThat(account.getBirthDay(), is(LocalDate.of(2000, 1, 1))); 49 | assertThat(account.getZip(), is("1000000")); 50 | assertThat(account.getAddress(), is("東京都")); 51 | } 52 | 53 | @Test 54 | public void testLoadUserByUsername_NotFound() throws Exception { 55 | expectedException.expect(UsernameNotFoundException.class); 56 | userDetailsService.loadUserByUsername("hoge@example.com"); 57 | } 58 | } -------------------------------------------------------------------------------- /src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/test/resources/sql/drop-tables.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE IF EXISTS order_line; 2 | DROP TABLE IF EXISTS goods; 3 | DROP TABLE IF EXISTS account; 4 | DROP TABLE IF EXISTS category; 5 | DROP TABLE IF EXISTS ordr; -------------------------------------------------------------------------------- /src/test/resources/sql/insert-accounts.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO account (email, PASSWORD, name, birth_day, ZIP, address) 2 | VALUES ('demo1@example.com', 'demo', '山田太郎', '2000-01-01', '1000000', '東京都'); 3 | INSERT INTO account (email, PASSWORD, name, birth_day, ZIP, address) 4 | VALUES ('demo2@example.com', 'demo', '鈴木一朗', '2000-01-01', '1000000', '東京都'); 5 | INSERT INTO account (email, PASSWORD, name, birth_day, ZIP, address) 6 | VALUES ('demo3@example.com', 'demo', '田中二郎', '2000-01-01', '1000000', '東京都'); 7 | INSERT INTO account (email, PASSWORD, name, birth_day, ZIP, address) 8 | VALUES ('demo4@example.com', 'demo', '山本三郎', '2000-01-01', '1000000', '東京都'); 9 | INSERT INTO account (email, PASSWORD, name, birth_day, ZIP, address) 10 | VALUES ('demo5@example.com', 'demo', '橋下四郎', '2000-01-01', '1000000', '東京都'); -------------------------------------------------------------------------------- /src/test/resources/sql/insert-category.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO category (category_id, category_name) VALUES (1, '本'); 2 | INSERT INTO category (category_id, category_name) VALUES (2, '音楽'); 3 | INSERT INTO category (category_id, category_name) VALUES (3, '家電'); 4 | INSERT INTO category (category_id, category_name) VALUES (4, 'パソコン'); 5 | -------------------------------------------------------------------------------- /src/test/resources/sql/insert-goods.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO category (category_id, category_name) VALUES (1, '本'); 2 | 3 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 4 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76840', 'こころ', '夏目 漱石の本です', 1, 900); 5 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 6 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76841', '〔雨ニモマケズ〕', '宮沢 賢治の本です', 1, 800); 7 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 8 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76842', '走れメロス', '太宰 治の本です', 1, 880); 9 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 10 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76843', '吾輩は猫である', '夏目 漱石の本です', 1, 900); 11 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 12 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76844', '人間失格', '太宰 治の本です', 1, 880); -------------------------------------------------------------------------------- /src/test/resources/sql/insert-orders.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO category (category_id, category_name) VALUES (1, '本'); 2 | 3 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 4 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76840', 'こころ', '夏目 漱石の本です', 1, 900); 5 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 6 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76841', '〔雨ニモマケズ〕', '宮沢 賢治の本です', 1, 800); 7 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 8 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76842', '走れメロス', '太宰 治の本です', 1, 880); 9 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 10 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76843', '吾輩は猫である', '夏目 漱石の本です', 1, 900); 11 | INSERT INTO goods (goods_id, goods_name, description, category_id, price) 12 | VALUES ('366cf3a4-68c5-4dae-a557-673769f76844', '人間失格', '太宰 治の本です', 1, 880); 13 | 14 | INSERT INTO account (email, PASSWORD, name, birth_day, ZIP, address) 15 | VALUES ('demo1@example.com', 'demo', '山田太郎', '2000-01-01', '1000000', '東京都'); --------------------------------------------------------------------------------