Commit 8efec87581eb26ab62a5478b91b59b6b28378ba1

Authored by Julien Iguchi-Cartigny
1 parent 8609fe0b

switch to spring boot

1 <?xml version="1.0" encoding="UTF-8"?> 1 <?xml version="1.0" encoding="UTF-8"?>
2 -<project xmlns="http://maven.apache.org/POM/4.0.0"  
3 - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
4 - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0  
5 - http://maven.apache.org/maven-v4_0_0.xsd">  
6 -  
7 - <modelVersion>4.0.0</modelVersion>  
8 - <groupId>fr.plil.sio</groupId>  
9 - <artifactId>spring-mvc-sample</artifactId>  
10 - <packaging>war</packaging>  
11 - <version>0.2</version>  
12 -  
13 - <dependencies>  
14 -  
15 - <dependency>  
16 - <groupId>org.springframework</groupId>  
17 - <artifactId>spring-webmvc</artifactId>  
18 - <version>${spring.version}</version>  
19 - </dependency>  
20 -  
21 - <dependency>  
22 - <groupId>org.springframework</groupId>  
23 - <artifactId>spring-web</artifactId>  
24 - <version>${spring.version}</version>  
25 - </dependency>  
26 -  
27 - <dependency>  
28 - <groupId>org.springframework</groupId>  
29 - <artifactId>spring-context</artifactId>  
30 - <version>${spring.version}</version>  
31 - </dependency>  
32 -  
33 - <dependency>  
34 - <groupId>javax.servlet</groupId>  
35 - <artifactId>javax.servlet-api</artifactId>  
36 - <version>${servlet.version}</version>  
37 - <scope>provided</scope>  
38 - </dependency>  
39 -  
40 - <dependency>  
41 - <groupId>javax.servlet.jsp</groupId>  
42 - <artifactId>jsp-api</artifactId>  
43 - <version>${jsp.version}</version>  
44 - <scope>provided</scope>  
45 - </dependency>  
46 -  
47 - <dependency>  
48 - <groupId>javax.el</groupId>  
49 - <artifactId>el-api</artifactId>  
50 - <version>${jsp.el.version}</version>  
51 - <scope>provided</scope>  
52 - </dependency>  
53 - 2 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4 + <modelVersion>4.0.0</modelVersion>
  5 +
  6 + <groupId>fr.plil.sio.web</groupId>
  7 + <artifactId>mvc</artifactId>
  8 + <version>0.2</version>
  9 + <packaging>war</packaging>
  10 +
  11 + <name>spring-mvc-sample</name>
  12 + <description></description>
  13 +
  14 + <parent>
  15 + <groupId>org.springframework.boot</groupId>
  16 + <artifactId>spring-boot-starter-parent</artifactId>
  17 + <version>1.2.3.RELEASE</version>
  18 + <relativePath/> <!-- lookup parent from repository -->
  19 + </parent>
  20 +
  21 + <properties>
  22 + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  23 + <start-class>fr.plil.sio.web.mvc.Application</start-class>
  24 + <java.version>1.8</java.version>
  25 + </properties>
  26 +
  27 + <dependencies>
  28 + <dependency>
  29 + <groupId>org.springframework.boot</groupId>
  30 + <artifactId>spring-boot-starter-data-rest</artifactId>
  31 + </dependency>
  32 + <dependency>
  33 + <groupId>org.springframework.boot</groupId>
  34 + <artifactId>spring-boot-starter-web</artifactId>
  35 + </dependency>
  36 + <dependency>
  37 + <groupId>com.h2database</groupId>
  38 + <artifactId>h2</artifactId>
  39 + <scope>runtime</scope>
  40 + </dependency>
  41 + <dependency>
  42 + <groupId>org.springframework.boot</groupId>
  43 + <artifactId>spring-boot-starter-tomcat</artifactId>
  44 + <scope>provided</scope>
  45 + </dependency>
  46 + <dependency>
  47 + <groupId>org.springframework.boot</groupId>
  48 + <artifactId>spring-boot-starter-test</artifactId>
  49 + <scope>test</scope>
  50 + </dependency>
  51 + <dependency>
  52 + <groupId>org.apache.tomcat.embed</groupId>
  53 + <artifactId>tomcat-embed-jasper</artifactId>
  54 + <scope>provided</scope>
  55 + </dependency>
54 <dependency> 56 <dependency>
55 <groupId>javax.servlet</groupId> 57 <groupId>javax.servlet</groupId>
56 <artifactId>jstl</artifactId> 58 <artifactId>jstl</artifactId>
57 - <version>${jsp.jstl.version}</version>  
58 </dependency> 59 </dependency>
59 -  
60 - <dependency>  
61 - <groupId>junit</groupId>  
62 - <artifactId>junit</artifactId>  
63 - <version>${junit.version}</version>  
64 - <scope>test</scope>  
65 - </dependency>  
66 -  
67 - <dependency>  
68 - <groupId>org.springframework</groupId>  
69 - <artifactId>spring-test</artifactId>  
70 - <version>${spring.version}</version>  
71 - <scope>test</scope>  
72 - </dependency>  
73 -  
74 - <dependency>  
75 - <groupId>org.slf4j</groupId>  
76 - <artifactId>slf4j-api</artifactId>  
77 - <version>${slf4j.version}</version>  
78 - <scope>compile</scope>  
79 - </dependency>  
80 -  
81 - <dependency>  
82 - <groupId>ch.qos.logback</groupId>  
83 - <artifactId>logback-classic</artifactId>  
84 - <version>${logback.version}</version>  
85 - </dependency>  
86 -  
87 - <!--dependency>  
88 - <groupId>org.slf4j</groupId>  
89 - <artifactId>log4j-over-slf4j</artifactId>  
90 - <version>${slf4j.version}</version>  
91 - </dependency>  
92 -  
93 - <dependency>  
94 - <groupId>org.slf4j</groupId>  
95 - <artifactId>jcl-over-slf4j</artifactId>  
96 - <version>${slf4j.version}</version>  
97 - </dependency>  
98 -  
99 - <dependency>  
100 - <groupId>org.slf4j</groupId>  
101 - <artifactId>jul-to-slf4j</artifactId>  
102 - <version>${slf4j.version}</version>  
103 - </dependency-->  
104 -  
105 - </dependencies>  
106 -  
107 - <build>  
108 - <plugins>  
109 - <plugin>  
110 - <groupId>org.apache.maven.plugins</groupId>  
111 - <artifactId>maven-compiler-plugin</artifactId>  
112 - <version>2.3.2</version>  
113 - <configuration>  
114 - <source>1.6</source>  
115 - <target>1.6</target>  
116 - </configuration>  
117 - </plugin>  
118 - <plugin>  
119 - <artifactId>maven-war-plugin</artifactId>  
120 - <configuration>  
121 - <failOnMissingWebXml>false</failOnMissingWebXml>  
122 - </configuration>  
123 - <version>2.1.1</version>  
124 - </plugin>  
125 - </plugins>  
126 - <finalName>spring-mvc-sample</finalName>  
127 - </build>  
128 -  
129 - <properties>  
130 - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
131 - <spring.version>4.0.0.RELEASE</spring.version>  
132 - <slf4j.version>1.7.5</slf4j.version>  
133 - <junit.version>4.10</junit.version>  
134 - <logback.version>1.0.13</logback.version>  
135 - <servlet.version>3.1.0</servlet.version>  
136 - <jsp.version>2.2</jsp.version>  
137 - <jsp.el.version>2.2</jsp.el.version>  
138 - <jsp.jstl.version>1.2</jsp.jstl.version>  
139 - </properties>  
140 -  
141 -</project>  
142 \ No newline at end of file 60 \ No newline at end of file
  61 + </dependencies>
  62 +
  63 + <build>
  64 + <plugins>
  65 + <plugin>
  66 + <groupId>org.springframework.boot</groupId>
  67 + <artifactId>spring-boot-maven-plugin</artifactId>
  68 + </plugin>
  69 + </plugins>
  70 + </build>
  71 +
  72 +</project>
src/main/java/fr/plil/sio/web/mvc/Application.java 0 โ†’ 100644
@@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
  1 +package fr.plil.sio.web.mvc;
  2 +
  3 +import org.springframework.boot.SpringApplication;
  4 +import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  5 +import org.springframework.boot.builder.SpringApplicationBuilder;
  6 +import org.springframework.boot.context.web.SpringBootServletInitializer;
  7 +import org.springframework.context.annotation.ComponentScan;
  8 +import org.springframework.context.annotation.Configuration;
  9 +
  10 +@EnableAutoConfiguration
  11 +@Configuration
  12 +@ComponentScan
  13 +public class Application extends SpringBootServletInitializer {
  14 +
  15 + public static void main(String[] args) {
  16 + SpringApplication.run(Application.class, args);
  17 + }
  18 +
  19 + @Override
  20 + protected final SpringApplicationBuilder configure(final SpringApplicationBuilder application) {
  21 + return application.sources(Application.class);
  22 + }
  23 +}
src/main/java/fr/plil/sio/web/mvc/WebAppConfig.java renamed to src/main/java/fr/plil/sio/web/mvc/ApplicationMvcConfiguration.java
1 package fr.plil.sio.web.mvc; 1 package fr.plil.sio.web.mvc;
2 2
  3 +
3 import org.slf4j.Logger; 4 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory; 5 import org.slf4j.LoggerFactory;
5 -import org.springframework.context.MessageSource;  
6 import org.springframework.context.annotation.Bean; 6 import org.springframework.context.annotation.Bean;
7 -import org.springframework.context.annotation.ComponentScan;  
8 import org.springframework.context.annotation.Configuration; 7 import org.springframework.context.annotation.Configuration;
9 import org.springframework.context.annotation.Scope; 8 import org.springframework.context.annotation.Scope;
10 import org.springframework.context.annotation.ScopedProxyMode; 9 import org.springframework.context.annotation.ScopedProxyMode;
11 -import org.springframework.context.support.ResourceBundleMessageSource;  
12 import org.springframework.web.context.WebApplicationContext; 10 import org.springframework.web.context.WebApplicationContext;
13 -import org.springframework.web.servlet.ViewResolver;  
14 -import org.springframework.web.servlet.config.annotation.EnableWebMvc;  
15 import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 11 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
16 -import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;  
17 -import org.springframework.web.servlet.view.InternalResourceViewResolver;  
18 import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 12 import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
19 13
20 @Configuration 14 @Configuration
21 -@ComponentScan(basePackages = {"fr.plil.sio.web.mvc"},scopedProxy = ScopedProxyMode.TARGET_CLASS)  
22 -@EnableWebMvc  
23 -public class WebAppConfig extends WebMvcConfigurerAdapter { 15 +public class ApplicationMvcConfiguration extends WebMvcConfigurerAdapter{
24 16
25 - private static final Logger logger = LoggerFactory.getLogger(WebAppConfig.class); 17 + private static final Logger logger = LoggerFactory.getLogger(ApplicationMvcConfiguration.class);
26 18
27 @Bean 19 @Bean
28 @Scope(value = WebApplicationContext.SCOPE_SESSION, proxyMode = ScopedProxyMode. TARGET_CLASS) 20 @Scope(value = WebApplicationContext.SCOPE_SESSION, proxyMode = ScopedProxyMode. TARGET_CLASS)
@@ -42,25 +34,4 @@ public class WebAppConfig extends WebMvcConfigurerAdapter { @@ -42,25 +34,4 @@ public class WebAppConfig extends WebMvcConfigurerAdapter {
42 interceptor.setUserSession(userSession()); 34 interceptor.setUserSession(userSession());
43 registry.addInterceptor(interceptor); 35 registry.addInterceptor(interceptor);
44 } 36 }
45 -  
46 - @Bean  
47 - public MessageSource messageSource() {  
48 - ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();  
49 - messageSource.setBasename("messages");  
50 - messageSource.setDefaultEncoding("UTF-8");  
51 - return messageSource;  
52 - }  
53 -  
54 - @Bean  
55 - public ViewResolver viewResolver() {  
56 - InternalResourceViewResolver resolver = new InternalResourceViewResolver();  
57 - resolver.setPrefix("/WEB-INF/views/");  
58 - resolver.setSuffix(".jsp");  
59 - return resolver;  
60 - }  
61 -  
62 - @Override  
63 - public void addResourceHandlers(ResourceHandlerRegistry registry) {  
64 - registry.addResourceHandler("/resources/").addResourceLocations("/resources/**");  
65 - }  
66 } 37 }
src/main/java/fr/plil/sio/web/mvc/CheckUserInterceptor.java
@@ -6,13 +6,14 @@ import javax.servlet.http.HttpServletRequest; @@ -6,13 +6,14 @@ import javax.servlet.http.HttpServletRequest;
6 import javax.servlet.http.HttpServletResponse; 6 import javax.servlet.http.HttpServletResponse;
7 import org.slf4j.Logger; 7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory; 8 import org.slf4j.LoggerFactory;
  9 +import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; 10 import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
10 11
11 public class CheckUserInterceptor extends HandlerInterceptorAdapter { 12 public class CheckUserInterceptor extends HandlerInterceptorAdapter {
12 13
13 private static final Logger logger = LoggerFactory.getLogger(CheckUserInterceptor.class); 14 private static final Logger logger = LoggerFactory.getLogger(CheckUserInterceptor.class);
14 15
15 - @Resource 16 + @Autowired
16 private UserSession userSession; 17 private UserSession userSession;
17 18
18 @Override 19 @Override
src/main/java/fr/plil/sio/web/mvc/LoginController.java
@@ -12,7 +12,7 @@ import org.springframework.web.servlet.ModelAndView; @@ -12,7 +12,7 @@ import org.springframework.web.servlet.ModelAndView;
12 public class LoginController { 12 public class LoginController {
13 13
14 @Resource 14 @Resource
15 - private UserDao userDao; 15 + private UserRepository userRepository;
16 16
17 @Resource 17 @Resource
18 private UserSession userSession; 18 private UserSession userSession;
@@ -25,7 +25,7 @@ public class LoginController { @@ -25,7 +25,7 @@ public class LoginController {
25 @RequestMapping(method = RequestMethod.POST) 25 @RequestMapping(method = RequestMethod.POST)
26 public String postLoginCheck(User user, BindingResult result) { 26 public String postLoginCheck(User user, BindingResult result) {
27 27
28 - User userFromDao = userDao.getFromUsername(user.getUsername()); 28 + User userFromDao = userRepository.getFromUsername(user.getUsername());
29 29
30 if (userFromDao == null) { 30 if (userFromDao == null) {
31 result.rejectValue("username","login.form.invalid"); 31 result.rejectValue("username","login.form.invalid");
@@ -42,8 +42,8 @@ public class LoginController { @@ -42,8 +42,8 @@ public class LoginController {
42 return "redirect:/"; 42 return "redirect:/";
43 } 43 }
44 44
45 - public void setUserDao(UserDao userDao) {  
46 - this.userDao = userDao; 45 + public void setUserRepository(UserRepository userRepository) {
  46 + this.userRepository = userRepository;
47 } 47 }
48 48
49 public void setUserSession(UserSession userSession) { 49 public void setUserSession(UserSession userSession) {
src/main/java/fr/plil/sio/web/mvc/NewUserController.java
@@ -11,9 +11,11 @@ import org.springframework.web.servlet.ModelAndView; @@ -11,9 +11,11 @@ import org.springframework.web.servlet.ModelAndView;
11 public class NewUserController { 11 public class NewUserController {
12 12
13 @Resource 13 @Resource
14 - private UserDao userDao; 14 + private UserRepository userRepository;
  15 +
15 @Resource 16 @Resource
16 private UserSession userSession; 17 private UserSession userSession;
  18 +
17 @Resource 19 @Resource
18 private UserValidator userValidator; 20 private UserValidator userValidator;
19 21
@@ -31,7 +33,7 @@ public class NewUserController { @@ -31,7 +33,7 @@ public class NewUserController {
31 33
32 userValidator.validate(user, result); 34 userValidator.validate(user, result);
33 35
34 - boolean present = (userDao.getFromUsername(user.getUsername()) != null); 36 + boolean present = (userRepository.getFromUsername(user.getUsername()) != null);
35 37
36 if (present) { 38 if (present) {
37 result.rejectValue("username", "new.user.form.present"); 39 result.rejectValue("username", "new.user.form.present");
@@ -41,13 +43,13 @@ public class NewUserController { @@ -41,13 +43,13 @@ public class NewUserController {
41 return "newUser"; 43 return "newUser";
42 } 44 }
43 45
44 - userDao.save(user); 46 + userRepository.save(user);
45 47
46 return "redirect:/"; 48 return "redirect:/";
47 } 49 }
48 50
49 - public void setUserDao(UserDao userDao) {  
50 - this.userDao = userDao; 51 + public void setUserRepository(UserRepository userRepository) {
  52 + this.userRepository = userRepository;
51 } 53 }
52 54
53 public void setUserSession(UserSession userSession) { 55 public void setUserSession(UserSession userSession) {
src/main/java/fr/plil/sio/web/mvc/UserDao.java renamed to src/main/java/fr/plil/sio/web/mvc/UserRepository.java
@@ -2,7 +2,7 @@ package fr.plil.sio.web.mvc; @@ -2,7 +2,7 @@ package fr.plil.sio.web.mvc;
2 2
3 import java.util.Set; 3 import java.util.Set;
4 4
5 -public interface UserDao { 5 +public interface UserRepository {
6 6
7 boolean save(User user); 7 boolean save(User user);
8 8
src/main/java/fr/plil/sio/web/mvc/UserDaoImpl.java renamed to src/main/java/fr/plil/sio/web/mvc/UserRepositoryImpl.java
@@ -5,11 +5,11 @@ import java.util.Set; @@ -5,11 +5,11 @@ import java.util.Set;
5 import org.springframework.stereotype.Repository; 5 import org.springframework.stereotype.Repository;
6 6
7 @Repository(value = "userDao") 7 @Repository(value = "userDao")
8 -public class UserDaoImpl implements UserDao { 8 +public class UserRepositoryImpl implements UserRepository {
9 9
10 private Set<User> users = new HashSet<User>(); 10 private Set<User> users = new HashSet<User>();
11 11
12 - public UserDaoImpl() { 12 + public UserRepositoryImpl() {
13 User user = new User(); 13 User user = new User();
14 user.setUsername("admin"); 14 user.setUsername("admin");
15 user.setPassword("admin"); 15 user.setPassword("admin");
src/main/java/fr/plil/sio/web/mvc/ViewUsersController.java
@@ -11,14 +11,14 @@ import org.springframework.web.bind.annotation.RequestMethod; @@ -11,14 +11,14 @@ import org.springframework.web.bind.annotation.RequestMethod;
11 public class ViewUsersController { 11 public class ViewUsersController {
12 12
13 @Resource 13 @Resource
14 - private UserDao userDao; 14 + private UserRepository userRepository;
15 15
16 @Resource 16 @Resource
17 private UserSession userSession; 17 private UserSession userSession;
18 18
19 @ModelAttribute("users") 19 @ModelAttribute("users")
20 public Set<User> populateUsers() { 20 public Set<User> populateUsers() {
21 - return userDao.getAllUsers(); 21 + return userRepository.getAllUsers();
22 } 22 }
23 23
24 @ModelAttribute("userSession") 24 @ModelAttribute("userSession")
@@ -31,8 +31,8 @@ public class ViewUsersController { @@ -31,8 +31,8 @@ public class ViewUsersController {
31 return "viewUsers"; 31 return "viewUsers";
32 } 32 }
33 33
34 - public void setUserDao(UserDao userDao) {  
35 - this.userDao = userDao; 34 + public void setUserRepository(UserRepository userRepository) {
  35 + this.userRepository = userRepository;
36 } 36 }
37 37
38 public void setUserSession(UserSession userSession) { 38 public void setUserSession(UserSession userSession) {
src/main/java/fr/plil/sio/web/mvc/WebAppInitializer.java deleted
@@ -1,35 +0,0 @@ @@ -1,35 +0,0 @@
1 -package fr.plil.sio.web.mvc;  
2 -  
3 -import javax.servlet.ServletContext;  
4 -import javax.servlet.ServletException;  
5 -import javax.servlet.ServletRegistration;  
6 -import org.slf4j.Logger;  
7 -import org.slf4j.LoggerFactory;  
8 -import org.springframework.web.WebApplicationInitializer;  
9 -import org.springframework.web.context.ContextLoaderListener;  
10 -import org.springframework.web.context.WebApplicationContext;  
11 -import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;  
12 -import org.springframework.web.servlet.DispatcherServlet;  
13 -  
14 -public class WebAppInitializer implements WebApplicationInitializer {  
15 -  
16 - private static final Logger logger = LoggerFactory.getLogger(WebAppInitializer.class);  
17 -  
18 - @Override  
19 - public void onStartup(ServletContext servletContext) throws ServletException {  
20 - logger.info("starting web app initializer");  
21 - WebApplicationContext context = getContext();  
22 - servletContext.addListener(new ContextLoaderListener(context));  
23 - ServletRegistration.Dynamic dispatcher = servletContext  
24 - .addServlet("dispatcher", new DispatcherServlet(context));  
25 - dispatcher.setLoadOnStartup(1);  
26 - dispatcher.addMapping("/");  
27 - }  
28 -  
29 - private AnnotationConfigWebApplicationContext getContext() {  
30 - logger.info("start web application context");  
31 - AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();  
32 - context.register(WebAppConfig.class);  
33 - return context;  
34 - }  
35 -}  
src/main/resources/application.properties 0 โ†’ 100644
@@ -0,0 +1,4 @@ @@ -0,0 +1,4 @@
  1 +logging.level.fr.plil.sio.web.mvc=DEBUG
  2 +
  3 +spring.view.prefix=/WEB-INF/views/
  4 +spring.view.suffix=.jsp
src/test/java/fr/plil/sio/web/mvc/LoginControllerTest.java
@@ -12,7 +12,7 @@ public class LoginControllerTest { @@ -12,7 +12,7 @@ public class LoginControllerTest {
12 private LoginController loginController; 12 private LoginController loginController;
13 private BindingResult results; 13 private BindingResult results;
14 private User user; 14 private User user;
15 - private UserDao userDao; 15 + private UserRepository userRepository;
16 private UserSession userSession; 16 private UserSession userSession;
17 17
18 @Before 18 @Before
@@ -20,8 +20,8 @@ public class LoginControllerTest { @@ -20,8 +20,8 @@ public class LoginControllerTest {
20 loginController = new LoginController(); 20 loginController = new LoginController();
21 user = new User(); 21 user = new User();
22 results = new BeanPropertyBindingResult(user, "user"); 22 results = new BeanPropertyBindingResult(user, "user");
23 - userDao = new UserDaoImpl();  
24 - loginController.setUserDao(userDao); 23 + userRepository = new UserRepositoryImpl();
  24 + loginController.setUserRepository(userRepository);
25 userSession = new UserSession(); 25 userSession = new UserSession();
26 loginController.setUserSession(userSession); 26 loginController.setUserSession(userSession);
27 } 27 }
src/test/java/fr/plil/sio/web/mvc/NewUserControllerTest.java
@@ -12,7 +12,7 @@ public class NewUserControllerTest { @@ -12,7 +12,7 @@ public class NewUserControllerTest {
12 private NewUserController newUserController; 12 private NewUserController newUserController;
13 private BindingResult results; 13 private BindingResult results;
14 private User user; 14 private User user;
15 - private UserDao userDao; 15 + private UserRepository userRepository;
16 private UserSession userSession; 16 private UserSession userSession;
17 private UserValidator userValidator; 17 private UserValidator userValidator;
18 18
@@ -21,8 +21,8 @@ public class NewUserControllerTest { @@ -21,8 +21,8 @@ public class NewUserControllerTest {
21 newUserController = new NewUserController(); 21 newUserController = new NewUserController();
22 user = new User(); 22 user = new User();
23 results = new BeanPropertyBindingResult(user, "user"); 23 results = new BeanPropertyBindingResult(user, "user");
24 - userDao = new UserDaoImpl();  
25 - newUserController.setUserDao(userDao); 24 + userRepository = new UserRepositoryImpl();
  25 + newUserController.setUserRepository(userRepository);
26 userSession = new UserSession(); 26 userSession = new UserSession();
27 userSession.setUsername("admin"); 27 userSession.setUsername("admin");
28 newUserController.setUserSession(userSession); 28 newUserController.setUserSession(userSession);
src/test/java/fr/plil/sio/web/mvc/UserDaoTest.java renamed to src/test/java/fr/plil/sio/web/mvc/UserRepositoryTest.java
@@ -4,20 +4,20 @@ import static org.junit.Assert.*; @@ -4,20 +4,20 @@ import static org.junit.Assert.*;
4 import org.junit.Before; 4 import org.junit.Before;
5 import org.junit.Test; 5 import org.junit.Test;
6 6
7 -public class UserDaoTest { 7 +public class UserRepositoryTest {
8 8
9 - private UserDao userDao; 9 + private UserRepository userRepository;
10 10
11 @Before 11 @Before
12 public void createInstances() { 12 public void createInstances() {
13 - userDao = new UserDaoImpl(); 13 + userRepository = new UserRepositoryImpl();
14 } 14 }
15 15
16 @Test 16 @Test
17 public void testAdminPresent() { 17 public void testAdminPresent() {
18 - assertEquals(1, userDao.getAllUsers().size());  
19 - assertNotNull(userDao.getFromUsername("admin"));  
20 - assertEquals("admin", userDao.getFromUsername("admin").getUsername()); 18 + assertEquals(1, userRepository.getAllUsers().size());
  19 + assertNotNull(userRepository.getFromUsername("admin"));
  20 + assertEquals("admin", userRepository.getFromUsername("admin").getUsername());
21 } 21 }
22 22
23 @Test 23 @Test
@@ -25,7 +25,7 @@ public class UserDaoTest { @@ -25,7 +25,7 @@ public class UserDaoTest {
25 User user = new User(); 25 User user = new User();
26 user.setUsername("abc"); 26 user.setUsername("abc");
27 user.setPassword("abc"); 27 user.setPassword("abc");
28 - assertTrue(userDao.save(user)); 28 + assertTrue(userRepository.save(user));
29 } 29 }
30 30
31 @Test 31 @Test
@@ -33,7 +33,7 @@ public class UserDaoTest { @@ -33,7 +33,7 @@ public class UserDaoTest {
33 User user = new User(); 33 User user = new User();
34 user.setUsername("admin"); 34 user.setUsername("admin");
35 user.setPassword("abc"); 35 user.setPassword("abc");
36 - assertFalse(userDao.save(user)); 36 + assertFalse(userRepository.save(user));
37 } 37 }
38 38
39 @Test 39 @Test
@@ -41,23 +41,23 @@ public class UserDaoTest { @@ -41,23 +41,23 @@ public class UserDaoTest {
41 User user = new User(); 41 User user = new User();
42 user.setUsername("abc"); 42 user.setUsername("abc");
43 user.setPassword("abc"); 43 user.setPassword("abc");
44 - userDao.save(user);  
45 - assertNotNull(userDao.getFromUsername("admin"));  
46 - assertEquals("admin",userDao.getFromUsername("admin").getUsername()); 44 + userRepository.save(user);
  45 + assertNotNull(userRepository.getFromUsername("admin"));
  46 + assertEquals("admin", userRepository.getFromUsername("admin").getUsername());
47 } 47 }
48 48
49 @Test 49 @Test
50 public void testGetFromUsernameNotFound() { 50 public void testGetFromUsernameNotFound() {
51 - assertNull(userDao.getFromUsername("abc")); 51 + assertNull(userRepository.getFromUsername("abc"));
52 } 52 }
53 53
54 @Test 54 @Test
55 public void testGetAllUsers() { 55 public void testGetAllUsers() {
56 - assertEquals(1,userDao.getAllUsers().size()); 56 + assertEquals(1, userRepository.getAllUsers().size());
57 User user = new User(); 57 User user = new User();
58 user.setUsername("abc"); 58 user.setUsername("abc");
59 user.setPassword("abc"); 59 user.setPassword("abc");
60 - assertTrue(userDao.save(user));  
61 - assertEquals(2,userDao.getAllUsers().size()); 60 + assertTrue(userRepository.save(user));
  61 + assertEquals(2, userRepository.getAllUsers().size());
62 } 62 }
63 } 63 }
64 \ No newline at end of file 64 \ No newline at end of file
src/test/java/fr/plil/sio/web/mvc/ViewUsersControllerTest.java
@@ -7,14 +7,14 @@ import org.junit.Test; @@ -7,14 +7,14 @@ import org.junit.Test;
7 public class ViewUsersControllerTest { 7 public class ViewUsersControllerTest {
8 8
9 private ViewUsersController viewUsersController; 9 private ViewUsersController viewUsersController;
10 - private UserDao userDao; 10 + private UserRepository userRepository;
11 private UserSession userSession; 11 private UserSession userSession;
12 12
13 @Before 13 @Before
14 public void createInstances() { 14 public void createInstances() {
15 viewUsersController = new ViewUsersController(); 15 viewUsersController = new ViewUsersController();
16 - userDao = new UserDaoImpl();  
17 - viewUsersController.setUserDao(userDao); 16 + userRepository = new UserRepositoryImpl();
  17 + viewUsersController.setUserRepository(userRepository);
18 userSession = new UserSession(); 18 userSession = new UserSession();
19 userSession.setUsername("admin"); 19 userSession.setUsername("admin");
20 viewUsersController.setUserSession(userSession); 20 viewUsersController.setUserSession(userSession);