meerkat-java/voter-registry/src/test/java/SimpleRegistryTest.java

385 lines
14 KiB
Java
Raw Normal View History

import com.google.common.util.concurrent.FutureCallback;
2016-03-11 09:02:09 -05:00
import meerkat.AsyncRegistry;
import meerkat.bulletinboard.AsyncBulletinBoardClient;
import meerkat.bulletinboard.ThreadedBulletinBoardClient;
import meerkat.crypto.DigitalSignature;
import meerkat.crypto.concrete.ECDSASignature;
import meerkat.protobuf.BulletinBoardAPI.BulletinBoardMessage;
import meerkat.protobuf.BulletinBoardAPI.MessageFilterList;
import meerkat.protobuf.VoterRegistry;
import meerkat.protobuf.VoterRegistry.GroupID;
import meerkat.protobuf.VoterRegistry.VoterID;
import meerkat.protobuf.VoterRegistry.VoterInfo;
import meerkat.protobuf.Voting;
import meerkat.registry.MessageCollectionUtils;
import meerkat.registry.RegistryTags;
import org.junit.Before;
import org.junit.Test;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.math.BigInteger;
import java.security.KeyStore;
import java.security.SecureRandom;
2016-03-11 09:02:09 -05:00
import java.security.SignatureException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Semaphore;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertTrue;
import static meerkat.util.BulletinBoardUtils.findTagWithPrefix;
import static meerkat.util.BulletinBoardUtils.getLatestMessage;
/**
* TODO: add logs prints for the tests to be clear what they are
*/
/**
* Created by Vladimir Eliezer Tokarev on 1/16/2016.
* Tests the Simple registry contents
* NOTE: for most of this tests to pass there should run BulletinBoardServer
* that should be reachable on BULLETIN_BOARD_SERVER_ADDRESS
*/
public class SimpleRegistryTest {
private Collection<DigitalSignature> signers;
private AsyncBulletinBoardClient bulletinBoardClient;
private InputStream certStream;
private SecureRandom random = new SecureRandom();
public static String KEYFILE_EXAMPLE = "/certs/enduser-certs/user1-key-with-password-secret.p12";
public static String CERT1_PEM_EXAMPLE = "/certs/enduser-certs/user1.crt";
public static String KEYFILE_PASSWORD = "secret";
Semaphore jobSemaphore;
2016-03-11 09:02:09 -05:00
class DummyRegistryCallBackHandler<T> implements FutureCallback<T>{
public int counter;
public T data;
public DummyRegistryCallBackHandler()
{
counter=0;
}
@Override
2016-03-11 09:02:09 -05:00
public void onSuccess(T result) {
counter++;
data = result;
jobSemaphore.release();
}
@Override
2016-03-11 09:02:09 -05:00
public void onFailure(Throwable throwable) {
System.out.print(throwable);
}
}
public class DummyBulletinBoardCallBackHandler implements FutureCallback<List<BulletinBoardMessage>> {
public List<BulletinBoardMessage> messages;
@Override
public void onSuccess(List<BulletinBoardMessage> msg)
{
messages = msg;
jobSemaphore.release();
}
@Override
public void onFailure(Throwable t){
messages = null;
jobSemaphore.release();
}
}
private void CommunicatorSetup() {
bulletinBoardClient = new ThreadedBulletinBoardClient();
String BULLETIN_BOARD_SERVER_ADDRESS = "http://localhost:8081/";
bulletinBoardClient.init(Voting.BulletinBoardClientParams.newBuilder()
.addBulletinBoardAddress(BULLETIN_BOARD_SERVER_ADDRESS)
.setMinRedundancy((float) 1.0)
.build());
}
private void SetSigner(){
try {
signers = new ArrayList<>();
ECDSASignature signer = new ECDSASignature();
InputStream keyStream = getClass().getResourceAsStream(KEYFILE_EXAMPLE);
char[] password = KEYFILE_PASSWORD.toCharArray();
KeyStore.Builder keyStore = signer.getPKCS12KeyStoreBuilder(keyStream, password);
signer.loadSigningCertificate(keyStore);
2016-03-11 09:02:09 -05:00
signer.loadVerificationCertificates(getClass().getResourceAsStream(CERT1_PEM_EXAMPLE));
keyStream.close();
signers.add(signer);
2016-03-11 09:02:09 -05:00
}
catch (Exception e){
assert false : "The signers creation failed ";
}
}
/**
* Initialize registry object
*/
@Before
public void setUp() {
SetSigner();
CommunicatorSetup();
jobSemaphore = new Semaphore(0);
}
2016-03-11 09:02:09 -05:00
private AsyncRegistry GetRegistry()
{
2016-03-11 09:02:09 -05:00
AsyncRegistry registry = new AsyncRegistry();
registry.init(signers, bulletinBoardClient);
return registry;
}
private String generateString()
{
return new BigInteger(130, random).toString(32);
}
/**
* Checks if the creation of the registry have been successful
*/
@Test
public void simpleRegistryCreation() {
try {
2016-03-11 09:02:09 -05:00
AsyncRegistry registry = GetRegistry();
} catch (Exception e) {
assert false : "While creating the registry exception have been thrown " + e;
}
}
/**
* Counts the amount of messages from messages that have all the wanted tags inside
* @param messages List<VoterRegistryMessage>
* @param tags List<RegistryTags>
* @return integer that represent the amount of messages with wanted tags
*/
private int countMessagesWithTags(List<BulletinBoardMessage> messages, List<String> tags)
{
int counter = 0 ;
for (BulletinBoardMessage message : messages) {
int wantedTagsCounter = 0;
for (String tag : tags) {
if(findTagWithPrefix(message, tag)!=null){
wantedTagsCounter++;
}
}
if(wantedTagsCounter == tags.size())
{
counter++;
}
}
return counter;
}
/**
* Reads messages from bulletinBoardClient by given tags and return the callback handler
* object
*
* @param tags list of strings that represents tags
* @return DummyBulletinBoardCallBackHandler which method will be called
*/
private DummyBulletinBoardCallBackHandler readMessagesByTags(List<String> tags)
{
MessageFilterList filters = MessageCollectionUtils.generateFiltersFromTags(tags);
DummyBulletinBoardCallBackHandler bulletinHandler = new DummyBulletinBoardCallBackHandler();
bulletinBoardClient.readMessages(filters, bulletinHandler);
return bulletinHandler;
}
/**
* Test that add voter creates new correct bulletin board message and adds the voter
*/
@Test
2016-03-11 09:02:09 -05:00
public void testAddVoter() throws InterruptedException, SignatureException {
DummyRegistryCallBackHandler<Boolean> handler = new DummyRegistryCallBackHandler<>();
String id = generateString();
String data = generateString();
VoterInfo voterInfo = VoterInfo.newBuilder().setId(VoterID.newBuilder().setId(id)).setInfo(data).build();
2016-03-11 09:02:09 -05:00
AsyncRegistry registry = GetRegistry();
registry.addVoter(voterInfo, handler);
jobSemaphore.acquire();
assertEquals(1, handler.counter );
List<String> tags = new ArrayList<String>(){{ add(RegistryTags.VOTER_ENTRY_TAG);}};
DummyBulletinBoardCallBackHandler bulletinHandler = readMessagesByTags(tags);
jobSemaphore.acquire();
tags.clear();
tags.add(RegistryTags.ID_TAG + id);
int counter = countMessagesWithTags(bulletinHandler.messages, tags);
assert counter == 1 : "The server don't have the new user data.";
}
/**
* Test that set voted posts creates correct bulletin board message and sets that the user have been voted
*/
@Test
2016-03-11 09:02:09 -05:00
public void testSetVoted() throws InterruptedException, SignatureException {
DummyRegistryCallBackHandler<Boolean> handler = new DummyRegistryCallBackHandler<>();
String id = generateString();
VoterID voterInfo = VoterID.newBuilder().setId(id).build();
2016-03-11 09:02:09 -05:00
AsyncRegistry registry = GetRegistry();
registry.setVoted(voterInfo, handler);
jobSemaphore.acquire();
assertEquals(1, handler.counter );
List<String> tags = new ArrayList<String>(){{ add(RegistryTags.VOTE_ACTION_TAG);}};
DummyBulletinBoardCallBackHandler bulletinHandler = readMessagesByTags(tags);
jobSemaphore.acquire();
tags.clear();
tags.add(RegistryTags.ID_TAG + id);
int counter = countMessagesWithTags(bulletinHandler.messages, tags);
assert counter == 1 : "The server don't have the new user id.";
}
/**
Added The protobufs file and its java representation Those protobufs are representing the messages that the registry will use when communicating with the bulletin-board Summary: D:/Work/Wombat Working/voter-registry/comment-info.txt Changed the location of the protobufs file The location have been changed to create order in the packages Changed the location of the ProtobufsMessages file so that the Registry file could use it freely Changed the location of the Protobufs file and added the Registry class The protobufs files location was changed for the right location of the packages for Registry class be able to use the protobufs files Changed the location of the ProtobufsMessages file for creating more organized project Created the SimpleRegistry file SimpleRegistry expose the ability of manging voters information (their groups, and personal data) Created RegistryTagTypes file this file have the different tags for registry messages Changed the SimpleRegistry file started to implement the different methods of this class (such as created basic messages) Changed the ProtobufMessages file now using only the basic registry messages Changed the SimpleRegistry file Managed to create the signatory and add empty builder Added the AccurateTimestamp file This file converts string timestamp to timestamp and the other way , its used for the SimpleRegistry tags Moved the AccurateTimeStamp and the RegistryTagTypes to package called util This way the project files are more organized Add the MessagesUtil file This file contain helpfull methods for working with messages (such as basicMessage and BulletinBoardMessage) Created VoterRegistryMessage VoterRegistryMessage extending the abilities of the basic message also changed the name of MessagesUtils to CollectionMessagesUtils because its suits more this class destination Changed the simpleRegistry file Edited the GetPersonIDDetails method , and refactored the basic methods of upload data to BulletinBoardServer Added the SimpleRegistryTest This object tests the simple registry functionality Added the SimpleRegistryTest This object tests the simple registry functionality Changed the RegistryTagsType to RegistryTags The Name RegistryTags more indicative Added The Wombat Code And Documentation This file describes the conventions of the wombat project Changed the SimpleRegistry and VoterRegistryMessage Documentation The documentation was partial in part of the methods Changed the SimpleRegistry to work with UnsignedBulletinBoardMessage The basicMessage is not needed Changed the SimpleRegistry to work with UnsignedBulletinBoardMessage The basicMessage is not needed Changed the VoterRegistryMessage to wrap UnsignedBulletinBoardMessage there is no need to wrap unused basic message when using UnsignedBulletinBoardMessage Re-organized the voter-registry Since there no need for basicMessage i have removed it, and changed few methods to be in language level 7 Re-organized the voter-registry Since there no need for basicMessage i have removed it, and changed few methods to be in language level 7 added the RegistryInstance interface Which gives the basic registry functionality (because there going to be at least two registries) Changed the SimpleRegistry The new Simple Registry works according to the RegistryInstance interface Changed the SimpleRegistry The new Simple Registry works according to the RegistryInstance interface Changed the SimpleRegistry The new Simple Registry works according to the RegistryInstance interface Added testing to the SimpleRegistryTest class The Test checking that SetVoter AddVoter AddToGroup RemoveFromGroup methods working. Added testing to the SimpleRegistryTest class The Test checking that SetVoter AddVoter AddToGroup RemoveFromGroup methods working. Test Plan: The idea is to create number of BulletinBoardMessage's that and post them, then ask from the server for message with relevant filter and check that all the messages that have been posted there. Reviewers: arbel.peled Differential Revision: https://proj-cs.idc.ac.il/D1
2016-01-30 12:19:25 -05:00
* Test that get groups retrieves the right groups the user are in
*/
@Test
public void testSetVoterGroups() throws InterruptedException, SignatureException, IOException, ClassNotFoundException {
DummyRegistryCallBackHandler<Boolean> handler = new DummyRegistryCallBackHandler<>();
String voterId = generateString();
String groupId1 = generateString();
VoterRegistry.VoterRegistryMessage voterInfo = VoterRegistry.VoterRegistryMessage.newBuilder()
.setVoterID(VoterID.newBuilder().setId(voterId))
.addGroupID(GroupID.newBuilder().setId(groupId1)).build();
2016-03-11 09:02:09 -05:00
AsyncRegistry registry = GetRegistry();
registry.setVoterGroups(voterInfo, handler);
jobSemaphore.acquire();
assertEquals("The callback handler hasn't been called yet", 1, handler.counter);
List<String> tags = new ArrayList<String>(){{add(RegistryTags.ADD_TO_GROUP_TAG);
add(RegistryTags.ID_TAG + voterId);}};
DummyBulletinBoardCallBackHandler bulletinHandler = readMessagesByTags(tags);
jobSemaphore.acquire();
BulletinBoardMessage latestMessage = getLatestMessage(bulletinHandler.messages);
assert findTagWithPrefix(latestMessage, RegistryTags.ID_TAG).equals(voterId) :
"The latest message recieved is not of our voter";
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(latestMessage.getMsg().getData().toByteArray()));
List<GroupID> groupsIds = (List<GroupID>)ois.readObject();
assert groupsIds.get(0).getId().equals(groupId1) : "The latest message doesn't have the voter group";
}
/**
Added The protobufs file and its java representation Those protobufs are representing the messages that the registry will use when communicating with the bulletin-board Summary: D:/Work/Wombat Working/voter-registry/comment-info.txt Changed the location of the protobufs file The location have been changed to create order in the packages Changed the location of the ProtobufsMessages file so that the Registry file could use it freely Changed the location of the Protobufs file and added the Registry class The protobufs files location was changed for the right location of the packages for Registry class be able to use the protobufs files Changed the location of the ProtobufsMessages file for creating more organized project Created the SimpleRegistry file SimpleRegistry expose the ability of manging voters information (their groups, and personal data) Created RegistryTagTypes file this file have the different tags for registry messages Changed the SimpleRegistry file started to implement the different methods of this class (such as created basic messages) Changed the ProtobufMessages file now using only the basic registry messages Changed the SimpleRegistry file Managed to create the signatory and add empty builder Added the AccurateTimestamp file This file converts string timestamp to timestamp and the other way , its used for the SimpleRegistry tags Moved the AccurateTimeStamp and the RegistryTagTypes to package called util This way the project files are more organized Add the MessagesUtil file This file contain helpfull methods for working with messages (such as basicMessage and BulletinBoardMessage) Created VoterRegistryMessage VoterRegistryMessage extending the abilities of the basic message also changed the name of MessagesUtils to CollectionMessagesUtils because its suits more this class destination Changed the simpleRegistry file Edited the GetPersonIDDetails method , and refactored the basic methods of upload data to BulletinBoardServer Added the SimpleRegistryTest This object tests the simple registry functionality Added the SimpleRegistryTest This object tests the simple registry functionality Changed the RegistryTagsType to RegistryTags The Name RegistryTags more indicative Added The Wombat Code And Documentation This file describes the conventions of the wombat project Changed the SimpleRegistry and VoterRegistryMessage Documentation The documentation was partial in part of the methods Changed the SimpleRegistry to work with UnsignedBulletinBoardMessage The basicMessage is not needed Changed the SimpleRegistry to work with UnsignedBulletinBoardMessage The basicMessage is not needed Changed the VoterRegistryMessage to wrap UnsignedBulletinBoardMessage there is no need to wrap unused basic message when using UnsignedBulletinBoardMessage Re-organized the voter-registry Since there no need for basicMessage i have removed it, and changed few methods to be in language level 7 Re-organized the voter-registry Since there no need for basicMessage i have removed it, and changed few methods to be in language level 7 added the RegistryInstance interface Which gives the basic registry functionality (because there going to be at least two registries) Changed the SimpleRegistry The new Simple Registry works according to the RegistryInstance interface Changed the SimpleRegistry The new Simple Registry works according to the RegistryInstance interface Changed the SimpleRegistry The new Simple Registry works according to the RegistryInstance interface Added testing to the SimpleRegistryTest class The Test checking that SetVoter AddVoter AddToGroup RemoveFromGroup methods working. Added testing to the SimpleRegistryTest class The Test checking that SetVoter AddVoter AddToGroup RemoveFromGroup methods working. Test Plan: The idea is to create number of BulletinBoardMessage's that and post them, then ask from the server for message with relevant filter and check that all the messages that have been posted there. Reviewers: arbel.peled Differential Revision: https://proj-cs.idc.ac.il/D1
2016-01-30 12:19:25 -05:00
* Test that remove from group creates correct bulletin board message and removes the user from a group
*/
@Test
public void testGetGroups() throws InterruptedException, SignatureException, IOException {
2016-03-11 09:02:09 -05:00
DummyRegistryCallBackHandler<Boolean> handler =
new DummyRegistryCallBackHandler<>();
String voterId = generateString();
String groupId1 = generateString();
String groupId2 = generateString();
VoterRegistry.VoterRegistryMessage voterInfo = VoterRegistry.VoterRegistryMessage.newBuilder()
.setVoterID(VoterID.newBuilder().setId(voterId))
.addGroupID(GroupID.newBuilder().setId(groupId1))
.addGroupID(GroupID.newBuilder().setId(groupId2)).build();
Added The protobufs file and its java representation Those protobufs are representing the messages that the registry will use when communicating with the bulletin-board Summary: D:/Work/Wombat Working/voter-registry/comment-info.txt Changed the location of the protobufs file The location have been changed to create order in the packages Changed the location of the ProtobufsMessages file so that the Registry file could use it freely Changed the location of the Protobufs file and added the Registry class The protobufs files location was changed for the right location of the packages for Registry class be able to use the protobufs files Changed the location of the ProtobufsMessages file for creating more organized project Created the SimpleRegistry file SimpleRegistry expose the ability of manging voters information (their groups, and personal data) Created RegistryTagTypes file this file have the different tags for registry messages Changed the SimpleRegistry file started to implement the different methods of this class (such as created basic messages) Changed the ProtobufMessages file now using only the basic registry messages Changed the SimpleRegistry file Managed to create the signatory and add empty builder Added the AccurateTimestamp file This file converts string timestamp to timestamp and the other way , its used for the SimpleRegistry tags Moved the AccurateTimeStamp and the RegistryTagTypes to package called util This way the project files are more organized Add the MessagesUtil file This file contain helpfull methods for working with messages (such as basicMessage and BulletinBoardMessage) Created VoterRegistryMessage VoterRegistryMessage extending the abilities of the basic message also changed the name of MessagesUtils to CollectionMessagesUtils because its suits more this class destination Changed the simpleRegistry file Edited the GetPersonIDDetails method , and refactored the basic methods of upload data to BulletinBoardServer Added the SimpleRegistryTest This object tests the simple registry functionality Added the SimpleRegistryTest This object tests the simple registry functionality Changed the RegistryTagsType to RegistryTags The Name RegistryTags more indicative Added The Wombat Code And Documentation This file describes the conventions of the wombat project Changed the SimpleRegistry and VoterRegistryMessage Documentation The documentation was partial in part of the methods Changed the SimpleRegistry to work with UnsignedBulletinBoardMessage The basicMessage is not needed Changed the SimpleRegistry to work with UnsignedBulletinBoardMessage The basicMessage is not needed Changed the VoterRegistryMessage to wrap UnsignedBulletinBoardMessage there is no need to wrap unused basic message when using UnsignedBulletinBoardMessage Re-organized the voter-registry Since there no need for basicMessage i have removed it, and changed few methods to be in language level 7 Re-organized the voter-registry Since there no need for basicMessage i have removed it, and changed few methods to be in language level 7 added the RegistryInstance interface Which gives the basic registry functionality (because there going to be at least two registries) Changed the SimpleRegistry The new Simple Registry works according to the RegistryInstance interface Changed the SimpleRegistry The new Simple Registry works according to the RegistryInstance interface Changed the SimpleRegistry The new Simple Registry works according to the RegistryInstance interface Added testing to the SimpleRegistryTest class The Test checking that SetVoter AddVoter AddToGroup RemoveFromGroup methods working. Added testing to the SimpleRegistryTest class The Test checking that SetVoter AddVoter AddToGroup RemoveFromGroup methods working. Test Plan: The idea is to create number of BulletinBoardMessage's that and post them, then ask from the server for message with relevant filter and check that all the messages that have been posted there. Reviewers: arbel.peled Differential Revision: https://proj-cs.idc.ac.il/D1
2016-01-30 12:19:25 -05:00
this.certStream = getClass().getResourceAsStream(CERT1_PEM_EXAMPLE);
2016-03-11 09:02:09 -05:00
AsyncRegistry registry = GetRegistry();
registry.setVoterGroups(voterInfo, handler);
Added The protobufs file and its java representation Those protobufs are representing the messages that the registry will use when communicating with the bulletin-board Summary: D:/Work/Wombat Working/voter-registry/comment-info.txt Changed the location of the protobufs file The location have been changed to create order in the packages Changed the location of the ProtobufsMessages file so that the Registry file could use it freely Changed the location of the Protobufs file and added the Registry class The protobufs files location was changed for the right location of the packages for Registry class be able to use the protobufs files Changed the location of the ProtobufsMessages file for creating more organized project Created the SimpleRegistry file SimpleRegistry expose the ability of manging voters information (their groups, and personal data) Created RegistryTagTypes file this file have the different tags for registry messages Changed the SimpleRegistry file started to implement the different methods of this class (such as created basic messages) Changed the ProtobufMessages file now using only the basic registry messages Changed the SimpleRegistry file Managed to create the signatory and add empty builder Added the AccurateTimestamp file This file converts string timestamp to timestamp and the other way , its used for the SimpleRegistry tags Moved the AccurateTimeStamp and the RegistryTagTypes to package called util This way the project files are more organized Add the MessagesUtil file This file contain helpfull methods for working with messages (such as basicMessage and BulletinBoardMessage) Created VoterRegistryMessage VoterRegistryMessage extending the abilities of the basic message also changed the name of MessagesUtils to CollectionMessagesUtils because its suits more this class destination Changed the simpleRegistry file Edited the GetPersonIDDetails method , and refactored the basic methods of upload data to BulletinBoardServer Added the SimpleRegistryTest This object tests the simple registry functionality Added the SimpleRegistryTest This object tests the simple registry functionality Changed the RegistryTagsType to RegistryTags The Name RegistryTags more indicative Added The Wombat Code And Documentation This file describes the conventions of the wombat project Changed the SimpleRegistry and VoterRegistryMessage Documentation The documentation was partial in part of the methods Changed the SimpleRegistry to work with UnsignedBulletinBoardMessage The basicMessage is not needed Changed the SimpleRegistry to work with UnsignedBulletinBoardMessage The basicMessage is not needed Changed the VoterRegistryMessage to wrap UnsignedBulletinBoardMessage there is no need to wrap unused basic message when using UnsignedBulletinBoardMessage Re-organized the voter-registry Since there no need for basicMessage i have removed it, and changed few methods to be in language level 7 Re-organized the voter-registry Since there no need for basicMessage i have removed it, and changed few methods to be in language level 7 added the RegistryInstance interface Which gives the basic registry functionality (because there going to be at least two registries) Changed the SimpleRegistry The new Simple Registry works according to the RegistryInstance interface Changed the SimpleRegistry The new Simple Registry works according to the RegistryInstance interface Changed the SimpleRegistry The new Simple Registry works according to the RegistryInstance interface Added testing to the SimpleRegistryTest class The Test checking that SetVoter AddVoter AddToGroup RemoveFromGroup methods working. Added testing to the SimpleRegistryTest class The Test checking that SetVoter AddVoter AddToGroup RemoveFromGroup methods working. Test Plan: The idea is to create number of BulletinBoardMessage's that and post them, then ask from the server for message with relevant filter and check that all the messages that have been posted there. Reviewers: arbel.peled Differential Revision: https://proj-cs.idc.ac.il/D1
2016-01-30 12:19:25 -05:00
jobSemaphore.acquire();
assertEquals("The callback handler hasn't been called yet", 1, handler.counter );
Added The protobufs file and its java representation Those protobufs are representing the messages that the registry will use when communicating with the bulletin-board Summary: D:/Work/Wombat Working/voter-registry/comment-info.txt Changed the location of the protobufs file The location have been changed to create order in the packages Changed the location of the ProtobufsMessages file so that the Registry file could use it freely Changed the location of the Protobufs file and added the Registry class The protobufs files location was changed for the right location of the packages for Registry class be able to use the protobufs files Changed the location of the ProtobufsMessages file for creating more organized project Created the SimpleRegistry file SimpleRegistry expose the ability of manging voters information (their groups, and personal data) Created RegistryTagTypes file this file have the different tags for registry messages Changed the SimpleRegistry file started to implement the different methods of this class (such as created basic messages) Changed the ProtobufMessages file now using only the basic registry messages Changed the SimpleRegistry file Managed to create the signatory and add empty builder Added the AccurateTimestamp file This file converts string timestamp to timestamp and the other way , its used for the SimpleRegistry tags Moved the AccurateTimeStamp and the RegistryTagTypes to package called util This way the project files are more organized Add the MessagesUtil file This file contain helpfull methods for working with messages (such as basicMessage and BulletinBoardMessage) Created VoterRegistryMessage VoterRegistryMessage extending the abilities of the basic message also changed the name of MessagesUtils to CollectionMessagesUtils because its suits more this class destination Changed the simpleRegistry file Edited the GetPersonIDDetails method , and refactored the basic methods of upload data to BulletinBoardServer Added the SimpleRegistryTest This object tests the simple registry functionality Added the SimpleRegistryTest This object tests the simple registry functionality Changed the RegistryTagsType to RegistryTags The Name RegistryTags more indicative Added The Wombat Code And Documentation This file describes the conventions of the wombat project Changed the SimpleRegistry and VoterRegistryMessage Documentation The documentation was partial in part of the methods Changed the SimpleRegistry to work with UnsignedBulletinBoardMessage The basicMessage is not needed Changed the SimpleRegistry to work with UnsignedBulletinBoardMessage The basicMessage is not needed Changed the VoterRegistryMessage to wrap UnsignedBulletinBoardMessage there is no need to wrap unused basic message when using UnsignedBulletinBoardMessage Re-organized the voter-registry Since there no need for basicMessage i have removed it, and changed few methods to be in language level 7 Re-organized the voter-registry Since there no need for basicMessage i have removed it, and changed few methods to be in language level 7 added the RegistryInstance interface Which gives the basic registry functionality (because there going to be at least two registries) Changed the SimpleRegistry The new Simple Registry works according to the RegistryInstance interface Changed the SimpleRegistry The new Simple Registry works according to the RegistryInstance interface Changed the SimpleRegistry The new Simple Registry works according to the RegistryInstance interface Added testing to the SimpleRegistryTest class The Test checking that SetVoter AddVoter AddToGroup RemoveFromGroup methods working. Added testing to the SimpleRegistryTest class The Test checking that SetVoter AddVoter AddToGroup RemoveFromGroup methods working. Test Plan: The idea is to create number of BulletinBoardMessage's that and post them, then ask from the server for message with relevant filter and check that all the messages that have been posted there. Reviewers: arbel.peled Differential Revision: https://proj-cs.idc.ac.il/D1
2016-01-30 12:19:25 -05:00
DummyRegistryCallBackHandler<List<GroupID>> groupsHandler = new DummyRegistryCallBackHandler<>();
registry.getGroups(VoterID.newBuilder().setId(voterId).build(), groupsHandler);
jobSemaphore.acquire(1);
List<GroupID> userGroups = groupsHandler.data;
assert userGroups.contains(GroupID.newBuilder().setId(groupId1).build()) :
"The simple voter registry object does not retrieved the first user groups";
assert userGroups.contains(GroupID.newBuilder().setId(groupId2).build()) :
"The simple voter registry object does not retrieved the second user groups";
}
/**
* Test that the personal data outputted about the user is right
*/
@Test
2016-03-11 09:02:09 -05:00
public void testGetVoter() throws InterruptedException, SignatureException {
DummyRegistryCallBackHandler<Boolean> handler =
new DummyRegistryCallBackHandler<>();
String id = generateString();
String data = generateString();
VoterInfo voterInfo = VoterInfo.newBuilder().
setId(VoterID.newBuilder().setId(id)).setInfo(data).build();
Added The protobufs file and its java representation Those protobufs are representing the messages that the registry will use when communicating with the bulletin-board Summary: D:/Work/Wombat Working/voter-registry/comment-info.txt Changed the location of the protobufs file The location have been changed to create order in the packages Changed the location of the ProtobufsMessages file so that the Registry file could use it freely Changed the location of the Protobufs file and added the Registry class The protobufs files location was changed for the right location of the packages for Registry class be able to use the protobufs files Changed the location of the ProtobufsMessages file for creating more organized project Created the SimpleRegistry file SimpleRegistry expose the ability of manging voters information (their groups, and personal data) Created RegistryTagTypes file this file have the different tags for registry messages Changed the SimpleRegistry file started to implement the different methods of this class (such as created basic messages) Changed the ProtobufMessages file now using only the basic registry messages Changed the SimpleRegistry file Managed to create the signatory and add empty builder Added the AccurateTimestamp file This file converts string timestamp to timestamp and the other way , its used for the SimpleRegistry tags Moved the AccurateTimeStamp and the RegistryTagTypes to package called util This way the project files are more organized Add the MessagesUtil file This file contain helpfull methods for working with messages (such as basicMessage and BulletinBoardMessage) Created VoterRegistryMessage VoterRegistryMessage extending the abilities of the basic message also changed the name of MessagesUtils to CollectionMessagesUtils because its suits more this class destination Changed the simpleRegistry file Edited the GetPersonIDDetails method , and refactored the basic methods of upload data to BulletinBoardServer Added the SimpleRegistryTest This object tests the simple registry functionality Added the SimpleRegistryTest This object tests the simple registry functionality Changed the RegistryTagsType to RegistryTags The Name RegistryTags more indicative Added The Wombat Code And Documentation This file describes the conventions of the wombat project Changed the SimpleRegistry and VoterRegistryMessage Documentation The documentation was partial in part of the methods Changed the SimpleRegistry to work with UnsignedBulletinBoardMessage The basicMessage is not needed Changed the SimpleRegistry to work with UnsignedBulletinBoardMessage The basicMessage is not needed Changed the VoterRegistryMessage to wrap UnsignedBulletinBoardMessage there is no need to wrap unused basic message when using UnsignedBulletinBoardMessage Re-organized the voter-registry Since there no need for basicMessage i have removed it, and changed few methods to be in language level 7 Re-organized the voter-registry Since there no need for basicMessage i have removed it, and changed few methods to be in language level 7 added the RegistryInstance interface Which gives the basic registry functionality (because there going to be at least two registries) Changed the SimpleRegistry The new Simple Registry works according to the RegistryInstance interface Changed the SimpleRegistry The new Simple Registry works according to the RegistryInstance interface Changed the SimpleRegistry The new Simple Registry works according to the RegistryInstance interface Added testing to the SimpleRegistryTest class The Test checking that SetVoter AddVoter AddToGroup RemoveFromGroup methods working. Added testing to the SimpleRegistryTest class The Test checking that SetVoter AddVoter AddToGroup RemoveFromGroup methods working. Test Plan: The idea is to create number of BulletinBoardMessage's that and post them, then ask from the server for message with relevant filter and check that all the messages that have been posted there. Reviewers: arbel.peled Differential Revision: https://proj-cs.idc.ac.il/D1
2016-01-30 12:19:25 -05:00
2016-03-11 09:02:09 -05:00
AsyncRegistry registry = GetRegistry();
registry.addVoter(voterInfo, handler);
Added The protobufs file and its java representation Those protobufs are representing the messages that the registry will use when communicating with the bulletin-board Summary: D:/Work/Wombat Working/voter-registry/comment-info.txt Changed the location of the protobufs file The location have been changed to create order in the packages Changed the location of the ProtobufsMessages file so that the Registry file could use it freely Changed the location of the Protobufs file and added the Registry class The protobufs files location was changed for the right location of the packages for Registry class be able to use the protobufs files Changed the location of the ProtobufsMessages file for creating more organized project Created the SimpleRegistry file SimpleRegistry expose the ability of manging voters information (their groups, and personal data) Created RegistryTagTypes file this file have the different tags for registry messages Changed the SimpleRegistry file started to implement the different methods of this class (such as created basic messages) Changed the ProtobufMessages file now using only the basic registry messages Changed the SimpleRegistry file Managed to create the signatory and add empty builder Added the AccurateTimestamp file This file converts string timestamp to timestamp and the other way , its used for the SimpleRegistry tags Moved the AccurateTimeStamp and the RegistryTagTypes to package called util This way the project files are more organized Add the MessagesUtil file This file contain helpfull methods for working with messages (such as basicMessage and BulletinBoardMessage) Created VoterRegistryMessage VoterRegistryMessage extending the abilities of the basic message also changed the name of MessagesUtils to CollectionMessagesUtils because its suits more this class destination Changed the simpleRegistry file Edited the GetPersonIDDetails method , and refactored the basic methods of upload data to BulletinBoardServer Added the SimpleRegistryTest This object tests the simple registry functionality Added the SimpleRegistryTest This object tests the simple registry functionality Changed the RegistryTagsType to RegistryTags The Name RegistryTags more indicative Added The Wombat Code And Documentation This file describes the conventions of the wombat project Changed the SimpleRegistry and VoterRegistryMessage Documentation The documentation was partial in part of the methods Changed the SimpleRegistry to work with UnsignedBulletinBoardMessage The basicMessage is not needed Changed the SimpleRegistry to work with UnsignedBulletinBoardMessage The basicMessage is not needed Changed the VoterRegistryMessage to wrap UnsignedBulletinBoardMessage there is no need to wrap unused basic message when using UnsignedBulletinBoardMessage Re-organized the voter-registry Since there no need for basicMessage i have removed it, and changed few methods to be in language level 7 Re-organized the voter-registry Since there no need for basicMessage i have removed it, and changed few methods to be in language level 7 added the RegistryInstance interface Which gives the basic registry functionality (because there going to be at least two registries) Changed the SimpleRegistry The new Simple Registry works according to the RegistryInstance interface Changed the SimpleRegistry The new Simple Registry works according to the RegistryInstance interface Changed the SimpleRegistry The new Simple Registry works according to the RegistryInstance interface Added testing to the SimpleRegistryTest class The Test checking that SetVoter AddVoter AddToGroup RemoveFromGroup methods working. Added testing to the SimpleRegistryTest class The Test checking that SetVoter AddVoter AddToGroup RemoveFromGroup methods working. Test Plan: The idea is to create number of BulletinBoardMessage's that and post them, then ask from the server for message with relevant filter and check that all the messages that have been posted there. Reviewers: arbel.peled Differential Revision: https://proj-cs.idc.ac.il/D1
2016-01-30 12:19:25 -05:00
jobSemaphore.acquire();
assertEquals("The callback handler hasn't been called yet", 1, handler.counter );
Added The protobufs file and its java representation Those protobufs are representing the messages that the registry will use when communicating with the bulletin-board Summary: D:/Work/Wombat Working/voter-registry/comment-info.txt Changed the location of the protobufs file The location have been changed to create order in the packages Changed the location of the ProtobufsMessages file so that the Registry file could use it freely Changed the location of the Protobufs file and added the Registry class The protobufs files location was changed for the right location of the packages for Registry class be able to use the protobufs files Changed the location of the ProtobufsMessages file for creating more organized project Created the SimpleRegistry file SimpleRegistry expose the ability of manging voters information (their groups, and personal data) Created RegistryTagTypes file this file have the different tags for registry messages Changed the SimpleRegistry file started to implement the different methods of this class (such as created basic messages) Changed the ProtobufMessages file now using only the basic registry messages Changed the SimpleRegistry file Managed to create the signatory and add empty builder Added the AccurateTimestamp file This file converts string timestamp to timestamp and the other way , its used for the SimpleRegistry tags Moved the AccurateTimeStamp and the RegistryTagTypes to package called util This way the project files are more organized Add the MessagesUtil file This file contain helpfull methods for working with messages (such as basicMessage and BulletinBoardMessage) Created VoterRegistryMessage VoterRegistryMessage extending the abilities of the basic message also changed the name of MessagesUtils to CollectionMessagesUtils because its suits more this class destination Changed the simpleRegistry file Edited the GetPersonIDDetails method , and refactored the basic methods of upload data to BulletinBoardServer Added the SimpleRegistryTest This object tests the simple registry functionality Added the SimpleRegistryTest This object tests the simple registry functionality Changed the RegistryTagsType to RegistryTags The Name RegistryTags more indicative Added The Wombat Code And Documentation This file describes the conventions of the wombat project Changed the SimpleRegistry and VoterRegistryMessage Documentation The documentation was partial in part of the methods Changed the SimpleRegistry to work with UnsignedBulletinBoardMessage The basicMessage is not needed Changed the SimpleRegistry to work with UnsignedBulletinBoardMessage The basicMessage is not needed Changed the VoterRegistryMessage to wrap UnsignedBulletinBoardMessage there is no need to wrap unused basic message when using UnsignedBulletinBoardMessage Re-organized the voter-registry Since there no need for basicMessage i have removed it, and changed few methods to be in language level 7 Re-organized the voter-registry Since there no need for basicMessage i have removed it, and changed few methods to be in language level 7 added the RegistryInstance interface Which gives the basic registry functionality (because there going to be at least two registries) Changed the SimpleRegistry The new Simple Registry works according to the RegistryInstance interface Changed the SimpleRegistry The new Simple Registry works according to the RegistryInstance interface Changed the SimpleRegistry The new Simple Registry works according to the RegistryInstance interface Added testing to the SimpleRegistryTest class The Test checking that SetVoter AddVoter AddToGroup RemoveFromGroup methods working. Added testing to the SimpleRegistryTest class The Test checking that SetVoter AddVoter AddToGroup RemoveFromGroup methods working. Test Plan: The idea is to create number of BulletinBoardMessage's that and post them, then ask from the server for message with relevant filter and check that all the messages that have been posted there. Reviewers: arbel.peled Differential Revision: https://proj-cs.idc.ac.il/D1
2016-01-30 12:19:25 -05:00
2016-03-11 09:02:09 -05:00
DummyRegistryCallBackHandler<VoterInfo> personalHandler = new DummyRegistryCallBackHandler<>();
registry.getVoter(VoterID.newBuilder().setId(id).build(), personalHandler);
jobSemaphore.acquire(1);
assertEquals("The voter id doesn't match the created on ",
2016-03-11 09:02:09 -05:00
id, personalHandler.data.getId().getId());
String personalData = personalHandler.data.getInfo();
assertTrue("The voter personal data can't be found.", data.equals(personalData));
}
/**
* Tests that the hasVoted method of registry works
* @throws InterruptedException
*/
@Test
2016-03-11 09:02:09 -05:00
public void testHasVoted () throws InterruptedException, SignatureException {
DummyRegistryCallBackHandler<Boolean> handler = new DummyRegistryCallBackHandler<>();
String id = generateString();
VoterID voterInfo = VoterID.newBuilder().setId(id).build();
2016-03-11 09:02:09 -05:00
AsyncRegistry registry = GetRegistry();
registry.setVoted(voterInfo, handler);
jobSemaphore.acquire();
assertEquals("The callback handler hasn't been called yet", 1, handler.counter);
DummyRegistryCallBackHandler<Boolean> personalHandler = new DummyRegistryCallBackHandler<>();
registry.hasVoted(VoterID.newBuilder().setId(id).build(), personalHandler);
jobSemaphore.acquire(1);
assertTrue("The voter hasn't voted yet.", personalHandler.data);
}
}