Change part of the code (java 8 usage) for gralde to be able to run the test and not fail.
parent
230dfe6d3f
commit
64a9356dc2
Binary file not shown.
|
@ -7,11 +7,7 @@ import meerkat.protobuf.BulletinBoardAPI.MessageFilter;
|
||||||
import meerkat.protobuf.BulletinBoardAPI.MessageFilterList;
|
import meerkat.protobuf.BulletinBoardAPI.MessageFilterList;
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: add logging to this utils
|
* TODO: add logging to this utils
|
||||||
|
@ -34,9 +30,13 @@ public abstract class CollectionMessagesUtils {
|
||||||
* @param messages list<VoterRegistryMessage>
|
* @param messages list<VoterRegistryMessage>
|
||||||
* @return List<VoterRegistryMessage>
|
* @return List<VoterRegistryMessage>
|
||||||
*/
|
*/
|
||||||
public static List<VoterRegistryMessage> ConvertToVoterRegistryMessages(
|
public static List<VoterRegistryMessage> ConvertToVoterRegistryMessages(List<BulletinBoardMessage> messages){
|
||||||
List<BulletinBoardMessage> messages){
|
List<VoterRegistryMessage> voterMessages = new ArrayList<>();
|
||||||
return messages.stream().map(VoterRegistryMessage::new).collect(Collectors.toList());
|
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) {
|
public static List<String> GetListOfGroupIds(Map<String, VoterRegistryMessage> groupIdToMessage) {
|
||||||
List<String> groupsIds = new ArrayList<>();
|
List<String> groupsIds = new ArrayList<>();
|
||||||
|
Iterator entries = groupIdToMessage.entrySet().iterator();
|
||||||
groupIdToMessage.values().stream().filter(VoterRegistryMessage::IsGroupAdding).forEach(message -> {
|
while (entries.hasNext()) {
|
||||||
|
Map.Entry tuple = (Map.Entry) entries.next();
|
||||||
|
VoterRegistryMessage message = (VoterRegistryMessage) tuple.getValue();
|
||||||
String groupId = message.GetWantedTagFromBasicMessage(RegistryTags.GROUP_ID_TAG.toString());
|
String groupId = message.GetWantedTagFromBasicMessage(RegistryTags.GROUP_ID_TAG.toString());
|
||||||
groupsIds.add(groupId);
|
groupsIds.add(groupId);
|
||||||
});
|
}
|
||||||
return groupsIds;
|
return groupsIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,6 +79,7 @@ public class RelevantDataCallBack implements ClientCallback<List<BulletinBoardMe
|
||||||
public void handleCallback(List<BulletinBoardMessage> msg) {
|
public void handleCallback(List<BulletinBoardMessage> msg) {
|
||||||
try {
|
try {
|
||||||
List<VoterRegistryMessage> messages = ConvertToVoterRegistryMessages(validate(msg));
|
List<VoterRegistryMessage> messages = ConvertToVoterRegistryMessages(validate(msg));
|
||||||
|
|
||||||
if(isAddToGroupsList(msg)) {
|
if(isAddToGroupsList(msg)) {
|
||||||
Map<String, VoterRegistryMessage> map = GetLatestGroupsActions(messages);
|
Map<String, VoterRegistryMessage> map = GetLatestGroupsActions(messages);
|
||||||
List<String> groupsOfUser = GetListOfGroupIds(map);
|
List<String> groupsOfUser = GetListOfGroupIds(map);
|
||||||
|
|
|
@ -2,15 +2,17 @@ import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import meerkat.Registry.CollectionMessagesUtils;
|
import meerkat.Registry.CollectionMessagesUtils;
|
||||||
import meerkat.Registry.RegistryTags;
|
import meerkat.Registry.RegistryTags;
|
||||||
import meerkat.VoterRegistry;
|
|
||||||
import meerkat.SimpleRegistry;
|
import meerkat.SimpleRegistry;
|
||||||
import meerkat.protobuf.VoterRegistry.*;
|
|
||||||
import meerkat.VoterRegistryMessage;
|
import meerkat.VoterRegistryMessage;
|
||||||
import meerkat.bulletinboard.BulletinBoardClient;
|
import meerkat.bulletinboard.BulletinBoardClient;
|
||||||
import meerkat.bulletinboard.ThreadedBulletinBoardClient;
|
import meerkat.bulletinboard.ThreadedBulletinBoardClient;
|
||||||
import meerkat.crypto.concrete.ECDSASignature;
|
import meerkat.crypto.concrete.ECDSASignature;
|
||||||
import meerkat.protobuf.BulletinBoardAPI.BulletinBoardMessage;
|
import meerkat.protobuf.BulletinBoardAPI.BulletinBoardMessage;
|
||||||
import meerkat.protobuf.BulletinBoardAPI.MessageFilterList;
|
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 meerkat.protobuf.Voting;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -45,7 +47,7 @@ public class SimpleRegistryTest extends TestCase {
|
||||||
public static String KEYFILE_PASSWORD = "secret";
|
public static String KEYFILE_PASSWORD = "secret";
|
||||||
Semaphore jobSemaphore;
|
Semaphore jobSemaphore;
|
||||||
|
|
||||||
class DummyRegistryCallBackHandler<T> implements VoterRegistry.RegistryCallBack<T>{
|
class DummyRegistryCallBackHandler<T> implements meerkat.VoterRegistry.RegistryCallBack<T>{
|
||||||
public int counter;
|
public int counter;
|
||||||
public T data;
|
public T data;
|
||||||
|
|
||||||
|
@ -167,7 +169,8 @@ public class SimpleRegistryTest extends TestCase {
|
||||||
|
|
||||||
String id = new BigInteger(130, random).toString(32);
|
String id = new BigInteger(130, random).toString(32);
|
||||||
String data = 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);
|
SimpleRegistry registry = new SimpleRegistry(signer, bulletinBoardClient, certStream);
|
||||||
registry.AddVoter(voterInfo, handler);
|
registry.AddVoter(voterInfo, handler);
|
||||||
|
@ -223,7 +226,8 @@ public class SimpleRegistryTest extends TestCase {
|
||||||
|
|
||||||
String voterId = new BigInteger(130, random).toString(32);
|
String voterId = new BigInteger(130, random).toString(32);
|
||||||
String groupId = 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();
|
.setGroupId(GroupID.newBuilder().setId(groupId)).build();
|
||||||
|
|
||||||
SimpleRegistry registry = new SimpleRegistry(signer, bulletinBoardClient, certStream);
|
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 voterId = new BigInteger(130, random).toString(32);
|
||||||
String groupId = 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();
|
.setGroupId(GroupID.newBuilder().setId(groupId)).build();
|
||||||
|
|
||||||
this.certStream = getClass().getResourceAsStream(CERT1_PEM_EXAMPLE);
|
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 id = new BigInteger(130, random).toString(32);
|
||||||
String data = 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);
|
SimpleRegistry registry = new SimpleRegistry(signer, bulletinBoardClient, certStream);
|
||||||
registry.AddVoter(voterInfo, handler);
|
registry.AddVoter(voterInfo, handler);
|
||||||
|
@ -296,9 +302,11 @@ public class SimpleRegistryTest extends TestCase {
|
||||||
DummyRegistryCallBackHandler<VoterRegistryMessage> personalHandler = new DummyRegistryCallBackHandler<>();
|
DummyRegistryCallBackHandler<VoterRegistryMessage> personalHandler = new DummyRegistryCallBackHandler<>();
|
||||||
registry.GetPersonIDDetails(VoterID.newBuilder().setId(id).build(), personalHandler);
|
registry.GetPersonIDDetails(VoterID.newBuilder().setId(id).build(), personalHandler);
|
||||||
|
|
||||||
jobSemaphore.acquire();
|
|
||||||
|
jobSemaphore.acquire(1);
|
||||||
assertEquals(RegistryTags.ID_TAG + id,
|
assertEquals(RegistryTags.ID_TAG + id,
|
||||||
personalHandler.data.GetWantedTagFromBasicMessage(RegistryTags.ID_TAG.toString()));
|
personalHandler.data.GetWantedTagFromBasicMessage(RegistryTags.ID_TAG.toString()));
|
||||||
assertEquals(data,personalHandler.data.base.getData().toStringUtf8());
|
assertEquals(data,personalHandler.data.base.getData().toStringUtf8());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue