Add client RequestManager integration test

PiperOrigin-RevId: 248175074
Change-Id: I121f05480b591147557d9ef09e904c2bbecb6bdd
diff --git a/src/main/java/com/google/android/libraries/feed/common/testing/BUILD b/src/main/java/com/google/android/libraries/feed/common/testing/BUILD
index d379262..abb20cb 100644
--- a/src/main/java/com/google/android/libraries/feed/common/testing/BUILD
+++ b/src/main/java/com/google/android/libraries/feed/common/testing/BUILD
@@ -8,6 +8,7 @@
     srcs = glob(["*.java"]),
     deps = [
         "//src/main/java/com/google/android/libraries/feed/api/client/lifecycle",
+        "//src/main/java/com/google/android/libraries/feed/api/client/requestmanager",
         "//src/main/java/com/google/android/libraries/feed/api/common",
         "//src/main/java/com/google/android/libraries/feed/api/host/config",
         "//src/main/java/com/google/android/libraries/feed/api/host/logging",
@@ -28,6 +29,7 @@
         "//src/main/java/com/google/android/libraries/feed/feedapplifecyclelistener",
         "//src/main/java/com/google/android/libraries/feed/feedmodelprovider",
         "//src/main/java/com/google/android/libraries/feed/feedprotocoladapter",
+        "//src/main/java/com/google/android/libraries/feed/feedrequestmanager",
         "//src/main/java/com/google/android/libraries/feed/feedsessionmanager",
         "//src/main/java/com/google/android/libraries/feed/feedstore",
         "//src/main/java/com/google/android/libraries/feed/hostimpl/storage",
diff --git a/src/main/java/com/google/android/libraries/feed/common/testing/InfraIntegrationScope.java b/src/main/java/com/google/android/libraries/feed/common/testing/InfraIntegrationScope.java
index aac03bf..09d9611 100644
--- a/src/main/java/com/google/android/libraries/feed/common/testing/InfraIntegrationScope.java
+++ b/src/main/java/com/google/android/libraries/feed/common/testing/InfraIntegrationScope.java
@@ -15,6 +15,7 @@
 package com.google.android.libraries.feed.common.testing;
 
 import com.google.android.libraries.feed.api.client.lifecycle.AppLifecycleListener;
+import com.google.android.libraries.feed.api.client.requestmanager.RequestManager;
 import com.google.android.libraries.feed.api.host.config.Configuration;
 import com.google.android.libraries.feed.api.host.config.Configuration.ConfigKey;
 import com.google.android.libraries.feed.api.host.proto.ProtoExtensionProvider;
@@ -35,6 +36,7 @@
 import com.google.android.libraries.feed.feedapplifecyclelistener.FeedAppLifecycleListener;
 import com.google.android.libraries.feed.feedmodelprovider.FeedModelProviderFactory;
 import com.google.android.libraries.feed.feedprotocoladapter.FeedProtocolAdapter;
+import com.google.android.libraries.feed.feedrequestmanager.RequestManagerImpl;
 import com.google.android.libraries.feed.feedsessionmanager.FeedSessionManagerFactory;
 import com.google.android.libraries.feed.feedsessionmanager.FeedSessionManagerImpl;
 import com.google.android.libraries.feed.feedstore.FeedStore;
@@ -78,6 +80,7 @@
   private final JournalStorageDirect journalStorage;
   private final SchedulerApi schedulerApi;
   private final TaskQueue taskQueue;
+  private final RequestManager requestManager;
 
   private InfraIntegrationScope(
       FakeThreadUtils fakeThreadUtils,
@@ -144,6 +147,7 @@
             taskQueue,
             fakeMainThreadRunner,
             configuration);
+    requestManager = new RequestManagerImpl(fakeFeedRequestManager, feedSessionManager);
   }
 
   public ProtocolAdapter getProtocolAdapter() {
@@ -186,6 +190,10 @@
     return appLifecycleListener;
   }
 
+  public RequestManager getRequestManager() {
+    return requestManager;
+  }
+
   @Override
   public InfraIntegrationScope clone() {
     return new InfraIntegrationScope(
diff --git a/src/test/java/com/google/android/libraries/feed/infraintegration/BUILD b/src/test/java/com/google/android/libraries/feed/infraintegration/BUILD
index 3dc925f..b03d473 100644
--- a/src/test/java/com/google/android/libraries/feed/infraintegration/BUILD
+++ b/src/test/java/com/google/android/libraries/feed/infraintegration/BUILD
@@ -29,6 +29,25 @@
 )
 
 android_local_test(
+    name = "ClientRequestManagerTest",
+    size = "small",
+    timeout = "moderate",
+    srcs = ["ClientRequestManagerTest.java"],
+    aapt_version = "aapt2",
+    manifest_values = DEFAULT_ANDROID_LOCAL_TEST_MANIFEST,
+    deps = [
+        "//src/main/java/com/google/android/libraries/feed/api/client/requestmanager",
+        "//src/main/java/com/google/android/libraries/feed/api/internal/modelprovider",
+        "//src/main/java/com/google/android/libraries/feed/common/testing",
+        "//src/main/proto/com/google/android/libraries/feed/api/internal/proto:client_feed_java_proto_lite",
+        "//src/main/proto/search/now/wire/feed:feed_java_proto_lite",
+        "//third_party:robolectric",
+        "@com_google_protobuf_javalite//:protobuf_java_lite",
+        "@robolectric//bazel:android-all",
+    ],
+)
+
+android_local_test(
     name = "ContentRemoveTest",
     size = "small",
     timeout = "moderate",
diff --git a/src/test/java/com/google/android/libraries/feed/infraintegration/ClientRequestManagerTest.java b/src/test/java/com/google/android/libraries/feed/infraintegration/ClientRequestManagerTest.java
new file mode 100644
index 0000000..66aa78e
--- /dev/null
+++ b/src/test/java/com/google/android/libraries/feed/infraintegration/ClientRequestManagerTest.java
@@ -0,0 +1,70 @@
+// Copyright 2018 The Feed Authors.
+//
+// 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 com.google.android.libraries.feed.infraintegration;
+
+import com.google.android.libraries.feed.api.client.requestmanager.RequestManager;
+import com.google.android.libraries.feed.api.internal.modelprovider.ModelProvider;
+import com.google.android.libraries.feed.common.testing.InfraIntegrationScope;
+import com.google.android.libraries.feed.common.testing.ModelProviderValidator;
+import com.google.android.libraries.feed.common.testing.ResponseBuilder;
+import com.google.search.now.feed.client.StreamDataProto.UiContext;
+import com.google.search.now.wire.feed.ContentIdProto.ContentId;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+
+/**
+ * Integration test for {@link
+ * com.google.android.libraries.feed.feedrequestmanager.RequestManagerImpl}
+ */
+@RunWith(RobolectricTestRunner.class)
+public class ClientRequestManagerTest {
+  private final InfraIntegrationScope scope = new InfraIntegrationScope.Builder().build();
+  private RequestManager requestManager;
+  private ModelProviderValidator modelValidator;
+
+  // Create a simple stream with a root and three features
+  private static final ContentId[] CARDS =
+      new ContentId[] {
+        ResponseBuilder.createFeatureContentId(1),
+        ResponseBuilder.createFeatureContentId(2),
+        ResponseBuilder.createFeatureContentId(3)
+      };
+
+  @Before
+  public void setup() {
+    requestManager = scope.getRequestManager();
+    modelValidator = new ModelProviderValidator(scope.getProtocolAdapter());
+  }
+
+  @Test
+  public void testRequestManager() {
+    // Set up new response with 3 cards
+    scope
+        .getFakeFeedRequestManager()
+        .queueResponse(ResponseBuilder.forClearAllWithCards(CARDS).build());
+
+    // Trigger refresh
+    requestManager.triggerScheduledRefresh();
+
+    // Create new session
+    ModelProvider modelProvider =
+        scope.getModelProviderFactory().createNew(null, UiContext.getDefaultInstance());
+
+    // Model provider should now hold the cards
+    modelValidator.assertCursorContents(modelProvider, CARDS);
+  }
+}