Java 类org.robolectric.tester.org.apache.http.RequestMatcher 实例源码

项目:Fabric-Example-App-Android    文件:MraidVideoViewControllerTest.java   
@Before
public void setUp() throws Exception {
    context = Robolectric.buildActivity(Activity.class).create().get();
    bundle = new Bundle();
    baseVideoViewControllerListener = mock(BaseVideoViewControllerListener.class);

    bundle.putString(VIDEO_URL, "http://video_url");

    Robolectric.getUiThreadScheduler().pause();
    Robolectric.getBackgroundScheduler().pause();

    Robolectric.addHttpResponseRule(new RequestMatcher() {
        @Override
        public boolean matches(HttpRequest request) {
            return true;
        }
    }, new TestHttpResponse(200, "body"));

    ShadowLocalBroadcastManager.getInstance(context).registerReceiver(broadcastReceiver, getHtmlInterstitialIntentFilter());
}
项目:Fabric-Example-App-Android    文件:HttpClientTest.java   
@Before
public void setup() {
    context = Robolectric.buildActivity(Activity.class).create().get();
    userAgent = new WebView(context).getSettings().getUserAgentString();

    Robolectric.addHttpResponseRule(new RequestMatcher() {
        @Override
        public boolean matches(HttpRequest request) {
            return true;
        }
    }, new TestHttpResponse(200, "body"));

    HttpClient.setWebViewUserAgent(null);
    Robolectric.getBackgroundScheduler().pause();
    Robolectric.clearPendingHttpResponses();
}
项目:FullRobolectricTestSample    文件:DefaultRequestDirectorTest.java   
@Test
public void shouldReturnRequestsByRule_WithCustomRequestMatcher() throws Exception {
  Robolectric.setDefaultHttpResponse(404, "no such page");

  Robolectric.addHttpResponseRule(new RequestMatcher() {
    @Override public boolean matches(HttpRequest request) {
      return request.getRequestLine().getUri().equals("http://matching.uri");
    }
  }, new TestHttpResponse(200, "a cheery response body"));

  HttpResponse response = requestDirector.execute(null, new HttpGet("http://matching.uri"), null);
  assertNotNull(response);
  assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);
  assertThat(Strings.fromStream(response.getEntity().getContent())).isEqualTo("a cheery response body");

  response = requestDirector.execute(null, new HttpGet("http://non-matching.uri"), null);
  assertNotNull(response);
  assertThat(response.getStatusLine().getStatusCode()).isEqualTo(404);
  assertThat(Strings.fromStream(response.getEntity().getContent())).isEqualTo("no such page");
}
项目:invio    文件:MapActivityTest.java   
/**
 * Get the specific URI RequestMatcher for the "tilemapresource.xml" HttpRequest.
 *
 * @return RequestMatcher returning true if the URI ends with "tilemapresource.xml" or false otherwise
 */
private RequestMatcher getTileMapResourceRequestMatcher() {
    RequestMatcher tileMapResourceRequestMatcher = new RequestMatcher() {
        @Override
        public boolean matches(HttpRequest request) {
            if (request.getRequestLine().getUri().endsWith("tilemapresource.xml")) {
                return true;
            }

            return false;
        }
    };

    return tileMapResourceRequestMatcher;
}
项目:invio    文件:MapActivityTest.java   
private RequestMatcher getGeneralMapDataMatcher() {
    RequestMatcher generalMapDataMatcher = new RequestMatcher() {
        @Override
        public boolean matches(HttpRequest request) {
            String uri = request.getRequestLine().getUri();
            if (uri.endsWith(".osm") || uri.endsWith(".json")) {
                return true;
            }

            return false;
        }
    };

    return generalMapDataMatcher;
}
项目:silent-text-android    文件:ClientTestFixture.java   
protected static void inject( RequestMatcher request, HttpResponse response ) {
    FakeHttpLayer http = Robolectric.getFakeHttpLayer();
    if( !http.isInterceptingHttpRequests() ) {
        http.interceptHttpRequests( true );
    }
    http.addHttpResponseRule( request, response );
}
项目:Fabric-Example-App-Android    文件:VastVideoViewControllerTest.java   
@TargetApi(VERSION_CODES.GINGERBREAD_MR1)
@Before
public void setUp() throws Exception {
    Networking.setRequestQueueForTesting(mockRequestQueue);
    Networking.setImageLoaderForTesting(mockImageLoader);
    context = Robolectric.buildActivity(Activity.class).create().get();
    bundle = new Bundle();
    savedInstanceState = new Bundle();
    testBroadcastIdentifier = 1111;

    VastVideoConfiguration vastVideoConfiguration = new VastVideoConfiguration();
    vastVideoConfiguration.setNetworkMediaFileUrl("video_url");
    vastVideoConfiguration.setDiskMediaFileUrl("disk_video_path");
    vastVideoConfiguration.addAbsoluteTrackers(
            Arrays.asList(new VastAbsoluteProgressTracker("start" + MACRO_TAGS, 2000)));
    vastVideoConfiguration.addFractionalTrackers(
            Arrays.asList(new VastFractionalProgressTracker("first" + MACRO_TAGS, 0.25f),
                    new VastFractionalProgressTracker("mid" + MACRO_TAGS, 0.5f),
                    new VastFractionalProgressTracker("third" + MACRO_TAGS, 0.75f)));
    vastVideoConfiguration.addPauseTrackers(
            Arrays.asList(new VastTracker("pause" + MACRO_TAGS, true)));
    vastVideoConfiguration.addResumeTrackers(
            Arrays.asList(new VastTracker("resume" + MACRO_TAGS, true)));
    vastVideoConfiguration.addCompleteTrackers(
            VastUtils.stringsToVastTrackers("complete" + MACRO_TAGS));
    vastVideoConfiguration.addCloseTrackers(
            VastUtils.stringsToVastTrackers("close" + MACRO_TAGS));
    vastVideoConfiguration.addSkipTrackers(VastUtils.stringsToVastTrackers("skip" + MACRO_TAGS));
    vastVideoConfiguration.addImpressionTrackers(
            VastUtils.stringsToVastTrackers("imp" + MACRO_TAGS));
    vastVideoConfiguration.addErrorTrackers(
            Collections.singletonList(new VastTracker("error" + MACRO_TAGS)));
    vastVideoConfiguration.setClickThroughUrl(CLICKTHROUGH_URL);
    vastVideoConfiguration.addClickTrackers(
            VastUtils.stringsToVastTrackers("click_1" + MACRO_TAGS, "click_2" + MACRO_TAGS));

    VastCompanionAd vastCompanionAd = new VastCompanionAd(
            300,
            250,
            new VastResource(COMPANION_IMAGE_URL,
                    VastResource.Type.STATIC_RESOURCE,
                    VastResource.CreativeType.IMAGE, 300, 250),
            COMPANION_CLICK_DESTINATION_URL,
            VastUtils.stringsToVastTrackers(COMPANION_CLICK_TRACKING_URL_1, COMPANION_CLICK_TRACKING_URL_2),
            VastUtils.stringsToVastTrackers(COMPANION_CREATIVE_VIEW_URL_1, COMPANION_CREATIVE_VIEW_URL_2)
    );
    vastVideoConfiguration.setVastCompanionAd(vastCompanionAd);

    when(mockVastIcon.getWidth()).thenReturn(40);
    when(mockVastIcon.getHeight()).thenReturn(40);
    VastResource vastResource = mock(VastResource.class);
    when(vastResource.getType()).thenReturn(VastResource.Type.STATIC_RESOURCE);
    when(vastResource.getResource()).thenReturn("static");
    when(vastResource.getCreativeType()).thenReturn(VastResource.CreativeType.IMAGE);
    when(mockVastIcon.getVastResource()).thenReturn(vastResource);
    vastVideoConfiguration.setVastIcon(mockVastIcon);

    when(mockMediaMetadataRetriever.getFrameAtTime(anyLong(), anyInt())).thenReturn(mockBitmap);

    bundle.putSerializable(VAST_VIDEO_CONFIGURATION, vastVideoConfiguration);

    expectedBrowserRequestCode = 1;

    Robolectric.getUiThreadScheduler().pause();
    Robolectric.getBackgroundScheduler().pause();
    Robolectric.clearPendingHttpResponses();

    // Used to give responses to Vast Download Tasks.
    Robolectric.addHttpResponseRule(new RequestMatcher() {
        @Override
        public boolean matches(HttpRequest request) {
            return true;
        }
    }, new TestHttpResponse(200, "body"));

    ShadowLocalBroadcastManager.getInstance(context).registerReceiver(broadcastReceiver, getHtmlInterstitialIntentFilter());

    expectedUserAgent = new WebView(context).getSettings().getUserAgentString();
}
项目:silent-text-android    文件:AccountsClientTestFixture.java   
protected static RequestMatcher whenLoginRequested() {
    return whenRequested( "PUT", "^https?://[^/]+/v1/me/device/([^/]+)/$" );
}
项目:silent-text-android    文件:AccountsClientTestFixture.java   
protected static RequestMatcher whenLogoutRequested() {
    return whenRequested( "DELETE", "^https?://[^/]+/v1/me/device/([^/]+)/(\\?.+)?$" );
}
项目:silent-text-android    文件:AccountsClientTestFixture.java   
protected static RequestMatcher whenPublicKeyRemoved() {
    return whenRequested( "DELETE", "^https?://[^/]+/v1/me/pubkey/([^/]+)/(\\?.+)?$" );
}
项目:silent-text-android    文件:AccountsClientTestFixture.java   
protected static RequestMatcher whenPublicKeyRevoked() {
    return whenRequested( "DELETE", "^https?://[^/]+/v1/me/pubkey/([^/]+)/(\\?.+)?$" );
}
项目:silent-text-android    文件:AccountsClientTestFixture.java   
protected static RequestMatcher whenPublicKeyUploaded() {
    return whenRequested( "PUT", "^https?://[^/]+/v1/me/pubkey/([^/]+)/(\\?.+)?$" );
}
项目:silent-text-android    文件:AccountsClientTestFixture.java   
protected static RequestMatcher whenPushRegistrationRequested() {
    return whenRequested( "PUT", "^https?://[^/]+/v1/me/device/([^/]+)/application/([^/]+)/(\\?.+)?$" );
}
项目:silent-text-android    文件:AccountsClientTestFixture.java   
protected static RequestMatcher whenPushUnregistrationRequested() {
    return whenRequested( "DELETE", "^https?://[^/]+/v1/me/device/([^/]+)/application/([^/]+)/(\\?.+)?$" );
}
项目:silent-text-android    文件:ClientTestFixture.java   
protected static RequestMatcher whenRequested( String method, String uriPattern ) {
    return new FakeHttpLayer.UriRegexMatcher( method, uriPattern );
}
项目:silent-text-android    文件:AccountManagementClientTest.java   
protected static RequestMatcher whenEditUserRequested() {
    return whenRequested( "PUT", "^https?://[^/]+/v1/user/[^/]+/$" );
}
项目:FullRobolectricTestSample    文件:Robolectric.java   
/**
 * Adds an HTTP response rule. The response will be returned when the rule is matched.
 *
 * @param requestMatcher custom {@code RequestMatcher}.
 * @param response       response to return when a match is found.
 */
public static void addHttpResponseRule(RequestMatcher requestMatcher, HttpResponse response) {
  getFakeHttpLayer().addHttpResponseRule(requestMatcher, response);
}
项目:FullRobolectricTestSample    文件:Robolectric.java   
/**
 * Adds an HTTP response rule. For each time the rule is matched, responses will be shifted
 * off the list and returned. When all responses have been given and the rule is matched again,
 * an exception will be thrown.
 *
 * @param requestMatcher custom {@code RequestMatcher}.
 * @param responses      responses to return in order when a match is found.
 */
public static void addHttpResponseRule(RequestMatcher requestMatcher, List<? extends HttpResponse> responses) {
  getFakeHttpLayer().addHttpResponseRule(requestMatcher, responses);
}