Skip to content
This repository was archived by the owner on Oct 2, 2024. It is now read-only.

Commit 2068e96

Browse files
authored
Merge pull request #94 from daboxu/dev
fix #89
2 parents c8f8204 + 833da77 commit 2068e96

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

onedrivesdk/src/androidTest/java/com/onedrive/sdk/http/BaseRequestTests.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
package com.onedrive.sdk.http;
22

3+
import android.graphics.Path;
34
import android.net.Uri;
45
import android.test.AndroidTestCase;
56

67
import com.onedrive.sdk.core.MockClient;
78
import com.onedrive.sdk.extensions.IOneDriveClient;
9+
import com.onedrive.sdk.options.Option;
10+
import com.onedrive.sdk.options.QueryOption;
811

912
import junit.framework.Assert;
1013

1114
import 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
}

onedrivesdk/src/main/java/com/onedrive/sdk/http/BaseRequest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ public URL getRequestUrl() {
128128
Uri baseUrl = Uri.parse(mRequestUrl);
129129
final Uri.Builder uriBuilder = new Uri.Builder()
130130
.scheme(baseUrl.getScheme())
131-
.encodedAuthority(baseUrl.getEncodedAuthority());
131+
.encodedAuthority(baseUrl.getEncodedAuthority())
132+
.encodedQuery(baseUrl.getEncodedQuery());
132133

133134
for (final String segment : baseUrl.getPathSegments()) {
134135
uriBuilder.appendPath(segment);

0 commit comments

Comments
 (0)