Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
briar
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Julian Dehm
briar
Commits
27a169c6
Verified
Commit
27a169c6
authored
Aug 24, 2018
by
akwizgran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minimise use of message constructor.
parent
d4a43517
Changes
18
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
284 additions
and
360 deletions
+284
-360
bramble-api/src/test/java/org/briarproject/bramble/test/TestUtils.java
...rc/test/java/org/briarproject/bramble/test/TestUtils.java
+2
-3
bramble-core/src/test/java/org/briarproject/bramble/client/BdfMessageValidatorTest.java
.../briarproject/bramble/client/BdfMessageValidatorTest.java
+11
-11
bramble-core/src/test/java/org/briarproject/bramble/client/ClientHelperImplTest.java
...org/briarproject/bramble/client/ClientHelperImplTest.java
+5
-5
bramble-core/src/test/java/org/briarproject/bramble/db/DatabaseComponentImplTest.java
...rg/briarproject/bramble/db/DatabaseComponentImplTest.java
+15
-15
bramble-core/src/test/java/org/briarproject/bramble/db/JdbcDatabaseTest.java
...st/java/org/briarproject/bramble/db/JdbcDatabaseTest.java
+51
-68
bramble-core/src/test/java/org/briarproject/bramble/properties/TransportPropertyManagerImplTest.java
.../bramble/properties/TransportPropertyManagerImplTest.java
+6
-16
bramble-core/src/test/java/org/briarproject/bramble/sync/SimplexOutgoingSessionTest.java
...briarproject/bramble/sync/SimplexOutgoingSessionTest.java
+2
-1
bramble-core/src/test/java/org/briarproject/bramble/sync/ValidationManagerImplTest.java
.../briarproject/bramble/sync/ValidationManagerImplTest.java
+86
-97
briar-core/src/test/java/org/briarproject/briar/blog/BlogManagerImplTest.java
...java/org/briarproject/briar/blog/BlogManagerImplTest.java
+24
-35
briar-core/src/test/java/org/briarproject/briar/blog/BlogPostValidatorTest.java
...va/org/briarproject/briar/blog/BlogPostValidatorTest.java
+6
-12
briar-core/src/test/java/org/briarproject/briar/feed/FeedManagerImplTest.java
...java/org/briarproject/briar/feed/FeedManagerImplTest.java
+4
-8
briar-core/src/test/java/org/briarproject/briar/introduction/MessageEncoderTest.java
...g/briarproject/briar/introduction/MessageEncoderTest.java
+7
-4
briar-core/src/test/java/org/briarproject/briar/messaging/MessageSizeIntegrationTest.java
...arproject/briar/messaging/MessageSizeIntegrationTest.java
+5
-5
briar-core/src/test/java/org/briarproject/briar/privategroup/invitation/AbstractProtocolEngineTest.java
...r/privategroup/invitation/AbstractProtocolEngineTest.java
+49
-63
briar-core/src/test/java/org/briarproject/briar/privategroup/invitation/CreatorProtocolEngineTest.java
...ar/privategroup/invitation/CreatorProtocolEngineTest.java
+3
-3
briar-core/src/test/java/org/briarproject/briar/privategroup/invitation/GroupInvitationManagerImplTest.java
...ivategroup/invitation/GroupInvitationManagerImplTest.java
+4
-9
briar-core/src/test/java/org/briarproject/briar/privategroup/invitation/InviteeProtocolEngineTest.java
...ar/privategroup/invitation/InviteeProtocolEngineTest.java
+2
-2
briar-core/src/test/java/org/briarproject/briar/sharing/BlogSharingManagerImplTest.java
...riarproject/briar/sharing/BlogSharingManagerImplTest.java
+2
-3
No files found.
bramble-api/src/test/java/org/briarproject/bramble/test/TestUtils.java
View file @
27a169c6
...
@@ -40,6 +40,7 @@ public class TestUtils {
...
@@ -40,6 +40,7 @@ public class TestUtils {
private
static
final
AtomicInteger
nextTestDir
=
private
static
final
AtomicInteger
nextTestDir
=
new
AtomicInteger
((
int
)
(
Math
.
random
()
*
1000
*
1000
));
new
AtomicInteger
((
int
)
(
Math
.
random
()
*
1000
*
1000
));
private
static
final
Random
random
=
new
Random
();
private
static
final
Random
random
=
new
Random
();
private
static
final
long
timestamp
=
System
.
currentTimeMillis
();
public
static
File
getTestDirectory
()
{
public
static
File
getTestDirectory
()
{
int
name
=
nextTestDir
.
getAndIncrement
();
int
name
=
nextTestDir
.
getAndIncrement
();
...
@@ -101,9 +102,8 @@ public class TestUtils {
...
@@ -101,9 +102,8 @@ public class TestUtils {
String
name
=
getRandomString
(
nameLength
);
String
name
=
getRandomString
(
nameLength
);
byte
[]
publicKey
=
getRandomBytes
(
MAX_PUBLIC_KEY_LENGTH
);
byte
[]
publicKey
=
getRandomBytes
(
MAX_PUBLIC_KEY_LENGTH
);
byte
[]
privateKey
=
getRandomBytes
(
MAX_PUBLIC_KEY_LENGTH
);
byte
[]
privateKey
=
getRandomBytes
(
MAX_PUBLIC_KEY_LENGTH
);
long
created
=
System
.
currentTimeMillis
();
return
new
LocalAuthor
(
id
,
FORMAT_VERSION
,
name
,
publicKey
,
privateKey
,
return
new
LocalAuthor
(
id
,
FORMAT_VERSION
,
name
,
publicKey
,
privateKey
,
created
);
timestamp
);
}
}
public
static
Author
getAuthor
()
{
public
static
Author
getAuthor
()
{
...
@@ -137,7 +137,6 @@ public class TestUtils {
...
@@ -137,7 +137,6 @@ public class TestUtils {
public
static
Message
getMessage
(
GroupId
groupId
,
int
rawLength
)
{
public
static
Message
getMessage
(
GroupId
groupId
,
int
rawLength
)
{
MessageId
id
=
new
MessageId
(
getRandomId
());
MessageId
id
=
new
MessageId
(
getRandomId
());
byte
[]
raw
=
getRandomBytes
(
rawLength
);
byte
[]
raw
=
getRandomBytes
(
rawLength
);
long
timestamp
=
System
.
currentTimeMillis
();
return
new
Message
(
id
,
groupId
,
timestamp
,
raw
);
return
new
Message
(
id
,
groupId
,
timestamp
,
raw
);
}
}
...
...
bramble-core/src/test/java/org/briarproject/bramble/client/BdfMessageValidatorTest.java
View file @
27a169c6
...
@@ -18,6 +18,8 @@ import org.junit.Test;
...
@@ -18,6 +18,8 @@ import org.junit.Test;
import
static
org
.
briarproject
.
bramble
.
api
.
sync
.
SyncConstants
.
MESSAGE_HEADER_LENGTH
;
import
static
org
.
briarproject
.
bramble
.
api
.
sync
.
SyncConstants
.
MESSAGE_HEADER_LENGTH
;
import
static
org
.
briarproject
.
bramble
.
api
.
transport
.
TransportConstants
.
MAX_CLOCK_DIFFERENCE
;
import
static
org
.
briarproject
.
bramble
.
api
.
transport
.
TransportConstants
.
MAX_CLOCK_DIFFERENCE
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getMessage
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getRandomBytes
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertSame
;
import
static
org
.
junit
.
Assert
.
assertSame
;
...
@@ -28,8 +30,7 @@ public class BdfMessageValidatorTest extends ValidatorTestCase {
...
@@ -28,8 +30,7 @@ public class BdfMessageValidatorTest extends ValidatorTestCase {
new
BdfMessageValidator
(
clientHelper
,
metadataEncoder
,
clock
)
{
new
BdfMessageValidator
(
clientHelper
,
metadataEncoder
,
clock
)
{
@Override
@Override
protected
BdfMessageContext
validateMessage
(
Message
m
,
Group
g
,
protected
BdfMessageContext
validateMessage
(
Message
m
,
Group
g
,
BdfList
body
)
BdfList
body
)
{
throws
InvalidMessageException
,
FormatException
{
throw
new
AssertionError
();
throw
new
AssertionError
();
}
}
};
};
...
@@ -69,7 +70,7 @@ public class BdfMessageValidatorTest extends ValidatorTestCase {
...
@@ -69,7 +70,7 @@ public class BdfMessageValidatorTest extends ValidatorTestCase {
metadataEncoder
,
clock
)
{
metadataEncoder
,
clock
)
{
@Override
@Override
protected
BdfMessageContext
validateMessage
(
Message
m
,
Group
g
,
protected
BdfMessageContext
validateMessage
(
Message
m
,
Group
g
,
BdfList
b
)
throws
InvalidMessageException
,
FormatException
{
BdfList
b
)
{
assertSame
(
message
,
m
);
assertSame
(
message
,
m
);
assertSame
(
group
,
g
);
assertSame
(
group
,
g
);
assertSame
(
body
,
b
);
assertSame
(
body
,
b
);
...
@@ -83,11 +84,12 @@ public class BdfMessageValidatorTest extends ValidatorTestCase {
...
@@ -83,11 +84,12 @@ public class BdfMessageValidatorTest extends ValidatorTestCase {
@Test
(
expected
=
InvalidMessageException
.
class
)
@Test
(
expected
=
InvalidMessageException
.
class
)
public
void
testRejectsTooShortMessage
()
throws
Exception
{
public
void
testRejectsTooShortMessage
()
throws
Exception
{
byte
[]
invalidRaw
=
new
byte
[
MESSAGE_HEADER_LENGTH
]
;
byte
[]
invalidRaw
=
getRandomBytes
(
MESSAGE_HEADER_LENGTH
)
;
// Use a mock message so the length of the raw message can be invalid
// Use a mock message so the length of the raw message can be invalid
Message
invalidMessage
=
context
.
mock
(
Message
.
class
);
Message
invalidMessage
=
context
.
mock
(
Message
.
class
);
context
.
checking
(
new
Expectations
()
{{
context
.
checking
(
new
Expectations
()
{{
//noinspection ResultOfMethodCallIgnored
oneOf
(
invalidMessage
).
getTimestamp
();
oneOf
(
invalidMessage
).
getTimestamp
();
will
(
returnValue
(
timestamp
));
will
(
returnValue
(
timestamp
));
oneOf
(
clock
).
currentTimeMillis
();
oneOf
(
clock
).
currentTimeMillis
();
...
@@ -101,15 +103,13 @@ public class BdfMessageValidatorTest extends ValidatorTestCase {
...
@@ -101,15 +103,13 @@ public class BdfMessageValidatorTest extends ValidatorTestCase {
@Test
@Test
public
void
testAcceptsMinLengthMessage
()
throws
Exception
{
public
void
testAcceptsMinLengthMessage
()
throws
Exception
{
byte
[]
shortRaw
=
new
byte
[
MESSAGE_HEADER_LENGTH
+
1
];
Message
shortMessage
=
getMessage
(
groupId
,
MESSAGE_HEADER_LENGTH
+
1
);
Message
shortMessage
=
new
Message
(
messageId
,
groupId
,
timestamp
,
shortRaw
);
context
.
checking
(
new
Expectations
()
{{
context
.
checking
(
new
Expectations
()
{{
oneOf
(
clock
).
currentTimeMillis
();
oneOf
(
clock
).
currentTimeMillis
();
will
(
returnValue
(
timestamp
));
will
(
returnValue
(
timestamp
));
oneOf
(
clientHelper
).
toList
(
short
Raw
,
MESSAGE_HEADER_LENGTH
,
oneOf
(
clientHelper
).
toList
(
short
Message
.
getRaw
()
,
shortRaw
.
length
-
MESSAGE_HEADER_LENGTH
);
MESSAGE_HEADER_LENGTH
,
1
);
will
(
returnValue
(
body
));
will
(
returnValue
(
body
));
oneOf
(
metadataEncoder
).
encode
(
dictionary
);
oneOf
(
metadataEncoder
).
encode
(
dictionary
);
will
(
returnValue
(
meta
));
will
(
returnValue
(
meta
));
...
@@ -120,7 +120,7 @@ public class BdfMessageValidatorTest extends ValidatorTestCase {
...
@@ -120,7 +120,7 @@ public class BdfMessageValidatorTest extends ValidatorTestCase {
metadataEncoder
,
clock
)
{
metadataEncoder
,
clock
)
{
@Override
@Override
protected
BdfMessageContext
validateMessage
(
Message
m
,
Group
g
,
protected
BdfMessageContext
validateMessage
(
Message
m
,
Group
g
,
BdfList
b
)
throws
InvalidMessageException
,
FormatException
{
BdfList
b
)
{
assertSame
(
shortMessage
,
m
);
assertSame
(
shortMessage
,
m
);
assertSame
(
group
,
g
);
assertSame
(
group
,
g
);
assertSame
(
body
,
b
);
assertSame
(
body
,
b
);
...
@@ -160,7 +160,7 @@ public class BdfMessageValidatorTest extends ValidatorTestCase {
...
@@ -160,7 +160,7 @@ public class BdfMessageValidatorTest extends ValidatorTestCase {
metadataEncoder
,
clock
)
{
metadataEncoder
,
clock
)
{
@Override
@Override
protected
BdfMessageContext
validateMessage
(
Message
m
,
Group
g
,
protected
BdfMessageContext
validateMessage
(
Message
m
,
Group
g
,
BdfList
b
)
throws
InvalidMessageException
,
FormatException
{
BdfList
b
)
throws
FormatException
{
throw
new
FormatException
();
throw
new
FormatException
();
}
}
};
};
...
...
bramble-core/src/test/java/org/briarproject/bramble/client/ClientHelperImplTest.java
View file @
27a169c6
...
@@ -39,6 +39,7 @@ import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_N
...
@@ -39,6 +39,7 @@ import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_N
import
static
org
.
briarproject
.
bramble
.
api
.
identity
.
AuthorConstants
.
MAX_PUBLIC_KEY_LENGTH
;
import
static
org
.
briarproject
.
bramble
.
api
.
identity
.
AuthorConstants
.
MAX_PUBLIC_KEY_LENGTH
;
import
static
org
.
briarproject
.
bramble
.
api
.
identity
.
AuthorConstants
.
MAX_SIGNATURE_LENGTH
;
import
static
org
.
briarproject
.
bramble
.
api
.
identity
.
AuthorConstants
.
MAX_SIGNATURE_LENGTH
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getAuthor
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getAuthor
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getMessage
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getRandomBytes
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getRandomBytes
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getRandomId
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getRandomId
;
import
static
org
.
briarproject
.
bramble
.
util
.
StringUtils
.
getRandomString
;
import
static
org
.
briarproject
.
bramble
.
util
.
StringUtils
.
getRandomString
;
...
@@ -67,11 +68,10 @@ public class ClientHelperImplTest extends BrambleTestCase {
...
@@ -67,11 +68,10 @@ public class ClientHelperImplTest extends BrambleTestCase {
private
final
GroupId
groupId
=
new
GroupId
(
getRandomId
());
private
final
GroupId
groupId
=
new
GroupId
(
getRandomId
());
private
final
BdfDictionary
dictionary
=
new
BdfDictionary
();
private
final
BdfDictionary
dictionary
=
new
BdfDictionary
();
private
final
long
timestamp
=
42L
;
private
final
Message
message
=
getMessage
(
groupId
);
private
final
byte
[]
rawMessage
=
getRandomBytes
(
42
);
private
final
MessageId
messageId
=
message
.
getId
();
private
final
MessageId
messageId
=
new
MessageId
(
getRandomId
());
private
final
long
timestamp
=
message
.
getTimestamp
();
private
final
Message
message
=
private
final
byte
[]
rawMessage
=
message
.
getRaw
();
new
Message
(
messageId
,
groupId
,
timestamp
,
rawMessage
);
private
final
Metadata
metadata
=
new
Metadata
();
private
final
Metadata
metadata
=
new
Metadata
();
private
final
BdfList
list
=
BdfList
.
of
(
"Sign this!"
,
getRandomBytes
(
42
));
private
final
BdfList
list
=
BdfList
.
of
(
"Sign this!"
,
getRandomBytes
(
42
));
private
final
String
label
=
StringUtils
.
getRandomString
(
5
);
private
final
String
label
=
StringUtils
.
getRandomString
(
5
);
...
...
bramble-core/src/test/java/org/briarproject/bramble/db/DatabaseComponentImplTest.java
View file @
27a169c6
...
@@ -64,6 +64,7 @@ import static java.util.Collections.singletonList;
...
@@ -64,6 +64,7 @@ import static java.util.Collections.singletonList;
import
static
org
.
briarproject
.
bramble
.
api
.
sync
.
Group
.
Visibility
.
INVISIBLE
;
import
static
org
.
briarproject
.
bramble
.
api
.
sync
.
Group
.
Visibility
.
INVISIBLE
;
import
static
org
.
briarproject
.
bramble
.
api
.
sync
.
Group
.
Visibility
.
SHARED
;
import
static
org
.
briarproject
.
bramble
.
api
.
sync
.
Group
.
Visibility
.
SHARED
;
import
static
org
.
briarproject
.
bramble
.
api
.
sync
.
Group
.
Visibility
.
VISIBLE
;
import
static
org
.
briarproject
.
bramble
.
api
.
sync
.
Group
.
Visibility
.
VISIBLE
;
import
static
org
.
briarproject
.
bramble
.
api
.
sync
.
SyncConstants
.
MAX_MESSAGE_LENGTH
;
import
static
org
.
briarproject
.
bramble
.
api
.
sync
.
ValidationManager
.
State
.
DELIVERED
;
import
static
org
.
briarproject
.
bramble
.
api
.
sync
.
ValidationManager
.
State
.
DELIVERED
;
import
static
org
.
briarproject
.
bramble
.
api
.
sync
.
ValidationManager
.
State
.
UNKNOWN
;
import
static
org
.
briarproject
.
bramble
.
api
.
sync
.
ValidationManager
.
State
.
UNKNOWN
;
import
static
org
.
briarproject
.
bramble
.
api
.
transport
.
TransportConstants
.
REORDERING_WINDOW_SIZE
;
import
static
org
.
briarproject
.
bramble
.
api
.
transport
.
TransportConstants
.
REORDERING_WINDOW_SIZE
;
...
@@ -72,6 +73,7 @@ import static org.briarproject.bramble.test.TestUtils.getAuthor;
...
@@ -72,6 +73,7 @@ import static org.briarproject.bramble.test.TestUtils.getAuthor;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getClientId
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getClientId
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getGroup
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getGroup
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getLocalAuthor
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getLocalAuthor
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getMessage
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getRandomId
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getRandomId
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getSecretKey
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getSecretKey
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getTransportId
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getTransportId
;
...
@@ -97,10 +99,9 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
...
@@ -97,10 +99,9 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
private
final
Group
group
;
private
final
Group
group
;
private
final
Author
author
;
private
final
Author
author
;
private
final
LocalAuthor
localAuthor
;
private
final
LocalAuthor
localAuthor
;
private
final
MessageId
messageId
,
messageId1
;
private
final
int
size
;
private
final
byte
[]
raw
;
private
final
Message
message
;
private
final
Message
message
;
private
final
MessageId
messageId
,
messageId1
;
private
final
byte
[]
raw
,
raw1
;
private
final
Metadata
metadata
;
private
final
Metadata
metadata
;
private
final
TransportId
transportId
;
private
final
TransportId
transportId
;
private
final
int
maxLatency
;
private
final
int
maxLatency
;
...
@@ -115,12 +116,12 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
...
@@ -115,12 +116,12 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
groupId
=
group
.
getId
();
groupId
=
group
.
getId
();
author
=
getAuthor
();
author
=
getAuthor
();
localAuthor
=
getLocalAuthor
();
localAuthor
=
getLocalAuthor
();
message
Id
=
new
MessageId
(
getRandomId
()
);
message
=
getMessage
(
groupId
);
messageId1
=
new
MessageId
(
getRandomId
()
);
Message
message1
=
getMessage
(
groupId
);
long
timestamp
=
System
.
currentTimeMillis
();
messageId
=
message
.
getId
();
size
=
1234
;
messageId1
=
message1
.
getId
()
;
raw
=
new
byte
[
size
]
;
raw
=
message
.
getRaw
()
;
message
=
new
Message
(
messageId
,
groupId
,
timestamp
,
raw
);
raw1
=
message1
.
getRaw
(
);
metadata
=
new
Metadata
();
metadata
=
new
Metadata
();
metadata
.
put
(
"foo"
,
new
byte
[]
{
'b'
,
'a'
,
'r'
});
metadata
.
put
(
"foo"
,
new
byte
[]
{
'b'
,
'a'
,
'r'
});
transportId
=
getTransportId
();
transportId
=
getTransportId
();
...
@@ -865,7 +866,6 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
...
@@ -865,7 +866,6 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
@Test
@Test
public
void
testGenerateBatch
()
throws
Exception
{
public
void
testGenerateBatch
()
throws
Exception
{
byte
[]
raw1
=
new
byte
[
size
];
Collection
<
MessageId
>
ids
=
Arrays
.
asList
(
messageId
,
messageId1
);
Collection
<
MessageId
>
ids
=
Arrays
.
asList
(
messageId
,
messageId1
);
Collection
<
byte
[]>
messages
=
Arrays
.
asList
(
raw
,
raw1
);
Collection
<
byte
[]>
messages
=
Arrays
.
asList
(
raw
,
raw1
);
context
.
checking
(
new
Expectations
()
{{
context
.
checking
(
new
Expectations
()
{{
...
@@ -873,7 +873,8 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
...
@@ -873,7 +873,8 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
will
(
returnValue
(
txn
));
will
(
returnValue
(
txn
));
oneOf
(
database
).
containsContact
(
txn
,
contactId
);
oneOf
(
database
).
containsContact
(
txn
,
contactId
);
will
(
returnValue
(
true
));
will
(
returnValue
(
true
));
oneOf
(
database
).
getMessagesToSend
(
txn
,
contactId
,
size
*
2
);
oneOf
(
database
).
getMessagesToSend
(
txn
,
contactId
,
MAX_MESSAGE_LENGTH
*
2
);
will
(
returnValue
(
ids
));
will
(
returnValue
(
ids
));
oneOf
(
database
).
getRawMessage
(
txn
,
messageId
);
oneOf
(
database
).
getRawMessage
(
txn
,
messageId
);
will
(
returnValue
(
raw
));
will
(
returnValue
(
raw
));
...
@@ -893,7 +894,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
...
@@ -893,7 +894,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
Transaction
transaction
=
db
.
startTransaction
(
false
);
Transaction
transaction
=
db
.
startTransaction
(
false
);
try
{
try
{
assertEquals
(
messages
,
db
.
generateBatch
(
transaction
,
contactId
,
assertEquals
(
messages
,
db
.
generateBatch
(
transaction
,
contactId
,
size
*
2
,
maxLatency
));
MAX_MESSAGE_LENGTH
*
2
,
maxLatency
));
db
.
commitTransaction
(
transaction
);
db
.
commitTransaction
(
transaction
);
}
finally
{
}
finally
{
db
.
endTransaction
(
transaction
);
db
.
endTransaction
(
transaction
);
...
@@ -961,7 +962,6 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
...
@@ -961,7 +962,6 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
@Test
@Test
public
void
testGenerateRequestedBatch
()
throws
Exception
{
public
void
testGenerateRequestedBatch
()
throws
Exception
{
byte
[]
raw1
=
new
byte
[
size
];
Collection
<
MessageId
>
ids
=
Arrays
.
asList
(
messageId
,
messageId1
);
Collection
<
MessageId
>
ids
=
Arrays
.
asList
(
messageId
,
messageId1
);
Collection
<
byte
[]>
messages
=
Arrays
.
asList
(
raw
,
raw1
);
Collection
<
byte
[]>
messages
=
Arrays
.
asList
(
raw
,
raw1
);
context
.
checking
(
new
Expectations
()
{{
context
.
checking
(
new
Expectations
()
{{
...
@@ -970,7 +970,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
...
@@ -970,7 +970,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
oneOf
(
database
).
containsContact
(
txn
,
contactId
);
oneOf
(
database
).
containsContact
(
txn
,
contactId
);
will
(
returnValue
(
true
));
will
(
returnValue
(
true
));
oneOf
(
database
).
getRequestedMessagesToSend
(
txn
,
contactId
,
oneOf
(
database
).
getRequestedMessagesToSend
(
txn
,
contactId
,
size
*
2
);
MAX_MESSAGE_LENGTH
*
2
);
will
(
returnValue
(
ids
));
will
(
returnValue
(
ids
));
oneOf
(
database
).
getRawMessage
(
txn
,
messageId
);
oneOf
(
database
).
getRawMessage
(
txn
,
messageId
);
will
(
returnValue
(
raw
));
will
(
returnValue
(
raw
));
...
@@ -990,7 +990,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
...
@@ -990,7 +990,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
Transaction
transaction
=
db
.
startTransaction
(
false
);
Transaction
transaction
=
db
.
startTransaction
(
false
);
try
{
try
{
assertEquals
(
messages
,
db
.
generateRequestedBatch
(
transaction
,
assertEquals
(
messages
,
db
.
generateRequestedBatch
(
transaction
,
contactId
,
size
*
2
,
maxLatency
));
contactId
,
MAX_MESSAGE_LENGTH
*
2
,
maxLatency
));
db
.
commitTransaction
(
transaction
);
db
.
commitTransaction
(
transaction
);
}
finally
{
}
finally
{
db
.
endTransaction
(
transaction
);
db
.
endTransaction
(
transaction
);
...
...
bramble-core/src/test/java/org/briarproject/bramble/db/JdbcDatabaseTest.java
View file @
27a169c6
This diff is collapsed.
Click to expand it.
bramble-core/src/test/java/org/briarproject/bramble/properties/TransportPropertyManagerImplTest.java
View file @
27a169c6
...
@@ -34,11 +34,10 @@ import static java.util.Collections.singletonList;
...
@@ -34,11 +34,10 @@ import static java.util.Collections.singletonList;
import
static
org
.
briarproject
.
bramble
.
api
.
properties
.
TransportPropertyManager
.
CLIENT_ID
;
import
static
org
.
briarproject
.
bramble
.
api
.
properties
.
TransportPropertyManager
.
CLIENT_ID
;
import
static
org
.
briarproject
.
bramble
.
api
.
properties
.
TransportPropertyManager
.
MAJOR_VERSION
;
import
static
org
.
briarproject
.
bramble
.
api
.
properties
.
TransportPropertyManager
.
MAJOR_VERSION
;
import
static
org
.
briarproject
.
bramble
.
api
.
sync
.
Group
.
Visibility
.
SHARED
;
import
static
org
.
briarproject
.
bramble
.
api
.
sync
.
Group
.
Visibility
.
SHARED
;
import
static
org
.
briarproject
.
bramble
.
api
.
sync
.
SyncConstants
.
MAX_MESSAGE_BODY_LENGTH
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getAuthor
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getAuthor
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getGroup
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getGroup
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getLocalAuthor
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getLocalAuthor
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
get
RandomBytes
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
get
Message
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getRandomId
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getRandomId
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
...
@@ -187,8 +186,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
...
@@ -187,8 +186,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
throws
Exception
{
throws
Exception
{
Transaction
txn
=
new
Transaction
(
null
,
false
);
Transaction
txn
=
new
Transaction
(
null
,
false
);
GroupId
contactGroupId
=
new
GroupId
(
getRandomId
());
GroupId
contactGroupId
=
new
GroupId
(
getRandomId
());
long
timestamp
=
123456789
;
Message
message
=
getMessage
(
contactGroupId
);
Message
message
=
getMessage
(
contactGroupId
,
timestamp
);
Metadata
meta
=
new
Metadata
();
Metadata
meta
=
new
Metadata
();
BdfDictionary
metaDictionary
=
BdfDictionary
.
of
(
BdfDictionary
metaDictionary
=
BdfDictionary
.
of
(
new
BdfEntry
(
"transportId"
,
"foo"
),
new
BdfEntry
(
"transportId"
,
"foo"
),
...
@@ -229,8 +227,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
...
@@ -229,8 +227,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
throws
Exception
{
throws
Exception
{
Transaction
txn
=
new
Transaction
(
null
,
false
);
Transaction
txn
=
new
Transaction
(
null
,
false
);
GroupId
contactGroupId
=
new
GroupId
(
getRandomId
());
GroupId
contactGroupId
=
new
GroupId
(
getRandomId
());
long
timestamp
=
123456789
;
Message
message
=
getMessage
(
contactGroupId
);
Message
message
=
getMessage
(
contactGroupId
,
timestamp
);
Metadata
meta
=
new
Metadata
();
Metadata
meta
=
new
Metadata
();
// Version 4 is being delivered
// Version 4 is being delivered
BdfDictionary
metaDictionary
=
BdfDictionary
.
of
(
BdfDictionary
metaDictionary
=
BdfDictionary
.
of
(
...
@@ -267,8 +264,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
...
@@ -267,8 +264,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
public
void
testDeletesObsoleteUpdateWhenDelivered
()
throws
Exception
{
public
void
testDeletesObsoleteUpdateWhenDelivered
()
throws
Exception
{
Transaction
txn
=
new
Transaction
(
null
,
false
);
Transaction
txn
=
new
Transaction
(
null
,
false
);
GroupId
contactGroupId
=
new
GroupId
(
getRandomId
());
GroupId
contactGroupId
=
new
GroupId
(
getRandomId
());
long
timestamp
=
123456789
;
Message
message
=
getMessage
(
contactGroupId
);
Message
message
=
getMessage
(
contactGroupId
,
timestamp
);
Metadata
meta
=
new
Metadata
();
Metadata
meta
=
new
Metadata
();
// Version 3 is being delivered
// Version 3 is being delivered
BdfDictionary
metaDictionary
=
BdfDictionary
.
of
(
BdfDictionary
metaDictionary
=
BdfDictionary
.
of
(
...
@@ -619,12 +615,6 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
...
@@ -619,12 +615,6 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
true
,
active
);
true
,
active
);
}
}
private
Message
getMessage
(
GroupId
g
,
long
timestamp
)
{
MessageId
messageId
=
new
MessageId
(
getRandomId
());
byte
[]
raw
=
getRandomBytes
(
MAX_MESSAGE_BODY_LENGTH
);
return
new
Message
(
messageId
,
g
,
timestamp
,
raw
);
}
private
void
expectGetLocalProperties
(
Transaction
txn
)
throws
Exception
{
private
void
expectGetLocalProperties
(
Transaction
txn
)
throws
Exception
{
Map
<
MessageId
,
BdfDictionary
>
messageMetadata
=
new
LinkedHashMap
<>();
Map
<
MessageId
,
BdfDictionary
>
messageMetadata
=
new
LinkedHashMap
<>();
// The latest update for transport "foo" should be returned
// The latest update for transport "foo" should be returned
...
@@ -664,9 +654,9 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
...
@@ -664,9 +654,9 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
private
void
expectStoreMessage
(
Transaction
txn
,
GroupId
g
,
private
void
expectStoreMessage
(
Transaction
txn
,
GroupId
g
,
String
transportId
,
BdfDictionary
properties
,
long
version
,
String
transportId
,
BdfDictionary
properties
,
long
version
,
boolean
local
,
boolean
shared
)
throws
Exception
{
boolean
local
,
boolean
shared
)
throws
Exception
{
long
timestamp
=
123456789
;
BdfList
body
=
BdfList
.
of
(
transportId
,
version
,
properties
);
BdfList
body
=
BdfList
.
of
(
transportId
,
version
,
properties
);
Message
message
=
getMessage
(
g
,
timestamp
);
Message
message
=
getMessage
(
g
);
long
timestamp
=
message
.
getTimestamp
();
BdfDictionary
meta
=
BdfDictionary
.
of
(
BdfDictionary
meta
=
BdfDictionary
.
of
(
new
BdfEntry
(
"transportId"
,
transportId
),
new
BdfEntry
(
"transportId"
,
transportId
),
new
BdfEntry
(
"version"
,
version
),
new
BdfEntry
(
"version"
,
version
),
...
...
bramble-core/src/test/java/org/briarproject/bramble/sync/SimplexOutgoingSessionTest.java
View file @
27a169c6
...
@@ -18,6 +18,7 @@ import java.util.Collections;
...
@@ -18,6 +18,7 @@ import java.util.Collections;
import
java.util.concurrent.Executor
;
import
java.util.concurrent.Executor
;
import
static
org
.
briarproject
.
bramble
.
api
.
sync
.
SyncConstants
.
MAX_MESSAGE_IDS
;
import
static
org
.
briarproject
.
bramble
.
api
.
sync
.
SyncConstants
.
MAX_MESSAGE_IDS
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getRandomBytes
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getRandomId
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getRandomId
;
public
class
SimplexOutgoingSessionTest
extends
BrambleMockTestCase
{
public
class
SimplexOutgoingSessionTest
extends
BrambleMockTestCase
{
...
@@ -72,7 +73,7 @@ public class SimplexOutgoingSessionTest extends BrambleMockTestCase {
...
@@ -72,7 +73,7 @@ public class SimplexOutgoingSessionTest extends BrambleMockTestCase {
@Test
@Test
public
void
testSomethingToSend
()
throws
Exception
{
public
void
testSomethingToSend
()
throws
Exception
{
Ack
ack
=
new
Ack
(
Collections
.
singletonList
(
messageId
));
Ack
ack
=
new
Ack
(
Collections
.
singletonList
(
messageId
));
byte
[]
raw
=
new
byte
[
1234
]
;
byte
[]
raw
=
getRandomBytes
(
1234
)
;
SimplexOutgoingSession
session
=
new
SimplexOutgoingSession
(
db
,
SimplexOutgoingSession
session
=
new
SimplexOutgoingSession
(
db
,
dbExecutor
,
eventBus
,
contactId
,
MAX_LATENCY
,
streamWriter
,
dbExecutor
,
eventBus
,
contactId
,
MAX_LATENCY
,
streamWriter
,
recordWriter
);
recordWriter
);
...
...
bramble-core/src/test/java/org/briarproject/bramble/sync/ValidationManagerImplTest.java
View file @
27a169c6
This diff is collapsed.
Click to expand it.
briar-core/src/test/java/org/briarproject/briar/blog/BlogManagerImplTest.java
View file @
27a169c6
...
@@ -32,10 +32,9 @@ import org.junit.Test;
...
@@ -32,10 +32,9 @@ import org.junit.Test;
import
static
org
.
briarproject
.
bramble
.
api
.
identity
.
Author
.
Status
.
NONE
;
import
static
org
.
briarproject
.
bramble
.
api
.
identity
.
Author
.
Status
.
NONE
;
import
static
org
.
briarproject
.
bramble
.
api
.
identity
.
Author
.
Status
.
OURSELVES
;
import
static
org
.
briarproject
.
bramble
.
api
.
identity
.
Author
.
Status
.
OURSELVES
;
import
static
org
.
briarproject
.
bramble
.
api
.
identity
.
Author
.
Status
.
VERIFIED
;
import
static
org
.
briarproject
.
bramble
.
api
.
identity
.
Author
.
Status
.
VERIFIED
;
import
static
org
.
briarproject
.
bramble
.
api
.
sync
.
SyncConstants
.
MAX_MESSAGE_LENGTH
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getGroup
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getGroup
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getLocalAuthor
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getLocalAuthor
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
get
RandomBytes
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
get
Message
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getRandomId
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getRandomId
;
import
static
org
.
briarproject
.
bramble
.
util
.
StringUtils
.
getRandomString
;
import
static
org
.
briarproject
.
bramble
.
util
.
StringUtils
.
getRandomString
;
import
static
org
.
briarproject
.
briar
.
api
.
blog
.
BlogConstants
.
KEY_AUTHOR
;
import
static
org
.
briarproject
.
briar
.
api
.
blog
.
BlogConstants
.
KEY_AUTHOR
;
...
@@ -75,9 +74,9 @@ public class BlogManagerImplTest extends BriarTestCase {
...
@@ -75,9 +74,9 @@ public class BlogManagerImplTest extends BriarTestCase {
private
final
LocalAuthor
localAuthor1
,
localAuthor2
,
rssLocalAuthor
;
private
final
LocalAuthor
localAuthor1
,
localAuthor2
,
rssLocalAuthor
;
private
final
BdfList
authorList1
,
authorList2
,
rssAuthorList
;
private
final
BdfList
authorList1
,
authorList2
,
rssAuthorList
;
private
final
Blog
blog1
,
blog2
,
rssBlog
;
private
final
Blog
blog1
,
blog2
,
rssBlog
;
private
final
long
timestamp
,
timeReceived
;
private
final
MessageId
messageId
,
rssMessageId
;
private
final
Message
message
,
rssMessage
;
private
final
Message
message
,
rssMessage
;
private
final
MessageId
messageId
,
rssMessageId
;
private
final
long
timestamp
,
timeReceived
;
private
final
String
comment
;
private
final
String
comment
;
public
BlogManagerImplTest
()
{
public
BlogManagerImplTest
()
{
...
@@ -94,14 +93,12 @@ public class BlogManagerImplTest extends BriarTestCase {
...
@@ -94,14 +93,12 @@ public class BlogManagerImplTest extends BriarTestCase {
blog1
=
createBlog
(
localAuthor1
,
false
);
blog1
=
createBlog
(
localAuthor1
,
false
);
blog2
=
createBlog
(
localAuthor2
,
false
);
blog2
=
createBlog
(
localAuthor2
,
false
);
rssBlog
=
createBlog
(
rssLocalAuthor
,
true
);
rssBlog
=
createBlog
(
rssLocalAuthor
,
true
);
timestamp
=
System
.
currentTimeMillis
();
message
=
getMessage
(
blog1
.
getId
());
rssMessage
=
getMessage
(
rssBlog
.
getId
());
messageId
=
message
.
getId
();
rssMessageId
=
rssMessage
.
getId
();
timestamp
=
message
.
getTimestamp
();
timeReceived
=
timestamp
+
1
;
timeReceived
=
timestamp
+
1
;
messageId
=
new
MessageId
(
getRandomId
());
rssMessageId
=
new
MessageId
(
getRandomId
());
message
=
new
Message
(
messageId
,
blog1
.
getId
(),
timestamp
,
getRandomBytes
(
MAX_MESSAGE_LENGTH
));
rssMessage
=
new
Message
(
rssMessageId
,
rssBlog
.
getId
(),
timestamp
,
getRandomBytes
(
MAX_MESSAGE_LENGTH
));
comment
=
getRandomString
(
MAX_BLOG_COMMENT_LENGTH
);
comment
=
getRandomString
(
MAX_BLOG_COMMENT_LENGTH
);
}
}
...
@@ -372,9 +369,8 @@ public class BlogManagerImplTest extends BriarTestCase {
...
@@ -372,9 +369,8 @@ public class BlogManagerImplTest extends BriarTestCase {
new
BdfEntry
(
KEY_TIMESTAMP
,
timestamp
),
new
BdfEntry
(
KEY_TIMESTAMP
,
timestamp
),
new
BdfEntry
(
KEY_TIME_RECEIVED
,
timeReceived
)
new
BdfEntry
(
KEY_TIME_RECEIVED
,
timeReceived
)
);
);
MessageId
commentId
=
new
MessageId
(
getRandomId
());
Message
commentMsg
=
getMessage
(
blog1
.
getId
());
Message
commentMsg
=
new
Message
(
commentId
,
blog1
.
getId
(),
MessageId
commentId
=
commentMsg
.
getId
();
timestamp
,
getRandomBytes
(
MAX_MESSAGE_LENGTH
));
BdfDictionary
commentMeta
=
BdfDictionary
.
of
(
BdfDictionary
commentMeta
=
BdfDictionary
.
of
(
new
BdfEntry
(
KEY_TYPE
,
COMMENT
.
getInt
()),
new
BdfEntry
(
KEY_TYPE
,
COMMENT
.
getInt
()),
new
BdfEntry
(
KEY_COMMENT
,
comment
),
new
BdfEntry
(
KEY_COMMENT
,
comment
),
...
@@ -457,9 +453,8 @@ public class BlogManagerImplTest extends BriarTestCase {
...
@@ -457,9 +453,8 @@ public class BlogManagerImplTest extends BriarTestCase {
// The post was originally posted to blog 1, then reblogged to
// The post was originally posted to blog 1, then reblogged to
// blog 2 with a comment
// blog 2 with a comment
BdfList
originalPostBody
=
BdfList
.
of
(
"originalPostBody"
);
BdfList
originalPostBody
=
BdfList
.
of
(
"originalPostBody"
);
MessageId
wrappedPostId
=
new
MessageId
(
getRandomId
());
Message
wrappedPostMsg
=
getMessage
(
blog2
.
getId
());
Message
wrappedPostMsg
=
new
Message
(
wrappedPostId
,
blog2
.
getId
(),
MessageId
wrappedPostId
=
wrappedPostMsg
.
getId
();
timestamp
,
getRandomBytes
(
MAX_MESSAGE_LENGTH
));
BdfDictionary
wrappedPostMeta
=
BdfDictionary
.
of
(
BdfDictionary
wrappedPostMeta
=
BdfDictionary
.
of
(
new
BdfEntry
(
KEY_TYPE
,
WRAPPED_POST
.
getInt
()),
new
BdfEntry
(
KEY_TYPE
,
WRAPPED_POST
.
getInt
()),
new
BdfEntry
(
KEY_RSS_FEED
,
false
),
new
BdfEntry
(
KEY_RSS_FEED
,
false
),
...
@@ -468,9 +463,8 @@ public class BlogManagerImplTest extends BriarTestCase {
...
@@ -468,9 +463,8 @@ public class BlogMana