Change part of the code (java 8 usage) for gralde to be able to run the test and not fail.

Voter-Registry
Vladimir Eliezer Tokarev 2016-02-26 05:52:03 -08:00
parent 230dfe6d3f
commit 64a9356dc2
4 changed files with 30 additions and 19 deletions

Binary file not shown.

View File

@ -7,11 +7,7 @@ import meerkat.protobuf.BulletinBoardAPI.MessageFilter;
import meerkat.protobuf.BulletinBoardAPI.MessageFilterList;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.*;
/**
* TODO: add logging to this utils
@ -34,9 +30,13 @@ public abstract class CollectionMessagesUtils {
* @param messages list<VoterRegistryMessage>
* @return List<VoterRegistryMessage>
*/
public static List<VoterRegistryMessage> ConvertToVoterRegistryMessages(
List<BulletinBoardMessage> messages){
return messages.stream().map(VoterRegistryMessage::new).collect(Collectors.toList());
public static List<VoterRegistryMessage> ConvertToVoterRegistryMessages(List<BulletinBoardMessage> messages){
List<VoterRegistryMessage> voterMessages = new ArrayList<>();
for (int i = 0 ; i < messages.size() ; i++)
{
voterMessages.add(new VoterRegistryMessage(messages.get(i)));
}
return voterMessages;
}
/**
@ -71,11 +71,13 @@ public abstract class CollectionMessagesUtils {
*/
public static List<String> GetListOfGroupIds(Map<String, VoterRegistryMessage> groupIdToMessage) {
List<String> groupsIds = new ArrayList<>();
groupIdToMessage.values().stream().filter(VoterRegistryMessage::IsGroupAdding).forEach(message -> {
Iterator entries = groupIdToMessage.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry tuple = (Map.Entry) entries.next();
VoterRegistryMessage message = (VoterRegistryMessage) tuple.getValue();
String groupId = message.GetWantedTagFromBasicMessage(RegistryTags.GROUP_ID_TAG.toString());
groupsIds.add(groupId);
});
}
return groupsIds;
}

View File

@ -79,6 +79,7 @@ public class RelevantDataCallBack implements ClientCallback<List<BulletinBoardMe
public void handleCallback(List<BulletinBoardMessage> msg) {
try {
List<VoterRegistryMessage> messages = ConvertToVoterRegistryMessages(validate(msg));
if(isAddToGroupsList(msg)) {
Map<String, VoterRegistryMessage> map = GetLatestGroupsActions(messages);
List<String> groupsOfUser = GetListOfGroupIds(map);

View File

@ -2,15 +2,17 @@ import com.google.protobuf.InvalidProtocolBufferException;
import junit.framework.TestCase;
import meerkat.Registry.CollectionMessagesUtils;
import meerkat.Registry.RegistryTags;
import meerkat.VoterRegistry;
import meerkat.SimpleRegistry;
import meerkat.protobuf.VoterRegistry.*;
import meerkat.VoterRegistryMessage;
import meerkat.bulletinboard.BulletinBoardClient;
import meerkat.bulletinboard.ThreadedBulletinBoardClient;
import meerkat.crypto.concrete.ECDSASignature;
import meerkat.protobuf.BulletinBoardAPI.BulletinBoardMessage;
import meerkat.protobuf.BulletinBoardAPI.MessageFilterList;
import meerkat.protobuf.VoterRegistry.GroupID;
import meerkat.protobuf.VoterRegistry.VoterGroup;
import meerkat.protobuf.VoterRegistry.VoterID;
import meerkat.protobuf.VoterRegistry.VoterInfo;
import meerkat.protobuf.Voting;
import java.io.InputStream;
@ -45,7 +47,7 @@ public class SimpleRegistryTest extends TestCase {
public static String KEYFILE_PASSWORD = "secret";
Semaphore jobSemaphore;
class DummyRegistryCallBackHandler<T> implements VoterRegistry.RegistryCallBack<T>{
class DummyRegistryCallBackHandler<T> implements meerkat.VoterRegistry.RegistryCallBack<T>{
public int counter;
public T data;
@ -167,7 +169,8 @@ public class SimpleRegistryTest extends TestCase {
String id = new BigInteger(130, random).toString(32);
String data = new BigInteger(130, random).toString(32);
VoterInfo voterInfo = VoterInfo.newBuilder().setId(VoterID.newBuilder().setId(id)).setInfo(data).build();
VoterInfo voterInfo = VoterInfo.newBuilder().
setId(VoterID.newBuilder().setId(id)).setInfo(data).build();
SimpleRegistry registry = new SimpleRegistry(signer, bulletinBoardClient, certStream);
registry.AddVoter(voterInfo, handler);
@ -223,7 +226,8 @@ public class SimpleRegistryTest extends TestCase {
String voterId = new BigInteger(130, random).toString(32);
String groupId = new BigInteger(130, random).toString(32);
VoterGroup voterInfo = VoterGroup.newBuilder().setVoterId(VoterID.newBuilder().setId(voterId))
VoterGroup voterInfo = VoterGroup.newBuilder()
.setVoterId(VoterID.newBuilder().setId(voterId))
.setGroupId(GroupID.newBuilder().setId(groupId)).build();
SimpleRegistry registry = new SimpleRegistry(signer, bulletinBoardClient, certStream);
@ -256,7 +260,8 @@ public class SimpleRegistryTest extends TestCase {
String voterId = new BigInteger(130, random).toString(32);
String groupId = new BigInteger(130, random).toString(32);
VoterGroup voterInfo = VoterGroup.newBuilder().setVoterId(VoterID.newBuilder().setId(voterId))
VoterGroup voterInfo = VoterGroup.newBuilder()
.setVoterId(VoterID.newBuilder().setId(voterId))
.setGroupId(GroupID.newBuilder().setId(groupId)).build();
this.certStream = getClass().getResourceAsStream(CERT1_PEM_EXAMPLE);
@ -285,7 +290,8 @@ public class SimpleRegistryTest extends TestCase {
String id = new BigInteger(130, random).toString(32);
String data = new BigInteger(130, random).toString(32);
VoterInfo voterInfo = VoterInfo.newBuilder().setId(VoterID.newBuilder().setId(id)).setInfo(data).build();
VoterInfo voterInfo = VoterInfo.newBuilder().
setId(VoterID.newBuilder().setId(id)).setInfo(data).build();
SimpleRegistry registry = new SimpleRegistry(signer, bulletinBoardClient, certStream);
registry.AddVoter(voterInfo, handler);
@ -296,9 +302,11 @@ public class SimpleRegistryTest extends TestCase {
DummyRegistryCallBackHandler<VoterRegistryMessage> personalHandler = new DummyRegistryCallBackHandler<>();
registry.GetPersonIDDetails(VoterID.newBuilder().setId(id).build(), personalHandler);
jobSemaphore.acquire();
jobSemaphore.acquire(1);
assertEquals(RegistryTags.ID_TAG + id,
personalHandler.data.GetWantedTagFromBasicMessage(RegistryTags.ID_TAG.toString()));
assertEquals(data,personalHandler.data.base.getData().toStringUtf8());
}
}