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
c2b7f85b
Verified
Commit
c2b7f85b
authored
6 years ago
by
Torsten Grote
Browse files
Options
Downloads
Patches
Plain Diff
Remove code from TestDataCreator that breaks encapsulation
parent
ae81eb37
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
briar-core/src/main/java/org/briarproject/briar/test/TestDataCreatorImpl.java
+10
-44
10 additions, 44 deletions
...java/org/briarproject/briar/test/TestDataCreatorImpl.java
with
10 additions
and
44 deletions
briar-core/src/main/java/org/briarproject/briar/test/TestDataCreatorImpl.java
+
10
−
44
View file @
c2b7f85b
...
...
@@ -2,7 +2,6 @@ package org.briarproject.briar.test;
import
org.briarproject.bramble.api.FormatException
;
import
org.briarproject.bramble.api.client.ClientHelper
;
import
org.briarproject.bramble.api.client.ContactGroupFactory
;
import
org.briarproject.bramble.api.contact.Contact
;
import
org.briarproject.bramble.api.contact.ContactId
;
import
org.briarproject.bramble.api.contact.ContactManager
;
...
...
@@ -25,7 +24,6 @@ import org.briarproject.bramble.api.plugin.TorConstants;
import
org.briarproject.bramble.api.plugin.TransportId
;
import
org.briarproject.bramble.api.properties.TransportProperties
;
import
org.briarproject.bramble.api.properties.TransportPropertyManager
;
import
org.briarproject.bramble.api.sync.ClientId
;
import
org.briarproject.bramble.api.sync.Group
;
import
org.briarproject.bramble.api.sync.GroupId
;
import
org.briarproject.bramble.api.sync.MessageId
;
...
...
@@ -34,12 +32,10 @@ import org.briarproject.briar.api.blog.Blog;
import
org.briarproject.briar.api.blog.BlogManager
;
import
org.briarproject.briar.api.blog.BlogPost
;
import
org.briarproject.briar.api.blog.BlogPostFactory
;
import
org.briarproject.briar.api.blog.BlogSharingManager
;
import
org.briarproject.briar.api.client.MessageTracker
;
import
org.briarproject.briar.api.forum.Forum
;
import
org.briarproject.briar.api.forum.ForumManager
;
import
org.briarproject.briar.api.forum.ForumPost
;
import
org.briarproject.briar.api.forum.ForumSharingManager
;
import
org.briarproject.briar.api.messaging.MessagingManager
;
import
org.briarproject.briar.api.messaging.PrivateMessage
;
import
org.briarproject.briar.api.messaging.PrivateMessageFactory
;
...
...
@@ -82,7 +78,6 @@ public class TestDataCreatorImpl implements TestDataCreator {
private
final
DatabaseComponent
db
;
private
final
IdentityManager
identityManager
;
private
final
ContactManager
contactManager
;
private
final
ContactGroupFactory
contactGroupFactory
;
private
final
TransportPropertyManager
transportPropertyManager
;
private
final
MessagingManager
messagingManager
;
private
final
BlogManager
blogManager
;
...
...
@@ -101,7 +96,6 @@ public class TestDataCreatorImpl implements TestDataCreator {
BlogPostFactory
blogPostFactory
,
CryptoComponent
cryptoComponent
,
DatabaseComponent
db
,
IdentityManager
identityManager
,
ContactManager
contactManager
,
ContactGroupFactory
contactGroupFactory
,
TransportPropertyManager
transportPropertyManager
,
MessagingManager
messagingManager
,
BlogManager
blogManager
,
ForumManager
forumManager
,
@IoExecutor
Executor
ioExecutor
)
{
...
...
@@ -115,7 +109,6 @@ public class TestDataCreatorImpl implements TestDataCreator {
this
.
db
=
db
;
this
.
identityManager
=
identityManager
;
this
.
contactManager
=
contactManager
;
this
.
contactGroupFactory
=
contactGroupFactory
;
this
.
transportPropertyManager
=
transportPropertyManager
;
this
.
messagingManager
=
messagingManager
;
this
.
blogManager
=
blogManager
;
...
...
@@ -183,7 +176,6 @@ public class TestDataCreatorImpl implements TestDataCreator {
timestamp
,
true
,
verified
,
true
);
transportPropertyManager
.
addRemoteProperties
(
txn
,
contactId
,
props
);
contact
=
db
.
getContact
(
txn
,
contactId
);
fakeClientVisibilities
(
txn
,
contact
);
db
.
commitTransaction
(
txn
);
}
finally
{
db
.
endTransaction
(
txn
);
...
...
@@ -199,11 +191,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
@Override
public
Contact
addContact
(
String
name
)
throws
DbException
{
// load localAuthor from DB, because cache doesn't get refreshed
// when Espresso tests run within one lifecycle
Transaction
txn
=
db
.
startTransaction
(
false
);
LocalAuthor
localAuthor
=
db
.
getLocalAuthors
(
txn
).
iterator
().
next
();
db
.
endTransaction
(
txn
);
LocalAuthor
localAuthor
=
identityManager
.
getLocalAuthor
();
return
addContact
(
localAuthor
.
getId
(),
getAuthor
(
name
));
}
...
...
@@ -309,8 +297,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
Group
group
=
messagingManager
.
getContactGroup
(
contact
);
for
(
int
i
=
0
;
i
<
numPrivateMsgs
;
i
++)
{
try
{
createRandomPrivateMessage
(
contact
.
getId
(),
group
.
getId
(),
i
);
createRandomPrivateMessage
(
group
.
getId
(),
i
);
}
catch
(
FormatException
e
)
{
throw
new
RuntimeException
(
e
);
}
...
...
@@ -322,30 +309,27 @@ public class TestDataCreatorImpl implements TestDataCreator {
}
}
private
void
createRandomPrivateMessage
(
ContactId
contactId
,
GroupId
groupId
,
int
num
)
throws
DbException
,
FormatException
{
private
void
createRandomPrivateMessage
(
GroupId
groupId
,
int
num
)
throws
DbException
,
FormatException
{
long
timestamp
=
clock
.
currentTimeMillis
()
-
num
*
60
*
1000
;
String
body
=
getRandomText
();
boolean
local
=
random
.
nextBoolean
();
createPrivateMessage
(
contactId
,
groupId
,
body
,
timestamp
,
local
);
createPrivateMessage
(
groupId
,
body
,
timestamp
,
local
);
}
private
void
createPrivateMessage
(
ContactId
contactId
,
GroupId
groupId
,
String
body
,
long
timestamp
,
boolean
local
)
throws
DbException
,
FormatException
{
private
void
createPrivateMessage
(
GroupId
groupId
,
String
body
,
long
timestamp
,
boolean
local
)
throws
DbException
,
FormatException
{
PrivateMessage
m
=
privateMessageFactory
.
createPrivateMessage
(
groupId
,
timestamp
,
body
);
BdfDictionary
meta
=
new
BdfDictionary
();
meta
.
put
(
"timestamp"
,
timestamp
);
meta
.
put
(
"local"
,
local
);
meta
.
put
(
"read"
,
local
);
// all local messages are read
Transaction
txn
=
db
.
startTransaction
(
false
);
try
{
clientHelper
.
addLocalMessage
(
txn
,
m
.
getMessage
(),
meta
,
true
);
if
(
local
)
{
messageTracker
.
trackOutgoingMessage
(
txn
,
m
.
getMessage
());
db
.
receiveMessage
(
txn
,
contactId
,
m
.
getMessage
());
}
if
(
local
)
messageTracker
.
trackOutgoingMessage
(
txn
,
m
.
getMessage
());
else
messageTracker
.
trackIncomingMessage
(
txn
,
m
.
getMessage
());
db
.
commitTransaction
(
txn
);
}
finally
{
...
...
@@ -357,8 +341,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
public
void
addPrivateMessage
(
Contact
contact
,
String
body
,
long
time
,
boolean
local
)
throws
DbException
,
FormatException
{
Group
group
=
messagingManager
.
getContactGroup
(
contact
);
createPrivateMessage
(
contact
.
getId
(),
group
.
getId
(),
body
,
time
,
local
);
createPrivateMessage
(
group
.
getId
(),
body
,
time
,
local
);
}
private
void
createBlogPosts
(
List
<
Contact
>
contacts
,
int
numBlogPosts
)
...
...
@@ -439,23 +422,6 @@ public class TestDataCreatorImpl implements TestDataCreator {
}
}
private
void
fakeClientVisibilities
(
Transaction
txn
,
Contact
contact
)
throws
DbException
{
fakeClientVisibilities
(
txn
,
contact
,
MessagingManager
.
CLIENT_ID
,
MessagingManager
.
MAJOR_VERSION
);
fakeClientVisibilities
(
txn
,
contact
,
ForumSharingManager
.
CLIENT_ID
,
ForumSharingManager
.
MAJOR_VERSION
);
fakeClientVisibilities
(
txn
,
contact
,
BlogSharingManager
.
CLIENT_ID
,
BlogSharingManager
.
MAJOR_VERSION
);
}
private
void
fakeClientVisibilities
(
Transaction
txn
,
Contact
contact
,
ClientId
clientId
,
int
majorVersion
)
throws
DbException
{
Group
group
=
contactGroupFactory
.
createContactGroup
(
clientId
,
majorVersion
,
contact
);
db
.
setGroupVisibility
(
txn
,
contact
.
getId
(),
group
.
getId
(),
SHARED
);
}
private
String
getRandomText
()
{
int
minLength
=
3
+
random
.
nextInt
(
500
);
int
maxWordLength
=
15
;
...
...
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