当前位置: 首页>>代码示例>>Java>>正文


Java RecordedRequest类代码示例

本文整理汇总了Java中com.squareup.okhttp.mockwebserver.RecordedRequest的典型用法代码示例。如果您正苦于以下问题:Java RecordedRequest类的具体用法?Java RecordedRequest怎么用?Java RecordedRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RecordedRequest类属于com.squareup.okhttp.mockwebserver包,在下文中一共展示了RecordedRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldSendEmailLinkAndroidWithCustomConnection

import com.squareup.okhttp.mockwebserver.RecordedRequest; //导入依赖的package包/类
@Test
public void shouldSendEmailLinkAndroidWithCustomConnection() throws Exception {
    mockAPI.willReturnSuccessfulPasswordlessStart();

    final MockAuthenticationCallback<Void> callback = new MockAuthenticationCallback<>();
    client.passwordlessWithEmail(SUPPORT_AUTH0_COM, PasswordlessType.ANDROID_LINK, MY_CONNECTION)
            .start(callback);

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    assertThat(request.getPath(), equalTo("/passwordless/start"));

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("client_id", CLIENT_ID));
    assertThat(body, hasEntry("email", SUPPORT_AUTH0_COM));
    assertThat(body, hasEntry("send", "link_android"));
    assertThat(body, hasEntry("connection", MY_CONNECTION));

    assertThat(callback, hasNoError());
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:21,代码来源:AuthenticationAPIClientTest.java

示例2: shouldRenewAuthWithDelegationIfNotOIDCConformant

import com.squareup.okhttp.mockwebserver.RecordedRequest; //导入依赖的package包/类
@Test
public void shouldRenewAuthWithDelegationIfNotOIDCConformant() throws Exception {
    Auth0 auth0 = new Auth0(CLIENT_ID, mockAPI.getDomain(), mockAPI.getDomain());
    auth0.setOIDCConformant(false);
    AuthenticationAPIClient client = new AuthenticationAPIClient(auth0);

    mockAPI.willReturnSuccessfulLogin();
    final MockAuthenticationCallback<Credentials> callback = new MockAuthenticationCallback<>();
    client.renewAuth("refreshToken")
            .start(callback);

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    assertThat(request.getPath(), equalTo("/delegation"));

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("client_id", CLIENT_ID));
    assertThat(body, hasEntry("refresh_token", "refreshToken"));
    assertThat(body, hasEntry("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer"));

    assertThat(callback, hasPayloadOfType(Credentials.class));
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:23,代码来源:AuthenticationAPIClientTest.java

示例3: shouldGetUserProfile

import com.squareup.okhttp.mockwebserver.RecordedRequest; //导入依赖的package包/类
@Test
public void shouldGetUserProfile() throws Exception {
    mockAPI.willReturnUserProfile();

    final MockManagementCallback<UserProfile> callback = new MockManagementCallback<>();
    client.getProfile(USER_ID_PRIMARY)
            .start(callback);

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getPath(), equalTo("/api/v2/users/" + USER_ID_PRIMARY));

    assertThat(request.getHeader(HEADER_AUTHORIZATION), equalTo(BEARER + TOKEN_PRIMARY));
    assertThat(request.getMethod(), equalTo(METHOD_GET));

    assertThat(callback, hasPayloadOfType(UserProfile.class));
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:17,代码来源:UsersAPIClientTest.java

示例4: shouldReturnValidResponseGivenValidGetSecretContentRequest

import com.squareup.okhttp.mockwebserver.RecordedRequest; //导入依赖的package包/类
@Test
public void shouldReturnValidResponseGivenValidGetSecretContentRequest() throws Exception {
    // set up mock server
    mockWebServer.enqueue(new MockResponse().setBody(FileUtil.readFile("getSecretContent.json")));
    SecretRequest secretRequest = new SecretRequest(IDENTITY_ID, SECRET_ID);

    // make a test call
    String response = createDeltaApiClient().getSecretContent(secretRequest);

    // assert the response
    assertEquals("base64String", response);

    // assert the request we made during the test call
    RecordedRequest request = mockWebServer.takeRequest(1, TimeUnit.SECONDS);
    assertEquals(IDENTITY_ID, getAuthIdentity(request.getHeader(AUTHORIZATION)));
    assertTrue(request.getPath().endsWith("/" + SECRET_ID + "/content"));
}
 
开发者ID:Covata,项目名称:delta-sdk-java,代码行数:18,代码来源:DeltaApiClientTest.java

示例5: shouldReturnValidResponseGivenValidGetSecretMetadataRequest

import com.squareup.okhttp.mockwebserver.RecordedRequest; //导入依赖的package包/类
@Test
public void shouldReturnValidResponseGivenValidGetSecretMetadataRequest() throws Exception {
    // set up mock server
    mockWebServer.enqueue(new MockResponse()
            .setBody(FileUtil.readFile("getSecretMetadata.json"))
            .addHeader(HttpHeaders.ETAG, "2"));
    SecretRequest secretRequest = new SecretRequest(IDENTITY_ID, SECRET_ID);

    // make a test call
    GetSecretMetadataResponse response = createDeltaApiClient().getSecretMetadata(secretRequest);

    // assert the response
    assertEquals(METADATA, response.getMetadata());

    // assert the request we made during the test call
    RecordedRequest request = mockWebServer.takeRequest(1, TimeUnit.SECONDS);
    assertEquals(IDENTITY_ID, getAuthIdentity(request.getHeader(AUTHORIZATION)));
    assertTrue(request.getPath().endsWith("/" + SECRET_ID + "/metadata"));
}
 
开发者ID:Covata,项目名称:delta-sdk-java,代码行数:20,代码来源:DeltaApiClientTest.java

示例6: shouldUpdateUserMetadata

import com.squareup.okhttp.mockwebserver.RecordedRequest; //导入依赖的package包/类
@Test
public void shouldUpdateUserMetadata() throws Exception {
    mockAPI.willReturnUserProfile();

    final Map<String, Object> metadata = new HashMap<>();
    metadata.put("boolValue", true);
    metadata.put("name", "my_name");
    metadata.put("list", Arrays.asList("my", "name", "is"));

    final MockManagementCallback<UserProfile> callback = new MockManagementCallback<>();
    client.updateMetadata(USER_ID_PRIMARY, metadata)
            .start(callback);

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getPath(), equalTo("/api/v2/users/" + USER_ID_PRIMARY));

    assertThat(request.getHeader(HEADER_AUTHORIZATION), equalTo(BEARER + TOKEN_PRIMARY));
    assertThat(request.getMethod(), equalTo(METHOD_PATCH));
    Map<String, Object> body = bodyFromRequest(request);

    assertThat(body, hasKey(KEY_USER_METADATA));
    assertThat(((Map<String, Object>) body.get(KEY_USER_METADATA)), is(equalTo(metadata)));

    assertThat(callback, hasPayloadOfType(UserProfile.class));
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:26,代码来源:UsersAPIClientTest.java

示例7: shouldReturnValidResponseGivenValidGetDerivedSecretsRequest

import com.squareup.okhttp.mockwebserver.RecordedRequest; //导入依赖的package包/类
@Test
public void shouldReturnValidResponseGivenValidGetDerivedSecretsRequest() throws Exception {
    // set up mock server
    mockWebServer.enqueue(new MockResponse().setBody(FileUtil.readFile("getDerivedSecrets.json")));
    GetDerivedSecretsRequest getDerivedSecretsRequest = new GetDerivedSecretsRequest(IDENTITY_ID, SECRET_ID, 0, 10);

    // make a test call
    List<GetSecretsResponse> response = createDeltaApiClient().getDerivedSecrets(getDerivedSecretsRequest);

    // assert the response
    assertEquals(1, response.size());
    GetSecretsResponse secret = response.get(0);
    assertEquals(SECRET_ID, secret.getId());
    assertEquals("https://example.server/secrets/067e6162-3b6f-4ae2-a171-2470b63dff00", secret.getHref());
    assertEquals("b15e50ea-ce07-4a3d-a4fc-0cd6b4d9ab13", secret.getCreatedBy());
    assertEquals("2016-08-23T17:02:47Z", secret.getCreated());
    assertEquals("eb4f44d0-1b47-4981-9661-1c1101d7a049", secret.getBaseSecret());
    assertEquals(METADATA, secret.getMetadata());

    // assert the request we made during the test call
    RecordedRequest request = mockWebServer.takeRequest(1, TimeUnit.SECONDS);
    assertEquals(IDENTITY_ID, getAuthIdentity(request.getHeader(AUTHORIZATION)));
    assertEquals("GET", request.getMethod());
    assertTrue(request.getPath()
            .endsWith("/secrets?baseSecret=" + SECRET_ID + "&createdBy=" + IDENTITY_ID + "&page=0&pageSize=10"));
}
 
开发者ID:Covata,项目名称:delta-sdk-java,代码行数:27,代码来源:DeltaApiClientTest.java

示例8: shouldFetchProfileAfterLoginRequest

import com.squareup.okhttp.mockwebserver.RecordedRequest; //导入依赖的package包/类
@Test
public void shouldFetchProfileAfterLoginRequest() throws Exception {
    mockAPI.willReturnSuccessfulLogin()
            .willReturnTokenInfo();

    MockAuthenticationCallback<Authentication> callback = new MockAuthenticationCallback<>();
    client.getProfileAfter(client.login(SUPPORT_AUTH0_COM, "voidpassword", MY_CONNECTION))
            .start(callback);

    final RecordedRequest firstRequest = mockAPI.takeRequest();
    assertThat(firstRequest.getPath(), equalTo("/oauth/ro"));

    Map<String, String> body = bodyFromRequest(firstRequest);
    assertThat(body, hasEntry("username", SUPPORT_AUTH0_COM));
    assertThat(body, hasEntry("password", "voidpassword"));
    assertThat(body, hasEntry("connection", MY_CONNECTION));

    final RecordedRequest secondRequest = mockAPI.takeRequest();
    assertThat(secondRequest.getHeader("Authorization"), is("Bearer " + AuthenticationAPI.ACCESS_TOKEN));
    assertThat(secondRequest.getPath(), equalTo("/userinfo"));

    assertThat(callback, hasPayloadOfType(Authentication.class));
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:24,代码来源:AuthenticationAPIClientTest.java

示例9: shouldReturnValidResponseGivenValidUpdateIdentityMetadataRequest

import com.squareup.okhttp.mockwebserver.RecordedRequest; //导入依赖的package包/类
@Test
public void shouldReturnValidResponseGivenValidUpdateIdentityMetadataRequest() throws Exception {
    // set up mock server
    mockWebServer.enqueue(new MockResponse().setBody(FileUtil.readFile("getIdentitiesByMetadata.json")));
    UpdateIdentityMetadataRequest updateIdentityMetadataRequest = new UpdateIdentityMetadataRequest(
            IDENTITY_ID,
            "identity2",
            10L,
            METADATA);

    // make a test call
    createDeltaApiClient().updateIdentityMetadata(updateIdentityMetadataRequest);

    // assert the request we made during the test call
    RecordedRequest request = mockWebServer.takeRequest(1, TimeUnit.SECONDS);
    assertEquals(IDENTITY_ID, getAuthIdentity(request.getHeader(AUTHORIZATION)));
    assertEquals("PUT", request.getMethod());
    assertTrue(request.getPath().endsWith("/identity2"));
}
 
开发者ID:Covata,项目名称:delta-sdk-java,代码行数:20,代码来源:DeltaApiClientTest.java

示例10: handleDownload

import com.squareup.okhttp.mockwebserver.RecordedRequest; //导入依赖的package包/类
private MockResponse handleDownload(RecordedRequest request, String root) {
    File rootDir = new File(root);
    File[] files = rootDir.listFiles();
    if(files!=null)
    try {
        for (File file:files){
            if(file.isFile()&&file.length()>500000){
                return GetHandle.fileToResponse(file.getAbsolutePath(),file);
            }
        }
    } catch (Exception e) {
        return new MockResponse()
                .setStatus("HTTP/1.1 500")
                .addHeader("content-type: text/plain; charset=utf-8")
                .setBody("SERVER ERROR: " + e);
    }
    return new MockResponse()
            .setStatus("HTTP/1.1 404")
            .addHeader("content-type: text/plain; charset=utf-8")
            .setBody("NOT FOUND: " + request.getPath());
}
 
开发者ID:alexclin0188,项目名称:httplite,代码行数:22,代码来源:MiscHandle.java

示例11: createBodyInfo

import com.squareup.okhttp.mockwebserver.RecordedRequest; //导入依赖的package包/类
private String createBodyInfo(RecordedRequest request) {
    if(HttpUtil.getMimeType(request).equals("application/json")){
        Charset charset = HttpUtil.getChartset(request);
        String json = request.getBody().readString(charset);
        System.out.println("createBodyInfo:"+json);
        return String.format("JsonBody charSet:%s,body:%s",charset.displayName(),json);
    }else if(HttpUtil.getMimeType(request).equals("application/x-www-form-urlencoded")){
        System.out.println("FormBody");
        String s;
        StringBuilder sb = new StringBuilder();
        try {
            while ((s = request.getBody().readUtf8Line())!=null){
                sb.append(URLDecoder.decode(s, Util.UTF_8.name()));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("createBodyInfo:"+sb.toString());
        return "FormBody:"+sb.toString();
    }else if(RecordedUpload.isMultipartContent(request)){
        return handleMultipart(request);
    }
    return HttpUtil.getMimeType(request);
}
 
开发者ID:alexclin0188,项目名称:httplite,代码行数:25,代码来源:MiscHandle.java

示例12: shouldSendSMSLinkWithCustomConnection

import com.squareup.okhttp.mockwebserver.RecordedRequest; //导入依赖的package包/类
@Test
public void shouldSendSMSLinkWithCustomConnection() throws Exception {
    mockAPI.willReturnSuccessfulPasswordlessStart();

    final MockAuthenticationCallback<Void> callback = new MockAuthenticationCallback<>();
    client.passwordlessWithSMS("+1123123123", PasswordlessType.WEB_LINK, MY_CONNECTION)
            .start(callback);

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    assertThat(request.getPath(), equalTo("/passwordless/start"));

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("client_id", CLIENT_ID));
    assertThat(body, hasEntry("phone_number", "+1123123123"));
    assertThat(body, hasEntry("send", "link"));
    assertThat(body, hasEntry("connection", MY_CONNECTION));

    assertThat(callback, hasNoError());
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:21,代码来源:AuthenticationAPIClientTest.java

示例13: dispatch

import com.squareup.okhttp.mockwebserver.RecordedRequest; //导入依赖的package包/类
@Override public MockResponse dispatch(RecordedRequest request) {
    System.out.println("Headers:"+request.getHeaders().toMultimap());
    String handleParam = request.getHeaders().get("handle");
    String method = request.getMethod().toUpperCase();
    MethodHandle handle = null;
    if(handleParam!=null){
        handle = mHandleMap.get(handleParam.toUpperCase());
    }
    System.out.printf("Path:%s,Method:%s\n",request.getPath(),method);
    if(handle==null){
        handle = mHandleMap.get(method);
    }
    if(handle!=null){
        return handle.handle(request,root);
    }else{
        return new MockResponse()
                .setStatus("HTTP/1.1 500")
                .addHeader("content-type: text/plain; charset=utf-8")
                .setBody("NO method handle for: " + method);
    }
}
 
开发者ID:alexclin0188,项目名称:httplite,代码行数:22,代码来源:SampleServer.java

示例14: getChartset

import com.squareup.okhttp.mockwebserver.RecordedRequest; //导入依赖的package包/类
public static Charset getChartset(RecordedRequest request){
    Headers headers = request.getHeaders();
    String value = headers.get("content-type");
    String[] array = value.split(";");
    Charset charset = null;
    try {
        if(array.length>1&&array[1].startsWith("charset=")){
            String charSetStr = array[1].split("=")[1];
            charset = Charset.forName(charSetStr);
        }
    } catch (Exception e) {
        System.out.println("ContentType:"+value);
        e.printStackTrace();
    }
    if(charset==null){
        charset = Charset.forName("utf-8");
    }
    return charset;
}
 
开发者ID:alexclin0188,项目名称:httplite,代码行数:20,代码来源:HttpUtil.java

示例15: testGetCoins

import com.squareup.okhttp.mockwebserver.RecordedRequest; //导入依赖的package包/类
@Test
public void testGetCoins() throws ShapeShiftException, IOException, InterruptedException, JSONException {
    // Schedule some responses.
    server.enqueue(new MockResponse().setBody(GET_COINS_JSON));

    ShapeShiftCoins coinsReply = shapeShift.getCoins();
    assertFalse(coinsReply.isError);
    assertEquals(3, coinsReply.coins.size());
    assertEquals(1, coinsReply.availableCoinTypes.size());
    assertEquals(BTC, coinsReply.availableCoinTypes.get(0));
    JSONObject coinsJson = new JSONObject(GET_COINS_JSON);
    for (ShapeShiftCoin coin : coinsReply.coins) {
        JSONObject json = coinsJson.getJSONObject(coin.symbol);
        assertEquals(json.getString("name"), coin.name);
        assertEquals(json.getString("symbol"), coin.symbol);
        assertEquals(json.getString("image"), coin.image.toString());
        assertEquals(json.getString("status").equals("available"), coin.isAvailable);
    }

    // Optional: confirm that your app made the HTTP requests you were expecting.
    RecordedRequest request = server.takeRequest();
    assertEquals("/getcoins", request.getPath());
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:24,代码来源:ServerTest.java


注:本文中的com.squareup.okhttp.mockwebserver.RecordedRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。