110 lines
3.6 KiB
Java
110 lines
3.6 KiB
Java
|
import com.google.protobuf.ByteString;
|
||
|
import meerkat.bulletinboard.BulletinBoardClient;
|
||
|
import meerkat.bulletinboard.SimpleBulletinBoardClient;
|
||
|
import meerkat.comm.CommunicationException;
|
||
|
import meerkat.protobuf.BulletinBoardAPI.*;
|
||
|
import meerkat.protobuf.Crypto;
|
||
|
|
||
|
import meerkat.util.BulletinBoardMessageComparator;
|
||
|
import org.junit.Before;
|
||
|
import org.junit.Test;
|
||
|
import static org.junit.Assert.*;
|
||
|
import static org.hamcrest.CoreMatchers.*;
|
||
|
|
||
|
import java.util.Comparator;
|
||
|
import java.util.LinkedList;
|
||
|
import java.util.List;
|
||
|
|
||
|
/**
|
||
|
* Created by Arbel Deutsch Peled on 05-Dec-15.
|
||
|
*/
|
||
|
public class BulletinBoardClientIntegrationTest {
|
||
|
|
||
|
private BulletinBoardClient bulletinBoardClient;
|
||
|
|
||
|
private static String PROP_GETTY_URL = "gretty.httpBaseURI";
|
||
|
private static String DEFAULT_BASE_URL = "http://localhost:8081";
|
||
|
private static String BASE_URL = System.getProperty(PROP_GETTY_URL, DEFAULT_BASE_URL);
|
||
|
|
||
|
@Before
|
||
|
public void init(){
|
||
|
|
||
|
bulletinBoardClient = new SimpleBulletinBoardClient();
|
||
|
|
||
|
List<String> testDB = new LinkedList<String>();
|
||
|
testDB.add(BASE_URL);
|
||
|
|
||
|
bulletinBoardClient.init(testDB);
|
||
|
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void postTest(){
|
||
|
|
||
|
byte[] b1 = {(byte) 1, (byte) 2, (byte) 3, (byte) 4};
|
||
|
byte[] b2 = {(byte) 11, (byte) 12, (byte) 13, (byte) 14};
|
||
|
byte[] b3 = {(byte) 21, (byte) 22, (byte) 23, (byte) 24};
|
||
|
byte[] b4 = {(byte) 4, (byte) 5, (byte) 100, (byte) -50, (byte) 0};
|
||
|
|
||
|
BulletinBoardMessage msg;
|
||
|
|
||
|
MessageFilterList filterList;
|
||
|
List<BulletinBoardMessage> msgList;
|
||
|
|
||
|
MessageID messageID;
|
||
|
|
||
|
Comparator<BulletinBoardMessage> msgComparator = new BulletinBoardMessageComparator();
|
||
|
|
||
|
msg = BulletinBoardMessage.newBuilder()
|
||
|
.setMsg(UnsignedBulletinBoardMessage.newBuilder()
|
||
|
.addTag("Signature")
|
||
|
.addTag("Trustee")
|
||
|
.setData(ByteString.copyFrom(b1))
|
||
|
.build())
|
||
|
.addSig(Crypto.Signature.newBuilder()
|
||
|
.setType(Crypto.SignatureType.DSA)
|
||
|
.setData(ByteString.copyFrom(b2))
|
||
|
.setSignerId(ByteString.copyFrom(b3))
|
||
|
.build())
|
||
|
.addSig(Crypto.Signature.newBuilder()
|
||
|
.setType(Crypto.SignatureType.ECDSA)
|
||
|
.setData(ByteString.copyFrom(b3))
|
||
|
.setSignerId(ByteString.copyFrom(b2))
|
||
|
.build())
|
||
|
.build();
|
||
|
|
||
|
try {
|
||
|
messageID = bulletinBoardClient.postMessage(msg);
|
||
|
} catch (CommunicationException e) {
|
||
|
System.err.println("Error posting to BB Server: " + e.getMessage());
|
||
|
assert false;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
assertThat(bulletinBoardClient.getRedundancy(messageID), is((float) 1.00));
|
||
|
|
||
|
filterList = MessageFilterList.newBuilder()
|
||
|
.addFilter(
|
||
|
MessageFilter.newBuilder()
|
||
|
.setType(FilterType.TAG)
|
||
|
.setTag("Signature")
|
||
|
.build()
|
||
|
)
|
||
|
// .addFilter(
|
||
|
// MessageFilter.newBuilder()
|
||
|
// .setType(FilterType.TAG)
|
||
|
// .setTag("Trustee")
|
||
|
// .build()
|
||
|
// )
|
||
|
.build();
|
||
|
|
||
|
msgList = bulletinBoardClient.readMessages(filterList);
|
||
|
|
||
|
assertThat(msgList.size(), is(1));
|
||
|
|
||
|
assertThat(msgComparator.compare(msgList.iterator().next(), msg), is(0));
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|