Added testing to the SimpleRegistryTest class
The Test checking that SetVoter AddVoter AddToGroup RemoveFromGroup methods working.Voter-Registry
parent
6020ed3ab8
commit
003720839c
|
@ -6,6 +6,7 @@ import meerkat.bulletinboard.SimpleBulletinBoardClient;
|
||||||
|
|
||||||
import meerkat.comm.CommunicationException;
|
import meerkat.comm.CommunicationException;
|
||||||
import meerkat.crypto.Encryption;
|
import meerkat.crypto.Encryption;
|
||||||
|
import meerkat.protobuf.BulletinBoardAPI;
|
||||||
import meerkat.protobuf.BulletinBoardAPI.BulletinBoardMessage;
|
import meerkat.protobuf.BulletinBoardAPI.BulletinBoardMessage;
|
||||||
import meerkat.protobuf.BulletinBoardAPI.MessageFilter;
|
import meerkat.protobuf.BulletinBoardAPI.MessageFilter;
|
||||||
import meerkat.protobuf.BulletinBoardAPI.MessageFilterList;
|
import meerkat.protobuf.BulletinBoardAPI.MessageFilterList;
|
||||||
|
@ -77,7 +78,7 @@ public class SimpleRegistry implements RegistryInstance{
|
||||||
|
|
||||||
for (String tag : tags) {
|
for (String tag : tags) {
|
||||||
MessageFilter.Builder idFilter =
|
MessageFilter.Builder idFilter =
|
||||||
MessageFilter.newBuilder().setTag(tag);
|
MessageFilter.newBuilder().setTag(tag).setType(BulletinBoardAPI.FilterType.TAG);
|
||||||
|
|
||||||
filters.addFilter(idFilter);
|
filters.addFilter(idFilter);
|
||||||
}
|
}
|
||||||
|
@ -115,9 +116,9 @@ public class SimpleRegistry implements RegistryInstance{
|
||||||
public void AddVoter(String voterID, String personalData, RegistryCallBack callback) {
|
public void AddVoter(String voterID, String personalData, RegistryCallBack callback) {
|
||||||
UnsignedBulletinBoardMessage.Builder basicMessage =
|
UnsignedBulletinBoardMessage.Builder basicMessage =
|
||||||
UnsignedBulletinBoardMessage.newBuilder().
|
UnsignedBulletinBoardMessage.newBuilder().
|
||||||
addTag(RegistryTags.ID_TAG + " " + voterID)
|
addTag(RegistryTags.ID_TAG + voterID)
|
||||||
.addTag(RegistryTags.VOTER_ENTRY_TAG.toString())
|
.addTag(RegistryTags.VOTER_ENTRY_TAG.toString())
|
||||||
.addTag(RegistryTags.ACTION_TIMESTAMP_TAG + " " + AccurateTimestamp.GetCurrentTimestampString());
|
.addTag(RegistryTags.ACTION_TIMESTAMP_TAG + AccurateTimestamp.GetCurrentTimestampString());
|
||||||
|
|
||||||
basicMessage.setData(ByteString.copyFrom(personalData.getBytes()));
|
basicMessage.setData(ByteString.copyFrom(personalData.getBytes()));
|
||||||
|
|
||||||
|
@ -127,10 +128,10 @@ public class SimpleRegistry implements RegistryInstance{
|
||||||
public void AddToGroup(String voterID, String groupID, RegistryCallBack callback) {
|
public void AddToGroup(String voterID, String groupID, RegistryCallBack callback) {
|
||||||
UnsignedBulletinBoardMessage.Builder basicMessage =
|
UnsignedBulletinBoardMessage.Builder basicMessage =
|
||||||
UnsignedBulletinBoardMessage.newBuilder()
|
UnsignedBulletinBoardMessage.newBuilder()
|
||||||
.addTag(RegistryTags.ID_TAG + " " + voterID)
|
.addTag(RegistryTags.ID_TAG + voterID)
|
||||||
.addTag(RegistryTags.GROUP_ID_TAG + " " + groupID)
|
.addTag(RegistryTags.GROUP_ID_TAG + groupID)
|
||||||
.addTag(RegistryTags.GROUP_ACTION_TAG + " " + RegistryTags.ADD_TO_GROUP_TAG)
|
.addTag(RegistryTags.GROUP_ACTION_TAG .toString() + RegistryTags.ADD_TO_GROUP_TAG)
|
||||||
.addTag(RegistryTags.ACTION_TIMESTAMP_TAG + " " + AccurateTimestamp.GetCurrentTimestampString());
|
.addTag(RegistryTags.ACTION_TIMESTAMP_TAG + AccurateTimestamp.GetCurrentTimestampString());
|
||||||
|
|
||||||
callback.HandleVoterAddedToGroup(SafePost(CreateBulletinBoardMessage(basicMessage.build())));
|
callback.HandleVoterAddedToGroup(SafePost(CreateBulletinBoardMessage(basicMessage.build())));
|
||||||
}
|
}
|
||||||
|
@ -138,10 +139,10 @@ public class SimpleRegistry implements RegistryInstance{
|
||||||
public void RemoveFromGroup(String voterID, String groupID, RegistryCallBack callback) {
|
public void RemoveFromGroup(String voterID, String groupID, RegistryCallBack callback) {
|
||||||
UnsignedBulletinBoardMessage.Builder basicMessage =
|
UnsignedBulletinBoardMessage.Builder basicMessage =
|
||||||
UnsignedBulletinBoardMessage.newBuilder()
|
UnsignedBulletinBoardMessage.newBuilder()
|
||||||
.addTag(RegistryTags.ID_TAG + " " + voterID)
|
.addTag(RegistryTags.ID_TAG + voterID)
|
||||||
.addTag(RegistryTags.GROUP_ID_TAG + " " + groupID)
|
.addTag(RegistryTags.GROUP_ID_TAG + groupID)
|
||||||
.addTag(RegistryTags.GROUP_ACTION_TAG + " " + RegistryTags.REMOVE_FROM_GROUP_TAG)
|
.addTag(RegistryTags.GROUP_ACTION_TAG .toString()+ RegistryTags.REMOVE_FROM_GROUP_TAG)
|
||||||
.addTag(RegistryTags.ACTION_TIMESTAMP_TAG + " " + AccurateTimestamp.GetCurrentTimestampString());
|
.addTag(RegistryTags.ACTION_TIMESTAMP_TAG + AccurateTimestamp.GetCurrentTimestampString());
|
||||||
|
|
||||||
callback.HandleVoterRemovedFromGroup(SafePost(CreateBulletinBoardMessage(basicMessage.build())));
|
callback.HandleVoterRemovedFromGroup(SafePost(CreateBulletinBoardMessage(basicMessage.build())));
|
||||||
}
|
}
|
||||||
|
@ -149,9 +150,9 @@ public class SimpleRegistry implements RegistryInstance{
|
||||||
public void SetVoted(String id, RegistryCallBack callback) {
|
public void SetVoted(String id, RegistryCallBack callback) {
|
||||||
UnsignedBulletinBoardMessage.Builder basicMessage =
|
UnsignedBulletinBoardMessage.Builder basicMessage =
|
||||||
UnsignedBulletinBoardMessage.newBuilder()
|
UnsignedBulletinBoardMessage.newBuilder()
|
||||||
.addTag(RegistryTags.ID_TAG + " " + id)
|
.addTag(RegistryTags.ID_TAG + id)
|
||||||
.addTag(RegistryTags.VOTE_ACTION_TAG.toString())
|
.addTag(RegistryTags.VOTE_ACTION_TAG.toString())
|
||||||
.addTag(RegistryTags.ACTION_TIMESTAMP_TAG + " " + AccurateTimestamp.GetCurrentTimestampString());
|
.addTag(RegistryTags.ACTION_TIMESTAMP_TAG + AccurateTimestamp.GetCurrentTimestampString());
|
||||||
|
|
||||||
callback.HandleVoterAddedToGroup(SafePost(CreateBulletinBoardMessage(basicMessage.build())));
|
callback.HandleVoterAddedToGroup(SafePost(CreateBulletinBoardMessage(basicMessage.build())));
|
||||||
}
|
}
|
||||||
|
@ -159,9 +160,9 @@ public class SimpleRegistry implements RegistryInstance{
|
||||||
public void GetGroups(String id, RegistryCallBack callback) {
|
public void GetGroups(String id, RegistryCallBack callback) {
|
||||||
try {
|
try {
|
||||||
List<String> GroupsActionsTags = new ArrayList<String>() {{
|
List<String> GroupsActionsTags = new ArrayList<String>() {{
|
||||||
add(RegistryTags.ID_TAG + " " + id);
|
add(RegistryTags.ID_TAG + id);
|
||||||
add(RegistryTags.GROUP_ACTION_TAG + " " + RegistryTags.REMOVE_FROM_GROUP_TAG);
|
add(RegistryTags.GROUP_ACTION_TAG .toString() + RegistryTags.REMOVE_FROM_GROUP_TAG);
|
||||||
add(RegistryTags.GROUP_ACTION_TAG + " " + RegistryTags.ADD_TO_GROUP_TAG);
|
add(RegistryTags.GROUP_ACTION_TAG.toString() + RegistryTags.ADD_TO_GROUP_TAG);
|
||||||
}};
|
}};
|
||||||
List<VoterRegistryMessage> voterRegistryMessages = GetRelevantVoterRegistryMessages(GroupsActionsTags);
|
List<VoterRegistryMessage> voterRegistryMessages = GetRelevantVoterRegistryMessages(GroupsActionsTags);
|
||||||
|
|
||||||
|
@ -176,7 +177,7 @@ public class SimpleRegistry implements RegistryInstance{
|
||||||
public void GetPersonIDDetails(String id, RegistryCallBack callback) {
|
public void GetPersonIDDetails(String id, RegistryCallBack callback) {
|
||||||
try {
|
try {
|
||||||
List<String> GroupsActionsTags = new ArrayList<String>() {{
|
List<String> GroupsActionsTags = new ArrayList<String>() {{
|
||||||
add(RegistryTags.ID_TAG + " " + id);
|
add(RegistryTags.ID_TAG + id);
|
||||||
add(RegistryTags.VOTER_ENTRY_TAG.toString());
|
add(RegistryTags.VOTER_ENTRY_TAG.toString());
|
||||||
}};
|
}};
|
||||||
List<VoterRegistryMessage> voterRegistryMessages = GetRelevantVoterRegistryMessages(GroupsActionsTags);
|
List<VoterRegistryMessage> voterRegistryMessages = GetRelevantVoterRegistryMessages(GroupsActionsTags);
|
||||||
|
|
|
@ -17,7 +17,9 @@ public class VoterRegistryMessage {
|
||||||
public BulletinBoardAPI.UnsignedBulletinBoardMessage base;
|
public BulletinBoardAPI.UnsignedBulletinBoardMessage base;
|
||||||
|
|
||||||
public VoterRegistryMessage(BulletinBoardAPI.UnsignedBulletinBoardMessage message) {
|
public VoterRegistryMessage(BulletinBoardAPI.UnsignedBulletinBoardMessage message) {
|
||||||
base = BulletinBoardAPI.UnsignedBulletinBoardMessage.newBuilder().addAllTag(message.getTagList()).build();
|
BulletinBoardAPI.UnsignedBulletinBoardMessage.Builder unsignedBase = BulletinBoardAPI.UnsignedBulletinBoardMessage.newBuilder().addAllTag(message.getTagList());
|
||||||
|
unsignedBase.setData(message.getData());
|
||||||
|
base = unsignedBase.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,7 +74,7 @@ public class VoterRegistryMessage {
|
||||||
*
|
*
|
||||||
* @return List of strings
|
* @return List of strings
|
||||||
*/
|
*/
|
||||||
public List<String> tagsToStringList(){
|
public List<String> tagsToStringList() {
|
||||||
return base.getTagList();
|
return base.getTagList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ public enum RegistryTags {
|
||||||
|
|
||||||
ID_TAG("ID:"),
|
ID_TAG("ID:"),
|
||||||
VOTER_ENTRY_TAG("Voter Entry"),
|
VOTER_ENTRY_TAG("Voter Entry"),
|
||||||
GROUP_ID_TAG("Group ID:"),
|
GROUP_ID_TAG("GroupID:"),
|
||||||
GROUP_ACTION_TAG("Group Action:"),
|
GROUP_ACTION_TAG("Group Action:"),
|
||||||
REMOVE_FROM_GROUP_TAG("Remove From Group"),
|
REMOVE_FROM_GROUP_TAG("Remove From Group"),
|
||||||
ADD_TO_GROUP_TAG("Add To Group"),
|
ADD_TO_GROUP_TAG("Add To Group"),
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class SimpleRegistryCallBackHandler implements RegistryCallBack {
|
||||||
*/
|
*/
|
||||||
public List<String> WantedInformation;
|
public List<String> WantedInformation;
|
||||||
|
|
||||||
public static int counter = 0;
|
public int counter = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void HandleVoterAdded(boolean succeeded) {
|
public void HandleVoterAdded(boolean succeeded) {
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
import meerkat.RegistryCallBack;
|
||||||
import meerkat.SimpleRegistry;
|
import meerkat.SimpleRegistry;
|
||||||
|
import meerkat.VoterRegistryMessage;
|
||||||
import meerkat.bulletinboard.SimpleBulletinBoardClient;
|
import meerkat.bulletinboard.SimpleBulletinBoardClient;
|
||||||
import meerkat.crypto.concrete.ECElGamalEncryption;
|
import meerkat.crypto.concrete.ECElGamalEncryption;
|
||||||
import meerkat.crypto.concrete.ECElGamalUtils;
|
import meerkat.crypto.concrete.ECElGamalUtils;
|
||||||
import meerkat.protobuf.BulletinBoardAPI.*;
|
import meerkat.protobuf.BulletinBoardAPI;
|
||||||
import meerkat.protobuf.ConcreteCrypto;
|
import meerkat.protobuf.ConcreteCrypto;
|
||||||
import meerkat.protobuf.Voting;
|
import meerkat.protobuf.Voting;
|
||||||
import org.factcenter.qilin.primitives.concrete.ECElGamal;
|
import org.factcenter.qilin.primitives.concrete.ECElGamal;
|
||||||
|
@ -11,29 +14,33 @@ import org.factcenter.qilin.primitives.concrete.ECGroup;
|
||||||
import util.RegistryTags;
|
import util.RegistryTags;
|
||||||
import util.SimpleRegistryCallBackHandler;
|
import util.SimpleRegistryCallBackHandler;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
import java.security.SecureRandom;
|
||||||
import java.security.spec.InvalidKeySpecException;
|
import java.security.spec.InvalidKeySpecException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
|
||||||
|
import static util.CollectionMessagesUtils.ConvertToVoterRegistryMessages;
|
||||||
|
import static util.CollectionMessagesUtils.GetUnsignedBulletinBoardMessages;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Vladimir Eliezer Tokarev on 1/16/2016.
|
* Created by Vladimir Eliezer Tokarev on 1/16/2016.
|
||||||
* Tests the Simple Registry contents
|
* Tests the Simple Registry contents
|
||||||
*
|
|
||||||
* NOTE: for most of this tests to pass there should run BulletinBoardServer
|
* NOTE: for most of this tests to pass there should run BulletinBoardServer
|
||||||
* and the sql server and it should be reachable on
|
* that should be reachable on BULLETIN_BOARD_SERVER_ADDRESS
|
||||||
* BULLETIN_BOARD_SERVER_ADDRESS location
|
|
||||||
*/
|
*/
|
||||||
public class SimpleRegistryTest extends TestCase{
|
public class SimpleRegistryTest extends TestCase {
|
||||||
|
|
||||||
private ECElGamalEncryption signatory;
|
private ECElGamalEncryption signatory;
|
||||||
private SimpleBulletinBoardClient communicator;
|
private SimpleBulletinBoardClient communicator;
|
||||||
private static String BULLETIN_BOARD_SERVER_ADDRESS = "http://localhost:3306";
|
private static String BULLETIN_BOARD_SERVER_ADDRESS = "http://localhost:8081";
|
||||||
private Random random = new Random(0); // Insecure deterministic random for testing.
|
private SecureRandom random = new SecureRandom();
|
||||||
private SimpleRegistryCallBackHandler handler;
|
|
||||||
|
|
||||||
private void ElGamalSetup(){
|
/**
|
||||||
|
* Creates the ElGamal encryption object
|
||||||
|
*/
|
||||||
|
private void ElGamalSetup() {
|
||||||
try {
|
try {
|
||||||
ECGroup group = new ECGroup("secp256k1");
|
ECGroup group = new ECGroup("secp256k1");
|
||||||
BigInteger sk = ECElGamal.generateSecretKey(group, random);
|
BigInteger sk = ECElGamal.generateSecretKey(group, random);
|
||||||
|
@ -46,7 +53,10 @@ public class SimpleRegistryTest extends TestCase{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CommunicatorSetup(){
|
/**
|
||||||
|
* Creates the communication object (the bulletinBoardClient)
|
||||||
|
*/
|
||||||
|
private void CommunicatorSetup() {
|
||||||
communicator = new SimpleBulletinBoardClient();
|
communicator = new SimpleBulletinBoardClient();
|
||||||
communicator.init(Voting.BulletinBoardClientParams.newBuilder()
|
communicator.init(Voting.BulletinBoardClientParams.newBuilder()
|
||||||
.addBulletinBoardAddress(BULLETIN_BOARD_SERVER_ADDRESS)
|
.addBulletinBoardAddress(BULLETIN_BOARD_SERVER_ADDRESS)
|
||||||
|
@ -54,95 +64,211 @@ public class SimpleRegistryTest extends TestCase{
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RegistryAnswersHandlerSetup(){
|
|
||||||
handler = new SimpleRegistryCallBackHandler();
|
private SimpleRegistryCallBackHandler RegistryAnswersHandlerSetup() {
|
||||||
|
return new SimpleRegistryCallBackHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize SimpleRegistry object
|
* Initialize SimpleRegistry object
|
||||||
*/
|
*/
|
||||||
public void setUp(){
|
public void setUp() {
|
||||||
ElGamalSetup();
|
ElGamalSetup();
|
||||||
CommunicatorSetup();
|
CommunicatorSetup();
|
||||||
RegistryAnswersHandlerSetup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the creation of the registry have been successful
|
* Checks if the creation of the registry have been successful
|
||||||
*/
|
*/
|
||||||
public void testSimpleRegistryCreation(){
|
public void testSimpleRegistryCreation() {
|
||||||
try {
|
try {
|
||||||
SimpleRegistry registry = new SimpleRegistry(signatory, communicator);
|
new SimpleRegistry(signatory, communicator);
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
assert false : "While creating the SimpleRegistry exception have been thrown " + e;
|
assert false : "While creating the SimpleRegistry exception have been thrown " + e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that add voter creates new correct bulletin board message and adds the voter
|
* Creates list of lists of strings for different testing purposes
|
||||||
|
* @param actionDataNumber number of string in a list
|
||||||
|
* @param numberOfInstances number of lists in a list
|
||||||
|
* @return List<List<String>>
|
||||||
*/
|
*/
|
||||||
public void testAddVoter(){
|
private List<List<String>> getActionsData(int actionDataNumber, int numberOfInstances)
|
||||||
List<String> ids = new ArrayList<>();
|
{
|
||||||
|
System.out.println("- Creating "+ numberOfInstances +" ids and personal data strings for adding different voters.");
|
||||||
|
|
||||||
for (int i = 0 ; i < 10 ; i++ ){
|
List<List<String>> actionData = new ArrayList<>();
|
||||||
ids.add("" + (10000000 + random.nextInt(90000000)));
|
for (int i = 0 ; i < numberOfInstances ; i++ ){
|
||||||
|
List<String> data = new ArrayList<>();
|
||||||
|
for (int j = 0 ; j < actionDataNumber ; j++){
|
||||||
|
data.add(new BigInteger(130, random).toString(32));
|
||||||
|
}
|
||||||
|
actionData.add(data);
|
||||||
|
}
|
||||||
|
return actionData;
|
||||||
}
|
}
|
||||||
SimpleRegistry registry = new SimpleRegistry(signatory, communicator);
|
|
||||||
|
|
||||||
// check that the callbacks have been called and the this been successful
|
/**
|
||||||
for (String id : ids) {
|
* Create Message filter list from list of tags
|
||||||
registry.AddVoter(id, "some personal info", handler);
|
* @param tags list of string with wanted tags
|
||||||
|
* @return MessageFilterList
|
||||||
|
*/
|
||||||
|
private BulletinBoardAPI.MessageFilterList createFiltersFromTags(List<String> tags){
|
||||||
|
if (tags == null){
|
||||||
|
return BulletinBoardAPI.MessageFilterList.newBuilder().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
BulletinBoardAPI.MessageFilterList.Builder filters = BulletinBoardAPI.MessageFilterList.newBuilder();
|
||||||
|
|
||||||
|
for (String tag : tags) {
|
||||||
|
filters.addFilter(BulletinBoardAPI.MessageFilter.newBuilder()
|
||||||
|
.setTag(tag).setType(BulletinBoardAPI.FilterType.TAG));
|
||||||
|
}
|
||||||
|
|
||||||
|
return filters.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Counts the amount of posted messaages that have their tags in voterData
|
||||||
|
* @param votersData List<List<String>> of information about voters (tags etc...)
|
||||||
|
* @param tags List<String> of tags
|
||||||
|
* @return int
|
||||||
|
* @throws InvalidProtocolBufferException
|
||||||
|
*/
|
||||||
|
private int countActualAddedMessages(List<List<String>> votersData, List<String> tags) throws InvalidProtocolBufferException {
|
||||||
|
System.out.println("- Check that the server have the new voters data:");
|
||||||
|
|
||||||
|
BulletinBoardAPI.MessageFilterList filters = createFiltersFromTags(tags);
|
||||||
|
List<VoterRegistryMessage> messages =
|
||||||
|
ConvertToVoterRegistryMessages(GetUnsignedBulletinBoardMessages(communicator.readMessages(filters)));
|
||||||
|
|
||||||
|
System.out.println(messages.size() + " asdasasdasdasasasdaasddas");
|
||||||
|
|
||||||
|
int addedMessagesCounter = 0;
|
||||||
|
|
||||||
|
for (List<String> voterData : votersData) {
|
||||||
|
for (VoterRegistryMessage message : messages) {
|
||||||
|
String addedVoterId = message.GetWantedTagFromBasicMessage(RegistryTags.ID_TAG);
|
||||||
|
String addedVoterData = new String(message.base.getData().toByteArray());
|
||||||
|
|
||||||
|
if (voterData.size() == 2 && addedVoterId.contains(voterData.get(0)) && addedVoterData.contains(voterData.get(1))) {
|
||||||
|
addedMessagesCounter++;
|
||||||
|
}
|
||||||
|
else if (addedVoterId.contains(voterData.get(0)) ){
|
||||||
|
addedMessagesCounter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return addedMessagesCounter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call methodToCheck voterData as list of params
|
||||||
|
* @param methodToCheck the name of the wanted method
|
||||||
|
* @param numberOfParamsWithoutHandler the amount of params to pass to the wanted method
|
||||||
|
* @param handler object which method will be called as callback from SimpleRegistry
|
||||||
|
* @param registry the simpleRegistry object
|
||||||
|
* @param voterData List of string which is the params to pass to the wantedMethod
|
||||||
|
*/
|
||||||
|
private void CallWantedMethod(String methodToCheck, int numberOfParamsWithoutHandler,
|
||||||
|
SimpleRegistryCallBackHandler handler, SimpleRegistry registry,
|
||||||
|
List<String> voterData) {
|
||||||
|
try {
|
||||||
|
if (numberOfParamsWithoutHandler == 1)
|
||||||
|
{
|
||||||
|
java.lang.reflect.Method method =
|
||||||
|
registry.getClass().getMethod(methodToCheck,String.class, RegistryCallBack.class);
|
||||||
|
method.invoke(registry, voterData.get(0), handler);
|
||||||
|
assertTrue(handler.ActionSucceed);
|
||||||
|
}else {
|
||||||
|
java.lang.reflect.Method method =
|
||||||
|
registry.getClass().getMethod( methodToCheck, String.class, String.class, RegistryCallBack.class);
|
||||||
|
method.invoke(registry, voterData.get(0), voterData.get(1), handler);
|
||||||
assertTrue(handler.ActionSucceed);
|
assertTrue(handler.ActionSucceed);
|
||||||
}
|
}
|
||||||
|
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||||
// check that the callbacks have been called exactly 10 times
|
e.printStackTrace();
|
||||||
assertEquals(10, SimpleRegistryCallBackHandler.counter);
|
|
||||||
|
|
||||||
|
|
||||||
// check that the server have the new voters data
|
|
||||||
for (String id : ids){
|
|
||||||
MessageFilterList.Builder filters = MessageFilterList.newBuilder()
|
|
||||||
.addFilter(MessageFilter.newBuilder().setTag(RegistryTags.ID_TAG + " " + id))
|
|
||||||
.addFilter(MessageFilter.newBuilder().setTag(RegistryTags.VOTER_ENTRY_TAG.toString()));
|
|
||||||
|
|
||||||
List<BulletinBoardMessage> messages = communicator.readMessages(filters.build());
|
|
||||||
assertTrue(messages != null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates new Registry information then sends it to the server then checks the server
|
||||||
|
* have all sent data
|
||||||
|
* @param methodToCheck the name of the method we want to call in SimpleRegistry
|
||||||
|
* @param numberOfParamsToPass the number of params to pass to the methodToCheck
|
||||||
|
* @param numberOfChecks the amount of checks to run
|
||||||
|
* @param tags list of String that represent the tags to filter on the messages
|
||||||
|
* @throws InvalidProtocolBufferException
|
||||||
|
*/
|
||||||
|
private void checkMessagesPostedSuccessfully(String methodToCheck, int numberOfParamsToPass, int numberOfChecks, List<String> tags) throws InvalidProtocolBufferException {
|
||||||
|
SimpleRegistryCallBackHandler handler = RegistryAnswersHandlerSetup();
|
||||||
|
System.out.println("Starting testing the " + methodToCheck + " capability.");
|
||||||
|
List<List<String>> votersData = getActionsData(numberOfParamsToPass, numberOfChecks);
|
||||||
|
|
||||||
|
SimpleRegistry registry = new SimpleRegistry(signatory, communicator);
|
||||||
|
|
||||||
|
System.out.println("- Check that all the callbacks have been called successfully after voters adding:");
|
||||||
|
for (List<String> voterData : votersData) {
|
||||||
|
CallWantedMethod(methodToCheck, numberOfParamsToPass, handler, registry, voterData);
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("- Check that for every voter added, the callback have been called:");
|
||||||
|
assertEquals(numberOfChecks, handler.counter);
|
||||||
|
int addedMessagesCounter = countActualAddedMessages(votersData, tags);
|
||||||
|
|
||||||
|
assert addedMessagesCounter == numberOfChecks : "The number of added messages actually is " + addedMessagesCounter;
|
||||||
|
System.out.println("Ended addVoter testing.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that add voter creates new correct bulletin board message and adds the voter
|
||||||
|
*/
|
||||||
|
public void testAddVoter() throws InvalidProtocolBufferException {
|
||||||
|
checkMessagesPostedSuccessfully("AddVoter", 2, 3,
|
||||||
|
new ArrayList<String>(){{add(RegistryTags.VOTER_ENTRY_TAG.toString());}});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that set voted posts creates correct bulletin board message and sets that the user have been voted
|
* Test that set voted posts creates correct bulletin board message and sets that the user have been voted
|
||||||
*/
|
*/
|
||||||
public void testSetVoted(){
|
public void testSetVoted() throws InvalidProtocolBufferException {
|
||||||
assertEquals(null, null);
|
checkMessagesPostedSuccessfully("SetVoted", 1, 3,
|
||||||
|
new ArrayList<String>(){{add(RegistryTags.VOTE_ACTION_TAG.toString());}});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that add to group creates correct bulletin board message and adds a user to a group
|
* Test that add to group creates correct bulletin board message and adds a user to a group
|
||||||
*/
|
*/
|
||||||
public void testAddToGroup(){
|
public void testRemoveFromGroup() throws InvalidProtocolBufferException {
|
||||||
assertEquals(null, null);
|
checkMessagesPostedSuccessfully("RemoveFromGroup", 2, 3, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that remove from group creates correct bulletin board message and removes the user from a group
|
* Test that remove from group creates correct bulletin board message and removes the user from a group
|
||||||
*/
|
*/
|
||||||
public void testRemoveFromGroup(){
|
public void testGetGroups() {
|
||||||
assertEquals(null, null);
|
// print start of gorups testing
|
||||||
|
// Create Registry check creation
|
||||||
|
// Add to X groups remove y group and z group
|
||||||
|
// for every action check that it happened
|
||||||
|
// count the number of callback activated
|
||||||
|
// get the relevant groups
|
||||||
|
// check they are right
|
||||||
|
// print and of groups
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that get groups retrieves the right groups the user are in
|
* Test that get groups retrieves the right groups the user are in
|
||||||
*/
|
*/
|
||||||
public void testGetGroups(){
|
public void testAddToGroup() throws InvalidProtocolBufferException {
|
||||||
assertEquals(null, null);
|
checkMessagesPostedSuccessfully("AddToGroup", 2, 3, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that the personal data outputted about the user is right
|
* Test that the personal data outputted about the user is right
|
||||||
*/
|
*/
|
||||||
public void testGetPersonalIDDetails(){
|
public void testGetPersonalIDDetails() {
|
||||||
assertEquals(null, null);
|
assertEquals(1, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue