From 1b254ee1fa0b3084c435bae8db7fc71e1113f6d3 Mon Sep 17 00:00:00 2001 From: Norbel Ambanumben Date: Wed, 29 Nov 2023 11:50:36 +0100 Subject: [PATCH] Updated functions and tests --- .github/workflows/test.yml | 2 +- .../ooniprobe/ui/RunningActivityTest.java | 4 +- .../ui/resultdetails/CircumventionTest.java | 22 ++++------ .../resultdetails/InstantMessagingTest.java | 20 ++++----- .../ui/resultdetails/PerformanceTest.java | 18 ++++---- .../TestResultsMainScreenTest.java | 33 +++++++-------- .../ui/resultdetails/WebsitesTest.java | 11 ++--- .../ooniprobe/domain/GetTestSuite.java | 1 + .../ooniprobe/model/database/Result.java | 20 ++++++++- .../test/suite/AbstractSuiteExtensions.kt | 17 +++++--- .../ooniprobe/test/suite/DynamicTestSuite.kt | 4 +- .../ooniprobe/common/ResubmitTaskTest.java | 10 ++--- .../ooniprobe/domain/GetResultsTest.java | 12 +++--- .../ooniprobe/domain/GetTestSuiteTest.java | 2 +- .../domain/MeasurementsManagerTest.java | 14 +++---- .../ooniprobe/model/database/NetworkTest.java | 2 +- .../ooniprobe/model/database/ResultTest.java | 20 +-------- .../ooniprobe/test/TestAsyncTaskTest.java | 4 +- .../test/suite/AbstractSuiteTest.java | 20 +++------ .../ooniprobe/test/test/AbstractTestTest.java | 18 ++++---- .../ooniprobe/factory/ResultFactory.java | 41 ++++++++++--------- 21 files changed, 145 insertions(+), 150 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f743fca58..ef0bc109f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,4 +17,4 @@ jobs: if: failure() with: name: test-results - path: app/build/test-results/testStableFullDebugUnitTest + path: app/build/reports/tests/testStableFullReleaseUnitTest diff --git a/app/src/androidTest/java/org/openobservatory/ooniprobe/ui/RunningActivityTest.java b/app/src/androidTest/java/org/openobservatory/ooniprobe/ui/RunningActivityTest.java index c32b53906..1a9f6e62b 100644 --- a/app/src/androidTest/java/org/openobservatory/ooniprobe/ui/RunningActivityTest.java +++ b/app/src/androidTest/java/org/openobservatory/ooniprobe/ui/RunningActivityTest.java @@ -17,12 +17,12 @@ import org.openobservatory.ooniprobe.AbstractTest; import org.openobservatory.ooniprobe.activity.MainActivity; import org.openobservatory.ooniprobe.activity.RunningActivity; +import org.openobservatory.ooniprobe.common.OONITests; import org.openobservatory.ooniprobe.common.service.RunTestService; import org.openobservatory.ooniprobe.engine.TestEngineInterface; import org.openobservatory.ooniprobe.model.jsonresult.EventResult; import org.openobservatory.ooniprobe.test.EngineProvider; import org.openobservatory.ooniprobe.test.suite.AbstractSuite; -import org.openobservatory.ooniprobe.test.suite.InstantMessagingSuite; import org.openobservatory.ooniprobe.utils.DatabaseUtils; import java.util.ArrayList; @@ -87,7 +87,7 @@ private void startRunTestService() { serviceRule.startService( new Intent(c, RunTestService.class) .putExtra("testSuites", new ArrayList() {{ - add(new InstantMessagingSuite()); + add(OONITests.WEBSITES.toOONIDescriptor(c).getTest(c)); }}) ); } catch (TimeoutException e) { diff --git a/app/src/androidTest/java/org/openobservatory/ooniprobe/ui/resultdetails/CircumventionTest.java b/app/src/androidTest/java/org/openobservatory/ooniprobe/ui/resultdetails/CircumventionTest.java index 233060e1b..74490219a 100644 --- a/app/src/androidTest/java/org/openobservatory/ooniprobe/ui/resultdetails/CircumventionTest.java +++ b/app/src/androidTest/java/org/openobservatory/ooniprobe/ui/resultdetails/CircumventionTest.java @@ -1,26 +1,22 @@ package org.openobservatory.ooniprobe.ui.resultdetails; import androidx.test.ext.junit.runners.AndroidJUnit4; - import com.schibsted.spain.barista.rule.flaky.AllowFlaky; import com.schibsted.spain.barista.rule.flaky.FlakyTestRule; - import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.openobservatory.ooniprobe.R; +import org.openobservatory.ooniprobe.common.OONITests; import org.openobservatory.ooniprobe.factory.ResultFactory; import org.openobservatory.ooniprobe.model.database.Measurement; import org.openobservatory.ooniprobe.model.database.Result; -import org.openobservatory.ooniprobe.test.suite.CircumventionSuite; import org.openobservatory.ooniprobe.utils.FormattingUtils; import static androidx.test.espresso.Espresso.onView; import static androidx.test.espresso.action.ViewActions.click; import static androidx.test.espresso.assertion.ViewAssertions.matches; -import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; -import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static androidx.test.espresso.matcher.ViewMatchers.withText; +import static androidx.test.espresso.matcher.ViewMatchers.*; @RunWith(AndroidJUnit4.class) public class CircumventionTest extends MeasurementAbstractTest { @@ -32,7 +28,7 @@ public class CircumventionTest extends MeasurementAbstractTest { @AllowFlaky(attempts = 3) public void testHeaderData() { // Arrange - Result testResult = ResultFactory.createAndSave(new CircumventionSuite(), 3, 0); + Result testResult = ResultFactory.createAndSave(OONITests.CIRCUMVENTION.toOONIDescriptor(c), 3, 0); // Act launchDetails(testResult.id); @@ -44,7 +40,7 @@ public void testHeaderData() { @Test public void testSuccessPsiphon() { // Arrange - Result testResult = ResultFactory.createAndSave(new CircumventionSuite(), 3, 0); + Result testResult = ResultFactory.createAndSave(OONITests.CIRCUMVENTION.toOONIDescriptor(c), 3, 0); Measurement measurement = testResult.getMeasurement("psiphon"); String formattedBootstrap = FormattingUtils.formatBootstrap(measurement.getTestKeys().bootstrap_time); @@ -61,7 +57,7 @@ public void testSuccessPsiphon() { @Test public void testBlockedPsiphon() { // Arrange - Result testResult = ResultFactory.createAndSave(new CircumventionSuite(), 0, 3); + Result testResult = ResultFactory.createAndSave(OONITests.CIRCUMVENTION.toOONIDescriptor(c), 0, 3); Measurement measurement = testResult.getMeasurement("psiphon"); // Act @@ -77,7 +73,7 @@ public void testBlockedPsiphon() { @Test public void testSuccessTor() { // Arrange - Result testResult = ResultFactory.createAndSave(new CircumventionSuite(), 3, 0); + Result testResult = ResultFactory.createAndSave(OONITests.CIRCUMVENTION.toOONIDescriptor(c), 3, 0); Measurement measurement = testResult.getMeasurement("tor"); String formattedBridges = FormattingUtils.getFormattedBridges(measurement); @@ -97,7 +93,7 @@ public void testSuccessTor() { @Test public void testBlockedTor() { // Arrange - Result testResult = ResultFactory.createAndSave(new CircumventionSuite(), 0, 3); + Result testResult = ResultFactory.createAndSave(OONITests.CIRCUMVENTION.toOONIDescriptor(c), 0, 3); Measurement measurement = testResult.getMeasurement("tor"); String formattedBridges = FormattingUtils.getFormattedBridges(measurement); @@ -117,7 +113,7 @@ public void testBlockedTor() { @Test public void testSuccessfulRiseUpVPN() { // Arrange - Result testResult = ResultFactory.createAndSave(new CircumventionSuite(), 3, 0); + Result testResult = ResultFactory.createAndSave(OONITests.CIRCUMVENTION.toOONIDescriptor(c), 3, 0); Measurement measurement = testResult.getMeasurement("riseupvpn"); // Act @@ -135,7 +131,7 @@ public void testSuccessfulRiseUpVPN() { @Test public void testBlockedRiseUpVPN() { // Arrange - Result testResult = ResultFactory.createAndSave(new CircumventionSuite(), 0, 3); + Result testResult = ResultFactory.createAndSave(OONITests.CIRCUMVENTION.toOONIDescriptor(c), 0, 3); Measurement measurement = testResult.getMeasurement("riseupvpn"); // Act diff --git a/app/src/androidTest/java/org/openobservatory/ooniprobe/ui/resultdetails/InstantMessagingTest.java b/app/src/androidTest/java/org/openobservatory/ooniprobe/ui/resultdetails/InstantMessagingTest.java index f76732f4a..9fe71176e 100644 --- a/app/src/androidTest/java/org/openobservatory/ooniprobe/ui/resultdetails/InstantMessagingTest.java +++ b/app/src/androidTest/java/org/openobservatory/ooniprobe/ui/resultdetails/InstantMessagingTest.java @@ -9,9 +9,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.openobservatory.ooniprobe.R; +import org.openobservatory.ooniprobe.common.OONITests; import org.openobservatory.ooniprobe.factory.ResultFactory; import org.openobservatory.ooniprobe.model.database.Result; -import org.openobservatory.ooniprobe.test.suite.InstantMessagingSuite; import static androidx.test.espresso.Espresso.onView; import static androidx.test.espresso.action.ViewActions.click; @@ -30,7 +30,7 @@ public class InstantMessagingTest extends MeasurementAbstractTest { @AllowFlaky(attempts = 3) public void testHeaderData() { // Arrange - Result testResult = ResultFactory.createAndSave(new InstantMessagingSuite()); + Result testResult = ResultFactory.createAndSave(OONITests.INSTANT_MESSAGING.toOONIDescriptor(c)); // Act launchDetails(testResult.id); @@ -43,7 +43,7 @@ public void testHeaderData() { @AllowFlaky(attempts = 2) public void testSuccessWhatsApp() { // Arrange - Result testResult = ResultFactory.createAndSave(new InstantMessagingSuite()); + Result testResult = ResultFactory.createAndSave(OONITests.INSTANT_MESSAGING.toOONIDescriptor(c)); // Act launchDetails(testResult.id); @@ -57,7 +57,7 @@ public void testSuccessWhatsApp() { @Test public void testBlockedWhatsApp() { // Arrange - Result testResult = ResultFactory.createAndSave(new InstantMessagingSuite(), 0, 4); + Result testResult = ResultFactory.createAndSave(OONITests.INSTANT_MESSAGING.toOONIDescriptor(c), 0, 4); // Act launchDetails(testResult.id); @@ -72,7 +72,7 @@ public void testBlockedWhatsApp() { @Test public void testSuccessTelegram() { // Arrange - Result testResult = ResultFactory.createAndSave(new InstantMessagingSuite()); + Result testResult = ResultFactory.createAndSave(OONITests.INSTANT_MESSAGING.toOONIDescriptor(c)); // Act launchDetails(testResult.id); @@ -87,7 +87,7 @@ public void testSuccessTelegram() { @Test public void testBlockedTelegram() { // Arrange - Result testResult = ResultFactory.createAndSave(new InstantMessagingSuite(), 0, 4); + Result testResult = ResultFactory.createAndSave(OONITests.INSTANT_MESSAGING.toOONIDescriptor(c), 0, 4); // Act launchDetails(testResult.id); @@ -102,7 +102,7 @@ public void testBlockedTelegram() { @Test public void testSuccessFacebookMessenger() { // Arrange - Result testResult = ResultFactory.createAndSave(new InstantMessagingSuite()); + Result testResult = ResultFactory.createAndSave(OONITests.INSTANT_MESSAGING.toOONIDescriptor(c)); // Act launchDetails(testResult.id); @@ -117,7 +117,7 @@ public void testSuccessFacebookMessenger() { @Test public void testBlockedFacebookMessenger() { // Arrange - Result testResult = ResultFactory.createAndSave(new InstantMessagingSuite(), 0, 4); + Result testResult = ResultFactory.createAndSave(OONITests.INSTANT_MESSAGING.toOONIDescriptor(c), 0, 4); // Act launchDetails(testResult.id); @@ -132,7 +132,7 @@ public void testBlockedFacebookMessenger() { @Test public void testSuccessSignal() { // Arrange - Result testResult = ResultFactory.createAndSave(new InstantMessagingSuite()); + Result testResult = ResultFactory.createAndSave(OONITests.INSTANT_MESSAGING.toOONIDescriptor(c)); // Act launchDetails(testResult.id); @@ -146,7 +146,7 @@ public void testSuccessSignal() { @Test public void testBlockedSignal() { // Arrange - Result testResult = ResultFactory.createAndSave(new InstantMessagingSuite(), 0, 4); + Result testResult = ResultFactory.createAndSave(OONITests.INSTANT_MESSAGING.toOONIDescriptor(c), 0, 4); // Act launchDetails(testResult.id); diff --git a/app/src/androidTest/java/org/openobservatory/ooniprobe/ui/resultdetails/PerformanceTest.java b/app/src/androidTest/java/org/openobservatory/ooniprobe/ui/resultdetails/PerformanceTest.java index 130d8c779..be966e492 100644 --- a/app/src/androidTest/java/org/openobservatory/ooniprobe/ui/resultdetails/PerformanceTest.java +++ b/app/src/androidTest/java/org/openobservatory/ooniprobe/ui/resultdetails/PerformanceTest.java @@ -9,11 +9,11 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.openobservatory.ooniprobe.R; +import org.openobservatory.ooniprobe.common.OONITests; import org.openobservatory.ooniprobe.factory.ResultFactory; import org.openobservatory.ooniprobe.model.database.Measurement; import org.openobservatory.ooniprobe.model.database.Result; import org.openobservatory.ooniprobe.model.jsonresult.TestKeys; -import org.openobservatory.ooniprobe.test.suite.PerformanceSuite; import org.openobservatory.ooniprobe.test.test.Dash; import org.openobservatory.ooniprobe.test.test.HttpHeaderFieldManipulation; import org.openobservatory.ooniprobe.test.test.HttpInvalidRequestLine; @@ -43,7 +43,7 @@ public class PerformanceTest extends MeasurementAbstractTest { @AllowFlaky(attempts = 3) public void testHeaderData() { // Arrange - Result testResult = ResultFactory.createAndSave(new PerformanceSuite()); + Result testResult = ResultFactory.createAndSave(OONITests.PERFORMANCE.toOONIDescriptor(c)); Measurement dashMeasurement = testResult.getMeasurement(Dash.NAME); String videoQuality = getResourceString(dashMeasurement.getTestKeys().getVideoQuality(false)); @@ -90,7 +90,7 @@ public void testHeaderData() { @Test public void testListOfMeasurements() { // Arrange - Result testResult = ResultFactory.createAndSave(new PerformanceSuite()); + Result testResult = ResultFactory.createAndSave(OONITests.PERFORMANCE.toOONIDescriptor(c)); Measurement dashMeasurement = testResult.getMeasurement(Dash.NAME); String videoQuality = getResourceString(dashMeasurement.getTestKeys().getVideoQuality(true)); String notDetected = getResourceString(R.string.TestResults_Overview_MiddleBoxes_NotFound); @@ -147,7 +147,7 @@ public void testListOfMeasurements() { @Test public void testNDT() { // Arrange - Result testResult = ResultFactory.createAndSave(new PerformanceSuite()); + Result testResult = ResultFactory.createAndSave(OONITests.PERFORMANCE.toOONIDescriptor(c)); Measurement ndtMeasurement = testResult.getMeasurement(Ndt.NAME); Integer ndtProtocol = ndtMeasurement.getTestKeys().protocol; TestKeys.Summary ndtSummary = ndtMeasurement.getTestKeys().summary; @@ -193,7 +193,7 @@ public void testNDT() { @Test public void testStreaming() { // Arrange - Result testResult = ResultFactory.createAndSave(new PerformanceSuite()); + Result testResult = ResultFactory.createAndSave(OONITests.PERFORMANCE.toOONIDescriptor(c)); Measurement dashMeasurement = testResult.getMeasurement(Dash.NAME); String videoQuality = getResourceString(dashMeasurement.getTestKeys().getVideoQuality(true)); String bitrateUnit = getResourceString(dashMeasurement.getTestKeys().getMedianBitrateUnit()); @@ -214,7 +214,7 @@ public void testStreaming() { @Test public void testRequestLine() { // Arrange - Result testResult = ResultFactory.createAndSave(new PerformanceSuite()); + Result testResult = ResultFactory.createAndSave(OONITests.PERFORMANCE.toOONIDescriptor(c)); Measurement invalidRequest = testResult.getMeasurement(HttpInvalidRequestLine.NAME); // Act @@ -229,7 +229,7 @@ public void testRequestLine() { @Test public void testRequestLineDetection() { // Arrange - Result testResult = ResultFactory.createAndSave(new PerformanceSuite(), 2, 2); + Result testResult = ResultFactory.createAndSave(OONITests.PERFORMANCE.toOONIDescriptor(c), 2, 2); Measurement invalidRequest = testResult.getMeasurement(HttpInvalidRequestLine.NAME); // Act @@ -244,7 +244,7 @@ public void testRequestLineDetection() { @Test public void testFieldManipulation() { // Arrange - Result testResult = ResultFactory.createAndSave(new PerformanceSuite()); + Result testResult = ResultFactory.createAndSave(OONITests.PERFORMANCE.toOONIDescriptor(c)); Measurement fieldManipulation = testResult.getMeasurement(HttpHeaderFieldManipulation.NAME); // Act @@ -259,7 +259,7 @@ public void testFieldManipulation() { @Test public void testFieldManipulationDetection() { // Arrange - Result testResult = ResultFactory.createAndSave(new PerformanceSuite(), 2, 2); + Result testResult = ResultFactory.createAndSave(OONITests.PERFORMANCE.toOONIDescriptor(c), 2, 2); Measurement fieldManipulation = testResult.getMeasurement(HttpHeaderFieldManipulation.NAME); // Act diff --git a/app/src/androidTest/java/org/openobservatory/ooniprobe/ui/resultdetails/TestResultsMainScreenTest.java b/app/src/androidTest/java/org/openobservatory/ooniprobe/ui/resultdetails/TestResultsMainScreenTest.java index ce29aa11a..9ecb2c9cb 100644 --- a/app/src/androidTest/java/org/openobservatory/ooniprobe/ui/resultdetails/TestResultsMainScreenTest.java +++ b/app/src/androidTest/java/org/openobservatory/ooniprobe/ui/resultdetails/TestResultsMainScreenTest.java @@ -9,13 +9,10 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.openobservatory.ooniprobe.R; +import org.openobservatory.ooniprobe.common.OONITests; import org.openobservatory.ooniprobe.factory.ResultFactory; import org.openobservatory.ooniprobe.model.database.Result; import org.openobservatory.ooniprobe.model.jsonresult.TestKeys; -import org.openobservatory.ooniprobe.test.suite.CircumventionSuite; -import org.openobservatory.ooniprobe.test.suite.InstantMessagingSuite; -import org.openobservatory.ooniprobe.test.suite.PerformanceSuite; -import org.openobservatory.ooniprobe.test.suite.WebsitesSuite; import org.openobservatory.ooniprobe.test.test.Dash; import org.openobservatory.ooniprobe.test.test.Ndt; import org.openobservatory.ooniprobe.utils.FormattingUtils; @@ -49,10 +46,10 @@ public class TestResultsMainScreenTest extends MeasurementAbstractTest { @AllowFlaky(attempts = 3) public void testHeaderData() { // Arrange - Result websites = ResultFactory.createAndSave(new WebsitesSuite()); - Result messaging = ResultFactory.createAndSave(new InstantMessagingSuite()); - Result circumvention = ResultFactory.createAndSave(new CircumventionSuite(), 1, 2); - Result performance = ResultFactory.createAndSave(new PerformanceSuite()); + Result websites = ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c)); + Result messaging = ResultFactory.createAndSave(OONITests.INSTANT_MESSAGING.toOONIDescriptor(c)); + Result circumvention = ResultFactory.createAndSave(OONITests.CIRCUMVENTION.toOONIDescriptor(c), 1, 2); + Result performance = ResultFactory.createAndSave(OONITests.PERFORMANCE.toOONIDescriptor(c)); long totalDownload = websites.data_usage_down + messaging.data_usage_down + @@ -78,19 +75,19 @@ public void testHeaderData() { @AllowFlaky(attempts = 3) public void testListOfResults() { // Arrange - Result websites = ResultFactory.createAndSave(new WebsitesSuite()); + Result websites = ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c)); websites.start_time = getDateFrom(1, Calendar.JANUARY, 2020); websites.save(); - Result messaging = ResultFactory.createAndSave(new InstantMessagingSuite()); + Result messaging = ResultFactory.createAndSave(OONITests.INSTANT_MESSAGING.toOONIDescriptor(c)); messaging.start_time = getDateFrom(1, Calendar.FEBRUARY, 2020); messaging.save(); - Result circumvention = ResultFactory.createAndSave(new CircumventionSuite(), 1, 2); + Result circumvention = ResultFactory.createAndSave(OONITests.CIRCUMVENTION.toOONIDescriptor(c), 1, 2); circumvention.start_time = getDateFrom(1, Calendar.MARCH, 2020); circumvention.save(); - Result performance = ResultFactory.createAndSave(new PerformanceSuite()); + Result performance = ResultFactory.createAndSave(OONITests.PERFORMANCE.toOONIDescriptor(c)); performance.start_time = getDateFrom(1, Calendar.APRIL, 2020); performance.save(); @@ -189,8 +186,8 @@ public void testListOfResults() { @AllowFlaky(attempts = 3) public void deleteResultsTest() { // Arrange - ResultFactory.createAndSave(new WebsitesSuite()); - ResultFactory.createAndSave(new PerformanceSuite()); + ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c)); + ResultFactory.createAndSave(OONITests.PERFORMANCE.toOONIDescriptor(c)); // Act launchResults(); @@ -208,19 +205,19 @@ public void deleteResultsTest() { @AllowFlaky(attempts = 3) public void filterTest() { // Arrange - Result websites = ResultFactory.createAndSave(new WebsitesSuite()); + Result websites = ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c)); websites.start_time = getDateFrom(1, Calendar.JANUARY, 2020); websites.save(); - Result messaging = ResultFactory.createAndSave(new InstantMessagingSuite()); + Result messaging = ResultFactory.createAndSave(OONITests.INSTANT_MESSAGING.toOONIDescriptor(c)); messaging.start_time = getDateFrom(1, Calendar.FEBRUARY, 2020); messaging.save(); - Result circumvention = ResultFactory.createAndSave(new CircumventionSuite(), 1, 2); + Result circumvention = ResultFactory.createAndSave(OONITests.CIRCUMVENTION.toOONIDescriptor(c), 1, 2); circumvention.start_time = getDateFrom(1, Calendar.MARCH, 2020); circumvention.save(); - Result performance = ResultFactory.createAndSave(new PerformanceSuite()); + Result performance = ResultFactory.createAndSave(OONITests.PERFORMANCE.toOONIDescriptor(c)); performance.start_time = getDateFrom(1, Calendar.APRIL, 2020); performance.save(); diff --git a/app/src/androidTest/java/org/openobservatory/ooniprobe/ui/resultdetails/WebsitesTest.java b/app/src/androidTest/java/org/openobservatory/ooniprobe/ui/resultdetails/WebsitesTest.java index 543b6d698..d2e9bb67e 100644 --- a/app/src/androidTest/java/org/openobservatory/ooniprobe/ui/resultdetails/WebsitesTest.java +++ b/app/src/androidTest/java/org/openobservatory/ooniprobe/ui/resultdetails/WebsitesTest.java @@ -10,6 +10,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.openobservatory.ooniprobe.R; +import org.openobservatory.ooniprobe.common.OONITests; import org.openobservatory.ooniprobe.factory.ResultFactory; import org.openobservatory.ooniprobe.model.database.Measurement; import org.openobservatory.ooniprobe.model.database.Result; @@ -41,7 +42,7 @@ public class WebsitesTest extends MeasurementAbstractTest { @AllowFlaky(attempts = 3) public void testHeaderData() { // Arrange - Result testResult = ResultFactory.createAndSave(new WebsitesSuite(), 10, 2); + Result testResult = ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c), 10, 2); // Act launchDetails(testResult.id); @@ -56,7 +57,7 @@ public void checkListOfMeasurementsTest() { int successfulMeasurements = 10; int failedMeasurement = 2; - Result testResult = ResultFactory.createAndSave(new WebsitesSuite(), successfulMeasurements, failedMeasurement); + Result testResult = ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c), successfulMeasurements, failedMeasurement); List measurements = testResult.getMeasurementsSorted(); // Act @@ -77,7 +78,7 @@ public void checkListOfMeasurementsTest() { @Test public void testSucceed() { // Arrange - Result testResult = ResultFactory.createAndSave(new WebsitesSuite()); + Result testResult = ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c)); Measurement measurement = testResult.getMeasurementsSorted().get(0); String headerOutcome = measurement.getUrlString() + "\n" + getResourceString(R.string.TestResults_Details_Websites_Reachable_Hero_Title); @@ -93,7 +94,7 @@ public void testSucceed() { @Test public void testBlocked() { // Arrange - Result testResult = ResultFactory.createAndSave(new WebsitesSuite(), 0, 3); + Result testResult = ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c), 0, 3); Measurement measurement = testResult.getMeasurementsSorted().get(0); String headerOutcome = measurement.getUrlString() + "\n" + BLOCKED_OUTCOME; @@ -114,7 +115,7 @@ public void canRerunTest() { int failedMeasurement = 2; int totalNumberOfMeasurements = successfulMeasurements + failedMeasurement; - Result testResult = ResultFactory.createAndSave(new WebsitesSuite(), successfulMeasurements, failedMeasurement); + Result testResult = ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c), successfulMeasurements, failedMeasurement); String websites = totalNumberOfMeasurements + " " + getResourceString(R.string.websites); List measurements = testResult.getMeasurementsSorted(); diff --git a/app/src/main/java/org/openobservatory/ooniprobe/domain/GetTestSuite.java b/app/src/main/java/org/openobservatory/ooniprobe/domain/GetTestSuite.java index 043202335..9e917f65c 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/domain/GetTestSuite.java +++ b/app/src/main/java/org/openobservatory/ooniprobe/domain/GetTestSuite.java @@ -12,6 +12,7 @@ import org.openobservatory.ooniprobe.model.database.Result; import org.openobservatory.ooniprobe.model.database.Url; import org.openobservatory.ooniprobe.test.suite.AbstractSuite; +import org.openobservatory.ooniprobe.test.suite.DynamicTestSuite; import org.openobservatory.ooniprobe.test.test.WebConnectivity; import java.util.List; diff --git a/app/src/main/java/org/openobservatory/ooniprobe/model/database/Result.java b/app/src/main/java/org/openobservatory/ooniprobe/model/database/Result.java index d0af38a01..c624a1069 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/model/database/Result.java +++ b/app/src/main/java/org/openobservatory/ooniprobe/model/database/Result.java @@ -13,10 +13,12 @@ import org.apache.commons.io.FileUtils; import org.openobservatory.engine.BaseNettest; +import org.openobservatory.ooniprobe.R; import org.openobservatory.ooniprobe.common.AppDatabase; import org.openobservatory.ooniprobe.common.OONIDescriptor; import org.openobservatory.ooniprobe.common.OONITests; import org.openobservatory.ooniprobe.test.suite.AbstractSuite; +import org.openobservatory.ooniprobe.test.suite.DynamicTestSuite; import org.openobservatory.ooniprobe.test.test.Dash; import org.openobservatory.ooniprobe.test.test.FacebookMessenger; import org.openobservatory.ooniprobe.test.test.HttpHeaderFieldManipulation; @@ -27,6 +29,7 @@ import org.openobservatory.ooniprobe.test.test.WebConnectivity; import org.openobservatory.ooniprobe.test.test.Whatsapp; +import javax.annotation.Nullable; import java.io.Serializable; import java.text.DecimalFormat; import java.util.ArrayList; @@ -201,6 +204,21 @@ public void delete(Context c) { } public OONIDescriptor getDescriptor(Context context) { - return OONITests.valueOf(test_group_name).toOONIDescriptor(context); + try { + return OONITests.valueOf(test_group_name).toOONIDescriptor(context); + } catch (IllegalArgumentException e) { + return new OONIDescriptor<>( + test_group_name, + test_group_name, + test_group_name, + test_group_name, + test_group_name, + R.color.color_gray7_1, + test_group_name, + R.string.TestResults_NotAvailable, + new ArrayList<>(), + new ArrayList<>() + ); + } } } diff --git a/app/src/main/java/org/openobservatory/ooniprobe/test/suite/AbstractSuiteExtensions.kt b/app/src/main/java/org/openobservatory/ooniprobe/test/suite/AbstractSuiteExtensions.kt index e879a3863..a6352d570 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/test/suite/AbstractSuiteExtensions.kt +++ b/app/src/main/java/org/openobservatory/ooniprobe/test/suite/AbstractSuiteExtensions.kt @@ -3,25 +3,30 @@ package org.openobservatory.ooniprobe.test.suite import org.openobservatory.ooniprobe.common.Application import org.openobservatory.ooniprobe.common.ooniDescriptors import org.openobservatory.ooniprobe.model.database.Url +import org.openobservatory.ooniprobe.test.test.AbstractTest fun getSuite( app: Application, tn: String, - urls: List?, + urls: List?, origin: String? ): AbstractSuite? { - for (suite in ooniDescriptors(app).map { return@map it.getTest(app) }) { - for (test in suite.getTestList(app.preferenceManager)) { + for (descriptor in ooniDescriptors(app)) { + for (test in descriptor.nettests) { if (test.name == tn) { if (urls != null) { for (url in urls) { Url.checkExistingUrl(url) } } - test.inputs = urls - test.setOrigin(origin) - suite.setTestList(test) + val suite: DynamicTestSuite = descriptor.getTest(app) + suite.setTestList( + AbstractTest.getTestByName(test.name).apply { + setOrigin(origin) + inputs = urls + } + ) return suite } } diff --git a/app/src/main/java/org/openobservatory/ooniprobe/test/suite/DynamicTestSuite.kt b/app/src/main/java/org/openobservatory/ooniprobe/test/suite/DynamicTestSuite.kt index 46f20b3cb..1b24d01c0 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/test/suite/DynamicTestSuite.kt +++ b/app/src/main/java/org/openobservatory/ooniprobe/test/suite/DynamicTestSuite.kt @@ -43,7 +43,9 @@ class DynamicTestSuite( } }.toTypedArray() - super.setTestList(*tests) + if(super.getTestList(pm)?.isEmpty() == true){ + super.setTestList(*tests) + } return super.getTestList(pm) } } diff --git a/app/src/test/java/org/openobservatory/ooniprobe/common/ResubmitTaskTest.java b/app/src/test/java/org/openobservatory/ooniprobe/common/ResubmitTaskTest.java index 4bd215a7c..4ceff6e72 100644 --- a/app/src/test/java/org/openobservatory/ooniprobe/common/ResubmitTaskTest.java +++ b/app/src/test/java/org/openobservatory/ooniprobe/common/ResubmitTaskTest.java @@ -40,8 +40,8 @@ public void setUp() { @Test public void notUploadedMeasurementsTest() { // Arrange - Result testResult = ResultFactory.createAndSaveWithEntryFiles(c, OONITests.WEBSITES.toOONIDescriptor(c).getTest(c), 5, 0, false); - ResultFactory.createAndSaveWithEntryFiles(c, OONITests.WEBSITES.toOONIDescriptor(c).getTest(c), 5, 0, false); + Result testResult = ResultFactory.createAndSaveWithEntryFiles(c, OONITests.WEBSITES.toOONIDescriptor(c), 5, 0, false); + ResultFactory.createAndSaveWithEntryFiles(c, OONITests.WEBSITES.toOONIDescriptor(c), 5, 0, false); ResubmitTask resubmitTask = build(testResult.id); when(managerMock.reSubmit(any(), any())).thenReturn(true); @@ -58,8 +58,8 @@ public void notUploadedMeasurementsTest() { @Test public void notUploadedByResultIdMeasurementsTest() { // Arrange - Result testResult = ResultFactory.createAndSaveWithEntryFiles(c, OONITests.WEBSITES.toOONIDescriptor(c).getTest(c), 5, 0, false); - ResultFactory.createAndSaveWithEntryFiles(c, OONITests.WEBSITES.toOONIDescriptor(c).getTest(c), 5, 0, false); + Result testResult = ResultFactory.createAndSaveWithEntryFiles(c, OONITests.WEBSITES.toOONIDescriptor(c), 5, 0, false); + ResultFactory.createAndSaveWithEntryFiles(c, OONITests.WEBSITES.toOONIDescriptor(c), 5, 0, false); ResubmitTask resubmitTask = build(testResult.id); when(managerMock.reSubmit(any(), any())).thenReturn(true); @@ -76,7 +76,7 @@ public void notUploadedByResultIdMeasurementsTest() { @Test public void notUploadedByMeasurementIdMeasurementsTest() { // Arrange - Result testResult = ResultFactory.createAndSaveWithEntryFiles(c, OONITests.WEBSITES.toOONIDescriptor(c).getTest(c), 5, 0, false); + Result testResult = ResultFactory.createAndSaveWithEntryFiles(c, OONITests.WEBSITES.toOONIDescriptor(c), 5, 0, false); ResubmitTask resubmitTask = build(testResult.id); when(managerMock.reSubmit(any(), any())).thenReturn(true); diff --git a/app/src/test/java/org/openobservatory/ooniprobe/domain/GetResultsTest.java b/app/src/test/java/org/openobservatory/ooniprobe/domain/GetResultsTest.java index e6d50dc75..1318cc033 100644 --- a/app/src/test/java/org/openobservatory/ooniprobe/domain/GetResultsTest.java +++ b/app/src/test/java/org/openobservatory/ooniprobe/domain/GetResultsTest.java @@ -26,7 +26,7 @@ public void setUp() { @Test public void getterTest() { // Arrange - Result result = ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c).getTest(c)); + Result result = ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c)); GetResults getResults = build(); // Act @@ -60,7 +60,7 @@ public void getterTest() { assertEquals(all.get(0).test_group_name, OONITests.PERFORMANCE.getLabel()); assertEquals(all.get(1).test_group_name, OONITests.CIRCUMVENTION.getLabel()); assertEquals(all.get(2).test_group_name, OONITests.INSTANT_MESSAGING.getLabel()); - assertEquals(all.get(3).test_group_name, OONITests.INSTANT_MESSAGING.getLabel()); + assertEquals(all.get(3).test_group_name, OONITests.WEBSITES.getLabel()); } @Test public void groupedByMonth() { @@ -100,19 +100,19 @@ public void getterTest() { private void createDatedResults() { - Result websites = ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c).getTest(c)); + Result websites = ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c)); websites.start_time = getDateFrom(1, Calendar.JANUARY, 2020); websites.save(); - Result messaging = ResultFactory.createAndSave(OONITests.INSTANT_MESSAGING.toOONIDescriptor(c).getTest(c)); + Result messaging = ResultFactory.createAndSave(OONITests.INSTANT_MESSAGING.toOONIDescriptor(c)); messaging.start_time = getDateFrom(1, Calendar.FEBRUARY, 2020); messaging.save(); - Result circumvention = ResultFactory.createAndSave(OONITests.CIRCUMVENTION.toOONIDescriptor(c).getTest(c), 1, 2); + Result circumvention = ResultFactory.createAndSave(OONITests.CIRCUMVENTION.toOONIDescriptor(c), 1, 2); circumvention.start_time = getDateFrom(1, Calendar.MARCH, 2020); circumvention.save(); - Result performance = ResultFactory.createAndSave(OONITests.PERFORMANCE.toOONIDescriptor(c).getTest(c)); + Result performance = ResultFactory.createAndSave(OONITests.PERFORMANCE.toOONIDescriptor(c)); performance.start_time = getDateFrom(1, Calendar.APRIL, 2020); performance.save(); } diff --git a/app/src/test/java/org/openobservatory/ooniprobe/domain/GetTestSuiteTest.java b/app/src/test/java/org/openobservatory/ooniprobe/domain/GetTestSuiteTest.java index eb085395b..a4dd79e74 100644 --- a/app/src/test/java/org/openobservatory/ooniprobe/domain/GetTestSuiteTest.java +++ b/app/src/test/java/org/openobservatory/ooniprobe/domain/GetTestSuiteTest.java @@ -64,7 +64,7 @@ public void testWithoutAttributes() { public void testGetFromResult() { // Arrange GetTestSuite getTestSuite = build(); - Result result = ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c).getTest(c)); + Result result = ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c)); int measurementsUrls = result.getMeasurements().size(); PreferenceManager pm = mock(PreferenceManager.class); diff --git a/app/src/test/java/org/openobservatory/ooniprobe/domain/MeasurementsManagerTest.java b/app/src/test/java/org/openobservatory/ooniprobe/domain/MeasurementsManagerTest.java index 02c524a8f..c7dff9ee4 100644 --- a/app/src/test/java/org/openobservatory/ooniprobe/domain/MeasurementsManagerTest.java +++ b/app/src/test/java/org/openobservatory/ooniprobe/domain/MeasurementsManagerTest.java @@ -80,7 +80,7 @@ public void testGetMeasurement() { public void testCanUpload() { // Arrange List measurements = - ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c).getTest(c), 1, 0, false) + ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c), 1, 0, false) .getMeasurements(); MeasurementFactory.addEntryFiles(c, measurements, false); @@ -223,7 +223,7 @@ public void checkAndDeleteReportFailTest() { @Test public void testUploadableReports() { // Arrange - Result testResult = ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c).getTest(c), 5, 0, false); + Result testResult = ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c), 5, 0, false); MeasurementFactory.addEntryFiles(c, testResult.getMeasurements(), false); testResult.save(); @@ -237,7 +237,7 @@ public void testUploadableReports() { @Test public void testNoUploadableReports() { // Arrange - ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c).getTest(c)); + ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c)); // Act boolean hasReports = manager.hasUploadables(); @@ -276,7 +276,7 @@ public void getReadableLog() throws IOException { public void getReadableEntry() throws IOException { // Arrange Measurement measurement = - ResultFactory.createAndSaveWithEntryFiles(c, OONITests.WEBSITES.toOONIDescriptor(c).getTest(c), 1, 0, false) + ResultFactory.createAndSaveWithEntryFiles(c, OONITests.WEBSITES.toOONIDescriptor(c), 1, 0, false) .getMeasurements().get(0); when(jsonPrinter.prettyText("test")).thenReturn("pretty test"); @@ -336,7 +336,7 @@ public void downloadReportSuccessTest() { @Test public void downloadReportFailTest() { // Arrange - Measurement measurement = ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c).getTest(c)).getMeasurements().get(0); + Measurement measurement = ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c)).getMeasurements().get(0); ApiMeasurement.Result result = new ApiMeasurement.Result(); result.measurement_url = faker.internet.url(); String failedCallbackResponse = "Something went wrong"; @@ -424,7 +424,7 @@ public void reSubmitTest() { String fileContent = "{}"; Measurement measurement = ResultFactory.createAndSaveWithEntryFiles( c, - OONITests.WEBSITES.toOONIDescriptor(c).getTest(c), + OONITests.WEBSITES.toOONIDescriptor(c), 5, 0, false @@ -462,7 +462,7 @@ public void reSubmitTest() { } private Measurement buildMeasurement() { - return ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c).getTest(c)) + return ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c)) .getMeasurements() .get(0); } diff --git a/app/src/test/java/org/openobservatory/ooniprobe/model/database/NetworkTest.java b/app/src/test/java/org/openobservatory/ooniprobe/model/database/NetworkTest.java index 9ab383c6f..244c1d919 100644 --- a/app/src/test/java/org/openobservatory/ooniprobe/model/database/NetworkTest.java +++ b/app/src/test/java/org/openobservatory/ooniprobe/model/database/NetworkTest.java @@ -88,7 +88,7 @@ public void deleteTest() { // Arrange Network noResultNetwork = NetworkFactory.build(); noResultNetwork.save(); - Network resultNetwork = ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c).getTest(c)).network; + Network resultNetwork = ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c)).network; // Act boolean noResultDelete = noResultNetwork.delete(); diff --git a/app/src/test/java/org/openobservatory/ooniprobe/model/database/ResultTest.java b/app/src/test/java/org/openobservatory/ooniprobe/model/database/ResultTest.java index ab1533a88..e07240b2d 100644 --- a/app/src/test/java/org/openobservatory/ooniprobe/model/database/ResultTest.java +++ b/app/src/test/java/org/openobservatory/ooniprobe/model/database/ResultTest.java @@ -129,24 +129,6 @@ public void getMeasurementsSorted_instantMessaging() { assertEquals(Signal.NAME, measurements.get(1).test_name); } - /*@Test - public void getMeasurementsSorted_middleBoxes() { - Result result = new Result(OONITests.MiddleBox.getLabel()); - result.save(); - Measurement httpHeader = new Measurement(result, HttpHeaderFieldManipulation.NAME); - httpHeader.is_done = true; - httpHeader.save(); - Measurement httpInvalid = new Measurement(result, HttpInvalidRequestLine.NAME); - httpInvalid.is_done = true; - httpInvalid.save(); - - List measurements = result.getMeasurementsSorted(); - - assertEquals(2, measurements.size()); - assertEquals(HttpInvalidRequestLine.NAME, measurements.get(0).test_name); - assertEquals(HttpHeaderFieldManipulation.NAME, measurements.get(1).test_name); - }*/ - @Test public void getMeasurementsSorted_performance() { Result result = new Result(OONITests.PERFORMANCE.getLabel()); @@ -232,7 +214,7 @@ public void getTestSuite() { assertEquals(OONITests.PERFORMANCE.getLabel(), new Result(OONITests.PERFORMANCE.getLabel()).getTestSuite(c).getName()); assertEquals(OONITests.CIRCUMVENTION.getLabel(), new Result(OONITests.CIRCUMVENTION.getLabel()).getTestSuite(c).getName()); assertEquals(OONITests.EXPERIMENTAL.getLabel(), new Result(OONITests.EXPERIMENTAL.getLabel()).getTestSuite(c).getName()); - assertNull(new Result("invalid").getTestSuite(c)); + assertEquals(new Result("invalid").getTestSuite(c).getName(),"invalid"); } @Test diff --git a/app/src/test/java/org/openobservatory/ooniprobe/test/TestAsyncTaskTest.java b/app/src/test/java/org/openobservatory/ooniprobe/test/TestAsyncTaskTest.java index 92bf03d62..accca53d5 100644 --- a/app/src/test/java/org/openobservatory/ooniprobe/test/TestAsyncTaskTest.java +++ b/app/src/test/java/org/openobservatory/ooniprobe/test/TestAsyncTaskTest.java @@ -75,7 +75,7 @@ public void storesTestSuitInDb() { AbstractSuite mockedSuite = mock(AbstractSuite.class); suiteList.add(mockedSuite); TestAsyncTask task = new TestAsyncTask(a, suiteList); - Result testResult = ResultFactory.build(OONITests.WEBSITES.toOONIDescriptor(c).getTest(c), true, true); + Result testResult = ResultFactory.build(OONITests.WEBSITES.toOONIDescriptor(c), true, true); when(mockedSuite.getTestList(any())).thenReturn(new AbstractTest[0]); @@ -102,7 +102,7 @@ public void downloadsWebSuitUrls() throws Exception { AbstractSuite mockedSuite = mock(AbstractSuite.class); suiteList.add(mockedSuite); TestAsyncTask task = new TestAsyncTask(a, suiteList); - Result testResult = ResultFactory.build(OONITests.WEBSITES.toOONIDescriptor(c).getTest(c), true, true); + Result testResult = ResultFactory.build(OONITests.WEBSITES.toOONIDescriptor(c), true, true); WebConnectivity test = new WebConnectivity(); test.setInputs(null); diff --git a/app/src/test/java/org/openobservatory/ooniprobe/test/suite/AbstractSuiteTest.java b/app/src/test/java/org/openobservatory/ooniprobe/test/suite/AbstractSuiteTest.java index 8f6d5fb9d..3f4b97db4 100644 --- a/app/src/test/java/org/openobservatory/ooniprobe/test/suite/AbstractSuiteTest.java +++ b/app/src/test/java/org/openobservatory/ooniprobe/test/suite/AbstractSuiteTest.java @@ -1,7 +1,5 @@ package org.openobservatory.ooniprobe.test.suite; -import static org.openobservatory.ooniprobe.test.suite.AbstractSuiteExtensionsKt.getSuite; - import org.junit.Before; import org.junit.Test; import org.openobservatory.ooniprobe.R; @@ -16,32 +14,29 @@ import java.util.ArrayList; import java.util.Collections; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.Assert.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import static org.openobservatory.ooniprobe.test.suite.AbstractSuiteExtensionsKt.getSuite; public class AbstractSuiteTest { - + private final Application app = mock(Application.class); private AbstractSuite suite = new AbstractSuite( "test", - app.getResources().getString(R.string.Test_Middleboxes_Fullname), - app.getResources().getString(R.string.Dashboard_Middleboxes_Card_Description), + "", + "", R.drawable.test_middle_boxes, R.drawable.test_middle_boxes_24, R.color.color_violet8, R.style.Theme_MaterialComponents_Light_DarkActionBar_App_NoActionBar_MiddleBoxes, R.style.Theme_MaterialComponents_NoActionBar_App_MiddleBoxes, - app.getResources().getString(R.string.Dashboard_Middleboxes_Overview_Paragraph), + "", "anim/middle_boxes.json", R.string.small_datausage ) { }; - private final Application app = mock(Application.class); private final PreferenceManager pm = mock(PreferenceManager.class); @Before @@ -52,13 +47,10 @@ public void setUp() { @Test public void fields() { assertEquals("test", suite.getName()); - assertEquals(app.getResources().getString(R.string.Test_Middleboxes_Fullname), suite.getTitle()); - assertEquals(app.getResources().getString(R.string.Dashboard_Middleboxes_Card_Description), suite.getCardDesc()); assertEquals(R.drawable.test_middle_boxes, suite.getIcon()); assertEquals(R.color.color_violet8, suite.getColor()); assertEquals(R.style.Theme_MaterialComponents_Light_DarkActionBar_App_NoActionBar_MiddleBoxes, suite.getThemeLight()); assertEquals(R.style.Theme_MaterialComponents_NoActionBar_App_MiddleBoxes, suite.getThemeDark()); - assertEquals(app.getResources().getString(R.string.Dashboard_Middleboxes_Overview_Paragraph), suite.getDesc1()); assertEquals("anim/middle_boxes.json", suite.getAnim()); assertEquals(R.string.small_datausage, suite.getDataUsage()); } diff --git a/app/src/test/java/org/openobservatory/ooniprobe/test/test/AbstractTestTest.java b/app/src/test/java/org/openobservatory/ooniprobe/test/test/AbstractTestTest.java index a57a8875d..4d8d02402 100644 --- a/app/src/test/java/org/openobservatory/ooniprobe/test/test/AbstractTestTest.java +++ b/app/src/test/java/org/openobservatory/ooniprobe/test/test/AbstractTestTest.java @@ -79,7 +79,7 @@ public void setUp() { public void testStartFinish() { // Arrange AbstractTest test = new WebConnectivity(); - Result result = ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c).getTest(c)); + Result result = ResultFactory.createAndSave(OONITests.WEBSITES.toOONIDescriptor(c)); // Act testEngine.sendNextEvent(EventResultFactory.buildStarted()); @@ -96,7 +96,7 @@ public void testStartFinish() { public void testCreateNewMeasurement() { // Arrange AbstractTest test = new WebConnectivity(); - Result result = ResultFactory.build(OONITests.WEBSITES.toOONIDescriptor(c).getTest(c), true, false); + Result result = ResultFactory.build(OONITests.WEBSITES.toOONIDescriptor(c), true, false); result.save(); Url ulr = UrlFactory.createAndSave(); @@ -150,7 +150,7 @@ public void testCreateNewMeasurement() { public void testNetworkEvent() { // Arrange AbstractTest test = new WebConnectivity(); - Result result = ResultFactory.build(OONITests.WEBSITES.toOONIDescriptor(c).getTest(c), true, false); + Result result = ResultFactory.build(OONITests.WEBSITES.toOONIDescriptor(c), true, false); result.save(); String networkName = faker.internet.domainName(); @@ -179,7 +179,7 @@ public void testNetworkEvent() { public void testLogEvent() throws IOException { // Arrange AbstractTest test = new WebConnectivity(); - Result result = ResultFactory.build(OONITests.WEBSITES.toOONIDescriptor(c).getTest(c), true, false); + Result result = ResultFactory.build(OONITests.WEBSITES.toOONIDescriptor(c), true, false); result.save(); String message = "Ipsum"; @@ -203,7 +203,7 @@ public void testLogEvent() throws IOException { public void testProgressEvent() throws IOException { // Arrange AbstractTest test = new WebConnectivity(); - Result result = ResultFactory.build(OONITests.WEBSITES.toOONIDescriptor(c).getTest(c), true, false); + Result result = ResultFactory.build(OONITests.WEBSITES.toOONIDescriptor(c), true, false); result.save(); String message = "Ipsum"; @@ -228,7 +228,7 @@ public void testProgressEvent() throws IOException { public void testResolverFailureEvent() { // Arrange AbstractTest test = new WebConnectivity(); - Result result = ResultFactory.build(OONITests.WEBSITES.toOONIDescriptor(c).getTest(c), true, false); + Result result = ResultFactory.build(OONITests.WEBSITES.toOONIDescriptor(c), true, false); result.save(); String message = "Ipsum"; @@ -250,7 +250,7 @@ public void testResolverFailureEvent() { public void testTaskInterrupt() { // Arrange AbstractTest test = new WebConnectivity(); - Result result = ResultFactory.build(OONITests.WEBSITES.toOONIDescriptor(c).getTest(c), true, false); + Result result = ResultFactory.build(OONITests.WEBSITES.toOONIDescriptor(c), true, false); result.save(); TestEngineInterface.TestOONIMKTask task = mock(TestEngineInterface.TestOONIMKTask.class); @@ -612,7 +612,7 @@ public void testExperimental() { public void testExperimentalFail() { // Arrange AbstractTest test = new Experimental(""); - Result result = ResultFactory.build(OONITests.WEBSITES.toOONIDescriptor(c).getTest(c), true, false); + Result result = ResultFactory.build(OONITests.WEBSITES.toOONIDescriptor(c), true, false); result.save(); // Act @@ -631,7 +631,7 @@ public void testExperimentalFail() { } private Result setupTestRun(AbstractTest test, boolean success) { - Result result = ResultFactory.build(OONITests.WEBSITES.toOONIDescriptor(c).getTest(c), true, false); + Result result = ResultFactory.build(OONITests.WEBSITES.toOONIDescriptor(c), true, false); result.save(); JsonResult jsonResult = JsonResultFactory.build(test, success); diff --git a/shared-test/src/main/java/org/openobservatory/ooniprobe/factory/ResultFactory.java b/shared-test/src/main/java/org/openobservatory/ooniprobe/factory/ResultFactory.java index c82c7bc72..bbca67183 100644 --- a/shared-test/src/main/java/org/openobservatory/ooniprobe/factory/ResultFactory.java +++ b/shared-test/src/main/java/org/openobservatory/ooniprobe/factory/ResultFactory.java @@ -2,6 +2,7 @@ import android.content.Context; +import org.openobservatory.ooniprobe.common.OONIDescriptor; import org.openobservatory.ooniprobe.common.OONITests; import org.openobservatory.ooniprobe.model.database.Network; import org.openobservatory.ooniprobe.model.database.Result; @@ -36,14 +37,14 @@ public class ResultFactory { private static final int DEFAULT_SUCCESS_MEASUREMENTS = 4; private static final int DEFAULT_FAILED_MEASUREMENTS = 0; - public static Result build(AbstractSuite suite) { - return build(suite, true, true); + public static Result build(OONIDescriptor descriptor) { + return build(descriptor, true, true); } - public static Result build(AbstractSuite suite, boolean wasViewed, boolean startNetworkData) { + public static Result build(OONIDescriptor descriptor, boolean wasViewed, boolean startNetworkData) { Result temp = new Result(); temp.id = faker.number.positive(); - temp.test_group_name = suite.getName(); + temp.test_group_name = descriptor.getName(); temp.data_usage_down = startNetworkData ? faker.number.positive() : 0; temp.data_usage_up = startNetworkData ? faker.number.positive() : 0; temp.start_time = faker.date.forward(); @@ -61,7 +62,7 @@ public static Result build(AbstractSuite suite, boolean wasViewed, boolean start * @param suite type of result (ex: Websites, Instant Messaging, Circumvention, Performance) * @return result with */ - public static Result createAndSave(AbstractSuite suite) { + public static Result createAndSave(OONIDescriptor suite) { return createAndSave(suite, DEFAULT_SUCCESS_MEASUREMENTS, DEFAULT_FAILED_MEASUREMENTS, true); } @@ -69,18 +70,18 @@ public static Result createAndSave(AbstractSuite suite) { * Saves a result in the DB and returns it with the given number of measurements, and * all related model objects in the DB. * - * @param suite type of result (ex: Websites, Instant Messaging, Circumvention, Performance) + * @param descriptor type of result (ex: Websites, Instant Messaging, Circumvention, Performance) * @param accessibleMeasurements number of accessible measurements * @param blockedMeasurements number of blocked measurements * @return result with * @throws IllegalArgumentException for excess number of measurements */ public static Result createAndSave( - AbstractSuite suite, + OONIDescriptor descriptor, int accessibleMeasurements, int blockedMeasurements ) throws IllegalArgumentException { - return createAndSave(suite, accessibleMeasurements, blockedMeasurements, true); + return createAndSave(descriptor, accessibleMeasurements, blockedMeasurements, true); } @@ -88,7 +89,7 @@ public static Result createAndSave( * Saves a result in the DB and returns it with the given number of measurements, and * all related model objects in the DB. * - * @param suite type of result (ex: Websites, Instant Messaging, Circumvention, Performance) + * @param descriptor type of result (ex: Websites, Instant Messaging, Circumvention, Performance) * @param accessibleMeasurements number of accessible measurements * @param blockedMeasurements number of blocked measurements * @param measurementsUploaded if the measurements are uploaded @@ -96,7 +97,7 @@ public static Result createAndSave( * @throws IllegalArgumentException for excess number of measurements */ public static Result createAndSave( - AbstractSuite suite, + OONIDescriptor descriptor, int accessibleMeasurements, int blockedMeasurements, boolean measurementsUploaded @@ -104,7 +105,7 @@ public static Result createAndSave( List measurementTestTypes = new ArrayList<>(); - if (suite.getName().equals(OONITests.INSTANT_MESSAGING.getLabel())) { + if (descriptor.getName().equals(OONITests.INSTANT_MESSAGING.getLabel())) { measurementTestTypes = Arrays.asList( new FacebookMessenger(), new Telegram(), @@ -113,7 +114,7 @@ public static Result createAndSave( ); } - if (suite.getName().equals(OONITests.CIRCUMVENTION.getLabel())) { + if (descriptor.getName().equals(OONITests.CIRCUMVENTION.getLabel())) { measurementTestTypes = Arrays.asList( new Psiphon(), new Tor(), @@ -121,13 +122,13 @@ public static Result createAndSave( ); } - if (suite.getName().equals(OONITests.WEBSITES.getLabel())) { + if (descriptor.getName().equals(OONITests.WEBSITES.getLabel())) { for (int i = 0; i < accessibleMeasurements + blockedMeasurements; i++) { measurementTestTypes.add(new WebConnectivity()); } } - if (suite.getName().equals(OONITests.PERFORMANCE.getLabel())) { + if (descriptor.getName().equals(OONITests.PERFORMANCE.getLabel())) { measurementTestTypes = Arrays.asList( new Ndt(), new Dash(), @@ -143,7 +144,7 @@ public static Result createAndSave( ); return createAndSave( - suite, + descriptor, measurements.getAccessibleTestTypes(), measurements.getBlockedTestTypes(), measurementsUploaded @@ -151,12 +152,12 @@ public static Result createAndSave( } private static Result createAndSave( - AbstractSuite suite, + OONIDescriptor descriptor, List successTestTypes, List failedTestTypes, boolean resultsUploaded ) { - Result tempResult = ResultFactory.build(suite); + Result tempResult = ResultFactory.build(descriptor); Network tempNetwork = NetworkFactory.createAndSave(tempResult); tempResult.network = tempNetwork; @@ -189,7 +190,7 @@ private static Result createAndSave( * all related model objects in the DB and files in storage. * * @param context to save the entry files - * @param suite type of result (ex: Websites, Instant Messaging, Circumvention, Performance) + * @param descriptor type of result (ex: Websites, Instant Messaging, Circumvention, Performance) * @param accessibleMeasurements number of accessible measurements * @param blockedMeasurements number of blocked measurements * @param measurementsUploaded if the measurements are uploaded @@ -198,12 +199,12 @@ private static Result createAndSave( */ public static Result createAndSaveWithEntryFiles( Context context, - AbstractSuite suite, + OONIDescriptor descriptor, int accessibleMeasurements, int blockedMeasurements, boolean measurementsUploaded ) throws IllegalArgumentException { - Result temp = createAndSave(suite, accessibleMeasurements, blockedMeasurements, measurementsUploaded); + Result temp = createAndSave(descriptor, accessibleMeasurements, blockedMeasurements, measurementsUploaded); MeasurementFactory.addEntryFiles(context, temp.getMeasurements(), false); temp.save();