From 7e956cc4cf02bb264a6df2ca6487688d93f0e19c Mon Sep 17 00:00:00 2001 From: srosse <none@none> Date: Thu, 3 Apr 2014 14:26:22 +0200 Subject: [PATCH] OO-1003: add a unit test --- .../java/org/olat/restapi/UserMgmtTest.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/test/java/org/olat/restapi/UserMgmtTest.java b/src/test/java/org/olat/restapi/UserMgmtTest.java index 5935a2aeda3..8c878aa898a 100644 --- a/src/test/java/org/olat/restapi/UserMgmtTest.java +++ b/src/test/java/org/olat/restapi/UserMgmtTest.java @@ -73,6 +73,7 @@ import org.olat.core.commons.persistence.DB; import org.olat.core.id.Identity; import org.olat.core.id.OLATResourceable; import org.olat.core.id.Roles; +import org.olat.core.id.UserConstants; import org.olat.core.util.nodes.INode; import org.olat.core.util.resource.OresHelper; import org.olat.core.util.tree.TreeVisitor; @@ -551,6 +552,42 @@ public class UserMgmtTest extends OlatJerseyTestCase { conn.shutdown(); } + /** + * Test the trim of email + */ + @Test + public void testCreateUser_emailWithTrailingSpace() throws IOException, URISyntaxException { + RestConnection conn = new RestConnection(); + assertTrue(conn.login("administrator", "openolat")); + + UserVO vo = new UserVO(); + String username = UUID.randomUUID().toString(); + vo.setLogin(username); + vo.setFirstName("John"); + vo.setLastName("Smith"); + vo.setEmail(username + "@frentix.com "); + vo.putProperty("gender", "male");//male or female + + + URI request = UriBuilder.fromUri(getContextURI()).path("users").build(); + HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true); + conn.addJsonEntity(method, vo); + method.addHeader("Accept-Language", "en"); + + HttpResponse response = conn.execute(method); + assertTrue(response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 201); + UserVO savedVo = conn.parse(response, UserVO.class); + Identity savedIdent = BaseSecurityManager.getInstance().findIdentityByName(username); + + assertNotNull(savedVo); + assertNotNull(savedIdent); + assertEquals(savedVo.getKey(), savedIdent.getKey()); + assertEquals(savedVo.getLogin(), savedIdent.getName()); + assertEquals(username + "@frentix.com", savedIdent.getUser().getProperty(UserConstants.EMAIL, null)); + + conn.shutdown(); + } + @Test public void testCreateUserWithValidationError() throws IOException, URISyntaxException { RestConnection conn = new RestConnection(); -- GitLab