# HG changeset patch # User ymh # Date 1386581010 -3600 # Node ID d92a90b2ad53a4ed0d90562dd8ff8cf404d0eaee # Parent bf599928e1ad5f3cec91bb3470b627fe6461e9cc add unit tests for users. diff -r bf599928e1ad -r d92a90b2ad53 server/src/main/java/org/iri_research/renkan/forms/UserFormValidator.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(); diff -r bf599928e1ad -r d92a90b2ad53 server/src/main/webapp/WEB-INF/i18n/messages.properties --- 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 diff -r bf599928e1ad -r d92a90b2ad53 server/src/main/webapp/WEB-INF/i18n/messages_en.properties --- 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 diff -r bf599928e1ad -r d92a90b2ad53 server/src/main/webapp/WEB-INF/i18n/messages_fr.properties --- 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 diff -r bf599928e1ad -r d92a90b2ad53 server/src/main/webapp/WEB-INF/templates/fragment/userForm.html --- 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 @@
- +
- +
diff -r bf599928e1ad -r d92a90b2ad53 server/src/test/java/org/iri_research/renkan/test/controller/UsersAdminControllerTest.java --- 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 { //