Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
briar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julian Dehm
briar
Commits
f20a1e8d
Unverified
Commit
f20a1e8d
authored
9 years ago
by
akwizgran
Browse files
Options
Downloads
Patches
Plain Diff
Fix merge problems in TransportPropertyValidatorTest.
parent
89ca0e5a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
briar-tests/src/org/briarproject/properties/TransportPropertyValidatorTest.java
+67
-82
67 additions, 82 deletions
...iarproject/properties/TransportPropertyValidatorTest.java
with
67 additions
and
82 deletions
briar-tests/src/org/briarproject/properties/TransportPropertyValidatorTest.java
+
67
−
82
View file @
f20a1e8d
package
org.briarproject.properties
;
import
org.briarproject.BriarTestCase
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
org.briarproject.api.data.BdfWriter
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
org.briarproject.properties.TransportPropertyValidator
;
import
org.briarproject.api.properties.TransportProperties
;
import
org.briarproject.TestUtils
;
import
org.briarproject.api.DeviceId
;
import
org.briarproject.api.FormatException
;
import
org.briarproject.api.TransportId
;
import
org.briarproject.api.sync.MessageId
;
import
org.briarproject.api.UniqueId
;
import
org.briarproject.api.sync.GroupId
;
import
org.briarproject.api.sync.ClientId
;
import
org.briarproject.api.DeviceId
;
import
org.briarproject.api.data.BdfWriter
;
import
org.briarproject.api.data.BdfList
;
import
org.briarproject.api.data.BdfReader
;
import
org.briarproject.api.clients.ClientHelper
;
import
org.briarproject.api.data.BdfDictionary
;
import
org.briarproject.api.data.Bdf
Entry
;
import
org.briarproject.api.data.Bdf
List
;
import
org.briarproject.api.data.MetadataEncoder
;
import
org.briarproject.api.system.Clock
;
import
org.briarproject.api.DeviceId
;
import
org.briarproject.api.FormatException
;
import
org.briarproject.api.sync.ClientId
;
import
org.briarproject.api.sync.Group
;
import
org.briarproject.api.sync.GroupId
;
import
org.briarproject.api.sync.Message
;
import
org.briarproject.api.properties.TransportPropertyManager
;
import
org.briarproject.TestUtils
;
import
org.briarproject.util.StringUtils
;
import
org.briarproject.api.sync.MessageId
;
import
org.briarproject.api.system.Clock
;
import
org.jmock.Mockery
;
import
org.junit.Test
;
import
java.io.IOException
;
import
static
org
.
briarproject
.
api
.
TransportId
.
MAX_TRANSPORT_ID_LENGTH
;
import
static
org
.
briarproject
.
api
.
properties
.
TransportPropertyConstants
.
MAX_PROPERTIES_PER_TRANSPORT
;
import
org.jmock.Expectations
;
import
org.jmock.Mockery
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
public
class
TransportPropertyValidatorTest
extends
BriarTestCase
{
private
TransportId
transportId
;
private
MessageId
messageId
;
private
GroupId
groupId
;
private
ClientId
clientId
;
private
DeviceId
deviceId
;
private
final
ClientHelper
h
;
private
final
MetadataEncoder
e
;
private
final
Clock
c
;
private
final
Group
g
;
private
final
TransportId
transportId
;
private
final
DeviceId
deviceId
;
private
final
BdfDictionary
bdfDictionary
;
private
final
Group
group
;
private
final
Message
message
;
private
final
TransportPropertyValidator
tpv
;
private
final
BdfDictionary
d
;
public
TransportPropertyValidatorTest
()
{
public
TransportPropertyValidatorTest
()
{
transportId
=
new
TransportId
(
"test"
);
messageId
=
new
MessageId
(
TestUtils
.
getRandomId
());
groupId
=
new
GroupId
(
TestUtils
.
getRandomId
());
clientId
=
new
ClientId
(
TestUtils
.
getRandomId
());
deviceId
=
new
DeviceId
(
TestUtils
.
getRandomId
());
Mockery
context
=
new
Mockery
();
h
=
context
.
mock
(
ClientHelper
.
class
);
e
=
context
.
mock
(
MetadataEncoder
.
class
);
c
=
context
.
mock
(
Clock
.
class
);
g
=
new
Group
(
groupId
,
clientId
,
TestUtils
.
getRandomBytes
(
12
));
d
=
new
BdfDictionary
();
tpv
=
new
TransportPropertyValidator
(
h
,
e
,
c
);
deviceId
=
new
DeviceId
(
TestUtils
.
getRandomId
());
bdfDictionary
=
new
BdfDictionary
();
GroupId
groupId
=
new
GroupId
(
TestUtils
.
getRandomId
());
ClientId
clientId
=
new
ClientId
(
TestUtils
.
getRandomId
());
byte
[]
descriptor
=
TestUtils
.
getRandomBytes
(
12
);
group
=
new
Group
(
groupId
,
clientId
,
descriptor
);
MessageId
messageId
=
new
MessageId
(
TestUtils
.
getRandomId
());
long
timestamp
=
System
.
currentTimeMillis
();
byte
[]
body
=
TestUtils
.
getRandomBytes
(
123
);
message
=
new
Message
(
messageId
,
groupId
,
timestamp
,
body
);
Mockery
context
=
new
Mockery
();
ClientHelper
clientHelper
=
context
.
mock
(
ClientHelper
.
class
);
MetadataEncoder
metadataEncoder
=
context
.
mock
(
MetadataEncoder
.
class
);
Clock
clock
=
context
.
mock
(
Clock
.
class
);
tpv
=
new
TransportPropertyValidator
(
clientHelper
,
metadataEncoder
,
clock
);
}
@Test
public
void
testValidateProperMessage
()
throws
IOException
{
Bdf
Dictionary
result
;
final
BdfList
m
=
BdfList
.
of
(
deviceId
,
transportId
.
getString
(),
4
,
d
);
Bdf
List
body
=
BdfList
.
of
(
deviceId
,
transportId
.
getString
(),
4
,
bdfDictionary
);
result
=
tpv
.
validateMessage
(
m
,
g
,
1L
);
BdfDictionary
result
=
tpv
.
validateMessage
(
m
essage
,
group
,
body
);
assertEquals
(
"test"
,
result
.
getString
(
"transportId"
));
assertEquals
(
result
.
getLong
(
"version"
).
longValue
(),
4
);
...
...
@@ -90,63 +74,64 @@ public class TransportPropertyValidatorTest extends BriarTestCase {
public
void
testValidateWrongVersionValue
()
throws
IOException
{
/* Will create a negative version number */
BdfList
m
=
BdfList
.
of
(
deviceId
,
transportId
.
getString
(),
-
1
,
d
);
tpv
.
validateMessage
(
m
,
g
,
1L
);
BdfList
body
=
BdfList
.
of
(
deviceId
,
transportId
.
getString
(),
-
1
,
bdfDictionary
);
tpv
.
validateMessage
(
message
,
group
,
body
);
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testValidateWrongVersionType
()
throws
IOException
{
/* Instead of sending a version number I'm sending a dict */
BdfList
m
=
BdfList
.
of
(
deviceId
,
transportId
.
getString
(),
d
,
d
);
tpv
.
validateMessage
(
m
,
g
,
1L
);
BdfList
body
=
BdfList
.
of
(
deviceId
,
transportId
.
getString
(),
bdfDictionary
,
bdfDictionary
);
tpv
.
validateMessage
(
message
,
group
,
body
);
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testValidateShortDeviceId
()
throws
IOException
{
/* Will create a Device Id with a short length, getRaw should work */
BdfList
m
=
BdfList
.
of
(
new
byte
[
UniqueId
.
LENGTH
-
1
],
transportId
.
getString
(),
1
,
d
);
tpv
.
validateMessage
(
m
,
g
,
1L
);
BdfList
body
=
BdfList
.
of
(
new
byte
[
UniqueId
.
LENGTH
-
1
],
transportId
.
getString
(),
1
,
bdfDictionary
);
tpv
.
validateMessage
(
m
essage
,
group
,
body
);
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testValidateLongDeviceId
()
throws
IOException
{
BdfList
m
=
BdfList
.
of
(
new
byte
[
UniqueId
.
LENGTH
+
1
],
transportId
.
getString
(),
1
,
d
);
tpv
.
validateMessage
(
m
,
g
,
1L
);
BdfList
body
=
BdfList
.
of
(
new
byte
[
UniqueId
.
LENGTH
+
1
],
transportId
.
getString
(),
1
,
bdfDictionary
);
tpv
.
validateMessage
(
m
essage
,
group
,
body
);
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testValidateWrongDeviceId
()
throws
IOException
{
BdfList
m
=
BdfList
.
of
(
d
,
transportId
.
getString
(),
1
,
d
);
tpv
.
validateMessage
(
m
,
g
,
1L
);
BdfList
body
=
BdfList
.
of
(
bdfDictionary
,
transportId
.
getString
(),
1
,
bdfDictionary
);
tpv
.
validateMessage
(
message
,
group
,
body
);
}
@Test
(
expected
=
FormatException
.
class
)
@Test
(
expected
=
FormatException
.
class
)
public
void
testValidateLongTransportId
()
throws
IOException
{
/* Generate a string or arbitrary length for the transport id*/
String
wrongTransportIdString
=
TestUtils
.
createRandomString
(
MAX_TRANSPORT_ID_LENGTH
+
1
);
BdfList
m
=
BdfList
.
of
(
deviceId
,
wrongTransportIdString
,
4
,
d
);
tpv
.
validateMessage
(
m
,
g
,
1L
);
String
wrongTransportIdString
=
TestUtils
.
createRandomString
(
MAX_TRANSPORT_ID_LENGTH
+
1
);
BdfList
body
=
BdfList
.
of
(
deviceId
,
wrongTransportIdString
,
4
,
bdfDictionary
);
tpv
.
validateMessage
(
message
,
group
,
body
);
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testValidateTooManyProperties
()
throws
IOException
{
/* Generate a big map for the BdfDictionary*/
HashMap
map
=
new
HashMap
();
BdfDictionary
d
=
new
BdfDictionary
();
for
(
int
i
=
0
;
i
<
MAX_PROPERTIES_PER_TRANSPORT
+
1
;
i
++)
map
.
put
(
""
+
i
,
""
+
i
);
BdfDictionary
d
=
new
BdfDictionary
(
map
);
BdfList
m
=
BdfList
.
of
(
deviceId
,
transportId
.
getString
(),
4
,
d
);
tpv
.
validateMessage
(
m
,
g
,
1L
);
d
.
put
(
String
.
valueOf
(
i
),
i
);
BdfList
body
=
BdfList
.
of
(
deviceId
,
transportId
.
getString
(),
4
,
d
);
tpv
.
validateMessage
(
message
,
group
,
body
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment