Skip to content

Commit

Permalink
Updated functions and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aanorbel committed Nov 29, 2023
1 parent 369adfa commit 1b254ee
Show file tree
Hide file tree
Showing 21 changed files with 145 additions and 150 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
if: failure()
with:
name: test-results
path: app/build/test-results/testStableFullDebugUnitTest
path: app/build/reports/tests/testStableFullReleaseUnitTest
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -87,7 +87,7 @@ private void startRunTestService() {
serviceRule.startService(
new Intent(c, RunTestService.class)
.putExtra("testSuites", new ArrayList<AbstractSuite>() {{
add(new InstantMessagingSuite());
add(OONITests.WEBSITES.toOONIDescriptor(c).getTest(c));
}})
);
} catch (TimeoutException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 +
Expand All @@ -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();

Expand Down Expand Up @@ -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();
Expand All @@ -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();

Expand Down
Loading

0 comments on commit 1b254ee

Please sign in to comment.