Allow the user to configure the percentage of test contacts with avatars

This commit is contained in:
Torsten Grote
2020-11-27 14:18:45 -03:00
parent 05f4d63356
commit 19db58ee19
6 changed files with 100 additions and 88 deletions

View File

@@ -116,7 +116,7 @@ public class SetupDataTest extends ScreenshotTest {
throws DbException {
Context ctx = getApplicationContext();
String bobName = ctx.getString(R.string.screenshot_bob);
Contact bob = testDataCreator.addContact(bobName);
Contact bob = testDataCreator.addContact(bobName, true);
// TODO add messages

View File

@@ -24,20 +24,9 @@ public class TestDataActivity extends BriarActivity {
@Inject
TestDataCreator testDataCreator;
private TextView contactsTextView;
private SeekBar contactsSeekBar;
private TextView messagesTextView;
private SeekBar messagesSeekBar;
private TextView blogPostsTextView;
private SeekBar blogPostsSeekBar;
private TextView forumsTextView;
private SeekBar forumsSeekBar;
private TextView forumPostsTextView;
private SeekBar forumPostsSeekBar;
private TextView contactsTextView, forumsTextView;
private SeekBar contactsSeekBar, messagesSeekBar, avatarsSeekBar,
blogPostsSeekBar, forumsSeekBar, forumPostsSeekBar;
@Override
public void onCreate(Bundle bundle) {
@@ -51,12 +40,15 @@ public class TestDataActivity extends BriarActivity {
setContentView(R.layout.activity_test_data);
contactsTextView = findViewById(R.id.textViewContactsSb);
messagesTextView = findViewById(R.id.textViewMessagesSb);
blogPostsTextView = findViewById(R.id.TextViewBlogPostsSb);
TextView messagesTextView = findViewById(R.id.textViewMessagesSb);
TextView avatarsTextView = findViewById(R.id.textViewAvatarsSb);
TextView blogPostsTextView = findViewById(R.id.TextViewBlogPostsSb);
forumsTextView = findViewById(R.id.TextViewForumsSb);
forumPostsTextView = findViewById(R.id.TextViewForumMessagesSb);
TextView forumPostsTextView =
findViewById(R.id.TextViewForumMessagesSb);
contactsSeekBar = findViewById(R.id.seekBarContacts);
messagesSeekBar = findViewById(R.id.seekBarMessages);
avatarsSeekBar = findViewById(R.id.seekBarAvatars);
blogPostsSeekBar = findViewById(R.id.seekBarBlogPosts);
forumsSeekBar = findViewById(R.id.seekBarForums);
forumPostsSeekBar = findViewById(R.id.seekBarForumMessages);
@@ -78,40 +70,12 @@ public class TestDataActivity extends BriarActivity {
}
});
messagesSeekBar
.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar,
int progress, boolean fromUser) {
messagesTextView.setText(String.valueOf(progress));
}
@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) {
}
});
messagesSeekBar.setOnSeekBarChangeListener(
new OnSeekBarChangeUpdateProgress(messagesTextView));
avatarsSeekBar.setOnSeekBarChangeListener(
new OnSeekBarChangeUpdateProgress(avatarsTextView));
blogPostsSeekBar.setOnSeekBarChangeListener(
new OnSeekBarChangeUpdateProgress(blogPostsTextView));
forumsSeekBar
.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
@@ -129,23 +93,8 @@ public class TestDataActivity extends BriarActivity {
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
forumPostsSeekBar
.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) {
}
});
forumPostsSeekBar.setOnSeekBarChangeListener(
new OnSeekBarChangeUpdateProgress(forumPostsTextView));
findViewById(R.id.buttonCreateTestData).setOnClickListener(
v -> createTestData());
@@ -153,8 +102,9 @@ public class TestDataActivity extends BriarActivity {
private void createTestData() {
testDataCreator.createTestData(contactsSeekBar.getProgress() + 1,
messagesSeekBar.getProgress(), blogPostsSeekBar.getProgress(),
forumsSeekBar.getProgress(), forumPostsSeekBar.getProgress());
messagesSeekBar.getProgress(), avatarsSeekBar.getProgress(),
blogPostsSeekBar.getProgress(), forumsSeekBar.getProgress(),
forumPostsSeekBar.getProgress());
Intent intent = new Intent(this, ENTRY_ACTIVITY);
intent.addFlags(FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
@@ -174,4 +124,28 @@ public class TestDataActivity extends BriarActivity {
}
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) {
}
}
}

View File

@@ -71,6 +71,36 @@
app:layout_constraintEnd_toEndOf="parent"
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
android:id="@+id/textViewBlogPosts"
android:layout_width="match_parent"
@@ -78,7 +108,7 @@
android:layout_margin="@dimen/margin_medium"
android:text="Number of blog posts"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/seekBarMessages" />
app:layout_constraintTop_toBottomOf="@+id/seekBarAvatars" />
<SeekBar
android:id="@+id/seekBarBlogPosts"

View File

@@ -14,13 +14,15 @@ public interface TestDataCreator {
* @param numContacts Number of contacts to create. Must be >= 1
* @param numPrivateMsgs Number of private messages to create for each
* 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 numForums Number of forums to create.
* @param numForumPosts Number of forum posts to create per forum.
*/
void createTestData(int numContacts, int numPrivateMsgs, int numBlogPosts,
int numForums, int numForumPosts);
void createTestData(int numContacts, int numPrivateMsgs, int avatarPercent,
int numBlogPosts, int numForums, int numForumPosts);
@IoExecutor
Contact addContact(String name) throws DbException;
Contact addContact(String name, boolean avatar) throws DbException;
}

View File

@@ -124,12 +124,15 @@ public class TestDataCreatorImpl implements TestDataCreator {
@Override
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 (avatarPercent < 0 || avatarPercent > 100)
throw new IllegalArgumentException();
ioExecutor.execute(() -> {
try {
createTestDataOnIoExecutor(numContacts, numPrivateMsgs,
numBlogPosts, numForums, numForumPosts);
avatarPercent, numBlogPosts, numForums, numForumPosts);
} catch (DbException e) {
logException(LOG, WARNING, e);
}
@@ -138,9 +141,9 @@ public class TestDataCreatorImpl implements TestDataCreator {
@IoExecutor
private void createTestDataOnIoExecutor(int numContacts, int numPrivateMsgs,
int numBlogPosts, int numForums, int numForumPosts)
throws DbException {
List<Contact> contacts = createContacts(numContacts);
int avatarPercent, int numBlogPosts, int numForums,
int numForumPosts) throws DbException {
List<Contact> contacts = createContacts(numContacts, avatarPercent);
createPrivateMessages(contacts, numPrivateMsgs);
createBlogPosts(contacts, numBlogPosts);
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);
LocalAuthor localAuthor = identityManager.getLocalAuthor();
for (int i = 0; i < numContacts; i++) {
LocalAuthor remote = getRandomAuthor();
Contact contact = addContact(localAuthor.getId(), remote);
Contact contact =
addContact(localAuthor.getId(), remote, avatarPercent);
contacts.add(contact);
}
return contacts;
}
private Contact addContact(AuthorId localAuthorId, LocalAuthor remote)
throws DbException {
private Contact addContact(AuthorId localAuthorId, LocalAuthor remote,
int avatarPercent) throws DbException {
// prepare to add contact
SecretKey secretKey = getSecretKey();
long timestamp = clock.currentTimeMillis();
@@ -181,7 +186,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
transportPropertyManager.addRemoteProperties(txn, contactId, props);
return db.getContact(txn, contactId);
});
if (random.nextInt(3) < 2) addAvatar(contact);
if (random.nextInt(100) + 1 < avatarPercent) addAvatar(contact);
if (LOG.isLoggable(INFO)) {
LOG.info("Added contact " + remote.getName() +
@@ -192,10 +197,11 @@ public class TestDataCreatorImpl implements TestDataCreator {
}
@Override
public Contact addContact(String name) throws DbException {
public Contact addContact(String name, boolean avatar) throws DbException {
LocalAuthor localAuthor = identityManager.getLocalAuthor();
LocalAuthor remote = authorFactory.createLocalAuthor(name);
return addContact(localAuthor.getId(), remote);
int avatarPercent = avatar ? 100 : 0;
return addContact(localAuthor.getId(), remote, avatarPercent);
}
private String getRandomAuthorName() {

View File

@@ -25,7 +25,7 @@ class ContactControllerIntegrationTest: IntegrationTest() {
// add one test contact
val testContactName= "testContactName"
testDataCreator.addContact(testContactName)
testDataCreator.addContact(testContactName, false)
// retrieve list with one test contact
response = get("$url/contacts")