Search in sources :

Example 16 with JobData

use of org.thoughtcrime.securesms.jobmanager.JobMigration.JobData in project Signal-Android by WhisperSystems.

the class RecipientIdJobMigrationTest method migrate_pushGroupSendJob_null.

@Test
public void migrate_pushGroupSendJob_null() throws Exception {
    JobData testData = new JobData("PushGroupSendJob", "someGroupId", new Data.Builder().putString("filter_address", null).putLong("message_id", 123).build());
    mockRecipientResolve("someGroupId", 5);
    RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
    JobData converted = subject.migrate(testData);
    assertEquals("PushGroupSendJob", converted.getFactoryKey());
    assertEquals(RecipientId.from(5).toQueueKey(), converted.getQueueKey());
    assertNull(converted.getData().getString("filter_recipient"));
    assertFalse(converted.getData().hasString("filter_address"));
    new PushGroupSendJob.Factory().create(mock(Job.Parameters.class), converted.getData());
}
Also used : PushGroupSendJob(org.thoughtcrime.securesms.jobs.PushGroupSendJob) JobData(org.thoughtcrime.securesms.jobmanager.JobMigration.JobData) Application(android.app.Application) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 17 with JobData

use of org.thoughtcrime.securesms.jobmanager.JobMigration.JobData in project Signal-Android by WhisperSystems.

the class RecipientIdJobMigrationTest method migrate_directoryRefreshJob_null.

@Test
public void migrate_directoryRefreshJob_null() throws Exception {
    JobData testData = new JobData("DirectoryRefreshJob", "DirectoryRefreshJob", new Data.Builder().putString("address", null).putBoolean("notify_of_new_users", true).build());
    RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
    JobData converted = subject.migrate(testData);
    assertEquals("DirectoryRefreshJob", converted.getFactoryKey());
    assertEquals("DirectoryRefreshJob", converted.getQueueKey());
    assertNull(converted.getData().getString("recipient"));
    assertTrue(converted.getData().getBoolean("notify_of_new_users"));
    assertFalse(converted.getData().hasString("address"));
    new DirectoryRefreshJob.Factory().create(mock(Job.Parameters.class), converted.getData());
}
Also used : DirectoryRefreshJob(org.thoughtcrime.securesms.jobs.DirectoryRefreshJob) JobData(org.thoughtcrime.securesms.jobmanager.JobMigration.JobData) Application(android.app.Application) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 18 with JobData

use of org.thoughtcrime.securesms.jobmanager.JobMigration.JobData in project Signal-Android by WhisperSystems.

the class RecipientIdJobMigrationTest method migrate_smsSendJob_nonNull.

@Test
public void migrate_smsSendJob_nonNull() throws Exception {
    JobData testData = new JobData("SmsSendJob", "+16101234567", new Data.Builder().putLong("message_id", 1).putInt("run_attempt", 0).build());
    mockRecipientResolve("+16101234567", 1);
    RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
    JobData converted = subject.migrate(testData);
    assertEquals("SmsSendJob", converted.getFactoryKey());
    assertEquals(RecipientId.from(1).toQueueKey(), converted.getQueueKey());
    assertEquals(1, converted.getData().getLong("message_id"));
    assertEquals(0, converted.getData().getInt("run_attempt"));
    new SmsSendJob.Factory().create(mock(Job.Parameters.class), converted.getData());
}
Also used : SmsSendJob(org.thoughtcrime.securesms.jobs.SmsSendJob) JobData(org.thoughtcrime.securesms.jobmanager.JobMigration.JobData) Application(android.app.Application) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 19 with JobData

use of org.thoughtcrime.securesms.jobmanager.JobMigration.JobData in project Signal-Android by WhisperSystems.

the class RecipientIdJobMigrationTest method migrate_multiDeviceReadUpdateJob_twoIds.

@Test
public void migrate_multiDeviceReadUpdateJob_twoIds() throws Exception {
    OldSerializableSyncMessageId id1 = new OldSerializableSyncMessageId("+16101234567", 1);
    OldSerializableSyncMessageId id2 = new OldSerializableSyncMessageId("+16101112222", 2);
    JobData testData = new JobData("MultiDeviceReadUpdateJob", null, new Data.Builder().putStringArray("message_ids", new String[] { JsonUtils.toJson(id1), JsonUtils.toJson(id2) }).build());
    mockRecipientResolve("+16101234567", 1);
    mockRecipientResolve("+16101112222", 2);
    RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
    JobData converted = subject.migrate(testData);
    assertEquals("MultiDeviceReadUpdateJob", converted.getFactoryKey());
    assertNull(converted.getQueueKey());
    String[] updated = converted.getData().getStringArray("message_ids");
    assertEquals(2, updated.length);
    assertEquals(JsonUtils.toJson(new NewSerializableSyncMessageId("1", 1)), updated[0]);
    assertEquals(JsonUtils.toJson(new NewSerializableSyncMessageId("2", 2)), updated[1]);
    new MultiDeviceReadUpdateJob.Factory().create(mock(Job.Parameters.class), converted.getData());
}
Also used : OldSerializableSyncMessageId(org.thoughtcrime.securesms.jobmanager.migrations.RecipientIdJobMigration.OldSerializableSyncMessageId) NewSerializableSyncMessageId(org.thoughtcrime.securesms.jobmanager.migrations.RecipientIdJobMigration.NewSerializableSyncMessageId) JobData(org.thoughtcrime.securesms.jobmanager.JobMigration.JobData) Data(org.thoughtcrime.securesms.jobmanager.Data) JobData(org.thoughtcrime.securesms.jobmanager.JobMigration.JobData) Application(android.app.Application) MultiDeviceReadUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceReadUpdateJob) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 20 with JobData

use of org.thoughtcrime.securesms.jobmanager.JobMigration.JobData in project Signal-Android by WhisperSystems.

the class RecipientIdJobMigrationTest method migrate_sendDeliveryReceiptJob.

@Test
public void migrate_sendDeliveryReceiptJob() throws Exception {
    JobData testData = new JobData("SendDeliveryReceiptJob", null, new Data.Builder().putString("address", "+16101234567").putLong("message_id", 1).putLong("timestamp", 2).build());
    mockRecipientResolve("+16101234567", 1);
    RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
    JobData converted = subject.migrate(testData);
    assertEquals("SendDeliveryReceiptJob", converted.getFactoryKey());
    assertNull(converted.getQueueKey());
    assertEquals("1", converted.getData().getString("recipient"));
    assertEquals(1, converted.getData().getLong("message_id"));
    assertEquals(2, converted.getData().getLong("timestamp"));
    new SendDeliveryReceiptJob.Factory().create(mock(Job.Parameters.class), converted.getData());
}
Also used : SendDeliveryReceiptJob(org.thoughtcrime.securesms.jobs.SendDeliveryReceiptJob) JobData(org.thoughtcrime.securesms.jobmanager.JobMigration.JobData) Data(org.thoughtcrime.securesms.jobmanager.Data) JobData(org.thoughtcrime.securesms.jobmanager.JobMigration.JobData) Application(android.app.Application) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

JobData (org.thoughtcrime.securesms.jobmanager.JobMigration.JobData)22 Test (org.junit.Test)21 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)21 Application (android.app.Application)17 Data (org.thoughtcrime.securesms.jobmanager.Data)9 NewSerializableSyncMessageId (org.thoughtcrime.securesms.jobmanager.migrations.RecipientIdJobMigration.NewSerializableSyncMessageId)2 OldSerializableSyncMessageId (org.thoughtcrime.securesms.jobmanager.migrations.RecipientIdJobMigration.OldSerializableSyncMessageId)2 DirectoryRefreshJob (org.thoughtcrime.securesms.jobs.DirectoryRefreshJob)2 FailingJob (org.thoughtcrime.securesms.jobs.FailingJob)2 MultiDeviceReadUpdateJob (org.thoughtcrime.securesms.jobs.MultiDeviceReadUpdateJob)2 PushGroupSendJob (org.thoughtcrime.securesms.jobs.PushGroupSendJob)2 RequestGroupInfoJob (org.thoughtcrime.securesms.jobs.RequestGroupInfoJob)2 SendDeliveryReceiptJob (org.thoughtcrime.securesms.jobs.SendDeliveryReceiptJob)2 SmsSendJob (org.thoughtcrime.securesms.jobs.SmsSendJob)2 SuppressLint (android.annotation.SuppressLint)1 JobSpec (org.thoughtcrime.securesms.jobmanager.persistence.JobSpec)1 MultiDeviceContactUpdateJob (org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob)1 MultiDeviceVerifiedUpdateJob (org.thoughtcrime.securesms.jobs.MultiDeviceVerifiedUpdateJob)1 MultiDeviceViewOnceOpenJob (org.thoughtcrime.securesms.jobs.MultiDeviceViewOnceOpenJob)1 PushGroupUpdateJob (org.thoughtcrime.securesms.jobs.PushGroupUpdateJob)1