Search in sources :

Example 1 with EmailVerificationTicket

use of com.auth0.json.mgmt.tickets.EmailVerificationTicket in project auth0-java by auth0.

the class EmailVerificationTicketTest method shouldSerializeWithIdentity.

@Test
public void shouldSerializeWithIdentity() throws Exception {
    EmailVerificationTicket ticket = new EmailVerificationTicket("usr123");
    ticket.setResultUrl("https://page.auth0.com/result");
    ticket.setTTLSeconds(36000);
    EmailVerificationIdentity identity = new EmailVerificationIdentity("some-provider", "some-user-id");
    ticket.setIdentity(identity);
    String serialized = toJSON(ticket);
    assertThat(serialized, is(notNullValue()));
    assertThat(serialized, JsonMatcher.hasEntry("user_id", "usr123"));
    assertThat(serialized, JsonMatcher.hasEntry("result_url", "https://page.auth0.com/result"));
    assertThat(serialized, JsonMatcher.hasEntry("ttl_sec", 36000));
    Map<String, String> identityMap = new HashMap<>();
    identityMap.put("provider", "some-provider");
    identityMap.put("user_id", "some-user-id");
    assertThat(serialized, JsonMatcher.hasEntry("identity", identityMap));
}
Also used : HashMap(java.util.HashMap) EmailVerificationIdentity(com.auth0.json.mgmt.EmailVerificationIdentity) JsonTest(com.auth0.json.JsonTest) Test(org.junit.Test)

Example 2 with EmailVerificationTicket

use of com.auth0.json.mgmt.tickets.EmailVerificationTicket in project auth0-java by auth0.

the class TicketsEntityTest method shouldCreateEmailVerificationTicket.

@Test
public void shouldCreateEmailVerificationTicket() throws Exception {
    EmailVerificationTicket ticket = new EmailVerificationTicket("uid123");
    ticket.setIncludeEmailInRedirect(true);
    ticket.setTTLSeconds(42);
    Request<EmailVerificationTicket> request = api.tickets().requestEmailVerification(ticket);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_EMAIL_VERIFICATION_TICKET, 200);
    EmailVerificationTicket response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("POST", "/api/v2/tickets/email-verification"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    Map<String, Object> body = bodyFromRequest(recordedRequest);
    assertThat(body.size(), is(3));
    assertThat(body, hasEntry("user_id", "uid123"));
    assertThat(body, hasEntry("includeEmailInRedirect", true));
    assertThat(body, hasEntry("ttl_sec", 42));
    assertThat(response, is(notNullValue()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) EmailVerificationTicket(com.auth0.json.mgmt.tickets.EmailVerificationTicket) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 JsonTest (com.auth0.json.JsonTest)1 EmailVerificationIdentity (com.auth0.json.mgmt.EmailVerificationIdentity)1 EmailVerificationTicket (com.auth0.json.mgmt.tickets.EmailVerificationTicket)1 HashMap (java.util.HashMap)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1