Skip to content

Commit 2351867

Browse files
committed
Add test files for Authentication handler and clean test file for batch request content
1 parent fc3dfae commit 2351867

File tree

2 files changed

+47
-16
lines changed

2 files changed

+47
-16
lines changed

src/test/java/com/microsoft/graph/content/MSBatchRequestContentTest.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,6 @@
1515

1616
public class MSBatchRequestContentTest {
1717

18-
@BeforeClass
19-
public static void setUpBeforeClass() throws Exception {
20-
}
21-
22-
@AfterClass
23-
public static void tearDownAfterClass() throws Exception {
24-
}
25-
26-
@Before
27-
public void setUp() throws Exception {
28-
}
29-
30-
@After
31-
public void tearDown() throws Exception {
32-
}
33-
3418
@Test
3519
public void testMSBatchRequestContentCreation() {
3620

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.microsoft.graph.httpcore;
2+
3+
import static org.junit.Assert.assertTrue;
4+
import static org.junit.Assert.fail;
5+
6+
import java.io.IOException;
7+
8+
import org.apache.http.Header;
9+
import org.apache.http.HttpException;
10+
import org.apache.http.HttpRequest;
11+
import org.apache.http.client.methods.HttpGet;
12+
import org.apache.http.client.protocol.HttpClientContext;
13+
import org.junit.Test;
14+
15+
public class AuthenticationHandlerTest {
16+
17+
static String token = "TEST-TOKEN";
18+
19+
public static class AuthProvider implements IAuthenticationProvider{
20+
public static String getToken() {
21+
return "Bearer " + token;
22+
}
23+
public void authenticateRequest(HttpRequest request) {
24+
// TODO Auto-generated method stub
25+
request.addHeader("Authorization", AuthProvider.getToken());
26+
}
27+
}
28+
29+
@Test
30+
public void testAuthenticationHandler() {
31+
AuthProvider authProvider = new AuthProvider();
32+
AuthenticationHandler authHandler = new AuthenticationHandler(authProvider);
33+
HttpGet httpget = new HttpGet("https://graph.microsoft.com/v1.0/me/");
34+
HttpClientContext localContext = HttpClientContext.create();
35+
36+
try {
37+
authHandler.process(httpget, localContext);
38+
Header header = httpget.getFirstHeader("Authorization");
39+
assertTrue(header.getValue().equals("Bearer " + token));
40+
} catch (HttpException | IOException e) {
41+
// TODO Auto-generated catch block
42+
e.printStackTrace();
43+
fail("Authentication handler failure");
44+
}
45+
}
46+
47+
}

0 commit comments

Comments
 (0)