1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.volley.toolbox; 18 19 import com.android.volley.Request.Method; 20 import com.android.volley.mock.TestRequest; 21 22 import org.apache.http.client.methods.HttpDelete; 23 import org.apache.http.client.methods.HttpGet; 24 import org.apache.http.client.methods.HttpPost; 25 import org.apache.http.client.methods.HttpPut; 26 import org.apache.http.client.methods.HttpUriRequest; 27 28 import android.test.AndroidTestCase; 29 import android.test.suitebuilder.annotation.SmallTest; 30 31 @SmallTest 32 public class HttpClientStackTest extends AndroidTestCase { 33 34 @Override 35 protected void setUp() throws Exception { 36 super.setUp(); 37 mContext = getContext(); 38 } 39 40 public void testCreateDeprecatedGetRequest() throws Exception { 41 TestRequest.DeprecatedGet request = new TestRequest.DeprecatedGet(); 42 assertEquals(request.getMethod(), Method.DEPRECATED_GET_OR_POST); 43 44 HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null); 45 assertTrue(httpRequest instanceof HttpGet); 46 } 47 48 public void testCreateDeprecatedPostRequest() throws Exception { 49 TestRequest.DeprecatedPost request = new TestRequest.DeprecatedPost(); 50 assertEquals(request.getMethod(), Method.DEPRECATED_GET_OR_POST); 51 52 HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null); 53 assertTrue(httpRequest instanceof HttpPost); 54 } 55 56 public void testCreateGetRequest() throws Exception { 57 TestRequest.Get request = new TestRequest.Get(); 58 assertEquals(request.getMethod(), Method.GET); 59 60 HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null); 61 assertTrue(httpRequest instanceof HttpGet); 62 } 63 64 public void testCreatePostRequest() throws Exception { 65 TestRequest.Post request = new TestRequest.Post(); 66 assertEquals(request.getMethod(), Method.POST); 67 68 HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null); 69 assertTrue(httpRequest instanceof HttpPost); 70 } 71 72 public void testCreatePostRequestWithBody() throws Exception { 73 TestRequest.PostWithBody request = new TestRequest.PostWithBody(); 74 assertEquals(request.getMethod(), Method.POST); 75 76 HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null); 77 assertTrue(httpRequest instanceof HttpPost); 78 } 79 80 public void testCreatePutRequest() throws Exception { 81 TestRequest.Put request = new TestRequest.Put(); 82 assertEquals(request.getMethod(), Method.PUT); 83 84 HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null); 85 assertTrue(httpRequest instanceof HttpPut); 86 } 87 88 public void testCreatePutRequestWithBody() throws Exception { 89 TestRequest.PutWithBody request = new TestRequest.PutWithBody(); 90 assertEquals(request.getMethod(), Method.PUT); 91 92 HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null); 93 assertTrue(httpRequest instanceof HttpPut); 94 } 95 96 public void testCreateDeleteRequest() throws Exception { 97 TestRequest.Delete request = new TestRequest.Delete(); 98 assertEquals(request.getMethod(), Method.DELETE); 99 100 HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null); 101 assertTrue(httpRequest instanceof HttpDelete); 102 } 103 } 104