• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.appsearch.app.helper_b;
18 
19 import static android.app.appsearch.testutil.AppSearchTestUtils.convertSearchResultsToDocuments;
20 
21 import static com.google.common.truth.Truth.assertThat;
22 
23 import android.app.appsearch.GenericDocument;
24 import android.app.appsearch.GlobalSearchSessionShim;
25 import android.app.appsearch.SearchSpec;
26 import android.app.appsearch.testutil.GlobalSearchSessionShimImpl;
27 
28 import androidx.test.ext.junit.runners.AndroidJUnit4;
29 
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 
34 import java.util.List;
35 
36 @RunWith(AndroidJUnit4.class)
37 public class AppSearchDeviceTest {
38 
39     private static final String NAMESPACE = "namespace";
40     private static final String ID = "id";
41     private static final GenericDocument DOCUMENT =
42             new GenericDocument.Builder<>(NAMESPACE, ID, "testSchema")
43                     .setPropertyString("subject", "testPut example1")
44                     .setCreationTimestampMillis(12345L)
45                     .build();
46 
47     private GlobalSearchSessionShim mGlobalSearch;
48 
49     @Before
setUp()50     public void setUp() throws Exception {
51         mGlobalSearch = GlobalSearchSessionShimImpl.createGlobalSearchSessionAsync().get();
52     }
53 
54     @Test
testGlobalGetDocuments_exist()55     public void testGlobalGetDocuments_exist() throws Exception {
56         List<GenericDocument> outDocuments = convertSearchResultsToDocuments(
57                 mGlobalSearch.search(/*queryExpression=*/"",
58                         new SearchSpec.Builder().setTermMatch(SearchSpec.TERM_MATCH_PREFIX)
59                                 .build()));
60         assertThat(outDocuments).containsExactly(DOCUMENT);
61     }
62 
63     @Test
testGlobalGetDocuments_nonexist()64     public void testGlobalGetDocuments_nonexist() throws Exception {
65         List<GenericDocument> outDocuments = convertSearchResultsToDocuments(
66                 mGlobalSearch.search(/*queryExpression=*/"",
67                         new SearchSpec.Builder().setTermMatch(SearchSpec.TERM_MATCH_PREFIX)
68                                 .build()));
69         assertThat(outDocuments).isEmpty();
70     }
71 }
72