类com.squareup.okhttp.mockwebserver.RecordedRequest源码实例Demo

下面列出了怎么用com.squareup.okhttp.mockwebserver.RecordedRequest的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: Auth0.Android   文件: UsersAPIClientTest.java
@Test
public void shouldUnlinkAccountSync() throws Exception {
    mockAPI.willReturnSuccessfulUnlink();

    final List<UserIdentity> result = client.unlink(USER_ID_PRIMARY, USER_ID_SECONDARY, PROVIDER)
            .execute();

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

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


    TypeToken<List<UserIdentity>> typeToken = new TypeToken<List<UserIdentity>>() {
    };
    assertThat(result, TypeTokenMatcher.isA(typeToken));
    assertThat(result.size(), is(1));
}
 
@Test
public void shouldSendSMSLinkSync() throws Exception {
    mockAPI.willReturnSuccessfulPasswordlessStart();

    client.passwordlessWithSMS("+1123123123", PasswordlessType.WEB_LINK)
            .execute();

    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", "sms"));
}
 
源代码3 项目: jenkins-rest   文件: BaseJenkinsMockTest.java
protected RecordedRequest assertSent(final MockWebServer server, 
        final String method, 
        final String expectedPath, 
        final Map<String, ?> queryParams) throws InterruptedException {

    RecordedRequest request = server.takeRequest();
    assertThat(request.getMethod()).isEqualTo(method);
    assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo(APPLICATION_JSON);

    final String path = request.getPath();
    final String rawPath = path.contains("?") ? path.substring(0, path.indexOf('?')) : path;
    assertThat(rawPath).isEqualTo(expectedPath);

    final Map<String, String> normalizedParams = Maps.transformValues(queryParams, Functions.toStringFunction());
    assertThat(normalizedParams).isEqualTo(extractParams(path));

    return request;
}
 
源代码4 项目: async-google-pubsub-client   文件: PubsubTest.java
private void testAcknowledge(final String... ackIds)
    throws InterruptedException, ExecutionException, TimeoutException {
  final PubsubFuture<Void> future = pubsub.acknowledge(PROJECT, SUBSCRIPTION_1, ackIds);

  final String expectedPath =
      BASE_PATH + Subscription.canonicalSubscription(PROJECT, SUBSCRIPTION_1) + ":acknowledge";

  assertThat(future.operation(), is("acknowledge"));
  assertThat(future.method(), is("POST"));
  assertThat(future.uri(), is(server.getUrl(expectedPath).toString()));
  assertThat(future.payloadSize(), is(greaterThan(0L)));

  final RecordedRequest request = server.takeRequest(10, SECONDS);

  assertThat(request.getMethod(), is("POST"));
  assertThat(request.getPath(), is(expectedPath));
  assertThat(request.getHeader(CONTENT_ENCODING), is("gzip"));
  assertThat(request.getHeader(CONTENT_LENGTH), is(String.valueOf(future.payloadSize())));
  assertThat(request.getHeader(CONTENT_TYPE), is("application/json; charset=UTF-8"));

  assertRequestHeaders(request);

  server.enqueue(new MockResponse());
  future.get(10, SECONDS);
}
 
@Test
public void shouldRevokeTokenSync() throws Exception {
    Auth0 auth0 = new Auth0(CLIENT_ID, mockAPI.getDomain(), mockAPI.getDomain());
    AuthenticationAPIClient client = new AuthenticationAPIClient(auth0);

    mockAPI.willReturnSuccessfulEmptyBody();
    client.revokeToken("refreshToken")
            .execute();

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

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("client_id", CLIENT_ID));
    assertThat(body, hasEntry("token", "refreshToken"));
}
 
源代码6 项目: jus   文件: AuthTest.java
@Test
public void authRetryOn407Fail() throws Exception {
    server.enqueue(new MockResponse().setResponseCode(407)
            .setBody("Invalid token"));
    server.enqueue(new MockResponse().setResponseCode(407)
            .setBody("Invalid token"));
    try {
        queue.add(new StringRequest("POST", server.url("/").toString())
                .setRequestBody("try me!")).getFuture().get();
        fail("Must not retry 2 times");
    } catch (Exception ex) {
        assertThat(ex).hasCauseExactlyInstanceOf(AuthError.class);
    }
    RecordedRequest request = server.takeRequest();

    assertThat(request.getBody().readByteString().utf8()).isEqualTo("try me!");

    server.shutdown();
}
 
源代码7 项目: httplite   文件: MiscHandle.java
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);
}
 
@Test
public void shouldSendSMSCodeSync() throws Exception {
    mockAPI.willReturnSuccessfulPasswordlessStart();

    client.passwordlessWithSMS("+1123123123", PasswordlessType.CODE)
            .execute();

    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", "code"));
    assertThat(body, hasEntry("connection", "sms"));
}
 
private void assertImpressionURL(int positionInQueue) {

        // Wait for Impression URL to Fire succesfully
        waitForTasks();
        Robolectric.flushBackgroundThreadScheduler();
        Robolectric.flushForegroundThreadScheduler();

        RecordedRequest request = null;
        try {
            for (int i = 1; i <= positionInQueue; i++) {
                request = server.takeRequest();
                if (i == positionInQueue) {
                    String impression_url = request.getRequestLine();
                    System.out.print("impression_url::" + impression_url + "\n");
                    assertTrue(impression_url.startsWith("GET /impression_url? HTTP/1.1"));
                }
            }

        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
 
源代码10 项目: jus   文件: JsonElementRequestTest.java
@Test
public void aJsonArray() throws IOException, InterruptedException, ExecutionException {
    server.enqueue(new MockResponse().setBody(
            "[{\"theName\":\"value1\"}, " +
                    "{\"theName\":\"value2\"}]"));

    JsonObjectArrayWrapper<RespWrapper> body =
            service.aJsonArray(new JsonObjectArrayWrapper()
                    .wrap(JsonArray.readFrom("[\"name\",\"value\"]").asJsonArray(),
                            ReqWrapper.class))
                    .getFuture().get();
    assertThat(body.get(0).getTheName()).isEqualTo("value1");
    assertThat(body.get(1).getTheName()).isEqualTo("value2");

    RecordedRequest request = server.takeRequest();

    assertThat(request.getBody().readUtf8()).isEqualTo("[\"name\",\"value\"]");
    assertThat(request.getHeader("Content-Type")).isEqualTo("application/json; charset=UTF-8");
    assertThat(request.getHeader("Accept")).isEqualTo("application/json");
}
 
源代码11 项目: jus   文件: AuthTest.java
@Test
public void authRetryOn401Fail() throws Exception {
    server.enqueue(new MockResponse().setResponseCode(401)
            .setBody("Invalid token"));
    server.enqueue(new MockResponse().setResponseCode(401)
            .setBody("Invalid token"));
    try {
        queue.add(new StringRequest("POST", server.url("/").toString())
                .setRequestBody("try me!")).getFuture().get();
        fail("Must not retry 2 times");
    } catch (Exception ex) {
        assertThat(ex).hasCauseExactlyInstanceOf(AuthError.class);
    }
    RecordedRequest request = server.takeRequest();

    assertThat(request.getBody().readByteString().utf8()).isEqualTo("try me!");

    server.shutdown();
}
 
@Test
public void shouldLoginWithUserAndPasswordSync() throws Exception {
    mockAPI.willReturnSuccessfulLogin();

    final Credentials credentials = client
            .login(SUPPORT_AUTH0_COM, "voidpassword", MY_CONNECTION)
            .execute();

    assertThat(credentials, is(notNullValue()));

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("connection", MY_CONNECTION));
    assertThat(body, not(hasKey("realm")));
}
 
源代码13 项目: wasp   文件: WaspTest.java
@Test
public void syncGetForFailure() throws Exception {
  server.enqueue(new MockResponse().setStatus("404"));

  MyApiSync myApi = new Wasp.Builder(context)
      .setEndpoint(server.url("/v1").toString())
      .setNetworkStack(VolleyNetworkStack.newInstance(requestQueue))
      .build()
      .create(MyApiSync.class);

  try {
    myApi.getUser();
    fail();
  } catch (Exception e) {
    //TODO add WaspError
    // assertThat(e).isInstanceOf(WaspError.class);
    assertTrue(e.getMessage(), true);
  }

  RecordedRequest request = server.takeRequest();
  assertThat(request.getPath()).isEqualTo("/v1/user");

  verify(executor).execute(any(Runnable.class));
  verifyNoMoreInteractions(executor);
}
 
@Test
public void shouldLoginWithUserAndPasswordUsingOAuthTokenEndpoint() throws Exception {
    mockAPI.willReturnSuccessfulLogin();
    final MockAuthenticationCallback<Credentials> callback = new MockAuthenticationCallback<>();

    client.login(SUPPORT_AUTH0_COM, "some-password")
            .start(callback);
    assertThat(callback, hasPayloadOfType(Credentials.class));

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getPath(), is("/oauth/token"));
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("client_id", CLIENT_ID));
    assertThat(body, hasEntry("grant_type", "password"));
    assertThat(body, hasEntry("username", SUPPORT_AUTH0_COM));
    assertThat(body, hasEntry("password", "some-password"));
    assertThat(body, not(hasKey("realm")));
    assertThat(body, not(hasKey("connection")));
    assertThat(body, not(hasKey("scope")));
    assertThat(body, not(hasKey("audience")));
}
 
源代码15 项目: Auth0.Android   文件: UsersAPIClientTest.java
@Test
public void shouldLinkAccountSync() throws Exception {
    mockAPI.willReturnSuccessfulLink();

    final List<UserIdentity> result = client.link(USER_ID_PRIMARY, TOKEN_SECONDARY)
            .execute();

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

    assertThat(request.getHeader(HEADER_AUTHORIZATION), equalTo(BEARER + TOKEN_PRIMARY));
    assertThat(request.getMethod(), equalTo(METHOD_POST));
    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry(KEY_LINK_WITH, TOKEN_SECONDARY));


    TypeToken<List<UserIdentity>> typeToken = new TypeToken<List<UserIdentity>>() {
    };
    assertThat(result, TypeTokenMatcher.isA(typeToken));
    assertThat(result.size(), is(2));
}
 
@Test
public void shouldSendSMSCode() throws Exception {
    mockAPI.willReturnSuccessfulPasswordlessStart();

    final MockAuthenticationCallback<Void> callback = new MockAuthenticationCallback<>();
    client.passwordlessWithSMS("+1123123123", PasswordlessType.CODE)
            .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", "code"));
    assertThat(body, hasEntry("connection", "sms"));

    assertThat(callback, hasNoError());
}
 
@Test
public void shouldFetchTokenInfoSync() throws Exception {
    mockAPI.willReturnTokenInfo();

    final UserProfile profile = client
            .tokenInfo("ID_TOKEN")
            .execute();

    assertThat(profile, is(notNullValue()));

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

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("id_token", "ID_TOKEN"));
}
 
@Test
public void shouldLoginWithNativeSocialToken() throws Exception {
    mockAPI.willReturnSuccessfulLogin();

    final MockAuthenticationCallback<Credentials> callback = new MockAuthenticationCallback<>();
    client.loginWithNativeSocialToken("test-token-value", "test-token-type")
            .start(callback);

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

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("client_id", CLIENT_ID));
    assertThat(body, hasEntry("grant_type", ParameterBuilder.GRANT_TYPE_TOKEN_EXCHANGE));
    assertThat(body, hasEntry("subject_token", "test-token-value"));
    assertThat(body, hasEntry("subject_token_type", "test-token-type"));
    assertThat(body, hasEntry("scope", OPENID));

    assertThat(callback, hasPayloadOfType(Credentials.class));
}
 
@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));
}
 
@Test
public void shouldLoginWithPhoneNumberWithCustomConnectionWithOTPGrantIfOIDCConformant() throws Exception {
    mockAPI.willReturnSuccessfulLogin();

    Auth0 auth0 = new Auth0(CLIENT_ID, mockAPI.getDomain(), mockAPI.getDomain());
    auth0.setOIDCConformant(true);
    AuthenticationAPIClient client = new AuthenticationAPIClient(auth0);

    final MockAuthenticationCallback<Credentials> callback = new MockAuthenticationCallback<>();
    client.loginWithPhoneNumber("+10101010101", "1234", MY_CONNECTION)
            .start(callback);

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

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("grant_type", ParameterBuilder.GRANT_TYPE_PASSWORDLESS_OTP));
    assertThat(body, hasEntry("realm", MY_CONNECTION));
    assertThat(body, hasEntry("username", "+10101010101"));
    assertThat(body, hasEntry("otp", "1234"));
    assertThat(body, hasEntry("scope", OPENID));

    assertThat(callback, hasPayloadOfType(Credentials.class));
}
 
源代码21 项目: jus   文件: GsonRequestTest.java
@Test
public void serializeUsesConfiguration() throws IOException, InterruptedException,
        ExecutionException {
    server.enqueue(new MockResponse().setBody("{}"));

    GsonRequest<AnImplementation> request =
            new GsonRequest<AnImplementation>(Request.Method.POST,
                    server.url("").toString(), AnImplementation.class)
                    .setRequestData(new AnImplementation(null));

    queue.add(request).getFuture().get();

    RecordedRequest sRequest = server.takeRequest();
    assertThat(sRequest.getBody().readUtf8()).isEqualTo("{}"); // Null value was not serialized.
    assertThat(sRequest.getHeader("Content-Type")).isEqualTo("application/json; charset=UTF-8");
    assertThat(sRequest.getHeader("Accept")).isEqualTo("application/json");
}
 
源代码22 项目: async-google-pubsub-client   文件: PubsubTest.java
@Test
public void testListSubscriptions() throws Exception {
  final PubsubFuture<SubscriptionList> future = pubsub.listSubscriptions(PROJECT);

  final String expectedPath = BASE_PATH + "projects/" + PROJECT + "/subscriptions";

  assertThat(future.operation(), is("list subscriptions"));
  assertThat(future.method(), is("GET"));
  assertThat(future.uri(), is(server.getUrl(expectedPath).toString()));
  assertThat(future.payloadSize(), is(0L));

  final RecordedRequest request = server.takeRequest(10, SECONDS);

  assertThat(request.getMethod(), is("GET"));
  assertThat(request.getPath(), is(expectedPath));
  assertRequestHeaders(request);

  final SubscriptionList response = SubscriptionList.of(Subscription.of(PROJECT, SUBSCRIPTION_1, TOPIC_1),
                                                        Subscription.of(PROJECT, SUBSCRIPTION_2, TOPIC_2));
  server.enqueue(new MockResponse().setBody(json(response)));

  final SubscriptionList subscriptionList = future.get(10, SECONDS);
  assertThat(subscriptionList, is(response));
}
 
@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());
}
 
@Test
public void shouldLoginWithPhoneNumberWithCustomConnection() throws Exception {
    mockAPI.willReturnSuccessfulLogin();

    final MockAuthenticationCallback<Credentials> callback = new MockAuthenticationCallback<>();
    client.loginWithPhoneNumber("+10101010101", "1234", MY_CONNECTION)
            .start(callback);

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

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("grant_type", ParameterBuilder.GRANT_TYPE_PASSWORD));
    assertThat(body, hasEntry("connection", MY_CONNECTION));
    assertThat(body, hasEntry("username", "+10101010101"));
    assertThat(body, hasEntry("password", "1234"));
    assertThat(body, hasEntry("scope", OPENID));

    assertThat(callback, hasPayloadOfType(Credentials.class));
}
 
@Test
public void shouldLoginWithPhoneNumber() throws Exception {
    mockAPI.willReturnSuccessfulLogin();

    final MockAuthenticationCallback<Credentials> callback = new MockAuthenticationCallback<>();
    client.loginWithPhoneNumber("+10101010101", "1234")
            .start(callback);

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

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("grant_type", ParameterBuilder.GRANT_TYPE_PASSWORD));
    assertThat(body, hasEntry("connection", "sms"));
    assertThat(body, hasEntry("username", "+10101010101"));
    assertThat(body, hasEntry("password", "1234"));
    assertThat(body, hasEntry("scope", OPENID));

    assertThat(callback, hasPayloadOfType(Credentials.class));
}
 
@Test
public void shouldLoginWithPhoneNumberSync() throws Exception {
    mockAPI.willReturnSuccessfulLogin();

    final Credentials credentials = client
            .loginWithPhoneNumber("+10101010101", "1234")
            .execute();

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

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("grant_type", ParameterBuilder.GRANT_TYPE_PASSWORD));
    assertThat(body, hasEntry("connection", "sms"));
    assertThat(body, hasEntry("username", "+10101010101"));
    assertThat(body, hasEntry("password", "1234"));
    assertThat(body, hasEntry("scope", OPENID));

    assertThat(credentials, is(notNullValue()));
}
 
@Test
public void shouldLoginWithEmailOnly() throws Exception {
    mockAPI.willReturnSuccessfulLogin();

    final MockAuthenticationCallback<Credentials> callback = new MockAuthenticationCallback<>();
    client.loginWithEmail(SUPPORT_AUTH0_COM, "1234")
            .start(callback);

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

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("grant_type", ParameterBuilder.GRANT_TYPE_PASSWORD));
    assertThat(body, hasEntry("connection", "email"));
    assertThat(body, hasEntry("username", SUPPORT_AUTH0_COM));
    assertThat(body, hasEntry("password", "1234"));
    assertThat(body, hasEntry("scope", OPENID));

    assertThat(callback, hasPayloadOfType(Credentials.class));
}
 
@Test
public void shouldLoginWithEmailOnlySync() throws Exception {
    mockAPI.willReturnSuccessfulLogin()
            .willReturnTokenInfo();

    final Credentials credentials = client
            .loginWithEmail(SUPPORT_AUTH0_COM, "1234")
            .execute();

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

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("grant_type", ParameterBuilder.GRANT_TYPE_PASSWORD));
    assertThat(body, hasEntry("connection", "email"));
    assertThat(body, hasEntry("username", SUPPORT_AUTH0_COM));
    assertThat(body, hasEntry("password", "1234"));
    assertThat(body, hasEntry("scope", OPENID));

    assertThat(credentials, is(notNullValue()));
}
 
@Test
public void shouldCreateUserWithoutUsername() throws Exception {
    mockAPI.willReturnSuccessfulSignUp();

    final MockAuthenticationCallback<DatabaseUser> callback = new MockAuthenticationCallback<>();
    client.createUser(SUPPORT_AUTH0_COM, PASSWORD, MY_CONNECTION)
            .start(callback);

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

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("email", SUPPORT_AUTH0_COM));
    assertThat(body, not(hasKey("username")));
    assertThat(body, hasEntry("password", PASSWORD));
    assertThat(body, hasEntry("connection", MY_CONNECTION));

    assertThat(callback, hasPayloadOfType(DatabaseUser.class));
}
 
@Test
public void shouldCreateUserWithoutUsernameSync() throws Exception {
    mockAPI.willReturnSuccessfulSignUp();

    final DatabaseUser user = client
            .createUser(SUPPORT_AUTH0_COM, PASSWORD, MY_CONNECTION)
            .execute();

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

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("email", SUPPORT_AUTH0_COM));
    assertThat(body, not(hasKey("username")));
    assertThat(body, hasEntry("password", PASSWORD));
    assertThat(body, hasEntry("connection", MY_CONNECTION));

    assertThat(user, is(notNullValue()));
}
 
 类所在包
 类方法
 同包方法