Skip to content
Snippets Groups Projects
Commit 54c415d0 authored by srosse's avatar srosse
Browse files

OO-586: fix special query for non-mysql database

parent cee5df99
No related branches found
No related tags found
No related merge requests found
......@@ -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) ");
......
......@@ -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
......
/**
* <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));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment