11package com .onedrive .sdk .http ;
22
3+ import android .graphics .Path ;
34import android .net .Uri ;
45import android .test .AndroidTestCase ;
56
67import com .onedrive .sdk .core .MockClient ;
78import com .onedrive .sdk .extensions .IOneDriveClient ;
9+ import com .onedrive .sdk .options .Option ;
10+ import com .onedrive .sdk .options .QueryOption ;
811
912import junit .framework .Assert ;
1013
1114import java .net .URL ;
15+ import java .util .ArrayList ;
16+ import java .util .List ;
1217
1318/**
1419 * Test cases for (@see BaseRequest)
@@ -17,7 +22,7 @@ public class BaseRequestTests extends AndroidTestCase{
1722 private IOneDriveClient mockClient ;
1823 private BaseRequest mRequest ;
1924
20- private final String baseUrl = "https://localhost:8080/ " ;
25+ private final String baseUrl = "https://localhost:8080" ;
2126 private final String [] testingSegments = { "Hello World" , "你好世界" , "Καλημέρα κόσμε" , "안녕하세요" , "コンニチハ" , "แผ่นดินฮั่นเสื่อมโทรมแสนสังเวช" };
2227
2328 @ Override
@@ -26,19 +31,18 @@ public void setUp() {
2631 StringBuilder sb = new StringBuilder (baseUrl );
2732
2833 for (String segment : testingSegments ) {
29- sb .append (segment );
3034 sb .append ("/" );
35+ sb .append (segment );
3136 }
3237
33- sb .deleteCharAt (sb .length ()-1 );
34-
3538 mRequest = new BaseRequest (sb .toString (), mockClient , /*options:*/ null , null ) {
3639 @ Override
3740 public IOneDriveClient getClient () {
3841 return mockClient ;
3942 }
4043 };
4144 }
45+
4246 public void testUrlEncoded () throws Exception {
4347 URL requestUrl = mRequest .getRequestUrl ();
4448 final Uri .Builder expectBuilder = Uri .parse (baseUrl ).buildUpon ();
@@ -49,4 +53,28 @@ public void testUrlEncoded() throws Exception {
4953
5054 Assert .assertEquals (expectBuilder .build ().toString (), requestUrl .toString ());
5155 }
56+
57+ public void testUrlWithQuery () throws Exception {
58+ final String queryInUrl = "expand=foo&$select=id,name" ;
59+ final String testUrl = baseUrl + "?" + queryInUrl ;
60+
61+ final List <Option > options = new ArrayList <Option >();
62+ final QueryOption queryInOption = new QueryOption ("queryWithEncode" , "!" );
63+ options .add (queryInOption );
64+
65+ mRequest = new BaseRequest (testUrl , mockClient , options , null ) {
66+ public IOneDriveClient getClient () {
67+ return mockClient ;
68+ }
69+ };
70+
71+ URL requestUrl = mRequest .getRequestUrl ();
72+
73+ final Uri .Builder expectBuilder = Uri .parse (testUrl ).buildUpon ();
74+ for (final Option option : options ) {
75+ expectBuilder .appendQueryParameter (option .getName (), option .getValue ());
76+ }
77+
78+ Assert .assertEquals (expectBuilder .build ().toString (), requestUrl .toString ());
79+ }
5280}
0 commit comments