Skip to content
This repository was archived by the owner on Oct 15, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.rulez.demokracia.pdengine;

import java.util.List;

public interface ADAAssuranceProvider {
List<String> getassurancesFor(String proxyId);
}
9 changes: 7 additions & 2 deletions src/main/java/org/rulez/demokracia/pdengine/CastVote.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ public CastVote(final String proxyId, final List<RankedChoice> preferences) {
super();
this.proxyId = proxyId;
this.preferences = new ArrayList<>(preferences);
secretId = RandomUtils.createRandomKey();
this.secretId = RandomUtils.createRandomKey();
}

public CastVote(final String proxyId, final List<RankedChoice> preferences, final List<String> assurances) {
this(proxyId, preferences);
this.assurances = assurances;
}

@Override
Expand All @@ -23,6 +28,6 @@ public List<RankedChoice> getPreferences() {

@Override
public List<String> getAssurances() {
throw new UnsupportedOperationException();
return assurances;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.rulez.demokracia.pdengine;

import java.util.List;

public class FakeADAAssuranceProvider implements ADAAssuranceProvider{
private ADAAssuranceProvider assuranceProvider;

public FakeADAAssuranceProvider(final FakeADAAssuranceProvider adaAssuranceProvider) {
assuranceProvider = adaAssuranceProvider;
}

@Override
public List<String> getassurancesFor(final String proxyId) {
return getUser(proxyId).getAssurances();
}

private User getUser(final String proxyId) {
User user = new User(proxyId);
user.assurances.add("TestAssurances");
return user;
}
}
2 changes: 2 additions & 0 deletions src/main/java/org/rulez/demokracia/pdengine/IVoteManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ VoteAdminInfo createVote(final String voteName, final Set<String> neededAssuranc
String getWsUserName();

boolean hasAssurance(final String role);

List<String> getAssurances();

void modifyVote(final VoteAdminInfo voteAdminInfo, final String voteName);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package org.rulez.demokracia.pdengine;

import java.util.List;

import javax.xml.ws.WebServiceContext;

import org.hibernate.Session;

public class SessionFactoryManager {

protected Session session;
private final ADAAssuranceProvider adaAssuranceProvider;
private final WebServiceContext wsContext;

public SessionFactoryManager(final WebServiceContext wsContext) {
super();
this.wsContext = wsContext;
session = DBSessionManagerUtils.getDBSession();
adaAssuranceProvider = new FakeADAAssuranceProvider(null);
}

public WebServiceContext getWsContext() {
Expand All @@ -26,5 +30,13 @@ public String getWsUserName() {
public boolean hasAssurance(final String role) {
return getWsContext().isUserInRole(role);
}

public ADAAssuranceProvider getFakeADAAssuranceProvider() {
return adaAssuranceProvider;
}

public List<String> getAssurances() {
return getFakeADAAssuranceProvider().getassurancesFor(getWsUserName());
}

}
5 changes: 5 additions & 0 deletions src/main/java/org/rulez/demokracia/pdengine/User.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.rulez.demokracia.pdengine;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;

Expand All @@ -16,5 +17,9 @@ public User(final String proxyId) {
this.proxyId = proxyId;
assurances = new ArrayList<>();
}

public List<String> getAssurances() {
return assurances;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public CastVote castVote(final String voteId, final String ballot, final List<Ra
CastVote receipt;

if (vote.getParameters().canUpdate) {
receipt = vote.addCastVote(getWsUserName(), theVote);
String proxyId = getWsUserName();
receipt = vote.addCastVote(proxyId, theVote, getAssurances());
} else {
receipt = vote.addCastVote(null, theVote);
}
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/org/rulez/demokracia/pdengine/Voteable.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@
public interface Voteable extends VoteInterface {

default CastVote addCastVote(final String proxyId, final List<RankedChoice> theVote) {
CastVote castVote = new CastVote(proxyId, theVote);
getVotesCast().add(castVote);
return castVote;
}

default CastVote addCastVote(final String proxyId, final List<RankedChoice> theVote, final List<String> assurances) {
Iterator<CastVote> listIterator = getVotesCast().iterator();
while (listIterator.hasNext()) {
CastVote element = listIterator.next();

if (element.proxyId != null && element.proxyId.equals(proxyId)) {
if (element.proxyId.equals(proxyId)) {
listIterator.remove();
}
}

CastVote castVote = new CastVote(proxyId, theVote);
CastVote castVote = new CastVote(proxyId, theVote, assurances);
getVotesCast().add(castVote);
return castVote;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public class CastVoteEntity extends BaseEntity {
public List<RankedChoice> preferences;
public String proxyId;
public String secretId;
public List<String> assurances;

}
28 changes: 21 additions & 7 deletions src/test/java/org/rulez/demokracia/pdengine/CastVoteTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.rulez.demokracia.pdengine;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -12,35 +13,48 @@
import org.rulez.demokracia.pdengine.annotations.TestedOperation;
import org.rulez.demokracia.pdengine.testhelpers.CreatedDefaultChoice;

@TestedFeature("Supporting functionality")
@TestedOperation("CastVote")
public class CastVoteTest extends CreatedDefaultChoice {

@Override
@Before
public void setUp() {
super.setUp();
initializeVoteCastTest();
}

@TestedFeature("Supporting functionality")
@TestedOperation("CastVote")
@TestedBehaviour("The preferences described by a cast vote can be obtained")
@Test
public void the_preferences_can_be_obtained_when_they_are_empty() {
List<RankedChoice> theCastVote = new ArrayList<>();
CastVote castVote = new CastVote(TEST_USER_NAME, theCastVote);
List<RankedChoice> preferences = castVote.getPreferences();
assertEquals(new ArrayList<>(), preferences);
}

@TestedFeature("Supporting functionality")
@TestedOperation("CastVote")

@TestedBehaviour("The preferences described by a cast vote can be obtained")
@Test
public void the_preferences_can_be_obtained_when_they_contain_choices() {
List<RankedChoice> theCastVote = new ArrayList<>();
theCastVote.add(new RankedChoice("1", 1));
CastVote castVote = new CastVote(TEST_USER_NAME, theCastVote);
List<RankedChoice> preferences = castVote.getPreferences();
assertEquals(theCastVote, preferences);
}

@TestedBehaviour("The assurances of the voter can be obtained from a cast vote if canupdateis true")
@Test
public void the_assurances_of_the_voter_can_be_obtained_from_a_cast_vote_if_canupdate_is_true() {
vote.parameters.canUpdate = true;
CastVote castVote = voteManager.castVote(adminInfo.voteId, ballot, theCastVote);
assertEquals("TestAssurances", castVote.assurances.get(0));
}

@TestedBehaviour("The assurances of the voter can be obtained from a cast vote if canupdateis true")
@Test
public void the_assurances_of_the_voter_is_null_if_canupdate_is_false() {
vote.parameters.canUpdate = false;
CastVote castVote = voteManager.castVote(adminInfo.voteId, ballot, theCastVote);
List<String> assurances = castVote.getAssurances();
assertTrue(assurances == null);
}
}

This file was deleted.