This repository was archived by the owner on Oct 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathCreatedDefaultVoteRegistry.java
More file actions
85 lines (69 loc) · 2.75 KB
/
CreatedDefaultVoteRegistry.java
File metadata and controls
85 lines (69 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package org.rulez.demokracia.pdengine.testhelpers;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.security.Principal;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import javax.xml.ws.WebServiceContext;
import org.junit.Before;
import org.rulez.demokracia.pdengine.AssuranceManager;
import org.rulez.demokracia.pdengine.IVoteManager;
import org.rulez.demokracia.pdengine.Vote;
import org.rulez.demokracia.pdengine.dataobjects.VoteAdminInfo;
import org.rulez.demokracia.testhelpers.ThrowableTester;
public class CreatedDefaultVoteRegistry extends ThrowableTester{
public static final String ASSURANCE_NAME = "magyar";
public static final String TEST_USER_NAME = "test_user_in_ws_context";
public IVoteManager voteManager;
public VoteAdminInfo adminInfo;
public String voteName = "VoteInitialValuesTest";
protected Set<String> neededAssurances;
protected Set<String> countedAssurances;
protected boolean isPrivate;
protected int minEndorsements;
protected AssuranceManager fakeAssuranceManager;
@Before
public void setUp() {
WebServiceContext wsContext = setupMockWsContext();
fakeAssuranceManager = mock(AssuranceManager.class);
when(fakeAssuranceManager.getAssurances(TEST_USER_NAME)).thenReturn(Arrays.asList("magyar", "német"));
voteManager = IVoteManager.getVoteManager(wsContext, fakeAssuranceManager);
neededAssurances = new HashSet<>();
countedAssurances = new HashSet<>();
isPrivate = true;
minEndorsements = 0;
neededAssurances.add(ASSURANCE_NAME);
voteName = "testVote";
adminInfo = createAVote();
}
private WebServiceContext setupMockWsContext() {
WebServiceContext wsContext = mock(WebServiceContext.class);
Principal principal = mock(Principal.class);
when(wsContext.getUserPrincipal()).thenReturn(principal);
when(principal.getName()).thenReturn(TEST_USER_NAME);
when(wsContext.isUserInRole(ASSURANCE_NAME)).thenReturn(true);
when(wsContext.isUserInRole("appmagyar")).thenReturn(true);
return wsContext;
}
public void setupUnauthenticatedMockWsContext() {
WebServiceContext wsContext = mock(WebServiceContext.class);
when(wsContext.getUserPrincipal()).thenReturn(null);
voteManager = IVoteManager.getVoteManager(wsContext, fakeAssuranceManager);
}
protected VoteAdminInfo createAVote() {
return voteManager.createVote(voteName, neededAssurances, countedAssurances, isPrivate, minEndorsements );
}
protected Vote getTheVote() {
return voteManager.getVote(adminInfo.voteId);
}
protected void setVoteEndorseable() {
Vote vote = getTheVote();
vote.parameters.canEndorse=true;
}
protected String createLongString(final int length) {
char[] charArray = new char[length];
Arrays.fill(charArray, 'w');
return new String(charArray);
}
}