mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-21 15:19:53 +01:00
Allow the user to configure the percentage of test contacts with avatars
This commit is contained in:
@@ -116,7 +116,7 @@ public class SetupDataTest extends ScreenshotTest {
|
|||||||
throws DbException {
|
throws DbException {
|
||||||
Context ctx = getApplicationContext();
|
Context ctx = getApplicationContext();
|
||||||
String bobName = ctx.getString(R.string.screenshot_bob);
|
String bobName = ctx.getString(R.string.screenshot_bob);
|
||||||
Contact bob = testDataCreator.addContact(bobName);
|
Contact bob = testDataCreator.addContact(bobName, true);
|
||||||
|
|
||||||
// TODO add messages
|
// TODO add messages
|
||||||
|
|
||||||
|
|||||||
@@ -24,20 +24,9 @@ public class TestDataActivity extends BriarActivity {
|
|||||||
@Inject
|
@Inject
|
||||||
TestDataCreator testDataCreator;
|
TestDataCreator testDataCreator;
|
||||||
|
|
||||||
private TextView contactsTextView;
|
private TextView contactsTextView, forumsTextView;
|
||||||
private SeekBar contactsSeekBar;
|
private SeekBar contactsSeekBar, messagesSeekBar, avatarsSeekBar,
|
||||||
|
blogPostsSeekBar, forumsSeekBar, forumPostsSeekBar;
|
||||||
private TextView messagesTextView;
|
|
||||||
private SeekBar messagesSeekBar;
|
|
||||||
|
|
||||||
private TextView blogPostsTextView;
|
|
||||||
private SeekBar blogPostsSeekBar;
|
|
||||||
|
|
||||||
private TextView forumsTextView;
|
|
||||||
private SeekBar forumsSeekBar;
|
|
||||||
|
|
||||||
private TextView forumPostsTextView;
|
|
||||||
private SeekBar forumPostsSeekBar;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle bundle) {
|
public void onCreate(Bundle bundle) {
|
||||||
@@ -51,12 +40,15 @@ public class TestDataActivity extends BriarActivity {
|
|||||||
|
|
||||||
setContentView(R.layout.activity_test_data);
|
setContentView(R.layout.activity_test_data);
|
||||||
contactsTextView = findViewById(R.id.textViewContactsSb);
|
contactsTextView = findViewById(R.id.textViewContactsSb);
|
||||||
messagesTextView = findViewById(R.id.textViewMessagesSb);
|
TextView messagesTextView = findViewById(R.id.textViewMessagesSb);
|
||||||
blogPostsTextView = findViewById(R.id.TextViewBlogPostsSb);
|
TextView avatarsTextView = findViewById(R.id.textViewAvatarsSb);
|
||||||
|
TextView blogPostsTextView = findViewById(R.id.TextViewBlogPostsSb);
|
||||||
forumsTextView = findViewById(R.id.TextViewForumsSb);
|
forumsTextView = findViewById(R.id.TextViewForumsSb);
|
||||||
forumPostsTextView = findViewById(R.id.TextViewForumMessagesSb);
|
TextView forumPostsTextView =
|
||||||
|
findViewById(R.id.TextViewForumMessagesSb);
|
||||||
contactsSeekBar = findViewById(R.id.seekBarContacts);
|
contactsSeekBar = findViewById(R.id.seekBarContacts);
|
||||||
messagesSeekBar = findViewById(R.id.seekBarMessages);
|
messagesSeekBar = findViewById(R.id.seekBarMessages);
|
||||||
|
avatarsSeekBar = findViewById(R.id.seekBarAvatars);
|
||||||
blogPostsSeekBar = findViewById(R.id.seekBarBlogPosts);
|
blogPostsSeekBar = findViewById(R.id.seekBarBlogPosts);
|
||||||
forumsSeekBar = findViewById(R.id.seekBarForums);
|
forumsSeekBar = findViewById(R.id.seekBarForums);
|
||||||
forumPostsSeekBar = findViewById(R.id.seekBarForumMessages);
|
forumPostsSeekBar = findViewById(R.id.seekBarForumMessages);
|
||||||
@@ -78,40 +70,12 @@ public class TestDataActivity extends BriarActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
messagesSeekBar
|
messagesSeekBar.setOnSeekBarChangeListener(
|
||||||
.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
|
new OnSeekBarChangeUpdateProgress(messagesTextView));
|
||||||
@Override
|
avatarsSeekBar.setOnSeekBarChangeListener(
|
||||||
public void onProgressChanged(SeekBar seekBar,
|
new OnSeekBarChangeUpdateProgress(avatarsTextView));
|
||||||
int progress, boolean fromUser) {
|
blogPostsSeekBar.setOnSeekBarChangeListener(
|
||||||
messagesTextView.setText(String.valueOf(progress));
|
new OnSeekBarChangeUpdateProgress(blogPostsTextView));
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
blogPostsSeekBar
|
|
||||||
.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
|
|
||||||
@Override
|
|
||||||
public void onProgressChanged(SeekBar seekBar,
|
|
||||||
int progress, boolean fromUser) {
|
|
||||||
blogPostsTextView.setText(String.valueOf(progress));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
forumsSeekBar
|
forumsSeekBar
|
||||||
.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
|
.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -129,23 +93,8 @@ public class TestDataActivity extends BriarActivity {
|
|||||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
forumPostsSeekBar.setOnSeekBarChangeListener(
|
||||||
forumPostsSeekBar
|
new OnSeekBarChangeUpdateProgress(forumPostsTextView));
|
||||||
.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
|
|
||||||
@Override
|
|
||||||
public void onProgressChanged(SeekBar seekBar,
|
|
||||||
int progress, boolean fromUser) {
|
|
||||||
forumPostsTextView.setText(String.valueOf(progress));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
findViewById(R.id.buttonCreateTestData).setOnClickListener(
|
findViewById(R.id.buttonCreateTestData).setOnClickListener(
|
||||||
v -> createTestData());
|
v -> createTestData());
|
||||||
@@ -153,8 +102,9 @@ public class TestDataActivity extends BriarActivity {
|
|||||||
|
|
||||||
private void createTestData() {
|
private void createTestData() {
|
||||||
testDataCreator.createTestData(contactsSeekBar.getProgress() + 1,
|
testDataCreator.createTestData(contactsSeekBar.getProgress() + 1,
|
||||||
messagesSeekBar.getProgress(), blogPostsSeekBar.getProgress(),
|
messagesSeekBar.getProgress(), avatarsSeekBar.getProgress(),
|
||||||
forumsSeekBar.getProgress(), forumPostsSeekBar.getProgress());
|
blogPostsSeekBar.getProgress(), forumsSeekBar.getProgress(),
|
||||||
|
forumPostsSeekBar.getProgress());
|
||||||
Intent intent = new Intent(this, ENTRY_ACTIVITY);
|
Intent intent = new Intent(this, ENTRY_ACTIVITY);
|
||||||
intent.addFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
intent.addFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
@@ -174,4 +124,28 @@ public class TestDataActivity extends BriarActivity {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class OnSeekBarChangeUpdateProgress
|
||||||
|
implements OnSeekBarChangeListener {
|
||||||
|
private final TextView textView;
|
||||||
|
|
||||||
|
private OnSeekBarChangeUpdateProgress(TextView textView) {
|
||||||
|
this.textView = textView;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProgressChanged(SeekBar seekBar, int progress,
|
||||||
|
boolean fromUser) {
|
||||||
|
textView.setText(String.valueOf(progress));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,6 +71,36 @@
|
|||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/textViewMessages" />
|
app:layout_constraintTop_toBottomOf="@+id/textViewMessages" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textViewAvatars"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="@dimen/margin_medium"
|
||||||
|
android:text="Percentage of contacts with profile pictures"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/seekBarMessages" />
|
||||||
|
|
||||||
|
<SeekBar
|
||||||
|
android:id="@+id/seekBarAvatars"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:max="100"
|
||||||
|
android:paddingTop="5dp"
|
||||||
|
android:progress="75"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/textViewAvatarsSb"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/textViewAvatars" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textViewAvatarsSb"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ems="2"
|
||||||
|
android:text="75"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@+id/seekBarAvatars"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/textViewAvatars" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textViewBlogPosts"
|
android:id="@+id/textViewBlogPosts"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -78,7 +108,7 @@
|
|||||||
android:layout_margin="@dimen/margin_medium"
|
android:layout_margin="@dimen/margin_medium"
|
||||||
android:text="Number of blog posts"
|
android:text="Number of blog posts"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/seekBarMessages" />
|
app:layout_constraintTop_toBottomOf="@+id/seekBarAvatars" />
|
||||||
|
|
||||||
<SeekBar
|
<SeekBar
|
||||||
android:id="@+id/seekBarBlogPosts"
|
android:id="@+id/seekBarBlogPosts"
|
||||||
|
|||||||
@@ -14,13 +14,15 @@ public interface TestDataCreator {
|
|||||||
* @param numContacts Number of contacts to create. Must be >= 1
|
* @param numContacts Number of contacts to create. Must be >= 1
|
||||||
* @param numPrivateMsgs Number of private messages to create for each
|
* @param numPrivateMsgs Number of private messages to create for each
|
||||||
* contact.
|
* contact.
|
||||||
|
* @param avatarPercent Percentage of contacts
|
||||||
|
* that will use a random profile image. Between 0 and 100.
|
||||||
* @param numBlogPosts Number of blog posts to create.
|
* @param numBlogPosts Number of blog posts to create.
|
||||||
* @param numForums Number of forums to create.
|
* @param numForums Number of forums to create.
|
||||||
* @param numForumPosts Number of forum posts to create per forum.
|
* @param numForumPosts Number of forum posts to create per forum.
|
||||||
*/
|
*/
|
||||||
void createTestData(int numContacts, int numPrivateMsgs, int numBlogPosts,
|
void createTestData(int numContacts, int numPrivateMsgs, int avatarPercent,
|
||||||
int numForums, int numForumPosts);
|
int numBlogPosts, int numForums, int numForumPosts);
|
||||||
|
|
||||||
@IoExecutor
|
@IoExecutor
|
||||||
Contact addContact(String name) throws DbException;
|
Contact addContact(String name, boolean avatar) throws DbException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,12 +124,15 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createTestData(int numContacts, int numPrivateMsgs,
|
public void createTestData(int numContacts, int numPrivateMsgs,
|
||||||
int numBlogPosts, int numForums, int numForumPosts) {
|
int avatarPercent, int numBlogPosts, int numForums,
|
||||||
|
int numForumPosts) {
|
||||||
if (numContacts == 0) throw new IllegalArgumentException();
|
if (numContacts == 0) throw new IllegalArgumentException();
|
||||||
|
if (avatarPercent < 0 || avatarPercent > 100)
|
||||||
|
throw new IllegalArgumentException();
|
||||||
ioExecutor.execute(() -> {
|
ioExecutor.execute(() -> {
|
||||||
try {
|
try {
|
||||||
createTestDataOnIoExecutor(numContacts, numPrivateMsgs,
|
createTestDataOnIoExecutor(numContacts, numPrivateMsgs,
|
||||||
numBlogPosts, numForums, numForumPosts);
|
avatarPercent, numBlogPosts, numForums, numForumPosts);
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
logException(LOG, WARNING, e);
|
logException(LOG, WARNING, e);
|
||||||
}
|
}
|
||||||
@@ -138,9 +141,9 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
|||||||
|
|
||||||
@IoExecutor
|
@IoExecutor
|
||||||
private void createTestDataOnIoExecutor(int numContacts, int numPrivateMsgs,
|
private void createTestDataOnIoExecutor(int numContacts, int numPrivateMsgs,
|
||||||
int numBlogPosts, int numForums, int numForumPosts)
|
int avatarPercent, int numBlogPosts, int numForums,
|
||||||
throws DbException {
|
int numForumPosts) throws DbException {
|
||||||
List<Contact> contacts = createContacts(numContacts);
|
List<Contact> contacts = createContacts(numContacts, avatarPercent);
|
||||||
createPrivateMessages(contacts, numPrivateMsgs);
|
createPrivateMessages(contacts, numPrivateMsgs);
|
||||||
createBlogPosts(contacts, numBlogPosts);
|
createBlogPosts(contacts, numBlogPosts);
|
||||||
List<Forum> forums = createForums(contacts, numForums);
|
List<Forum> forums = createForums(contacts, numForums);
|
||||||
@@ -149,19 +152,21 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Contact> createContacts(int numContacts) throws DbException {
|
private List<Contact> createContacts(int numContacts, int avatarPercent)
|
||||||
|
throws DbException {
|
||||||
List<Contact> contacts = new ArrayList<>(numContacts);
|
List<Contact> contacts = new ArrayList<>(numContacts);
|
||||||
LocalAuthor localAuthor = identityManager.getLocalAuthor();
|
LocalAuthor localAuthor = identityManager.getLocalAuthor();
|
||||||
for (int i = 0; i < numContacts; i++) {
|
for (int i = 0; i < numContacts; i++) {
|
||||||
LocalAuthor remote = getRandomAuthor();
|
LocalAuthor remote = getRandomAuthor();
|
||||||
Contact contact = addContact(localAuthor.getId(), remote);
|
Contact contact =
|
||||||
|
addContact(localAuthor.getId(), remote, avatarPercent);
|
||||||
contacts.add(contact);
|
contacts.add(contact);
|
||||||
}
|
}
|
||||||
return contacts;
|
return contacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Contact addContact(AuthorId localAuthorId, LocalAuthor remote)
|
private Contact addContact(AuthorId localAuthorId, LocalAuthor remote,
|
||||||
throws DbException {
|
int avatarPercent) throws DbException {
|
||||||
// prepare to add contact
|
// prepare to add contact
|
||||||
SecretKey secretKey = getSecretKey();
|
SecretKey secretKey = getSecretKey();
|
||||||
long timestamp = clock.currentTimeMillis();
|
long timestamp = clock.currentTimeMillis();
|
||||||
@@ -181,7 +186,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
|||||||
transportPropertyManager.addRemoteProperties(txn, contactId, props);
|
transportPropertyManager.addRemoteProperties(txn, contactId, props);
|
||||||
return db.getContact(txn, contactId);
|
return db.getContact(txn, contactId);
|
||||||
});
|
});
|
||||||
if (random.nextInt(3) < 2) addAvatar(contact);
|
if (random.nextInt(100) + 1 < avatarPercent) addAvatar(contact);
|
||||||
|
|
||||||
if (LOG.isLoggable(INFO)) {
|
if (LOG.isLoggable(INFO)) {
|
||||||
LOG.info("Added contact " + remote.getName() +
|
LOG.info("Added contact " + remote.getName() +
|
||||||
@@ -192,10 +197,11 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Contact addContact(String name) throws DbException {
|
public Contact addContact(String name, boolean avatar) throws DbException {
|
||||||
LocalAuthor localAuthor = identityManager.getLocalAuthor();
|
LocalAuthor localAuthor = identityManager.getLocalAuthor();
|
||||||
LocalAuthor remote = authorFactory.createLocalAuthor(name);
|
LocalAuthor remote = authorFactory.createLocalAuthor(name);
|
||||||
return addContact(localAuthor.getId(), remote);
|
int avatarPercent = avatar ? 100 : 0;
|
||||||
|
return addContact(localAuthor.getId(), remote, avatarPercent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getRandomAuthorName() {
|
private String getRandomAuthorName() {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class ContactControllerIntegrationTest: IntegrationTest() {
|
|||||||
|
|
||||||
// add one test contact
|
// add one test contact
|
||||||
val testContactName= "testContactName"
|
val testContactName= "testContactName"
|
||||||
testDataCreator.addContact(testContactName)
|
testDataCreator.addContact(testContactName, false)
|
||||||
|
|
||||||
// retrieve list with one test contact
|
// retrieve list with one test contact
|
||||||
response = get("$url/contacts")
|
response = get("$url/contacts")
|
||||||
|
|||||||
Reference in New Issue
Block a user