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
4c533188
Verified
Commit
4c533188
authored
6 years ago
by
akwizgran
Browse files
Options
Downloads
Patches
Plain Diff
Unit tests for client versioning validator.
parent
c5efb6e1
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
bramble-core/src/test/java/org/briarproject/bramble/versioning/ClientVersioningValidatorTest.java
+274
-0
274 additions, 0 deletions
...ect/bramble/versioning/ClientVersioningValidatorTest.java
with
274 additions
and
0 deletions
bramble-core/src/test/java/org/briarproject/bramble/versioning/ClientVersioningValidatorTest.java
0 → 100644
+
274
−
0
View file @
4c533188
package
org.briarproject.bramble.versioning
;
import
org.briarproject.bramble.api.FormatException
;
import
org.briarproject.bramble.api.client.BdfMessageContext
;
import
org.briarproject.bramble.api.client.ClientHelper
;
import
org.briarproject.bramble.api.data.BdfDictionary
;
import
org.briarproject.bramble.api.data.BdfEntry
;
import
org.briarproject.bramble.api.data.BdfList
;
import
org.briarproject.bramble.api.data.MetadataEncoder
;
import
org.briarproject.bramble.api.sync.ClientId
;
import
org.briarproject.bramble.api.sync.Group
;
import
org.briarproject.bramble.api.sync.Message
;
import
org.briarproject.bramble.api.system.Clock
;
import
org.briarproject.bramble.test.BrambleMockTestCase
;
import
org.junit.Test
;
import
static
java
.
util
.
Collections
.
emptyList
;
import
static
org
.
briarproject
.
bramble
.
api
.
sync
.
ClientId
.
MAX_CLIENT_ID_LENGTH
;
import
static
org
.
briarproject
.
bramble
.
api
.
versioning
.
ClientVersioningManager
.
CLIENT_ID
;
import
static
org
.
briarproject
.
bramble
.
api
.
versioning
.
ClientVersioningManager
.
MAJOR_VERSION
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getClientId
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getGroup
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getMessage
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getRandomBytes
;
import
static
org
.
briarproject
.
bramble
.
util
.
StringUtils
.
getRandomString
;
import
static
org
.
briarproject
.
bramble
.
versioning
.
ClientVersioningConstants
.
MSG_KEY_LOCAL
;
import
static
org
.
briarproject
.
bramble
.
versioning
.
ClientVersioningConstants
.
MSG_KEY_UPDATE_VERSION
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
public
class
ClientVersioningValidatorTest
extends
BrambleMockTestCase
{
private
final
ClientHelper
clientHelper
=
context
.
mock
(
ClientHelper
.
class
);
private
final
MetadataEncoder
metadataEncoder
=
context
.
mock
(
MetadataEncoder
.
class
);
private
final
Clock
clock
=
context
.
mock
(
Clock
.
class
);
private
final
ClientVersioningValidator
validator
=
new
ClientVersioningValidator
(
clientHelper
,
metadataEncoder
,
clock
);
private
final
Group
group
=
getGroup
(
CLIENT_ID
,
MAJOR_VERSION
);
private
final
Message
message
=
getMessage
(
group
.
getId
());
private
final
ClientId
clientId
=
getClientId
();
@Test
(
expected
=
FormatException
.
class
)
public
void
testRejectsTooShortBody
()
throws
Exception
{
BdfList
body
=
BdfList
.
of
(
new
BdfList
());
validator
.
validateMessage
(
message
,
group
,
body
);
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testRejectsTooLongBody
()
throws
Exception
{
BdfList
body
=
BdfList
.
of
(
new
BdfList
(),
123
,
null
);
validator
.
validateMessage
(
message
,
group
,
body
);
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testRejectsNullStatesList
()
throws
Exception
{
BdfList
body
=
BdfList
.
of
(
null
,
123
);
validator
.
validateMessage
(
message
,
group
,
body
);
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testRejectsNonListStatesList
()
throws
Exception
{
BdfList
body
=
BdfList
.
of
(
""
,
123
);
validator
.
validateMessage
(
message
,
group
,
body
);
}
@Test
public
void
testAcceptsEmptyStatesList
()
throws
Exception
{
BdfList
body
=
BdfList
.
of
(
new
BdfList
(),
123
);
BdfMessageContext
context
=
validator
.
validateMessage
(
message
,
group
,
body
);
assertEquals
(
emptyList
(),
context
.
getDependencies
());
BdfDictionary
expectedMeta
=
BdfDictionary
.
of
(
new
BdfEntry
(
MSG_KEY_UPDATE_VERSION
,
123L
),
new
BdfEntry
(
MSG_KEY_LOCAL
,
false
));
assertEquals
(
expectedMeta
,
context
.
getDictionary
());
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testRejectsNullUpdateVersion
()
throws
Exception
{
BdfList
body
=
BdfList
.
of
(
new
BdfList
(),
null
);
validator
.
validateMessage
(
message
,
group
,
body
);
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testRejectsNonLongUpdateVersion
()
throws
Exception
{
BdfList
body
=
BdfList
.
of
(
new
BdfList
(),
"123"
);
validator
.
validateMessage
(
message
,
group
,
body
);
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testRejectsNegativeUpdateVersion
()
throws
Exception
{
BdfList
body
=
BdfList
.
of
(
new
BdfList
(),
-
1
);
validator
.
validateMessage
(
message
,
group
,
body
);
}
@Test
public
void
testAcceptsZeroUpdateVersion
()
throws
Exception
{
BdfList
body
=
BdfList
.
of
(
new
BdfList
(),
0
);
BdfMessageContext
context
=
validator
.
validateMessage
(
message
,
group
,
body
);
assertEquals
(
emptyList
(),
context
.
getDependencies
());
BdfDictionary
expectedMeta
=
BdfDictionary
.
of
(
new
BdfEntry
(
MSG_KEY_UPDATE_VERSION
,
0L
),
new
BdfEntry
(
MSG_KEY_LOCAL
,
false
));
assertEquals
(
expectedMeta
,
context
.
getDictionary
());
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testRejectsTooShortClientState
()
throws
Exception
{
BdfList
state
=
BdfList
.
of
(
clientId
.
getString
(),
123
,
234
);
BdfList
body
=
BdfList
.
of
(
BdfList
.
of
(
state
),
345
);
validator
.
validateMessage
(
message
,
group
,
body
);
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testRejectsTooLongClientState
()
throws
Exception
{
BdfList
state
=
BdfList
.
of
(
clientId
.
getString
(),
123
,
234
,
true
,
null
);
BdfList
body
=
BdfList
.
of
(
BdfList
.
of
(
state
),
345
);
validator
.
validateMessage
(
message
,
group
,
body
);
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testRejectsNullClientId
()
throws
Exception
{
BdfList
state
=
BdfList
.
of
(
null
,
123
,
234
,
true
);
BdfList
body
=
BdfList
.
of
(
BdfList
.
of
(
state
),
345
);
validator
.
validateMessage
(
message
,
group
,
body
);
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testRejectsNonStringClientId
()
throws
Exception
{
byte
[]
id
=
getRandomBytes
(
MAX_CLIENT_ID_LENGTH
);
BdfList
state
=
BdfList
.
of
(
id
,
123
,
234
,
true
);
BdfList
body
=
BdfList
.
of
(
BdfList
.
of
(
state
),
345
);
validator
.
validateMessage
(
message
,
group
,
body
);
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testRejectsTooShortClientId
()
throws
Exception
{
BdfList
state
=
BdfList
.
of
(
""
,
123
,
234
,
true
);
BdfList
body
=
BdfList
.
of
(
BdfList
.
of
(
state
),
345
);
validator
.
validateMessage
(
message
,
group
,
body
);
}
@Test
public
void
testAcceptsMinLengthClientId
()
throws
Exception
{
BdfList
state
=
BdfList
.
of
(
getRandomString
(
1
),
123
,
234
,
true
);
BdfList
body
=
BdfList
.
of
(
BdfList
.
of
(
state
),
345
);
BdfMessageContext
context
=
validator
.
validateMessage
(
message
,
group
,
body
);
assertEquals
(
emptyList
(),
context
.
getDependencies
());
BdfDictionary
expectedMeta
=
BdfDictionary
.
of
(
new
BdfEntry
(
MSG_KEY_UPDATE_VERSION
,
345L
),
new
BdfEntry
(
MSG_KEY_LOCAL
,
false
));
assertEquals
(
expectedMeta
,
context
.
getDictionary
());
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testRejectsTooLongClientId
()
throws
Exception
{
String
id
=
getRandomString
(
MAX_CLIENT_ID_LENGTH
+
1
);
BdfList
state
=
BdfList
.
of
(
id
,
123
,
234
,
true
);
BdfList
body
=
BdfList
.
of
(
BdfList
.
of
(
state
),
345
);
validator
.
validateMessage
(
message
,
group
,
body
);
}
@Test
public
void
testAcceptsMaxLengthClientId
()
throws
Exception
{
String
id
=
getRandomString
(
MAX_CLIENT_ID_LENGTH
);
BdfList
state
=
BdfList
.
of
(
id
,
123
,
234
,
true
);
BdfList
body
=
BdfList
.
of
(
BdfList
.
of
(
state
),
345
);
BdfMessageContext
context
=
validator
.
validateMessage
(
message
,
group
,
body
);
assertEquals
(
emptyList
(),
context
.
getDependencies
());
BdfDictionary
expectedMeta
=
BdfDictionary
.
of
(
new
BdfEntry
(
MSG_KEY_UPDATE_VERSION
,
345L
),
new
BdfEntry
(
MSG_KEY_LOCAL
,
false
));
assertEquals
(
expectedMeta
,
context
.
getDictionary
());
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testRejectsNullMajorVersion
()
throws
Exception
{
BdfList
state
=
BdfList
.
of
(
clientId
.
getString
(),
null
,
234
,
true
);
BdfList
body
=
BdfList
.
of
(
BdfList
.
of
(
state
),
345
);
validator
.
validateMessage
(
message
,
group
,
body
);
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testRejectsNonLongMajorVersion
()
throws
Exception
{
BdfList
state
=
BdfList
.
of
(
clientId
.
getString
(),
"123"
,
234
,
true
);
BdfList
body
=
BdfList
.
of
(
BdfList
.
of
(
state
),
345
);
validator
.
validateMessage
(
message
,
group
,
body
);
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testRejectsNegativeMajorVersion
()
throws
Exception
{
BdfList
state
=
BdfList
.
of
(
clientId
.
getString
(),
-
1
,
234
,
true
);
BdfList
body
=
BdfList
.
of
(
BdfList
.
of
(
state
),
345
);
validator
.
validateMessage
(
message
,
group
,
body
);
}
@Test
public
void
testAcceptsZeroMajorVersion
()
throws
Exception
{
BdfList
state
=
BdfList
.
of
(
clientId
.
getString
(),
0
,
234
,
true
);
BdfList
body
=
BdfList
.
of
(
BdfList
.
of
(
state
),
345
);
BdfMessageContext
context
=
validator
.
validateMessage
(
message
,
group
,
body
);
assertEquals
(
emptyList
(),
context
.
getDependencies
());
BdfDictionary
expectedMeta
=
BdfDictionary
.
of
(
new
BdfEntry
(
MSG_KEY_UPDATE_VERSION
,
345L
),
new
BdfEntry
(
MSG_KEY_LOCAL
,
false
));
assertEquals
(
expectedMeta
,
context
.
getDictionary
());
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testRejectsNullMinorVersion
()
throws
Exception
{
BdfList
state
=
BdfList
.
of
(
clientId
.
getString
(),
123
,
null
,
true
);
BdfList
body
=
BdfList
.
of
(
BdfList
.
of
(
state
),
345
);
validator
.
validateMessage
(
message
,
group
,
body
);
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testRejectsNonLongMinorVersion
()
throws
Exception
{
BdfList
state
=
BdfList
.
of
(
clientId
.
getString
(),
123
,
"234"
,
true
);
BdfList
body
=
BdfList
.
of
(
BdfList
.
of
(
state
),
345
);
validator
.
validateMessage
(
message
,
group
,
body
);
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testRejectsNegativeMinorVersion
()
throws
Exception
{
BdfList
state
=
BdfList
.
of
(
clientId
.
getString
(),
123
,
-
1
,
true
);
BdfList
body
=
BdfList
.
of
(
BdfList
.
of
(
state
),
345
);
validator
.
validateMessage
(
message
,
group
,
body
);
}
@Test
public
void
testAcceptsZeroMinorVersion
()
throws
Exception
{
BdfList
state
=
BdfList
.
of
(
clientId
.
getString
(),
123
,
0
,
true
);
BdfList
body
=
BdfList
.
of
(
BdfList
.
of
(
state
),
345
);
BdfMessageContext
context
=
validator
.
validateMessage
(
message
,
group
,
body
);
assertEquals
(
emptyList
(),
context
.
getDependencies
());
BdfDictionary
expectedMeta
=
BdfDictionary
.
of
(
new
BdfEntry
(
MSG_KEY_UPDATE_VERSION
,
345L
),
new
BdfEntry
(
MSG_KEY_LOCAL
,
false
));
assertEquals
(
expectedMeta
,
context
.
getDictionary
());
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testRejectsNullActiveFlag
()
throws
Exception
{
BdfList
state
=
BdfList
.
of
(
clientId
.
getString
(),
123
,
234
,
null
);
BdfList
body
=
BdfList
.
of
(
BdfList
.
of
(
state
),
345
);
validator
.
validateMessage
(
message
,
group
,
body
);
}
@Test
(
expected
=
FormatException
.
class
)
public
void
testRejectsNonBooleanActiveFlag
()
throws
Exception
{
BdfList
state
=
BdfList
.
of
(
clientId
.
getString
(),
123
,
234
,
"true"
);
BdfList
body
=
BdfList
.
of
(
BdfList
.
of
(
state
),
345
);
validator
.
validateMessage
(
message
,
group
,
body
);
}
@Test
public
void
testAcceptsNegativeActiveFlag
()
throws
Exception
{
BdfList
state
=
BdfList
.
of
(
clientId
.
getString
(),
123
,
234
,
false
);
BdfList
body
=
BdfList
.
of
(
BdfList
.
of
(
state
),
345
);
BdfMessageContext
context
=
validator
.
validateMessage
(
message
,
group
,
body
);
assertEquals
(
emptyList
(),
context
.
getDependencies
());
BdfDictionary
expectedMeta
=
BdfDictionary
.
of
(
new
BdfEntry
(
MSG_KEY_UPDATE_VERSION
,
345L
),
new
BdfEntry
(
MSG_KEY_LOCAL
,
false
));
assertEquals
(
expectedMeta
,
context
.
getDictionary
());
}
}
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