3030import com .microsoft .graph .serializer .ISerializer ;
3131
3232import org .junit .jupiter .api .Test ;
33+ import org .junit .jupiter .params .ParameterizedTest ;
34+ import org .junit .jupiter .params .provider .ValueSource ;
3335
3436import okhttp3 .Call ;
3537import okhttp3 .MediaType ;
4143
4244class BatchRequestContentTest {
4345
44- String testurl = "http://graph.microsoft.com/me" ;
46+ String testurl = "http://graph.microsoft.com/v1.0/ me" ;
4547
4648 @ Test
4749 void testBatchRequestContentCreation () throws MalformedURLException {
@@ -61,11 +63,21 @@ void testGetBatchRequestContent() throws MalformedURLException {
6163 BatchRequestContent requestContent = new BatchRequestContent ();
6264 String stepId = requestContent .addBatchRequestStep (requestStep );
6365 String content = new DefaultSerializer (mock (ILogger .class )).serializeObject (requestContent );
64- String expectedContent = "{\" requests\" :[{\" url\" :\" http://graph.microsoft.com /me\" ,\" method\" :\" GET\" ,\" id\" :\" "
66+ String expectedContent = "{\" requests\" :[{\" url\" :\" /me\" ,\" method\" :\" GET\" ,\" id\" :\" "
6567 + stepId + "\" }]}" ;
6668 assertEquals (expectedContent , content );
6769 }
6870
71+ @ ParameterizedTest
72+ @ ValueSource (strings = { "https://microsoftgraph.chinacloudapi.cn/v1.0/me" , "https://graph.microsoft.com/v1.0/me" , "https://graph.microsoft.us/v1.0/me" , "https://dod-graph.microsoft.us/v1.0/me" , "https://graph.microsoft.de/v1.0/me" })
73+ void testItReplacesNationalHost (final String url ) throws MalformedURLException {
74+ IHttpRequest requestStep = mock (IHttpRequest .class );
75+ when (requestStep .getRequestUrl ()).thenReturn (new URL (url ));
76+ BatchRequestContent requestContent = new BatchRequestContent ();
77+ requestContent .addBatchRequestStep (requestStep );
78+ var step = requestContent .requests .get (0 );
79+ assertEquals ("/me" , step .url );
80+ }
6981 @ Test
7082 void testGetBatchRequestContentWithHeader () throws MalformedURLException {
7183 IHttpRequest requestStep = mock (IHttpRequest .class );
@@ -74,7 +86,7 @@ void testGetBatchRequestContentWithHeader() throws MalformedURLException {
7486 BatchRequestContent requestContent = new BatchRequestContent ();
7587 String stepId = requestContent .addBatchRequestStep (requestStep );
7688 String content = new DefaultSerializer (mock (ILogger .class )).serializeObject (requestContent );
77- String expectedContent = "{\" requests\" :[{\" url\" :\" http://graph.microsoft.com /me\" ,\" method\" :\" GET\" ,\" id\" :\" "
89+ String expectedContent = "{\" requests\" :[{\" url\" :\" /me\" ,\" method\" :\" GET\" ,\" id\" :\" "
7890 + stepId + "\" ,\" headers\" :{\" testkey\" :\" testvalue\" }}]}" ;
7991 assertEquals (expectedContent , content );
8092 }
@@ -105,7 +117,7 @@ void testRemoveBatchRequesStepWithIdByAddingMultipleBatchSteps() throws Malforme
105117
106118 requestContent .removeBatchRequestStepWithId (stepId );
107119 String content = new DefaultSerializer (mock (ILogger .class )).serializeObject (requestContent );
108- String expectedContent = "{\" requests\" :[{\" url\" :\" http://graph.microsoft.com /me\" ,\" method\" :\" GET\" ,\" id\" :\" "
120+ String expectedContent = "{\" requests\" :[{\" url\" :\" /me\" ,\" method\" :\" GET\" ,\" id\" :\" "
109121 + step1Id + "\" }]}" ;
110122 assertEquals (expectedContent , content );
111123 }
0 commit comments