aboutsummaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorAlexander Dorokhine <adorokhine@google.com>2020-08-11 01:22:16 -0700
committerAlexander Dorokhine <adorokhine@google.com>2020-08-11 01:22:16 -0700
commit8304af0aa4f2b8e21cb39dbd78b3bc16ce915a6f (patch)
treeb504c5c089a04199185387fb0715bce1252749ac /java
parent6684feed5eeae150c9f8e24b7c4d71745138558c (diff)
downloadicing-8304af0aa4f2b8e21cb39dbd78b3bc16ce915a6f.tar.gz
Add a smoke test for androidx.
This makes sure that the distribution in the android tree keeps working. Due to b/162892721, the libicing.so inside the aar is not used. The libicing.so from this tree is used. So, this test serves the dual purpose of making sure the version of icing code available here supports the java code in androidx-appsearch.aar. Bug: 162755601 Test: AppSearchSmokeTest Change-Id: Ib4ed1cb9cb546146de3e85e32b10f23ca374efbc
Diffstat (limited to 'java')
-rw-r--r--java/tests/instrumentation/Android.bp29
-rw-r--r--java/tests/instrumentation/src/androidx/appsearch/smoketest/AppSearchSmokeTest.java99
-rw-r--r--java/tests/instrumentation/src/androidx/appsearch/smoketest/TestDataClass.java41
3 files changed, 157 insertions, 12 deletions
diff --git a/java/tests/instrumentation/Android.bp b/java/tests/instrumentation/Android.bp
index 6cb579d..fd6c4d7 100644
--- a/java/tests/instrumentation/Android.bp
+++ b/java/tests/instrumentation/Android.bp
@@ -14,13 +14,9 @@
android_test {
name: "IcingSearchEngineTest",
-
- manifest: "AndroidManifest.xml",
-
srcs: [
- "src/**/*.java",
+ "src/com/google/android/icing/**/*.java",
],
-
static_libs: [
"androidx.test.ext.junit",
"androidx.test.rules",
@@ -28,15 +24,24 @@ android_test {
"libicing-java",
"icing-java-proto-lite",
],
+ jni_libs: ["libicing"],
+ test_suites: ["device-tests"],
+ platform_apis: true,
+ use_embedded_native_libs: true,
+}
- jni_libs: [
- "libicing",
- ],
-
- test_suites: [
- "device-tests",
+android_test {
+ name: "AndroidXSmokeTest",
+ srcs: ["src/androidx/**/*.java"],
+ static_libs: [
+ "androidx.appsearch_appsearch",
+ "androidx.test.ext.junit",
+ "androidx.test.runner",
+ "truth-prebuilt",
],
-
+ jni_libs: ["libicing"],
+ plugins: ["androidx.appsearch_appsearch-compiler-plugin"],
+ test_suites: ["device-tests"],
platform_apis: true,
use_embedded_native_libs: true,
}
diff --git a/java/tests/instrumentation/src/androidx/appsearch/smoketest/AppSearchSmokeTest.java b/java/tests/instrumentation/src/androidx/appsearch/smoketest/AppSearchSmokeTest.java
new file mode 100644
index 0000000..1c92c8d
--- /dev/null
+++ b/java/tests/instrumentation/src/androidx/appsearch/smoketest/AppSearchSmokeTest.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.appsearch.smoketest;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import androidx.appsearch.app.AppSearchManager;
+import androidx.appsearch.app.AppSearchManager.PutDocumentsRequest;
+import androidx.appsearch.app.AppSearchManager.SetSchemaRequest;
+import androidx.appsearch.app.AppSearchSchema;
+import androidx.appsearch.app.AppSearchSchema.PropertyConfig;
+import androidx.appsearch.app.SearchResults;
+import androidx.appsearch.app.SearchSpec;
+import androidx.test.core.app.ApplicationProvider;
+import androidx.test.filters.SmallTest;
+
+import com.google.android.icing.proto.IcingSearchEngineOptions;
+
+import org.junit.Test;
+
+@SmallTest
+public class AppSearchSmokeTest {
+ @Test
+ public void smokeTest() throws Exception {
+ IcingSearchEngineOptions o = IcingSearchEngineOptions.newBuilder().build();
+ AppSearchManager appSearch =
+ new AppSearchManager.Builder(ApplicationProvider.getApplicationContext())
+ .build()
+ .get()
+ .getResultValue();
+ AppSearchSchema schema =
+ new AppSearchSchema.Builder("testType")
+ .addProperty(
+ new PropertyConfig.Builder("prop")
+ .setDataType(PropertyConfig.DATA_TYPE_STRING)
+ .setCardinality(PropertyConfig.CARDINALITY_OPTIONAL)
+ .setIndexingType(PropertyConfig.INDEXING_TYPE_PREFIXES)
+ .setTokenizerType(PropertyConfig.TOKENIZER_TYPE_PLAIN)
+ .build())
+ .build();
+ appSearch
+ .setSchema(new SetSchemaRequest.Builder().addSchema(schema).build())
+ .get()
+ .getResultValue();
+ }
+
+ @Test
+ public void smokeTestAnnotationProcessor() throws Exception {
+ AppSearchManager appSearch =
+ new AppSearchManager.Builder(ApplicationProvider.getApplicationContext())
+ .build()
+ .get()
+ .getResultValue();
+ appSearch
+ .setSchema(new SetSchemaRequest.Builder().addDataClass(TestDataClass.class).build())
+ .get()
+ .getResultValue();
+
+ TestDataClass input = new TestDataClass("uri1", "avocado");
+ appSearch
+ .putDocuments(new PutDocumentsRequest.Builder().addDataClass(input).build())
+ .get()
+ .checkSuccess();
+ SearchResults results =
+ appSearch
+ .query(
+ "av",
+ SearchSpec.newBuilder().setTermMatchType(
+ SearchSpec.TERM_MATCH_TYPE_PREFIX).build())
+ .get()
+ .getResultValue();
+
+ assertTrue(results.hasNext());
+ SearchResults.Result result = results.next();
+ assertFalse(results.hasNext());
+
+ assertEquals("uri1", result.getDocument().getUri());
+ assertEquals("avocado", result.getDocument().getPropertyString("body"));
+ TestDataClass output = result.getDocument().toDataClass(TestDataClass.class);
+ assertEquals("uri1", output.getUri());
+ assertEquals("avocado", output.getBody());
+ }
+}
diff --git a/java/tests/instrumentation/src/androidx/appsearch/smoketest/TestDataClass.java b/java/tests/instrumentation/src/androidx/appsearch/smoketest/TestDataClass.java
new file mode 100644
index 0000000..45bbf64
--- /dev/null
+++ b/java/tests/instrumentation/src/androidx/appsearch/smoketest/TestDataClass.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.appsearch.smoketest;
+
+import androidx.appsearch.annotation.AppSearchDocument;
+import androidx.appsearch.app.AppSearchSchema.PropertyConfig;
+
+@AppSearchDocument
+public class TestDataClass {
+ @AppSearchDocument.Uri private final String uri;
+
+ @AppSearchDocument.Property(indexingType = PropertyConfig.INDEXING_TYPE_PREFIXES)
+ private final String body;
+
+ TestDataClass(String uri, String body) {
+ this.uri = uri;
+ this.body = body;
+ }
+
+ public String getUri() {
+ return uri;
+ }
+
+ public String getBody() {
+ return body;
+ }
+}