1
|
/**
|
2
|
* Copyright (C) 2007 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.model.common;
|
11
|
|
12
|
import static org.junit.Assert.assertEquals;
|
13
|
import static org.junit.Assert.assertNotNull;
|
14
|
import org.junit.Before;
|
15
|
import org.junit.Test;
|
16
|
import org.springframework.security.core.GrantedAuthority;
|
17
|
|
18
|
/**
|
19
|
* @author n.hoffmann
|
20
|
* @created Mar 9, 2011
|
21
|
* @version 1.0
|
22
|
*/
|
23
|
public class GroupTest {
|
24
|
|
25
|
private Group group;
|
26
|
private String groupName = "";
|
27
|
private GrantedAuthority grantedAuthority;
|
28
|
private User user;
|
29
|
|
30
|
/**
|
31
|
* @throws java.lang.Exception
|
32
|
*/
|
33
|
@Before
|
34
|
public void setUp() throws Exception {
|
35
|
group = Group.NewInstance(groupName);
|
36
|
grantedAuthority = GrantedAuthorityImpl.NewInstance();
|
37
|
user = User.NewInstance(null, null);
|
38
|
}
|
39
|
|
40
|
/**
|
41
|
* Test method for {@link eu.etaxonomy.cdm.model.common.Group#NewInstance(java.lang.String)}.
|
42
|
*/
|
43
|
@Test
|
44
|
public final void testNewInstanceString() {
|
45
|
assertNotNull("A new group should have been created.", group);
|
46
|
assertEquals("Created object should be of type Group.", Group.class, group.getClass());
|
47
|
assertEquals("Created group should have a name.", groupName, group.getName());
|
48
|
}
|
49
|
|
50
|
/**
|
51
|
* Test method for {@link eu.etaxonomy.cdm.model.common.Group#getGrantedAuthorities()}.
|
52
|
*/
|
53
|
@Test
|
54
|
public final void testGetGrantedAuthorities() {
|
55
|
// not yet implemented
|
56
|
}
|
57
|
|
58
|
/**
|
59
|
* Test method for {@link eu.etaxonomy.cdm.model.common.Group#addGrantedAuthority(org.springframework.security.core.GrantedAuthority)}.
|
60
|
*/
|
61
|
@Test
|
62
|
public final void testAddGrantedAuthority() {
|
63
|
group.addGrantedAuthority(grantedAuthority);
|
64
|
|
65
|
assertEquals("There should be exactly one GrantedAuthority.", 1, group.getGrantedAuthorities().size());
|
66
|
assertEquals("The containing GrantedAuthority should match the one we filled it with.", grantedAuthority, group.getGrantedAuthorities().iterator().next());
|
67
|
}
|
68
|
|
69
|
/**
|
70
|
* Test method for {@link eu.etaxonomy.cdm.model.common.Group#removeGrantedAuthority(org.springframework.security.core.GrantedAuthority)}.
|
71
|
*/
|
72
|
@Test
|
73
|
public final void testRemoveGrantedAuthority() {
|
74
|
group.addGrantedAuthority(grantedAuthority);
|
75
|
|
76
|
assertEquals("There should be exactly one GrantedAuthority.", 1, group.getGrantedAuthorities().size());
|
77
|
assertEquals("The containing GrantedAuthority should match the one we filled it with.", grantedAuthority, group.getGrantedAuthorities().iterator().next());
|
78
|
|
79
|
group.removeGrantedAuthority(grantedAuthority);
|
80
|
|
81
|
assertEquals("There should not contain GrantedAuthorities anymore.", 0, group.getGrantedAuthorities().size());
|
82
|
}
|
83
|
|
84
|
/**
|
85
|
* Test method for {@link eu.etaxonomy.cdm.model.common.Group#setName(java.lang.String)}.
|
86
|
*/
|
87
|
@Test
|
88
|
public final void testSetName() {
|
89
|
String newName = "";
|
90
|
group.setName(newName);
|
91
|
assertEquals("Groups name should have changed.", newName, group.getName());
|
92
|
}
|
93
|
|
94
|
/**
|
95
|
* Test method for {@link eu.etaxonomy.cdm.model.common.Group#getName()}.
|
96
|
*/
|
97
|
@Test
|
98
|
public final void testGetName() {
|
99
|
assertEquals("Group should have a name", groupName, group.getName());
|
100
|
}
|
101
|
|
102
|
/**
|
103
|
* Test method for {@link eu.etaxonomy.cdm.model.common.Group#getMembers()}.
|
104
|
*/
|
105
|
@Test
|
106
|
public final void testGetMembers() {
|
107
|
// not implemented yet
|
108
|
}
|
109
|
|
110
|
/**
|
111
|
* Test method for {@link eu.etaxonomy.cdm.model.common.Group#addMember(eu.etaxonomy.cdm.model.common.User)}.
|
112
|
*/
|
113
|
@Test
|
114
|
public final void testAddMember() {
|
115
|
group.addMember(user);
|
116
|
|
117
|
assertEquals("Group should have exactly one member.", 1, group.getMembers().size());
|
118
|
assertEquals("The member should match the one we filled it with.", user, group.getMembers().iterator().next());
|
119
|
|
120
|
assertEquals("The user should be in the group", group, user.getGroups().iterator().next());
|
121
|
}
|
122
|
|
123
|
/**
|
124
|
* Test method for {@link eu.etaxonomy.cdm.model.common.Group#removeMember(eu.etaxonomy.cdm.model.common.User)}.
|
125
|
*/
|
126
|
@Test
|
127
|
public final void testRemoveMember() {
|
128
|
group.addMember(user);
|
129
|
|
130
|
assertEquals("Group should have exactly one member.", 1, group.getMembers().size());
|
131
|
assertEquals("The member should match the one we filled it with.", user, group.getMembers().iterator().next());
|
132
|
|
133
|
group.removeMember(user);
|
134
|
|
135
|
assertEquals("Group should not have members anymore.", 0, group.getMembers().size());
|
136
|
|
137
|
assertEquals("The user should not be in any groups", 0, user.getGroups().size());
|
138
|
}
|
139
|
|
140
|
}
|