testing was changed according to the new interface of storage manager

vbdev2
Hai Brenner 2016-06-20 15:27:39 +03:00
parent 2bdf92b075
commit 559c714aac
1 changed files with 105 additions and 15 deletions

View File

@ -5,15 +5,14 @@ import meerkat.crypto.DigitalSignature;
import meerkat.crypto.Encryption;
import meerkat.protobuf.Voting.*;
import meerkat.voting.controller.*;
import meerkat.voting.controller.selector.SimpleListCategoriesSelector;
import meerkat.voting.output.*;
import meerkat.voting.storage.*;
import meerkat.voting.encryptor.*;
import meerkat.voting.ui.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;
/**
* Created by hai on 26/04/16.
@ -22,6 +21,14 @@ public class VotingBoothToyRun {
public static void main(String[] args) {
try {
generateSystemMessages();
generateDemoQuestions();
}
catch (Exception e) {
return;
}
Random rand = new Random();
Encryption enc = new ToyEncryption();
DigitalSignature sig = new ToySignature("MY_SIGNER_ID");
@ -33,9 +40,15 @@ public class VotingBoothToyRun {
VotingBoothImpl controller = new VotingBoothImpl();
controller.init(outputDevice, cryptoManager, ui, storageManager);
generateDemoQuestions(controller);
try {
controller.init(outputDevice, cryptoManager, ui, storageManager);
}
catch (Exception e) {
System.err.println("init failed");
return;
}
// create threads
@ -54,21 +67,29 @@ public class VotingBoothToyRun {
}
private static void generateDemoQuestions(VotingBoothController controller) {
private static void generateDemoQuestions() throws IOException {
List<BallotQuestion> channelChoiceQuestions = generateCahnnelChoiceQuestions();
controller.setBallotChannelChoiceQuestions(channelChoiceQuestions);
ElectionParams electionParams = ElectionParams.newBuilder()
.addAllRaceQuestions(generateBallotQuestions())
.addAllChannelChoiceQuestions(generateChannelChoiceQuestions())
.setSelectionData(generateSelectionData())
.build();
List<BallotQuestion> allBallotQuestions = generateBallotQuestions();
controller.setBallotRaceQuestions(allBallotQuestions);
try {
FileOutputStream output = new FileOutputStream(StorageManagerMockup.electionParamFullFilename);
electionParams.writeTo(output);
output.close();
System.out.println("Successfully wrote election parameter protobuf to a file");
}
catch (IOException e) {
System.err.println("Could not write to the election parameter file: '" + StorageManagerMockup.electionParamFullFilename + "'.");
throw e;
}
SimpleCategoriesSelectionData selectionData = generateSelectionData();
SimpleListCategoriesSelector selector = new SimpleListCategoriesSelector(allBallotQuestions, selectionData);
controller.setChannelQuestionSelector(selector);
}
private static List<BallotQuestion> generateCahnnelChoiceQuestions() {
private static List<BallotQuestion> generateChannelChoiceQuestions() {
ArrayList<BallotQuestion> channelChoiceQuestions = new ArrayList();
String[] ans1 = {"Red", "Blue", "Green"};
@ -192,9 +213,78 @@ public class VotingBoothToyRun {
.build();
}
private static ByteString stringToBytes (String s) {
return ByteString.copyFromUtf8(s);
}
private static void generateSystemMessages() throws IOException{
Map<String, UIElement> systemMessageMap = new HashMap();
systemMessageMap.put(StorageManager.WAIT_FOR_COMMIT_MESSAGE, UIElement.newBuilder()
.setType(UIElementDataType.TEXT)
.setData(ByteString.copyFromUtf8("Please wait while committing to ballot"))
.build());
systemMessageMap.put(StorageManager.WAIT_FOR_AUDIT_MESSAGE, UIElement.newBuilder()
.setType(UIElementDataType.TEXT)
.setData(ByteString.copyFromUtf8("Please wait while auditing your ballot"))
.build());
systemMessageMap.put(StorageManager.WAIT_FOR_CAST_MESSAGE, UIElement.newBuilder()
.setType(UIElementDataType.TEXT)
.setData(ByteString.copyFromUtf8("Please wait while finalizing your ballot for voting"))
.build());
systemMessageMap.put(StorageManager.RESTART_VOTING_BUTTON, UIElement.newBuilder()
.setType(UIElementDataType.TEXT)
.setData(ByteString.copyFromUtf8("Restart voting"))
.build());
systemMessageMap.put(StorageManager.UNRECOGNIZED_FINALIZE_RESPONSE_MESSAGE, UIElement.newBuilder()
.setType(UIElementDataType.TEXT)
.setData(ByteString.copyFromUtf8("Could not understand response for Cast or Audit. Force restarting."))
.build());
systemMessageMap.put(StorageManager.UNSUCCESSFUL_CHANNEL_CHOICE_MESSAGE, UIElement.newBuilder()
.setType(UIElementDataType.TEXT)
.setData(ByteString.copyFromUtf8("Choice of channel was unsuccessful. Force restarting."))
.build());
systemMessageMap.put(StorageManager.OUTPUT_DEVICE_FAILURE_MESSAGE, UIElement.newBuilder()
.setType(UIElementDataType.TEXT)
.setData(ByteString.copyFromUtf8("Ballot output device failure. Force restarting."))
.build());
systemMessageMap.put(StorageManager.UNSUCCESSFUL_VOTING_MESSAGE, UIElement.newBuilder()
.setType(UIElementDataType.TEXT)
.setData(ByteString.copyFromUtf8("Voting was unsuccessful. Force restarting."))
.build());
systemMessageMap.put(StorageManager.SOMETHING_WRONG_MESSAGE, UIElement.newBuilder()
.setType(UIElementDataType.TEXT)
.setData(ByteString.copyFromUtf8("Something was terribly wrong. Force restarting."))
.build());
systemMessageMap.put(StorageManager.ENCRYPTION_FAILED_MESSAGE, UIElement.newBuilder()
.setType(UIElementDataType.TEXT)
.setData(ByteString.copyFromUtf8("Encryption failed for some unknown reason."))
.build());
systemMessageMap.put(StorageManager.RETRY_BUTTON, UIElement.newBuilder()
.setType(UIElementDataType.TEXT)
.setData(ByteString.copyFromUtf8("Retry"))
.build());
systemMessageMap.put(StorageManager.CANCEL_VOTE_BUTTON, UIElement.newBuilder()
.setType(UIElementDataType.TEXT)
.setData(ByteString.copyFromUtf8("Cancel Vote"))
.build());
BoothSystemMessages systemMessages = BoothSystemMessages.newBuilder().putAllSystemMessage(systemMessageMap).build();
try {
FileOutputStream output = new FileOutputStream(StorageManagerMockup.systemMessagesFilename);
systemMessages.writeTo(output);
output.close();
System.out.println("Successfully wrote system messages protobuf to a file");
}
catch (IOException e) {
System.err.println("Could not write to the system messages file: '" + StorageManagerMockup.systemMessagesFilename + "'.");
throw e;
}
}
}