From 54c415d068145d3ead5b64b9e293e6afdbbd2d68 Mon Sep 17 00:00:00 2001 From: srosse <none@none> Date: Tue, 14 May 2013 12:13:31 +0200 Subject: [PATCH] OO-586: fix special query for non-mysql database --- .../java/org/olat/user/UserManagerImpl.java | 4 +- .../java/org/olat/test/AllTestsJunit4.java | 1 + .../java/org/olat/user/UserManagerTest.java | 75 +++++++++++++++++++ 3 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 src/test/java/org/olat/user/UserManagerTest.java diff --git a/src/main/java/org/olat/user/UserManagerImpl.java b/src/main/java/org/olat/user/UserManagerImpl.java index 338f37ba999..cebac7c6199 100644 --- a/src/main/java/org/olat/user/UserManagerImpl.java +++ b/src/main/java/org/olat/user/UserManagerImpl.java @@ -211,7 +211,7 @@ public class UserManagerImpl extends UserManager { if(mysql) { emailSb.append(" user.properties['").append(UserConstants.EMAIL).append("'] in (:emails) "); } else { - emailSb.append(" lower(user.properties['").append(UserConstants.EMAIL).append("']) = lower(:email)"); + emailSb.append(" lower(user.properties['").append(UserConstants.EMAIL).append("']) = lower(:emails)"); } List<Identity> identities = dbInstance.getCurrentEntityManager() @@ -223,7 +223,7 @@ public class UserManagerImpl extends UserManager { if(mysql) { institutionalSb.append(" user.properties['").append(UserConstants.INSTITUTIONALEMAIL).append("'] in (:emails) "); } else { - institutionalSb.append(" lower(user.properties['").append(UserConstants.INSTITUTIONALEMAIL).append("']) = lower(:email)"); + institutionalSb.append(" lower(user.properties['").append(UserConstants.INSTITUTIONALEMAIL).append("']) = lower(:emails)"); } if(!identities.isEmpty()) { institutionalSb.append(" and identity not in (:identities) "); diff --git a/src/test/java/org/olat/test/AllTestsJunit4.java b/src/test/java/org/olat/test/AllTestsJunit4.java index 5853c50e354..304203c7287 100644 --- a/src/test/java/org/olat/test/AllTestsJunit4.java +++ b/src/test/java/org/olat/test/AllTestsJunit4.java @@ -90,6 +90,7 @@ import org.junit.runners.Suite; org.olat.basesecurity.SecurityManagerTest.class,//ok org.olat.basesecurity.BaseSecurityTest.class,//ok org.olat.basesecurity.BaseSecurityManagerTest.class,//ok + org.olat.user.UserManagerTest.class,//ok org.olat.repository.RepositoryManagerTest.class,//ok org.olat.repository.RepositoryManagerConcurrentTest.class,//ok org.olat.repository.RepositoryManagerQueryTest.class,//ok diff --git a/src/test/java/org/olat/user/UserManagerTest.java b/src/test/java/org/olat/user/UserManagerTest.java new file mode 100644 index 00000000000..185861eebee --- /dev/null +++ b/src/test/java/org/olat/user/UserManagerTest.java @@ -0,0 +1,75 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.user; + +import java.util.Collections; +import java.util.List; +import java.util.UUID; + +import junit.framework.Assert; + +import org.junit.Test; +import org.olat.basesecurity.BaseSecurity; +import org.olat.basesecurity.BaseSecurityModule; +import org.olat.core.commons.persistence.DB; +import org.olat.core.id.Identity; +import org.olat.core.id.User; +import org.olat.core.util.Encoder; +import org.olat.test.OlatTestCase; +import org.springframework.beans.factory.annotation.Autowired; + + +/** + * + * Initial date: 14.05.2013<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +public class UserManagerTest extends OlatTestCase { + + @Autowired + private DB dbInstance; + @Autowired + private UserManager userManager; + @Autowired + private BaseSecurity securityManager; + + @Test + public void findIdentitiesByEmail() { + //create a user + String name = "createid-" + UUID.randomUUID().toString(); + String email = name + "@frentix.com"; + User user = userManager.createUser("first" + name, "last" + name, email); + Identity identity = securityManager.createAndPersistIdentityAndUser(name, user, BaseSecurityModule.getDefaultAuthProviderIdentifier(), name, Encoder.encrypt("secret")); + dbInstance.commitAndCloseSession(); + + //get empty (must survive) + List<Identity> emptyIdentities = userManager.findIdentitiesByEmail(Collections.<String>emptyList()); + Assert.assertNotNull(emptyIdentities); + Assert.assertTrue(emptyIdentities.isEmpty()); + + //get the identity + List<Identity> identities = userManager.findIdentitiesByEmail(Collections.singletonList(email)); + Assert.assertNotNull(identities); + Assert.assertEquals(1, identities.size()); + Assert.assertTrue(identities.contains(identity)); + } + +} -- GitLab