Skip to content

Commit

Permalink
Fixes part of #59: Build Domain with Bazel + Gradle + Robolectric tes…
Browse files Browse the repository at this point in the history
…ting [BLOCKED: #1488] (#1514)

* Working on having one module build with bazel

* Created initial app-level WORKSPACE file

* Added proto_library rule to build model app module

* Added newline at end of WORKSPACE file

* Created macro to process proto files

* Both Bazel and Gradle now build /model successfully

* Fixed typo in BUILD

* Added missing end of file empty lines

* Added Robolectric dependencies and general build rule

* Source files building in both systems - added a TODO for test files

* Turned two kt_android_library rules into one

* Added dependencies for test files

* Created kt_android_library rule for source files

* Add TODO for android_local_test rule

* Added a test manifest for android_local_test()

* Added Firebase dependencies and git_repository for tools_android

* Refactored google-services.json, imported new dependencies

* Fixed Bens nits

* Fixed space in WORKSPACE comment

* Got a demo test working in both Java and Kotlin

* Added rules_java dependencies for protocol buffers

* Added java_proto_library rules, each proto file now has its own rule

* Remove unnecessary srcs attribute for android_library

* Rename bzl file macro

* Added Robolectric dependencies and general build rule

* Source files building in both systems - added a TODO for test files

* Turned two kt_android_library rules into one

* Added dependencies for test files

* Created kt_android_library rule for source files

* Add TODO for android_local_test rule

* Changed model visability, added model and util dependencies to testing

* Added dependencies to testing_main_lib

* Testing source files now build

* Test files are building

* Changed to java_lite

* Added EOF newlines

* Each library now has its own build rule

* Utility is now one rule

* Changed visibility for utility_lib

* Added duplicate google-services.json file to please Gradle

* Utility tests are building and passing (except in_memory_blocking_cache_test)

* Added android_local_test() rules for testing, building but not passing

* Added a test manifest for testing module

* Oppia_android_test is working

* Utility_test is now working

* Testing_test.bzl is now working

* changed all android_local_test rules to utility_test rules

* Named test rules correctly

* Added missing dependency, all tests now pass

* Removed all unused dependencies

* Changed event_logger.proto to oppia_logger.proto

* Added missing EOF newlines

* Fixed visibility

* Initial BUILD file added

* Remove addressed TODOs

* Started writing build rule

* Fixed bug in import statements for exploration.proto, topic.proto, and question.proto

* Deleted DemoJava

* Removed unused dependencies in domain_lib

* Working on building domain test files

* Added a test manifest

* Test files now build

* Added test rules, some tests not building or passing

* Added data attribute to test macros

* All tests now build, some do not pass

* CHanged rules_kotlin version

* All tests now pass

* Firebase dependency errors have been resolved

* Save firebase dependency fixes for new PR

* Fixed typo

* Added Firebase dependencies

* Removed AsyncResultTest example

* Removed AsynchResultTest example

* Firebase dependencies added

* Removed unnecessary comments in WORKSPACE and moved rules_kotlin

* Added re-naming TODOs

* Renamed java_proto rules java_proto_lite

* Added doc comments to model/BUILD.bazel and format_import_proto_library

* Added comments to WORKSPACE file

* Fixed nits

* Added comment to kt_android_library() rule

* Fixed more nits

* Added Firebase comment

* Fixed merge conflicts and nits

* Deleted unused dependencies from testing_main_lib

* Fixed nits and error with testing lib dependencies

* Removed printStackTrace()

* Removed addressed TODOs, all tests pass

* Removed redundant public modifier

* Changed library name to model

* Formatted WORKSPACE comment

* Formatted TODO statement

* Changed format_import_proto_library comment

* Added EOF newline

* Created Issue and linked TODO in WORKSPACE

* Edited model BUILD file top comment

* Addressed nits

* Fixed nits and added comments

* Fixing nits

* Deleted unnecessary dependencies and testing example file

* Fixed manifest issues

* Move google json file

* Restore app version of json

* Edit TODO

* Deleted TODO

* Changed Firebase comment

* Added testing functionality from later PR

* Added comments to bzl files

* Added targetSDK to manifests

* Changed crashlytics_lib to crashlytics

* Changed testing_tests visibility

* Added comment to utility_test.bzl

* Changed type of comment ticks

* Fixed typos and all tests pass

* Removed empty line

* Fixed errors from merge

* Added comments to data and domain BUILD files

* Fixed indentation in domain_test

* Removed commented-out dependencies

* Fixed nits and added TODOs

* Added Args to document comment

* Changed targetSDK to 29

* Formatted TODO

* Added root BUILD file

* Moved google-services.json

* Added gogle-services.json back to app

* Trying to remove combined testing library

* Changed targetSDK to 29

* Tests pass now with deps passed in.

* Created TEST_DEPS list to avoid duplicate list of dependencies

* Removed unused resources and manifest

* Updated comments to reflect changes

* Changed deps to be a parameter, changed targetSDK back to 28 because tests do not pass at 29

* Fixed indentation in utility/BUILD

* Updated comment for utility_test.bzl

* Updated comment for testing_test

* Formatted dependencies and removed unused dependency

* Updated dependency list

* Header for oppia_android_test now fits on one line

* Simplifies comment on domain/BUILD file

* Changed cache_store to persistent_cache_store

* Removed glob() from data BUILD file

* Edited documentation for oppia_android_test

* Updated documentation for utility and testing BUILD files

* Changed src to srcs

* Changed src to srcs

* All dragAndDrop tests now pass, stateRetreiverTest fails

* Fixed the duplicate google-services.json issue

* Created Issue and added TODO

* Added minSDK back

* Alphabetized dependencies

* Fixed firebase target

* Trying to fix StateRetreiverTest

* Fixed ktlint violation

* Changed targetSdk to 28

* Created Issue and added TODOs for re-restricitng access

* Added min and target SDK to domain manifest

* Removed unused domain)tests library

* Added documentation, created an issue, added a TODO

* Added assets

* Testing module tests now pass, all domain tests pass except StateRetreiver

* Added TODO for StateRetreiver Tes

* Removed unnecessary data attribute

* StateRetrieverTest now passes
  • Loading branch information
miaboloix authored Aug 17, 2020
1 parent 31152c5 commit 8e778b3
Show file tree
Hide file tree
Showing 25 changed files with 386 additions and 42 deletions.
6 changes: 6 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,17 @@ load("@rules_jvm_external//:defs.bzl", "maven_install")

maven_install(
artifacts = DAGGER_ARTIFACTS + [
"android.arch.core:core-testing:1.1.1",
"androidx.annotation:annotation:1.1.0",
"androidx.appcompat:appcompat:1.0.2",
"androidx.arch.core:core-testing:2.1.0",
"androidx.core:core-ktx:1.0.1",
"androidx.lifecycle:lifecycle-livedata-ktx:2.2.0-alpha03",
"androidx.test.espresso:espresso-contrib:3.1.0",
"androidx.test.espresso:espresso-core:3.2.0",
"androidx.test.espresso:espresso-intents:3.1.0",
"androidx.test.ext:junit:1.1.1",
"androidx.test:runner:1.2.0",
"com.android.support:support-annotations:28.0.0",
"com.caverock:androidsvg-aar:1.4",
"com.crashlytics.sdk.android:crashlytics:2.9.8",
Expand Down
27 changes: 27 additions & 0 deletions data/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# TODO(#1532): Rename file to 'BUILD' post-Gradle.
'''
This library provides data to the rest of the application.
'''

load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")
load("@rules_jvm_external//:defs.bzl", "artifact")
load("@dagger//:workspace_defs.bzl", "dagger_rules")

kt_android_library(
name = "persistent_cache_store",
custom_package = "org.oppia.data.persistence",
srcs = ["src/main/java/org/oppia/data/persistence/PersistentCacheStore.kt"],
manifest = "src/main/AndroidManifest.xml",
deps = [
":dagger",
"//model",
"//utility",
artifact("androidx.appcompat:appcompat"),
artifact("com.github.bumptech.glide:glide"),
artifact("com.caverock:androidsvg-aar"),
artifact("androidx.lifecycle:lifecycle-livedata-ktx"),
],
visibility = ["//visibility:public"],
)

dagger_rules()
230 changes: 230 additions & 0 deletions domain/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
# TODO(#1532): Rename file to 'BUILD' post-Gradle.
'''
This library contains the frontend controller and business service logic for the application.
'''

load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")
load("@rules_jvm_external//:defs.bzl", "artifact")
load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("//domain:domain_test.bzl", "domain_test")

kt_android_library(
name = "domain",
custom_package = "org.oppia.domain",
srcs = glob(["src/main/java/org/oppia/domain/**/*.kt"]),
assets = glob(["src/main/assets/**"]),
assets_dir = "src/main/assets/",
manifest = "src/main/AndroidManifest.xml",
deps = [
":dagger",
"//data:persistent_cache_store",
],
visibility = ["//visibility:public"],
)

TEST_DEPS = [
":dagger",
":domain",
"//data:persistent_cache_store",
"//model",
"//testing",
"@robolectric//bazel:android-all",
artifact("androidx.arch.core:core-testing"),
artifact("androidx.test.ext:junit"),
artifact("com.google.truth:truth"),
artifact("org.jetbrains.kotlin:kotlin-test-junit"),
artifact("org.jetbrains.kotlin:kotlin-reflect"),
]

domain_test(
name = "AudioPlayerControllerTest",
srcs = ["src/test/java/org/oppia/domain/audio/AudioPlayerControllerTest.kt"],
test_class = "org.oppia.domain.audio.AudioPlayerControllerTest",
deps = TEST_DEPS,
)

domain_test(
name = "CellularAudioDialogControllerTest",
srcs = ["src/test/java/org/oppia/domain/audio/CellularAudioDialogControllerTest.kt"],
test_class = "org.oppia.domain.audio.CellularAudioDialogControllerTest",
deps = TEST_DEPS,
)

domain_test(
name = "AnswerClassificationControllerTest",
srcs = ["src/test/java/org/oppia/domain/classify/AnswerClassificationControllerTest.kt"],
test_class = "org.oppia.domain.classify.AnswerClassificationControllerTest",
deps = TEST_DEPS,
)

domain_test(
name = "NumericInputEqualsRuleClassifierProviderTest",
srcs = ["src/test/java/org/oppia/domain/classify/NumericInputEqualsRuleClassifierProviderTest.kt"],
test_class = "org.oppia.domain.classify.NumericInputEqualsRuleClassifierProviderTest",
deps = TEST_DEPS,
)

domain_test(
name = "DragDropSortInputHasElementXAtPositionYRuleClassifierProviderTest",
srcs = [
"src/test/java/org/oppia/domain/classify/rules/dragAndDropSortInput/DragDropSortInputHasElementXAtPositionYRuleClassifierProviderTest.kt"
],
test_class = "org.oppia.domain.classify.rules.dragAndDropSortInput.DragDropSortInputHasElementXAtPositionYRuleClassifierProviderTest",
deps = TEST_DEPS,
)

domain_test(
name = "DragDropSortInputHasElementXBeforeElementYRuleClassifierProviderTest",
srcs = [
"src/test/java/org/oppia/domain/classify/rules/dragAndDropSortInput/DragDropSortInputHasElementXBeforeElementYRuleClassifierProviderTest.kt"
],
test_class = "org.oppia.domain.classify.rules.dragAndDropSortInput.DragDropSortInputHasElementXBeforeElementYRuleClassifierProviderTest",
deps = TEST_DEPS,
)

domain_test(
name = "DragDropSortInputIsEqualToOrderingClassifierProviderTest",
srcs = [
"src/test/java/org/oppia/domain/classify/rules/dragAndDropSortInput/DragDropSortInputIsEqualToOrderingClassifierProviderTest.kt"
],
test_class = "org.oppia.domain.classify.rules.dragAndDropSortInput.DragDropSortInputIsEqualToOrderingClassifierProviderTest",
deps = TEST_DEPS,
)

domain_test(
name = "DragDropSortInputIsEqualToOrderingWithOneItemAtIncorrectPositionClassifierProviderTest",
srcs = [
"src/test/java/org/oppia/domain/classify/rules/dragAndDropSortInput/DragDropSortInputIsEqualToOrderingWithOneItemAtIncorrectPositionClassifierProviderTest.kt"
],
test_class = "org.oppia.domain.classify.rules.dragAndDropSortInput.DragDropSortInputIsEqualToOrderingWithOneItemAtIncorrectPositionClassifierProviderTest",
deps = TEST_DEPS,
)

domain_test(
name = "ImageClickInputIsInRegionRuleClassifierProviderTest",
srcs = [
"src/test/java/org/oppia/domain/classify/rules/imageClickInput/ImageClickInputIsInRegionRuleClassifierProviderTest.kt"
],
test_class = "org.oppia.domain.classify.rules.imageClickInput.ImageClickInputIsInRegionRuleClassifierProviderTest",
deps = TEST_DEPS,
)

domain_test(
name = "MultipleChoiceInputEqualsRuleClassifierProviderTest",
srcs = [
"src/test/java/org/oppia/domain/classify/rules/multiplechoiceinput/MultipleChoiceInputEqualsRuleClassifierProviderTest.kt"
],
test_class = "org.oppia.domain.classify.rules.multiplechoiceinput.MultipleChoiceInputEqualsRuleClassifierProviderTest",
deps = TEST_DEPS,
)

domain_test(
name = "TextInputContainsRuleClassifierProviderTest",
srcs = [
"src/test/java/org/oppia/domain/classify/rules/textinput/TextInputContainsRuleClassifierProviderTest.kt"
],
test_class = "org.oppia.domain.classify.rules.textinput.TextInputContainsRuleClassifierProviderTest",
deps = TEST_DEPS,
)

domain_test(
name = "TextInputEqualsRuleClassifierProviderTest",
srcs = [
"src/test/java/org/oppia/domain/classify/rules/textinput/TextInputEqualsRuleClassifierProviderTest.kt"
],
test_class = "org.oppia.domain.classify.rules.textinput.TextInputEqualsRuleClassifierProviderTest",
deps = TEST_DEPS,
)

domain_test(
name = "ExplorationDataControllerTest",
srcs = ["src/test/java/org/oppia/domain/exploration/ExplorationDataControllerTest.kt"],
test_class = "org.oppia.domain.exploration.ExplorationDataControllerTest",
deps = TEST_DEPS,
)

domain_test(
name = "ExplorationProgressControllerTest",
srcs = ["src/test/java/org/oppia/domain/exploration/ExplorationProgressControllerTest.kt"],
test_class = "org.oppia.domain.exploration.ExplorationProgressControllerTest",
deps = TEST_DEPS,
)

domain_test(
name = "OnboardingFlowControllerTest",
srcs = ["src/test/java/org/oppia/domain/onboarding/OnboardingFlowControllerTest.kt"],
test_class = "org.oppia.domain.onboarding.OnboardingFlowControllerTest",
deps = TEST_DEPS,
)

domain_test(
name = "AnalyticsControllerTest",
srcs = ["src/test/java/org/oppia/domain/oppialogger/analytics/AnalyticsControllerTest.kt"],
test_class = "org.oppia.domain.oppialogger.analytics.AnalyticsControllerTest",
deps = TEST_DEPS,
)

domain_test(
name = "ProfileManagementControllerTest",
srcs = ["src/test/java/org/oppia/domain/profile/ProfileManagementControllerTest.kt"],
test_class = "org.oppia.domain.profile.ProfileManagementControllerTest",
deps = TEST_DEPS,
)

domain_test(
name = "QuestionAssessmentProgressControllerTest",
srcs = ["src/test/java/org/oppia/domain/question/QuestionAssessmentProgressControllerTest.kt"],
test_class = "org.oppia.domain.question.QuestionAssessmentProgressControllerTest",
deps = TEST_DEPS,
)

domain_test(
name = "QuestionTrainingControllerTest",
srcs = ["src/test/java/org/oppia/domain/question/QuestionTrainingControllerTest.kt"],
test_class = "org.oppia.domain.question.QuestionTrainingControllerTest",
deps = TEST_DEPS,
)

domain_test(
name = "StoryProgressControllerTest",
srcs = ["src/test/java/org/oppia/domain/topic/StoryProgressControllerTest.kt"],
test_class = "org.oppia.domain.topic.StoryProgressControllerTest",
deps = TEST_DEPS,
)

domain_test(
name = "StoryProgressTestHelperTest",
srcs = ["src/test/java/org/oppia/domain/topic/StoryProgressTestHelperTest.kt"],
test_class = "org.oppia.domain.topic.StoryProgressTestHelperTest",
deps = TEST_DEPS,
)

domain_test(
name = "TopicControllerTest",
srcs = ["src/test/java/org/oppia/domain/topic/TopicControllerTest.kt"],
test_class = "org.oppia.domain.topic.TopicControllerTest",
deps = TEST_DEPS,
)

domain_test(
name = "TopicListControllerTest",
srcs = ["src/test/java/org/oppia/domain/topic/TopicListControllerTest.kt"],
test_class = "org.oppia.domain.topic.TopicListControllerTest",
deps = TEST_DEPS,
)

domain_test(
name = "InteractionObjectExtensionsTest",
srcs = ["src/test/java/org/oppia/domain/util/InteractionObjectExtensionsTest.kt"],
test_class = "org.oppia.domain.util.InteractionObjectExtensionsTest",
deps = TEST_DEPS,
)

domain_test(
name = "StateRetrieverTest",
srcs = ["src/test/java/org/oppia/domain/util/StateRetrieverTest.kt"],
test_class = "org.oppia.domain.util.StateRetrieverTest",
deps = TEST_DEPS,
)

dagger_rules()
24 changes: 24 additions & 0 deletions domain/domain_test.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
load("//:oppia_android_test.bzl", "oppia_android_test")
# TODO(#1620): Remove module-specific test macros once Gradle is removed
def domain_test(name, srcs, test_class, deps):
'''
Creates individual tests for test files in the domain module.
Args:
name: str. The name of the Kotlin test file without the '.kt' suffix.
srcs: list of str. The list of test files to be run.
test_class: str. The package of the src file. Example: If the src is 'AsyncResultTest.kt',
then the test_class would be "org.oppia.util.data.AsyncResultTest".
deps: list of str. The list of dependencies needed to build and run this test.
'''

oppia_android_test(
name = name,
srcs = srcs,
custom_package = "org.oppia.domain",
test_class = test_class,
test_manifest = "src/test/AndroidManifest.xml",
assets = native.glob(["src/main/assets/**"]),
assets_dir = "src/main/assets/",
deps = deps,
)
7 changes: 6 additions & 1 deletion domain/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
<manifest package="org.oppia.domain"/>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.oppia.domain">
<uses-sdk android:minSdkVersion="19"
android:targetSdkVersion="28" />
</manifest>
6 changes: 3 additions & 3 deletions domain/src/main/assets/image_click_input_exploration.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"labeledRegions": [
{
"region": {
"regionType": "Rectangle",
"regionType": "RECTANGLE",
"area": [
[
0.2755102040816326,
Expand All @@ -66,7 +66,7 @@
},
{
"region": {
"regionType": "Rectangle",
"regionType": "RECTANGLE",
"area": [
[
0.07346938775510205,
Expand All @@ -82,7 +82,7 @@
},
{
"region": {
"regionType": "Rectangle",
"regionType": "RECTANGLE",
"area": [
[
0.6204081632653061,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class AnswerClassificationController @Inject constructor(
* Classifies the specified answer in the context of the specified [Interaction] and returns the [Outcome] that best
* matches the learner's answer.
*/
internal fun classify(interaction: Interaction, answer: InteractionObject): Outcome {
// TODO(#1580): Re-restrict access using Bazel visibilities
fun classify(interaction: Interaction, answer: InteractionObject): Outcome {
val interactionClassifier = checkNotNull(
interactionClassifiers[interaction.id]
) {
Expand Down
Loading

0 comments on commit 8e778b3

Please sign in to comment.