Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3528: Setup Infrastructure to test using local dev server #3529

Merged
merged 82 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
b720222
Introducing UiAutomator
FareesHussain Jul 15, 2021
f90cbfc
Using 23 api level
FareesHussain Jul 15, 2021
930abe0
some local tweaks
FareesHussain Jul 16, 2021
bb6f5bb
Updated implementation based on adb commands
FareesHussain Jul 20, 2021
46a1b56
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
FareesHussain Jul 20, 2021
44f4003
Nit fixes
FareesHussain Jul 20, 2021
72620a2
Nit fixes
FareesHussain Jul 20, 2021
7a384c3
Merge branch 'setup-uiautomator' of https://github.com/FareesHussain/…
FareesHussain Jul 22, 2021
8a641d7
Requested changes
FareesHussain Jul 22, 2021
c58b6f6
fix class name
FareesHussain Jul 22, 2021
09c419e
update dependencies
FareesHussain Jul 22, 2021
311ee0e
init OppiaTestApplication.kt and TestApplicationComponent.kt
FareesHussain Jul 23, 2021
f6177e6
updated manifest
FareesHussain Jul 23, 2021
959e9d3
Nit fixes
FareesHussain Jul 24, 2021
004e3a1
Nit fixes
FareesHussain Jul 24, 2021
34e28c3
Using seperate Manifest for Test Application and instrumentation tests
FareesHussain Jul 26, 2021
7e42acf
bazel lint check
FareesHussain Jul 26, 2021
3eb2c75
Nit fix
FareesHussain Jul 26, 2021
7a1221d
Requested changes
FareesHussain Jul 30, 2021
0aec4a5
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
FareesHussain Jul 30, 2021
6e09966
updated maven_install
FareesHussain Jul 30, 2021
4486882
Nit fix
FareesHussain Jul 30, 2021
f64d32c
Add CODEOWNERS
FareesHussain Jul 30, 2021
dc66ba2
Added KDoc
FareesHussain Jul 30, 2021
c233b71
NIT
FareesHussain Jul 30, 2021
2044979
Added comments
FareesHussain Jul 30, 2021
7ac1ac5
Added oppia_instrumentation_test.bzl
FareesHussain Jul 31, 2021
3bb5348
added exempted_file_path
FareesHussain Jul 31, 2021
0f4ce65
Merge branch 'setup-uiautomator' of https://github.com/FareesHussain/…
FareesHussain Jul 31, 2021
b3ce32b
changed to EndToEndTest modules
FareesHussain Jul 31, 2021
68337d8
added exempted_file_paths
FareesHussain Jul 31, 2021
ec63ede
addded usesClearTextTraffix to reference the localhost
FareesHussain Jul 31, 2021
e5a6128
Helper utility shifted to testing module
FareesHussain Aug 4, 2021
425ebfa
NIT
FareesHussain Aug 4, 2021
067537f
NIT
FareesHussain Aug 4, 2021
b9233c6
deleted the previous utility
FareesHussain Aug 4, 2021
37b10e2
ignoring instrumentation in ComputeAffectedTests.kt
FareesHussain Aug 5, 2021
3c1e79f
NIT
FareesHussain Aug 5, 2021
44363c1
NIT
FareesHussain Aug 5, 2021
e95d29f
NIT
FareesHussain Aug 6, 2021
c608f7c
changed startsWith("instrumentation/")
FareesHussain Aug 6, 2021
66f6b51
filtered bazel targets
FareesHussain Aug 6, 2021
6514ba9
NIT
FareesHussain Aug 6, 2021
e81706b
NIT
FareesHussain Aug 6, 2021
a4266e4
filtering the instrumentation from the total affected targets
FareesHussain Aug 6, 2021
6f2836c
NIT
FareesHussain Aug 6, 2021
3660243
changed directory to javatests
FareesHussain Aug 10, 2021
d4aa4d4
NIT
FareesHussain Aug 10, 2021
41ea23f
NIT
FareesHussain Aug 10, 2021
b15451b
fixed scripts
FareesHussain Aug 11, 2021
73c650e
NIT
FareesHussain Aug 11, 2021
970d506
Merge branch 'setup-uiautomator' of https://github.com/FareesHussain/…
FareesHussain Aug 11, 2021
fd7bb06
Updated and NIT
FareesHussain Aug 11, 2021
7cd778c
Added tests for modules
FareesHussain Aug 12, 2021
2bb7076
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
FareesHussain Aug 12, 2021
084624e
updated testfile exemptions
FareesHussain Aug 12, 2021
0d50914
updated the ComputedAffectedTests
FareesHussain Aug 13, 2021
e2db957
ignoring player directory
FareesHussain Aug 13, 2021
31ac93b
Created NetworkConfigModule.kt
FareesHussain Aug 13, 2021
b12b8cc
Fixed CI failures
FareesHussain Aug 13, 2021
5721b87
NIT
FareesHussain Aug 13, 2021
018909b
Merge branch 'setup-uiautomator' of https://github.com/FareesHussain/…
FareesHussain Aug 14, 2021
e455076
Requested changes
FareesHussain Aug 14, 2021
81850b4
NIT
FareesHussain Aug 14, 2021
f44b9b2
NIT
FareesHussain Aug 14, 2021
70c1ba0
NIT
FareesHussain Aug 15, 2021
cd8361f
Added kdoc
FareesHussain Aug 16, 2021
84d3dd4
NIT
FareesHussain Aug 16, 2021
25bf74e
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
FareesHussain Aug 16, 2021
e7e979e
updated tests
FareesHussain Aug 17, 2021
48266ad
NIT
FareesHussain Aug 17, 2021
77b45a7
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
FareesHussain Aug 17, 2021
231760f
updated computedAffectedTEsts
FareesHussain Aug 17, 2021
db7c7b3
fix OppiaTestApplication
FareesHussain Aug 17, 2021
76646c1
updated failing tests
FareesHussain Aug 18, 2021
b6b4d7e
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
FareesHussain Aug 18, 2021
505532a
updated ComputeAffectedTestsTest
FareesHussain Aug 18, 2021
a4d3190
added TestBazelWorkspace tests
FareesHussain Aug 19, 2021
8989986
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
FareesHussain Aug 19, 2021
3a63e8a
fixed tests
FareesHussain Aug 19, 2021
ca6ff21
updated test_manifest
FareesHussain Aug 19, 2021
72bc501
fixed confict test
FareesHussain Aug 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ package_group(
],
)

package_group(
name = "oppia_e2e_testing_visibility",
packages = [
"//instrumentation/...",
],
)

# Special visibility group specific to debug mode. This provides access to the target for both the
# Oppia tests and specific debug only packages.
package_group(
Expand Down
1 change: 1 addition & 0 deletions app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ kt_android_library(
":resources",
":view_models",
":views",
"//data/src/main/java/org/oppia/android/data/backends/gae:network_config_prod_module",
"//data/src/main/java/org/oppia/android/data/backends/gae:prod_module",
"//model:arguments_java_proto_lite",
"//third_party:androidx_databinding_databinding-adapters",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.oppia.android.app.devoptions.DeveloperOptionsStarterModule
import org.oppia.android.app.shim.IntentFactoryShimModule
import org.oppia.android.app.shim.ViewBindingShimModule
import org.oppia.android.app.topic.PracticeTabModule
import org.oppia.android.data.backends.gae.NetworkConfigProdModule
import org.oppia.android.data.backends.gae.NetworkModule
import org.oppia.android.domain.classify.InteractionsModule
import org.oppia.android.domain.classify.rules.continueinteraction.ContinueModule
Expand Down Expand Up @@ -81,7 +82,7 @@ import javax.inject.Singleton
FirebaseLogUploaderModule::class, NetworkModule::class, PracticeTabModule::class,
PlatformParameterModule::class, ExplorationStorageModule::class,
DeveloperOptionsStarterModule::class, DeveloperOptionsModule::class,
NetworkConnectionUtilDebugModule::class,
NetworkConnectionUtilDebugModule::class, NetworkConfigProdModule::class,
// TODO(#59): Remove this module once we completely migrate to Bazel from Gradle as we can then
// directly exclude debug files from the build and thus won't be requiring this module.
NetworkConnectionDebugUtilModule::class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.oppia.android.app.devoptions.DeveloperOptionsModule
import org.oppia.android.app.devoptions.DeveloperOptionsStarterModule
import org.oppia.android.app.shim.ViewBindingShimModule
import org.oppia.android.app.topic.PracticeTabModule
import org.oppia.android.data.backends.gae.NetworkConfigProdModule
import org.oppia.android.data.backends.gae.NetworkModule
import org.oppia.android.domain.classify.InteractionsModule
import org.oppia.android.domain.classify.rules.continueinteraction.ContinueModule
Expand Down Expand Up @@ -131,8 +132,8 @@ class HelpActivityTest {
HintsAndSolutionConfigModule::class, HintsAndSolutionProdModule::class,
FirebaseLogUploaderModule::class, FakeOppiaClockModule::class, PracticeTabModule::class,
DeveloperOptionsStarterModule::class, DeveloperOptionsModule::class,
ExplorationStorageModule::class, NetworkConnectionUtilDebugModule::class,
NetworkConnectionDebugUtilModule::class
ExplorationStorageModule::class, NetworkConfigProdModule::class,
NetworkConnectionUtilDebugModule::class, NetworkConnectionDebugUtilModule::class
]
)
interface TestApplicationComponent : ApplicationComponent {
Expand Down
1 change: 1 addition & 0 deletions data/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ load("//data:data_test.bzl", "data_test")
# keep sorted
TEST_DEPS = [
":dagger",
"//data/src/main/java/org/oppia/android/data/backends/gae:network_config_prod_module",
"//data/src/main/java/org/oppia/android/data/backends/gae:oppia_retrofit",
"//data/src/main/java/org/oppia/android/data/backends/gae:prod_module",
"//data/src/main/java/org/oppia/android/data/backends/gae/model",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ kt_android_library(
visibility = ["//:oppia_testing_visibility"],
deps = [
":constants",
":network_settings",
":network_config_annotations",
"//model:arguments_java_proto_lite",
"//third_party:com_squareup_okhttp3_okhttp",
"//third_party:javax_inject_javax_inject",
Expand All @@ -25,11 +25,15 @@ kt_android_library(
)

kt_android_library(
name = "network_settings",
name = "network_config_prod_module",
srcs = [
"NetworkSettings.kt",
"NetworkConfigProdModule.kt",
],
visibility = ["//:oppia_prod_module_visibility"],
deps = [
":dagger",
":network_config_annotations",
],
visibility = ["//:oppia_testing_visibility"],
)

kt_android_library(
Expand All @@ -39,14 +43,26 @@ kt_android_library(
],
)

kt_android_library(
name = "network_config_annotations",
srcs = [
"BaseUrl.kt",
"XssiPrefix.kt",
],
visibility = ["//:oppia_api_visibility"],
deps = [
"//third_party:javax_inject_javax_inject",
],
)

kt_android_library(
name = "oppia_retrofit",
srcs = [
"OppiaRetrofit.kt",
],
visibility = ["//:oppia_testing_visibility"],
visibility = ["//:oppia_api_visibility"],
deps = [
":dagger",
"//third_party:javax_inject_javax_inject",
],
)

Expand All @@ -58,8 +74,8 @@ kt_android_library(
visibility = ["//:oppia_prod_module_visibility"],
deps = [
":dagger",
":network_config_annotations",
":network_interceptors",
":network_settings",
":oppia_retrofit",
"//data/src/main/java/org/oppia/android/data/backends/gae/api",
"//third_party:com_squareup_retrofit2_converter-moshi",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.oppia.android.data.backends.gae

import javax.inject.Qualifier

/** Qualifier for an application-injectable string representing the server URL used for networking. */
@Qualifier
annotation class BaseUrl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import javax.inject.Singleton
* The Interceptor removes XSSI_PREFIX from every response to produce valid Json.
*/
@Singleton
class JsonPrefixNetworkInterceptor @Inject constructor() : Interceptor {
class JsonPrefixNetworkInterceptor @Inject constructor(
@XssiPrefix private val xssiPrefix: String
) : Interceptor {

@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): Response {
Expand All @@ -34,6 +36,6 @@ class JsonPrefixNetworkInterceptor @Inject constructor() : Interceptor {

/** Removes the XSSI prefix from the specified raw JSON & returns the result. */
fun removeXssiPrefix(rawJson: String): String {
return rawJson.removePrefix(NetworkSettings.XSSI_PREFIX).trimStart()
return rawJson.removePrefix(xssiPrefix).trimStart()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.oppia.android.data.backends.gae

import dagger.Module
import dagger.Provides

/** Provides network-specific constants. */
@Module
class NetworkConfigProdModule {

/** Provides BaseUrl that connects to production server. */
@Provides
@BaseUrl
fun provideNetworkBaseUrl(): String {
return "https://oppia.org"
}

/**
* Prefix in Json response for extra layer of security in API calls
* https://github.com/oppia/oppia/blob/8f9eed/feconf.py#L319
* Remove this prefix from every Json response which is achieved in [NetworkInterceptor]
*/
@Provides
@XssiPrefix
fun provideXssiPrefix(): String {
return ")]}'"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ class NetworkModule {
@Singleton
fun provideRetrofitInstance(
jsonPrefixNetworkInterceptor: JsonPrefixNetworkInterceptor,
remoteAuthNetworkInterceptor: RemoteAuthNetworkInterceptor
remoteAuthNetworkInterceptor: RemoteAuthNetworkInterceptor,
@BaseUrl baseUrl: String
): Retrofit {
val client = OkHttpClient.Builder()
.addInterceptor(jsonPrefixNetworkInterceptor)
.addInterceptor(remoteAuthNetworkInterceptor)
.build()

return Retrofit.Builder()
.baseUrl(NetworkSettings.getBaseUrl())
.baseUrl(baseUrl)
.addConverterFactory(MoshiConverterFactory.create())
.client(client)
.build()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.oppia.android.data.backends.gae

import javax.inject.Qualifier

/**
* Qualifier for an application-injectable string representing the prefix in Json response used for
* security in API calls.
*/
@Qualifier
annotation class XssiPrefix
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import retrofit2.Retrofit
import javax.inject.Inject
import javax.inject.Singleton

/** Tests for [JsonPrefixNetworkInterceptorTest] */
/** Tests for [JsonPrefixNetworkInterceptor]. */
@RunWith(AndroidJUnit4::class)
@LooperMode(LooperMode.Mode.PAUSED)
class JsonPrefixNetworkInterceptorTest {
Expand Down Expand Up @@ -95,7 +95,7 @@ class JsonPrefixNetworkInterceptorTest {

// TODO(#89): Move this to a common test application component.
@Singleton
@Component(modules = [NetworkModule::class])
@Component(modules = [TestNetworkModule::class, NetworkConfigProdModule::class])
interface TestApplicationComponent {
@Component.Builder
interface Builder {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package org.oppia.android.data.backends.gae

import android.app.Application
import android.content.Context
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import dagger.BindsInstance
import dagger.Component
import dagger.Module
import dagger.Provides
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.annotation.Config
import org.robolectric.annotation.LooperMode
import javax.inject.Inject
import javax.inject.Singleton

/** Tests for [NetworkConfigProdModule]. */
@RunWith(AndroidJUnit4::class)
@LooperMode(LooperMode.Mode.PAUSED)
@Config(application = NetworkConfigProdModuleTest.TestApplication::class)
class NetworkConfigProdModuleTest {
anandwana001 marked this conversation as resolved.
Show resolved Hide resolved

@field:[Inject BaseUrl]
lateinit var baseUrl: String

@field:[Inject XssiPrefix]
lateinit var xssiPrefix: String

@Before
fun setUp() {
setUpTestApplicationComponent()
}

@Test
fun testModule_baseUrl_isProdUrl() {
assertThat(baseUrl).isEqualTo("https://oppia.org")
}

@Test
fun testModule_xssiPrefix_isXssiPrefix() {
assertThat(xssiPrefix).isEqualTo(")]}'")
}

private fun setUpTestApplicationComponent() {
ApplicationProvider.getApplicationContext<TestApplication>()
.inject(this)
}

@Module
class TestModule {
@Provides
@Singleton
fun provideContext(application: Application): Context {
return application
}
}

@Singleton
@Component(
modules = [
TestModule::class, NetworkConfigProdModule::class
]
)

interface TestApplicationComponent {
@Component.Builder
interface Builder {
@BindsInstance
fun setApplication(application: Application): Builder
fun build(): TestApplicationComponent
}

fun inject(networkConfigModuleTest: NetworkConfigProdModuleTest)
}

class TestApplication : Application() {
private val component: TestApplicationComponent by lazy {
DaggerNetworkConfigProdModuleTest_TestApplicationComponent.builder()
.setApplication(this)
.build()
}

fun inject(networkConfigModuleTest: NetworkConfigProdModuleTest) {
component.inject(networkConfigModuleTest)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import retrofit2.converter.moshi.MoshiConverterFactory
import javax.inject.Inject
import javax.inject.Singleton

/** Tests for [RemoteAuthNetworkInterceptor] */
/** Tests for [RemoteAuthNetworkInterceptor]. */
@RunWith(AndroidJUnit4::class)
@Config(application = RemoteAuthNetworkInterceptorTest.TestApplication::class)
@LooperMode(LooperMode.Mode.PAUSED)
Expand Down
Loading