package com.onedrive.sdk.http;

import android.net.Uri;
import android.test.AndroidTestCase;

import com.onedrive.sdk.core.MockClient;
import com.onedrive.sdk.extensions.IOneDriveClient;

import junit.framework.Assert;

import java.net.URL;

/**
 * Test cases for (@see BaseRequest)
 */
public class BaseRequestTests extends AndroidTestCase{
    private IOneDriveClient mockClient;
    private BaseRequest mRequest;

    private final String baseUrl = "https://localhost:8080/";
    private final String[] testingSegments = { "Hello World", "你好世界", "Καλημέρα κόσμε", "안녕하세요", "コンニチハ", "แผ่นดินฮั่นเสื่อมโทรมแสนสังเวช" };

    @Override
    public void setUp() {
        mockClient = new MockClient();
        StringBuilder sb = new StringBuilder(baseUrl);

        for (String segment : testingSegments) {
            sb.append(segment);
            sb.append("/");
        }

        sb.deleteCharAt(sb.length()-1);

        mRequest = new BaseRequest(sb.toString(), mockClient, /*options:*/ null, null) {
            @Override
            public IOneDriveClient getClient() {
                return mockClient;
            }
        };
    }
    public void testUrlEncoded() throws Exception {
        URL requestUrl = mRequest.getRequestUrl();
        final Uri.Builder expectBuilder = Uri.parse(baseUrl).buildUpon();

        for (String segment : testingSegments) {
            expectBuilder.appendPath(segment);
        }

        Assert.assertEquals(expectBuilder.build().toString(), requestUrl.toString());
    }
}

@@ -25,16 +25,46 @@
 .http;%0A%0A
+import android.graphics.Path;%0A
 import a
@@ -79,16 +79,16 @@
 et.Uri;%0A
-
 import a
@@ -209,16 +209,101 @@
 eClient;
+%0Aimport com.onedrive.sdk.options.Option;%0Aimport com.onedrive.sdk.options.QueryOption;
 %0A%0Aimport
@@ -348,16 +348,67 @@
 net.URL;
+%0Aimport java.util.ArrayList;%0Aimport java.util.List;
 %0A%0A/**%0A *
@@ -1299,24 +1299,29 @@
    %7D;%0A    %7D%0A
+    %0A
     public v
@@ -1527,32 +1527,32 @@
 tingSegments) %7B%0A
-
             expe
@@ -1585,32 +1585,935 @@
 nt);%0A        %7D%0A%0A
+        Assert.assertEquals(expectBuilder.build().toString(), requestUrl.toString());%0A    %7D%0A%0A    public void testUrlWithQuery() throws Exception %7B%0A        final String queryInUrl = %22expand=foo&$select=id,name%22;%0A        final String testUrl = baseUrl + %22?%22 + queryInUrl;%0A%0A        final List%3COption%3E options = new ArrayList%3COption%3E();%0A        final QueryOption queryInOption = new QueryOption(%22queryWithEncode%22, %22!%22);%0A        options.add(queryInOption);%0A%0A        mRequest = new BaseRequest(testUrl, mockClient, options, null) %7B%0A            public IOneDriveClient getClient() %7B%0A                return mockClient;%0A            %7D%0A        %7D;%0A%0A        URL requestUrl = mRequest.getRequestUrl();%0A%0A        final Uri.Builder expectBuilder = Uri.parse(testUrl).buildUpon();%0A        for (final Option option: options) %7B%0A            expectBuilder.appendQueryParameter(option.getName(), option.getValue());%0A        %7D%0A%0A
         Assert.a

add UT