add unit tests for users. user_management
authorymh <ymh.work@gmail.com>
Mon, 09 Dec 2013 10:23:30 +0100
branchuser_management
changeset 234 d92a90b2ad53
parent 233 bf599928e1ad
child 235 f8746a482459
add unit tests for users.
server/src/main/java/org/iri_research/renkan/forms/UserFormValidator.java
server/src/main/webapp/WEB-INF/i18n/messages.properties
server/src/main/webapp/WEB-INF/i18n/messages_en.properties
server/src/main/webapp/WEB-INF/i18n/messages_fr.properties
server/src/main/webapp/WEB-INF/templates/fragment/userForm.html
server/src/test/java/org/iri_research/renkan/test/controller/UsersAdminControllerTest.java
--- a/server/src/main/java/org/iri_research/renkan/forms/UserFormValidator.java	Mon Nov 18 23:34:22 2013 +0100
+++ b/server/src/main/java/org/iri_research/renkan/forms/UserFormValidator.java	Mon Dec 09 10:23:30 2013 +0100
@@ -24,7 +24,7 @@
         UserForm userForm = (UserForm) target;
 
         ValidationUtils.rejectIfEmptyOrWhitespace(errors, "title",
-                "renkan.error.title.empty");
+                "renkan.error.name.empty");
         
         //TODO : check for user name unicity
         String pswd = userForm.getPassword();
--- a/server/src/main/webapp/WEB-INF/i18n/messages.properties	Mon Nov 18 23:34:22 2013 +0100
+++ b/server/src/main/webapp/WEB-INF/i18n/messages.properties	Mon Dec 09 10:23:30 2013 +0100
@@ -81,6 +81,7 @@
 renkanAdmin.form.user.submit = Ok
 
 renkan.error.title.empty = Title must not be empty or null
+renkan.error.name.empty = Name must not be empty or null
 renkan.error.bin_config.json = bin config field must contain a valid json
 renkan.error.password.equals = Password and Password confimation do not match
 renkan.error.password.missing = Password missing
--- a/server/src/main/webapp/WEB-INF/i18n/messages_en.properties	Mon Nov 18 23:34:22 2013 +0100
+++ b/server/src/main/webapp/WEB-INF/i18n/messages_en.properties	Mon Dec 09 10:23:30 2013 +0100
@@ -91,6 +91,7 @@
 
 
 renkan.error.title.empty = Title must not be empty or null
+renkan.error.name.empty = Name must not be empty or null
 renkan.error.bin_config.json = bin config field must contain a valid json
 renkan.error.password.equals = Password and Password confimation do not match
 renkan.error.password.missing = Password missing
--- a/server/src/main/webapp/WEB-INF/i18n/messages_fr.properties	Mon Nov 18 23:34:22 2013 +0100
+++ b/server/src/main/webapp/WEB-INF/i18n/messages_fr.properties	Mon Dec 09 10:23:30 2013 +0100
@@ -89,6 +89,7 @@
 
 
 renkan.error.title.empty = Le champ titre ne doit pas ĂȘtre vide
+renkan.error.name.empty = Le champ nom ne doit pas ĂȘtre vide
 renkan.error.bin_config.json = le champ bin config doit contenir un json valide
 renkan.error.password.equals = Le mot de passe et sa confimation ne corresponde pas
 renkan.error.password.missing = Mot de passe manquant
--- a/server/src/main/webapp/WEB-INF/templates/fragment/userForm.html	Mon Nov 18 23:34:22 2013 +0100
+++ b/server/src/main/webapp/WEB-INF/templates/fragment/userForm.html	Mon Dec 09 10:23:30 2013 +0100
@@ -110,13 +110,13 @@
        <div>
          <label for="credentialExpirationDate" th:text="#{renkanAdmin.form.credentialExpirationDate}">Credential expiration date: </label>
          <input type="hidden" name="credentialExpirationDate" th:field="*{credentialExpirationDate}"/>
-         <input type="date" id="credentialExpirationDate-disp" class="datepicker" value="01/01/1970" th:value="${user.credentialExpirationDate != null}?${user.credentialExpirationDate.toString(#messages.msg('date.date.format'))}:''"/>
+         <input type="text" id="credentialExpirationDate-disp" class="datepicker" value="01/01/1970" th:value="${user.credentialExpirationDate != null}?${user.credentialExpirationDate.toString(#messages.msg('date.date.format'))}:''"/>
           
        </div>
        <div>
          <label for="expirationDate" th:text="#{renkanAdmin.form.expirationDate}">Expiration date: </label>
          <input type="hidden" name="expirationDate" th:field="*{expirationDate}" />
-         <input type="date" id="expirationDate-disp" class="datepicker" value="01/01/1970" th:value="${user.expirationDate != null}?${user.expirationDate.toString(#messages.msg('date.date.format'))}:''"/> 
+         <input type="text" id="expirationDate-disp" class="datepicker" value="01/01/1970" th:value="${user.expirationDate != null}?${user.expirationDate.toString(#messages.msg('date.date.format'))}:''"/> 
        </div>
        <div>
          <label for="email" th:text="#{renkanAdmin.form.email}">Email: </label> 
--- a/server/src/test/java/org/iri_research/renkan/test/controller/UsersAdminControllerTest.java	Mon Nov 18 23:34:22 2013 +0100
+++ b/server/src/test/java/org/iri_research/renkan/test/controller/UsersAdminControllerTest.java	Mon Dec 09 10:23:30 2013 +0100
@@ -80,7 +80,7 @@
 
         for(int i=0; i < USER_NB; i++) {
             String uuid = UUID.randomUUID().toString();
-            User user = new User(uuid, "user" + i, "User nb 1", "http://www.iri.centrepompidou.fr", "#ababab");
+            User user = new User(uuid, "user" + i, "User nb " + i, "http://www.iri.centrepompidou.fr", "#ababab");
             user.setLocked(false);
             user.setEnabled(true);
             user.setAvatar("A pretty picture");
@@ -203,97 +203,93 @@
             }
         }
     }
-//
-//    @Test
-//    public void testSpacePostUpdateEmptyTitle() throws Exception {
-//
-//        MockHttpServletRequestBuilder post = MockMvcRequestBuilders
-//                .post("/admin/spaces/save");
-//        post = post.param("id", this.spacesUuids.get(0));
-//        post = post.param("title", "");
-//        post = post.param("description", "New description");
-//        post = post.param("uri", "http://ldt.iri.centrepompidou.fr/new/uri");
-//        post = post.param("color", "#ffffff");
-//        post = post.param("binConfig", "{}");
-//
-//        this.mvc.perform(post)
-//                .andExpect(MockMvcResultMatchers.status().isOk())
-//                .andExpect(MockMvcResultMatchers.view().name("admin/spaceEdit"))
-//                .andExpect(MockMvcResultMatchers.model().hasErrors())
-//                .andExpect(MockMvcResultMatchers.model().errorCount(1))
-//                .andExpect(
-//                        MockMvcResultMatchers.model().attributeHasErrors(
-//                                "space"))
-//                .andExpect(
-//                        MockMvcResultMatchers.model().attributeHasFieldErrors(
-//                                "space", "title"));
-//
-//        Space sp = this.spacesRepository.findOne(this.spacesUuids.get(0));
-//
-//        Assert.assertNotNull("Should find space", sp);
-//        Assert.assertEquals("Title equals", "test 0", sp.getTitle());
-//
-//    }
-//
-//    @Test
-//    public void testSpacePostCreateEmptyTitle() throws Exception {
-//
-//        MockHttpServletRequestBuilder post = MockMvcRequestBuilders
-//                .post("/admin/spaces/save");
-//        post = post.param("title", "");
-//        post = post.param("description", "New description");
-//        post = post.param("uri", "http://ldt.iri.centrepompidou.fr/new/uri");
-//        post = post.param("color", "#ffffff");
-//        post = post.param("binConfig", "{}");
-//
-//        this.mvc.perform(post)
-//                .andExpect(MockMvcResultMatchers.status().isOk())
-//                .andExpect(MockMvcResultMatchers.view().name("admin/spaceEdit"))
-//                .andExpect(MockMvcResultMatchers.model().hasErrors())
-//                .andExpect(MockMvcResultMatchers.model().errorCount(1))
-//                .andExpect(
-//                        MockMvcResultMatchers.model().attributeHasErrors(
-//                                "space"))
-//                .andExpect(
-//                        MockMvcResultMatchers.model().attributeHasFieldErrors(
-//                                "space", "title"));
-//
-//        Assert.assertEquals("Must not have one more space", SPACE_NB,
-//                this.spacesRepository.count());
-//
-//    }
-//
-//    @Test
-//    public void testSpacePostUpdateBadJson() throws Exception {
-//
-//        MockHttpServletRequestBuilder post = MockMvcRequestBuilders
-//                .post("/admin/spaces/save");
-//        post = post.param("id", this.spacesUuids.get(0));
-//        post = post.param("title", "New Title");
-//        post = post.param("description", "New description");
-//        post = post.param("uri", "http://ldt.iri.centrepompidou.fr/new/uri");
-//        post = post.param("color", "#ffffff");
-//        post = post.param("binConfig", "{");
-//
-//        this.mvc.perform(post)
-//                .andExpect(MockMvcResultMatchers.status().isOk())
-//                .andExpect(MockMvcResultMatchers.view().name("admin/spaceEdit"))
-//                .andExpect(MockMvcResultMatchers.model().hasErrors())
-//                .andExpect(MockMvcResultMatchers.model().errorCount(1))
-//                .andExpect(
-//                        MockMvcResultMatchers.model().attributeHasErrors(
-//                                "space"))
-//                .andExpect(
-//                        MockMvcResultMatchers.model().attributeHasFieldErrors(
-//                                "space", "binConfig"));
-//
-//        Space sp = this.spacesRepository.findOne(this.spacesUuids.get(0));
-//
-//        Assert.assertNotNull("Should find space", sp);
-//        Assert.assertEquals("Bin config equals", "{}", sp.getBinConfig());
-//
-//    }
-//
+
+    @Test
+    public void testUserPostUpdateEmptyTitle() throws Exception {
+
+        MockHttpServletRequestBuilder post = MockMvcRequestBuilders
+                .post("/admin/users/save")
+                .param("id", this.usersUuids.get(0))
+                .param("title", "")
+                .param("description", "New description")
+                .param("uri", "http://ldt.iri.centrepompidou.fr/new/uri")
+                .param("color", "#ffffff")
+                .param("expirationDate","2007-11-24")
+                .param("credentialExpirationDate","2009-11-29")
+                .param("password", "test")
+                .param("passwordConfirm", "test");
+
+
+        this.mvc.perform(post)
+                .andExpect(MockMvcResultMatchers.status().isOk())
+                .andExpect(MockMvcResultMatchers.view().name("admin/userEdit"))
+                .andExpect(MockMvcResultMatchers.model().hasErrors())
+                .andExpect(MockMvcResultMatchers.model().errorCount(1))
+                .andExpect(MockMvcResultMatchers.model().attributeHasErrors("user"))
+                .andExpect(MockMvcResultMatchers.model().attributeHasFieldErrors("user", "title"));
+
+        User user = this.usersRepository.findOne(this.usersUuids.get(0));
+
+        Assert.assertNotNull("Should find user", user);
+        Assert.assertEquals("name equals", "user0", user.getTitle());
+        
+        Assert.assertEquals("name equals", "User nb 0", user.getDescription());
+
+    }
+
+    @Test
+    public void testUserPostCreateEmptyName() throws Exception {
+
+        MockHttpServletRequestBuilder post = MockMvcRequestBuilders
+                .post("/admin/users/save")
+                .param("title", "")
+                .param("description", "New description")
+                .param("uri", "http://ldt.iri.centrepompidou.fr/new/uri")
+                .param("color", "#ffffff")
+                .param("expirationDate","2007-11-24")
+                .param("credentialExpirationDate","2009-11-29")
+                .param("password", "test")
+                .param("passwordConfirm", "test");
+
+        
+        this.mvc.perform(post)
+                .andExpect(MockMvcResultMatchers.status().isOk())
+                .andExpect(MockMvcResultMatchers.view().name("admin/userEdit"))
+                .andExpect(MockMvcResultMatchers.model().hasErrors())
+                .andExpect(MockMvcResultMatchers.model().errorCount(1))
+                .andExpect(MockMvcResultMatchers.model().attributeHasErrors("user"))
+                .andExpect(MockMvcResultMatchers.model().attributeHasFieldErrors("user", "title"));
+
+        Assert.assertEquals("Must not have one more user", USER_NB,this.usersRepository.count());
+
+    }
+
+    @Test
+    public void testUserPostCreateBadPassword() throws Exception {
+
+        MockHttpServletRequestBuilder post = MockMvcRequestBuilders
+                .post("/admin/users/save")
+                .param("title", "user")
+                .param("description", "New description")
+                .param("uri", "http://ldt.iri.centrepompidou.fr/new/uri")
+                .param("color", "#ffffff")
+                .param("expirationDate","2007-11-24")
+                .param("credentialExpirationDate","2009-11-29")
+                .param("password", "test")
+                .param("passwordConfirm", "test2");
+
+        this.mvc.perform(post)
+            .andExpect(MockMvcResultMatchers.status().isOk())
+            .andExpect(MockMvcResultMatchers.view().name("admin/userEdit"))
+            .andExpect(MockMvcResultMatchers.model().hasErrors())
+            .andExpect(MockMvcResultMatchers.model().errorCount(1))
+            .andExpect(MockMvcResultMatchers.model().attributeHasErrors("user"))
+            .andExpect(MockMvcResultMatchers.model().attributeHasFieldErrors("user", "password"));
+        
+        Assert.assertEquals("Must not have one more user", USER_NB,this.usersRepository.count());
+
+    }
+
 //    @Test
 //    public void testSpacePostCreateBadJson() throws Exception {
 //