1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.apache.http.message;
29
30 import java.io.ByteArrayInputStream;
31 import java.io.ByteArrayOutputStream;
32 import java.io.ObjectInputStream;
33 import java.io.ObjectOutputStream;
34
35 import org.apache.http.HttpVersion;
36 import org.apache.http.RequestLine;
37 import org.junit.Assert;
38 import org.junit.Test;
39
40
41
42
43 public class TestRequestLine {
44
45 @Test
46 public void testConstructor() {
47 final RequestLine requestline = new BasicRequestLine("GET", "/stuff", HttpVersion.HTTP_1_1);
48 Assert.assertEquals("GET", requestline.getMethod());
49 Assert.assertEquals("/stuff", requestline.getUri());
50 Assert.assertEquals(HttpVersion.HTTP_1_1, requestline.getProtocolVersion());
51 }
52
53 @Test
54 public void testConstructorInvalidInput() {
55 try {
56 new BasicRequestLine(null, "/stuff", HttpVersion.HTTP_1_1);
57 Assert.fail("IllegalArgumentException should have been thrown");
58 } catch (final IllegalArgumentException e) { }
59 try {
60 new BasicRequestLine("GET", null, HttpVersion.HTTP_1_1);
61 Assert.fail("IllegalArgumentException should have been thrown");
62 } catch (final IllegalArgumentException e) { }
63 try {
64 new BasicRequestLine("GET", "/stuff", (HttpVersion)null);
65 Assert.fail("IllegalArgumentException should have been thrown");
66 } catch (final IllegalArgumentException e) { }
67 }
68
69 @Test
70 public void testCloning() throws Exception {
71 final BasicRequestLine orig = new BasicRequestLine("GET", "/stuff", HttpVersion.HTTP_1_1);
72 final BasicRequestLine clone = (BasicRequestLine) orig.clone();
73 Assert.assertEquals(orig.getMethod(), clone.getMethod());
74 Assert.assertEquals(orig.getUri(), clone.getUri());
75 Assert.assertEquals(orig.getProtocolVersion(), clone.getProtocolVersion());
76 }
77
78 @Test
79 public void testSerialization() throws Exception {
80 final BasicRequestLine orig = new BasicRequestLine("GET", "/stuff", HttpVersion.HTTP_1_1);
81 final ByteArrayOutputStream outbuffer = new ByteArrayOutputStream();
82 final ObjectOutputStream outStream = new ObjectOutputStream(outbuffer);
83 outStream.writeObject(orig);
84 outStream.close();
85 final byte[] raw = outbuffer.toByteArray();
86 final ByteArrayInputStream inBuffer = new ByteArrayInputStream(raw);
87 final ObjectInputStream inStream = new ObjectInputStream(inBuffer);
88 final BasicRequestLine clone = (BasicRequestLine) inStream.readObject();
89 Assert.assertEquals(orig.getMethod(), clone.getMethod());
90 Assert.assertEquals(orig.getUri(), clone.getUri());
91 Assert.assertEquals(orig.getProtocolVersion(), clone.getProtocolVersion());
92 }
93
94 }