Changed the simple voter registry tests (all passes) to the new strcutrue of the registry
parent
3347a6c42d
commit
6ec0d4a668
|
@ -31,7 +31,13 @@ public class RelevantDataCallBack implements BulletinBoardClient.ClientCallback<
|
||||||
* @return true if the messages are with GROUP_ID_TAG tags
|
* @return true if the messages are with GROUP_ID_TAG tags
|
||||||
*/
|
*/
|
||||||
private boolean isAddToGroupsList(List<BulletinBoardAPI.BulletinBoardMessage> msg) {
|
private boolean isAddToGroupsList(List<BulletinBoardAPI.BulletinBoardMessage> msg) {
|
||||||
return msg.get(0).getMsg().getTagList().get(0).contains(RegistryTags.GROUP_ID_TAG.toString());
|
for (String tag : msg.get(0).getMsg().getTagList()) {
|
||||||
|
if(tag.contains(RegistryTags.GROUP_ID_TAG.toString()))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,7 +54,8 @@ public class RelevantDataCallBack implements BulletinBoardClient.ClientCallback<
|
||||||
if(isAddToGroupsList(msg)){
|
if(isAddToGroupsList(msg)){
|
||||||
try {
|
try {
|
||||||
Map<String, VoterRegistryMessage> map = GetLatestGroupsActions(messages);
|
Map<String, VoterRegistryMessage> map = GetLatestGroupsActions(messages);
|
||||||
callback.HandleResult(GetListOfGroupIds(map));
|
List<String> groupsOfUser = GetListOfGroupIds(map);
|
||||||
|
callback.HandleResult(groupsOfUser);
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
callback.HandleResult(null);
|
callback.HandleResult(null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ public abstract class CollectionMessagesUtils {
|
||||||
|
|
||||||
// iterate trough all the messages and put into the map the last updated groups actions
|
// iterate trough all the messages and put into the map the last updated groups actions
|
||||||
for (VoterRegistryMessage message : messages) {
|
for (VoterRegistryMessage message : messages) {
|
||||||
String groupId = message.GetWantedTagFromBasicMessage(RegistryTags.GROUP_ID_TAG);
|
String groupId = message.GetWantedTagFromBasicMessage(RegistryTags.GROUP_ID_TAG.toString());
|
||||||
VoterRegistryMessage temp = groupIdToMessage.get(groupId);
|
VoterRegistryMessage temp = groupIdToMessage.get(groupId);
|
||||||
|
|
||||||
if (temp != null && temp != message) {
|
if (temp != null && temp != message) {
|
||||||
|
@ -59,7 +59,7 @@ public abstract class CollectionMessagesUtils {
|
||||||
List<String> groupsIds = new ArrayList<>();
|
List<String> groupsIds = new ArrayList<>();
|
||||||
|
|
||||||
groupIdToMessage.values().stream().filter(VoterRegistryMessage::IsGroupAdding).forEach(message -> {
|
groupIdToMessage.values().stream().filter(VoterRegistryMessage::IsGroupAdding).forEach(message -> {
|
||||||
String groupId = message.GetWantedTagFromBasicMessage(RegistryTags.GROUP_ID_TAG);
|
String groupId = message.GetWantedTagFromBasicMessage(RegistryTags.GROUP_ID_TAG.toString());
|
||||||
groupsIds.add(groupId);
|
groupsIds.add(groupId);
|
||||||
});
|
});
|
||||||
return groupsIds;
|
return groupsIds;
|
||||||
|
|
|
@ -22,8 +22,7 @@ import java.util.concurrent.Semaphore;
|
||||||
import static util.CollectionMessagesUtils.ConvertToVoterRegistryMessages;
|
import static util.CollectionMessagesUtils.ConvertToVoterRegistryMessages;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Have to do more relevant prints (print what happens)
|
* TODO: add logs prints for the tests to be clear what they are
|
||||||
* TODO: repair all the other methods
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,10 +69,9 @@ public class SimpleRegistryTest extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleFailure(Throwable t) throws Throwable {
|
public void handleFailure(Throwable t){
|
||||||
messages = null;
|
messages = null;
|
||||||
jobSemaphore.release();
|
jobSemaphore.release();
|
||||||
throw t;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,9 +140,9 @@ public class SimpleRegistryTest extends TestCase {
|
||||||
int wantedTagsCounter = 0;
|
int wantedTagsCounter = 0;
|
||||||
|
|
||||||
for (String tag : tags) {
|
for (String tag : tags) {
|
||||||
if(message.GetWantedTagFromBasicMessage(tag)!=null){
|
if(message.GetWantedTagFromBasicMessage(tag)!=null){
|
||||||
wantedTagsCounter++;
|
wantedTagsCounter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(wantedTagsCounter == tags.size())
|
if(wantedTagsCounter == tags.size())
|
||||||
|
@ -162,16 +160,16 @@ public class SimpleRegistryTest extends TestCase {
|
||||||
public void testAddVoter() throws InvalidProtocolBufferException, InterruptedException {
|
public void testAddVoter() throws InvalidProtocolBufferException, InterruptedException {
|
||||||
DummyRegistryCallBackHandler<Boolean> handler = new DummyRegistryCallBackHandler<>();
|
DummyRegistryCallBackHandler<Boolean> handler = new DummyRegistryCallBackHandler<>();
|
||||||
|
|
||||||
|
String id = new BigInteger(130, random).toString(32);
|
||||||
|
String data = new BigInteger(130, random).toString(32);
|
||||||
RegistryMessages.VoterInfo voterInfo = RegistryMessages.VoterInfo.newBuilder().
|
RegistryMessages.VoterInfo voterInfo = RegistryMessages.VoterInfo.newBuilder().
|
||||||
setId(RegistryMessages.VoterID.newBuilder()
|
setId(RegistryMessages.VoterID.newBuilder().setId(id)).setInfo(data).build();
|
||||||
.setId(new BigInteger(130, random).toString(32)))
|
|
||||||
.setInfo(new BigInteger(130, random).toString(32)).build();
|
|
||||||
|
|
||||||
SimpleRegistry registry = new SimpleRegistry(signer, communicator);
|
SimpleRegistry registry = new SimpleRegistry(signer, communicator);
|
||||||
registry.AddVoter(voterInfo, handler);
|
registry.AddVoter(voterInfo, handler);
|
||||||
|
|
||||||
jobSemaphore.acquire();
|
jobSemaphore.acquire();
|
||||||
assertEquals(handler.counter , 1);
|
assertEquals(1, handler.counter );
|
||||||
|
|
||||||
List<String> tags = new ArrayList<String>(){{ add(RegistryTags.VOTER_ENTRY_TAG.toString());}};
|
List<String> tags = new ArrayList<String>(){{ add(RegistryTags.VOTER_ENTRY_TAG.toString());}};
|
||||||
BulletinBoardAPI.MessageFilterList filters = registry.GetRelevantMessagesFilters(tags);
|
BulletinBoardAPI.MessageFilterList filters = registry.GetRelevantMessagesFilters(tags);
|
||||||
|
@ -180,6 +178,8 @@ public class SimpleRegistryTest extends TestCase {
|
||||||
|
|
||||||
jobSemaphore.acquire();
|
jobSemaphore.acquire();
|
||||||
|
|
||||||
|
tags.add(id);
|
||||||
|
|
||||||
int counter = countMessagesWithTags(ConvertToVoterRegistryMessages(bulletinHandler.messages), tags);
|
int counter = countMessagesWithTags(ConvertToVoterRegistryMessages(bulletinHandler.messages), tags);
|
||||||
assert counter == 1 : "The server don't have the new user data.";
|
assert counter == 1 : "The server don't have the new user data.";
|
||||||
}
|
}
|
||||||
|
@ -190,15 +190,14 @@ public class SimpleRegistryTest extends TestCase {
|
||||||
public void testSetVoted() throws InvalidProtocolBufferException, InterruptedException {
|
public void testSetVoted() throws InvalidProtocolBufferException, InterruptedException {
|
||||||
DummyRegistryCallBackHandler<Boolean> handler = new DummyRegistryCallBackHandler<>();
|
DummyRegistryCallBackHandler<Boolean> handler = new DummyRegistryCallBackHandler<>();
|
||||||
|
|
||||||
RegistryMessages.VoterID voterInfo = RegistryMessages.VoterID.newBuilder()
|
String id = new BigInteger(130, random).toString(32);
|
||||||
.setId(new BigInteger(130, random).toString(32)).build();
|
RegistryMessages.VoterID voterInfo = RegistryMessages.VoterID.newBuilder().setId(id).build();
|
||||||
|
|
||||||
SimpleRegistry registry = new SimpleRegistry(signer, communicator);
|
SimpleRegistry registry = new SimpleRegistry(signer, communicator);
|
||||||
registry.SetVoted(voterInfo, handler);
|
registry.SetVoted(voterInfo, handler);
|
||||||
|
|
||||||
jobSemaphore.acquire();
|
jobSemaphore.acquire();
|
||||||
|
assertEquals(1, handler.counter );
|
||||||
assertEquals(handler.counter , 0);
|
|
||||||
|
|
||||||
List<String> tags = new ArrayList<String>(){{ add(RegistryTags.VOTE_ACTION_TAG.toString());}};
|
List<String> tags = new ArrayList<String>(){{ add(RegistryTags.VOTE_ACTION_TAG.toString());}};
|
||||||
BulletinBoardAPI.MessageFilterList filters = registry.GetRelevantMessagesFilters(tags);
|
BulletinBoardAPI.MessageFilterList filters = registry.GetRelevantMessagesFilters(tags);
|
||||||
|
@ -207,6 +206,7 @@ public class SimpleRegistryTest extends TestCase {
|
||||||
|
|
||||||
jobSemaphore.acquire();
|
jobSemaphore.acquire();
|
||||||
|
|
||||||
|
tags.add(id);
|
||||||
int counter = countMessagesWithTags(ConvertToVoterRegistryMessages(bulletinHandler.messages), tags);
|
int counter = countMessagesWithTags(ConvertToVoterRegistryMessages(bulletinHandler.messages), tags);
|
||||||
assert counter == 1 : "The server don't have the new user id.";
|
assert counter == 1 : "The server don't have the new user id.";
|
||||||
}
|
}
|
||||||
|
@ -217,18 +217,17 @@ public class SimpleRegistryTest extends TestCase {
|
||||||
public void testAddToGroup() throws InvalidProtocolBufferException, InterruptedException {
|
public void testAddToGroup() throws InvalidProtocolBufferException, InterruptedException {
|
||||||
DummyRegistryCallBackHandler<Boolean> handler = new DummyRegistryCallBackHandler<>();
|
DummyRegistryCallBackHandler<Boolean> handler = new DummyRegistryCallBackHandler<>();
|
||||||
|
|
||||||
|
String voterId = new BigInteger(130, random).toString(32);
|
||||||
|
String groupId = new BigInteger(130, random).toString(32);
|
||||||
RegistryMessages.VoterGroup voterInfo = RegistryMessages.VoterGroup.newBuilder()
|
RegistryMessages.VoterGroup voterInfo = RegistryMessages.VoterGroup.newBuilder()
|
||||||
.setVoterId(RegistryMessages.VoterID.newBuilder()
|
.setVoterId(RegistryMessages.VoterID.newBuilder().setId(voterId))
|
||||||
.setId((new BigInteger(130, random).toString(32))))
|
.setGroupId(RegistryMessages.GroupID.newBuilder().setId(groupId)).build();
|
||||||
.setGroupId(RegistryMessages.GroupID.newBuilder()
|
|
||||||
.setId((new BigInteger(130, random).toString(32)))).build();
|
|
||||||
|
|
||||||
SimpleRegistry registry = new SimpleRegistry(signer, communicator);
|
SimpleRegistry registry = new SimpleRegistry(signer, communicator);
|
||||||
registry.AddToGroup(voterInfo, handler);
|
registry.AddToGroup(voterInfo, handler);
|
||||||
|
|
||||||
jobSemaphore.acquire();
|
jobSemaphore.acquire();
|
||||||
|
assertEquals(1, handler.counter);
|
||||||
assertEquals(handler.counter , 0);
|
|
||||||
|
|
||||||
List<String> tags = new ArrayList<String>(){{ add(RegistryTags.GROUP_ACTION_TAG .toString()
|
List<String> tags = new ArrayList<String>(){{ add(RegistryTags.GROUP_ACTION_TAG .toString()
|
||||||
+ RegistryTags.ADD_TO_GROUP_TAG.toString());}};
|
+ RegistryTags.ADD_TO_GROUP_TAG.toString());}};
|
||||||
|
@ -238,6 +237,9 @@ public class SimpleRegistryTest extends TestCase {
|
||||||
|
|
||||||
jobSemaphore.acquire();
|
jobSemaphore.acquire();
|
||||||
|
|
||||||
|
tags.add(voterId);
|
||||||
|
tags.add(groupId);
|
||||||
|
|
||||||
int counter = countMessagesWithTags(ConvertToVoterRegistryMessages(bulletinHandler.messages), tags);
|
int counter = countMessagesWithTags(ConvertToVoterRegistryMessages(bulletinHandler.messages), tags);
|
||||||
assert counter == 1 : "The server don't have the new user added to group.";
|
assert counter == 1 : "The server don't have the new user added to group.";
|
||||||
}
|
}
|
||||||
|
@ -249,33 +251,27 @@ public class SimpleRegistryTest extends TestCase {
|
||||||
DummyRegistryCallBackHandler<List<BulletinBoardAPI.BulletinBoardMessage>> handler =
|
DummyRegistryCallBackHandler<List<BulletinBoardAPI.BulletinBoardMessage>> handler =
|
||||||
new DummyRegistryCallBackHandler<>();
|
new DummyRegistryCallBackHandler<>();
|
||||||
|
|
||||||
|
String voterId = new BigInteger(130, random).toString(32);
|
||||||
|
String groupId = new BigInteger(130, random).toString(32);
|
||||||
RegistryMessages.VoterGroup voterInfo = RegistryMessages.VoterGroup.newBuilder()
|
RegistryMessages.VoterGroup voterInfo = RegistryMessages.VoterGroup.newBuilder()
|
||||||
.setVoterId(RegistryMessages.VoterID.newBuilder()
|
.setVoterId(RegistryMessages.VoterID.newBuilder().setId(voterId))
|
||||||
.setId((new BigInteger(130, random).toString(32))))
|
.setGroupId(RegistryMessages.GroupID.newBuilder().setId(groupId)).build();
|
||||||
.setGroupId(RegistryMessages.GroupID.newBuilder()
|
|
||||||
.setId((new BigInteger(130, random).toString(32)))).build();
|
|
||||||
|
|
||||||
SimpleRegistry registry = new SimpleRegistry(signer, communicator);
|
SimpleRegistry registry = new SimpleRegistry(signer, communicator);
|
||||||
registry.AddToGroup(voterInfo, handler);
|
registry.AddToGroup(voterInfo, handler);
|
||||||
|
|
||||||
jobSemaphore.acquire();
|
jobSemaphore.acquire();
|
||||||
|
assertEquals(1, handler.counter );
|
||||||
|
|
||||||
assertEquals(handler.counter , 0);
|
DummyRegistryCallBackHandler<List<String>> groupsHandler = new DummyRegistryCallBackHandler<>();
|
||||||
|
registry.GetGroups(RegistryMessages.GroupID.newBuilder().setId(groupId).build(), groupsHandler);
|
||||||
List<String> tags = new ArrayList<String>(){{ add(RegistryTags.GROUP_ACTION_TAG .toString()
|
|
||||||
+ RegistryTags.ADD_TO_GROUP_TAG.toString());}};
|
|
||||||
BulletinBoardAPI.MessageFilterList filters = registry.GetRelevantMessagesFilters(tags);
|
|
||||||
DummyBulletinBoardCallBackHandler bulletinHandler = new DummyBulletinBoardCallBackHandler();
|
|
||||||
communicator.readMessages(filters, bulletinHandler);
|
|
||||||
|
|
||||||
jobSemaphore.acquire();
|
jobSemaphore.acquire();
|
||||||
|
List<String> userGroups = groupsHandler.data;
|
||||||
List<VoterRegistryMessage> voterMessages = ConvertToVoterRegistryMessages(handler.data);
|
assert userGroups.contains(RegistryTags.GROUP_ID_TAG + groupId) :
|
||||||
assertTrue(voterMessages.get(0).GetWantedTagFromBasicMessage(RegistryTags.ID_TAG.toString()).contains(voterInfo.getVoterId().getId()));
|
"The simple voter registry object does not retrieved right user groups";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that the personal data outputted about the user is right
|
* Test that the personal data outputted about the user is right
|
||||||
*/
|
*/
|
||||||
|
@ -285,7 +281,6 @@ 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);
|
||||||
|
|
||||||
RegistryMessages.VoterInfo voterInfo = RegistryMessages.VoterInfo.newBuilder().
|
RegistryMessages.VoterInfo voterInfo = RegistryMessages.VoterInfo.newBuilder().
|
||||||
setId(RegistryMessages.VoterID.newBuilder().setId(id)).setInfo(data).build();
|
setId(RegistryMessages.VoterID.newBuilder().setId(id)).setInfo(data).build();
|
||||||
|
|
||||||
|
@ -293,18 +288,14 @@ public class SimpleRegistryTest extends TestCase {
|
||||||
registry.AddVoter(voterInfo, handler);
|
registry.AddVoter(voterInfo, handler);
|
||||||
|
|
||||||
jobSemaphore.acquire();
|
jobSemaphore.acquire();
|
||||||
|
assertEquals(1, handler.counter );
|
||||||
|
|
||||||
assertEquals(handler.counter , 0);
|
DummyRegistryCallBackHandler<VoterRegistryMessage> personalHandler = new DummyRegistryCallBackHandler<>();
|
||||||
|
registry.GetPersonIDDetails(RegistryMessages.VoterID.newBuilder().setId(id).build(), personalHandler);
|
||||||
List<String> tags = new ArrayList<String>(){{ add(RegistryTags.VOTER_ENTRY_TAG.toString());}};
|
|
||||||
BulletinBoardAPI.MessageFilterList filters = registry.GetRelevantMessagesFilters(tags);
|
|
||||||
DummyBulletinBoardCallBackHandler bulletinHandler = new DummyBulletinBoardCallBackHandler();
|
|
||||||
communicator.readMessages(filters, bulletinHandler);
|
|
||||||
|
|
||||||
jobSemaphore.acquire();
|
jobSemaphore.acquire();
|
||||||
|
assertEquals(RegistryTags.ID_TAG + id,
|
||||||
List<VoterRegistryMessage> voterMessages = ConvertToVoterRegistryMessages(handler.data);
|
personalHandler.data.GetWantedTagFromBasicMessage(RegistryTags.ID_TAG.toString()));
|
||||||
int counter = countMessagesWithTags(voterMessages, new ArrayList<String>(){{add(id);add(data);}});
|
assertEquals(data,personalHandler.data.base.getData().toStringUtf8());
|
||||||
assert counter == 1 : "The method doesnt retreived the wanted information.";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue