Project

General

Profile

« Previous | Next » 

Revision 395c5c70

Added by Andreas Müller about 13 years ago

first tests for list find methods for user and group services (#2283 and #2284).

View differences:

.gitattributes
1151 1151
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/CdmGenericDaoImplTest.java -text
1152 1152
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/DaoBaseTest.java -text
1153 1153
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/DefinedTermDaoImplTest.java -text
1154
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/GroupDaoHibernateImplTest.java -text
1154 1155
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/IdentifiableDaoBaseTest.java -text
1155 1156
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/TermVocabularyDaoImplTest.java -text
1156 1157
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/UserDaoHibernateImplTest.java -text
......
1235 1236
cdmlib-persistence/src/test/resources/eu/etaxonomy/cdm/persistence/dao/hibernate/common/CdmEntityDaoBaseTest.xml -text
1236 1237
cdmlib-persistence/src/test/resources/eu/etaxonomy/cdm/persistence/dao/hibernate/common/CdmGenericDaoImplTest.xml -text
1237 1238
cdmlib-persistence/src/test/resources/eu/etaxonomy/cdm/persistence/dao/hibernate/common/DefinedTermDaoImplTest.xml -text
1239
cdmlib-persistence/src/test/resources/eu/etaxonomy/cdm/persistence/dao/hibernate/common/GroupDaoHibernateImplTest.xml -text
1238 1240
cdmlib-persistence/src/test/resources/eu/etaxonomy/cdm/persistence/dao/hibernate/common/IdentifiableDaoBaseTest.xml -text
1239 1241
cdmlib-persistence/src/test/resources/eu/etaxonomy/cdm/persistence/dao/hibernate/common/TermVocabularyDaoImplTest.xml -text
1240 1242
cdmlib-persistence/src/test/resources/eu/etaxonomy/cdm/persistence/dao/hibernate/common/UserDaoHibernateImplTest.xml -text
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/GroupDaoHibernateImplTest.java
1
/**
2
* Copyright (C) 2009 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/ 
9

  
10
package eu.etaxonomy.cdm.persistence.dao.hibernate.common;
11

  
12
import static org.junit.Assert.assertEquals;
13
import static org.junit.Assert.assertNotNull;
14

  
15
import java.util.List;
16

  
17
import org.hibernate.criterion.Criterion;
18
import org.junit.Test;
19
import org.unitils.dbunit.annotation.DataSet;
20
import org.unitils.spring.annotation.SpringBeanByType;
21

  
22
import eu.etaxonomy.cdm.model.common.Group;
23
import eu.etaxonomy.cdm.model.common.User;
24
import eu.etaxonomy.cdm.persistence.dao.common.IGroupDao;
25
import eu.etaxonomy.cdm.persistence.dao.common.IUserDao;
26
import eu.etaxonomy.cdm.persistence.query.MatchMode;
27
import eu.etaxonomy.cdm.persistence.query.OrderHint;
28
import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
29

  
30
@DataSet
31
public class GroupDaoHibernateImplTest extends CdmIntegrationTest {
32
	
33
	@SpringBeanByType
34
	IGroupDao groupDao;
35
	
36
	@Test
37
	public void testFindGroupByUsername() {
38
		Group group = groupDao.findGroupByName("Admins");
39
		
40
		assertNotNull("findGroupByName should return a group", group);
41
//		assertEquals("the user should have had their authorities loaded",2,group.getAuthorities().size());
42
	}
43
	
44
	@Test
45
	public void findByName(){
46
		String queryString = "Admins";
47
		MatchMode matchmode = MatchMode.ANYWHERE;
48
		List<Criterion> criteria = null;
49
		Integer pageSize = null;
50
		Integer pageNumber = null;
51
		List<OrderHint> orderHints = null;
52
		List<String> propertyPaths = null;
53
		List<Group> list = groupDao.findByName(queryString, matchmode, criteria, pageSize, pageNumber, orderHints, propertyPaths);
54
		
55
		assertNotNull("A list should be returned", list);
56
		assertEquals("2 groups should be returned", 2, list.size());
57
		
58
	}
59

  
60
}
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/UserDaoHibernateImplTest.java
12 12
import static org.junit.Assert.assertEquals;
13 13
import static org.junit.Assert.assertNotNull;
14 14

  
15
import java.util.List;
16

  
17
import org.hibernate.criterion.Criterion;
15 18
import org.junit.Test;
16 19
import org.unitils.dbunit.annotation.DataSet;
17 20
import org.unitils.spring.annotation.SpringBeanByType;
18 21

  
19 22
import eu.etaxonomy.cdm.model.common.User;
20 23
import eu.etaxonomy.cdm.persistence.dao.common.IUserDao;
24
import eu.etaxonomy.cdm.persistence.query.MatchMode;
25
import eu.etaxonomy.cdm.persistence.query.OrderHint;
21 26
import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
22 27

  
23 28
@DataSet
......
33 38
		assertNotNull("findUserByUsername should return a user", user);
34 39
		assertEquals("the user should have had their authorities loaded",2,user.getAuthorities().size());
35 40
	}
41
	
42
	@Test
43
	public void findByUsername(){
44
		String queryString = "test";
45
		MatchMode matchmode = MatchMode.ANYWHERE;
46
		List<Criterion> criteria = null;
47
		Integer pageSize = null;
48
		Integer pageNumber = null;
49
		List<OrderHint> orderHints = null;
50
		List<String> propertyPaths = null;
51
		List<User> list = userDao.findByUsername(queryString, matchmode, criteria, pageSize, pageNumber, orderHints, propertyPaths);
52
		
53
		assertNotNull("A list should be returned", list);
54
		assertEquals("3 users should be returned", 3, list.size());
55
		
56
	}
36 57

  
37 58
}
cdmlib-persistence/src/test/resources/eu/etaxonomy/cdm/persistence/dao/hibernate/common/GroupDaoHibernateImplTest.xml
1
<?xml version='1.0' encoding='UTF-8'?>
2
<dataset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../dataset.xsd">
3
    <GRANTEDAUTHORITYIMPL ID="1" UUID="5dfa2adb-2fac-48f6-abe6-c032e4a995d1" CREATED="2008-12-10 09:56:07.0" AUTHORITY="USER"/>
4
    <GRANTEDAUTHORITYIMPL ID="2" UUID="45f13d2c-52c2-411f-afcd-bf5768ce200d" CREATED="2008-12-10 09:56:07.0" AUTHORITY="ADMINISTRATOR"/>
5
    <GRANTEDAUTHORITYIMPL ID="3" UUID="d95c8c68-c99d-4124-a65f-78f0d3db3aae" CREATED="2008-12-10 09:56:07.0" AUTHORITY="OWNER"/>
6
    <PERMISSIONGROUP ID="1" UUID="e16b2fee-3ec0-4492-a3c8-20eb9eb7bd64" CREATED="2008-12-10 09:56:07.0" NAME="Editors"/>
7
    <PERMISSIONGROUP ID="2" UUID="9699aa37-fecb-4618-a157-ef17dea81c23" CREATED="2008-12-10 09:56:07.0" NAME="Admins"/>
8
    <PERMISSIONGROUP ID="3" UUID="b334c0af-1e26-471f-94fc-ec9a76764a39" CREATED="2008-12-10 09:56:07.0" NAME="Testers"/>
9
    <PERMISSIONGROUP ID="4" UUID="2f5c0bb8-47e0-4134-9328-5dddd1243336" CREATED="2008-12-10 09:56:07.0" NAME="TestUser"/>
10
    <PERMISSIONGROUP ID="5" UUID="5b1d3baf-d23e-4807-a12d-dd94eb6db2fd" CREATED="2008-12-10 09:56:07.0" NAME="DatabaseAdmins"/>
11
    <PERMISSIONGROUP_GRANTEDAUTHORITYIMPL PERMISSIONGROUP_ID="1" GRANTEDAUTHORITIES_ID="1"/>
12
    <PERMISSIONGROUP_GRANTEDAUTHORITYIMPL PERMISSIONGROUP_ID="2" GRANTEDAUTHORITIES_ID="2"/>
13
    <USERACCOUNT ID="1" UUID="aa881853-70cd-4b2e-83d8-2ab89baae43d" CREATED="2008-12-10 09:56:07.0" ACCOUNTNONEXPIRED="false" ACCOUNTNONLOCKED="false" CREDENTIALSNONEXPIRED="false" ENABLED="true" PASSWORD="koala" USERNAME="test" EMAILADDRESS="test@example.com"/>
14
    <USERACCOUNT ID="2" UUID="39987cf6-60e4-4b9e-a324-ed3d0ce369c5" CREATED="2010-12-10 09:56:07.0" ACCOUNTNONEXPIRED="false" ACCOUNTNONLOCKED="false" CREDENTIALSNONEXPIRED="false" ENABLED="true" PASSWORD="abfge" USERNAME="testme" EMAILADDRESS="testme@example.com"/>
15
    <USERACCOUNT ID="3" UUID="e5abce0d-251c-4b92-98ca-e52622357c6e" CREATED="2010-12-10 09:56:07.0" ACCOUNTNONEXPIRED="false" ACCOUNTNONLOCKED="false" CREDENTIALSNONEXPIRED="false" ENABLED="true" PASSWORD="35ojkjdo" USERNAME="test3" EMAILADDRESS="test3@example.com"/>
16
    <USERACCOUNT ID="4" UUID="fedfb601-77df-4321-b70e-abd9923272cb" CREATED="2010-12-10 09:56:07.0" ACCOUNTNONEXPIRED="false" ACCOUNTNONLOCKED="false" CREDENTIALSNONEXPIRED="false" ENABLED="true" PASSWORD="9jli44" USERNAME="niels" EMAILADDRESS="niels@niels.com"/>
17
    <USERACCOUNT ID="5" UUID="1df8b990-4ced-4bea-b42c-f19f2b0e9abe" CREATED="2010-12-10 09:56:07.0" ACCOUNTNONEXPIRED="false" ACCOUNTNONLOCKED="false" CREDENTIALSNONEXPIRED="false" ENABLED="true" PASSWORD="ddsfioio34+" USERNAME="niels2" EMAILADDRESS="niels2@example.com"/>
18
    <USERACCOUNT_PERMISSIONGROUP MEMBERS_ID="1" GROUPS_ID="1"/>
19
    <USERACCOUNT_PERMISSIONGROUP MEMBERS_ID="1" GROUPS_ID="2"/>
20
</dataset>
cdmlib-persistence/src/test/resources/eu/etaxonomy/cdm/persistence/dao/hibernate/common/UserDaoHibernateImplTest.xml
8 8
    <PERMISSIONGROUP_GRANTEDAUTHORITYIMPL PERMISSIONGROUP_ID="1" GRANTEDAUTHORITIES_ID="1"/>
9 9
    <PERMISSIONGROUP_GRANTEDAUTHORITYIMPL PERMISSIONGROUP_ID="2" GRANTEDAUTHORITIES_ID="2"/>
10 10
    <USERACCOUNT ID="1" UUID="aa881853-70cd-4b2e-83d8-2ab89baae43d" CREATED="2008-12-10 09:56:07.0" ACCOUNTNONEXPIRED="false" ACCOUNTNONLOCKED="false" CREDENTIALSNONEXPIRED="false" ENABLED="true" PASSWORD="koala" USERNAME="test" EMAILADDRESS="test@example.com"/>
11
    <USERACCOUNT ID="2" UUID="39987cf6-60e4-4b9e-a324-ed3d0ce369c5" CREATED="2010-12-10 09:56:07.0" ACCOUNTNONEXPIRED="false" ACCOUNTNONLOCKED="false" CREDENTIALSNONEXPIRED="false" ENABLED="true" PASSWORD="abfge" USERNAME="testme" EMAILADDRESS="testme@example.com"/>
12
    <USERACCOUNT ID="3" UUID="e5abce0d-251c-4b92-98ca-e52622357c6e" CREATED="2010-12-10 09:56:07.0" ACCOUNTNONEXPIRED="false" ACCOUNTNONLOCKED="false" CREDENTIALSNONEXPIRED="false" ENABLED="true" PASSWORD="35ojkjdo" USERNAME="test3" EMAILADDRESS="test3@example.com"/>
13
    <USERACCOUNT ID="4" UUID="fedfb601-77df-4321-b70e-abd9923272cb" CREATED="2010-12-10 09:56:07.0" ACCOUNTNONEXPIRED="false" ACCOUNTNONLOCKED="false" CREDENTIALSNONEXPIRED="false" ENABLED="true" PASSWORD="9jli44" USERNAME="niels" EMAILADDRESS="niels@niels.com"/>
14
    <USERACCOUNT ID="5" UUID="1df8b990-4ced-4bea-b42c-f19f2b0e9abe" CREATED="2010-12-10 09:56:07.0" ACCOUNTNONEXPIRED="false" ACCOUNTNONLOCKED="false" CREDENTIALSNONEXPIRED="false" ENABLED="true" PASSWORD="ddsfioio34+" USERNAME="niels2" EMAILADDRESS="niels2@example.com"/>
11 15
    <USERACCOUNT_PERMISSIONGROUP MEMBERS_ID="1" GROUPS_ID="1"/>
12 16
    <USERACCOUNT_PERMISSIONGROUP MEMBERS_ID="1" GROUPS_ID="2"/>
13 17
</dataset>

Also available in: Unified diff