forked from howtoprogram/Java-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicAuthenticationTest.java
More file actions
40 lines (28 loc) · 1.15 KB
/
Copy pathBasicAuthenticationTest.java
File metadata and controls
40 lines (28 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.howtoprogram;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import com.mashape.unirest.http.utils.Base64Coder;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.*;
import org.junit.Test;
import java.io.IOException;
import static org.junit.Assert.assertTrue;
public class BasicAuthenticationTest {
@Test
public void testBasicAuthAPI() throws IOException, UnirestException {
HttpResponse<JsonNode> response = Unirest.get("http://httpbin.org/basic-auth/user/passwd")
.basicAuth("user", "passwd")
.asJson();
assertThat(response.getStatus(), equalTo(200));
}
@Test
public void testBasicAuthRawHeader() throws IOException, UnirestException {
HttpResponse<JsonNode> response = Unirest.get("http://httpbin.org/basic-auth/user/passwd").
header("Authorization", "Basic " + Base64Coder.encodeString("user" + ":" + "passwd"))
.asJson();
assertThat(response.getStatus(), equalTo(200));
}
}