summaryrefslogtreecommitdiffstats
path: root/simple/simple-http/src/test/java/org/simpleframework/http/core/MockRequest.java
blob: f382a321f0d8967136faf9cd3723c7dfe63b52f4 (plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package org.simpleframework.http.core;

import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.nio.channels.ReadableByteChannel;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.simpleframework.http.ContentDisposition;
import org.simpleframework.http.ContentType;
import org.simpleframework.http.Cookie;
import org.simpleframework.http.Part;
import org.simpleframework.http.Path;
import org.simpleframework.http.Query;
import org.simpleframework.http.Request;
import org.simpleframework.http.message.MessageHeader;
import org.simpleframework.http.message.RequestConsumer;
import org.simpleframework.http.parse.AddressParser;
import org.simpleframework.http.parse.ContentDispositionParser;
import org.simpleframework.http.parse.ContentTypeParser;
import org.simpleframework.transport.Certificate;
import org.simpleframework.transport.Channel;

public class MockRequest extends RequestMessage implements Request {
   
   private MessageHeader message;
   private Channel channel;
   private String target;   
   private String method = "GET";   
   private String content;   
   private String type;   
   private int major = 1;   
   private int minor = 1;
   
   public MockRequest() {
      this.header = new RequestConsumer();
      this.message = new MessageHeader();
      this.channel = new MockChannel(null);
   }
   
   public void setValue(String name, String value) {
      message.setValue(name, value);
   }
   
   public void add(String name, String value) {
      message.addValue(name, value);
   }
   
   public boolean isSecure(){
      return false;
   }
   
   public String getTarget() {
      return target;
   }
   
   public void setContentType(String value) {
      type = value;
   }
   
   public void setTarget(String target) {
      this.target = target;
   }
   
   public Path getPath() {
      return new AddressParser(target).getPath();
   }
  
   public Query getQuery() {
      return new AddressParser(target).getQuery();
   }
   
   public String getMethod() {
      return method;
   }

   public void setMethod(String method) {
      this.method = method;
   }

   public int getMajor() {
      return major;
   }

   public void setMajor(int major) {
      this.major = major;
   }

   public int getMinor() {
      return minor;
   }

   public void setMinor(int minor) {
      this.minor = minor;
   }   

   public Certificate getClientCertificate() {
      return null;
   }
   
   public String getContent() {
      return content;
   }
   
   public void setContent(String content) {
      this.content = content;
   }

   public InputStream getInputStream() {
      return null;
   }
   
   public Part getPart(String name) {
      return null;
   }
   
   public List<Part> getParts() {
      return Collections.emptyList();
   }
   
   public int size() {
      return 0;
   }

   public Cookie getCookie(String name) {     
      return null;
   }

   public String getParameter(String name) {      
      return null;
   }

   public Map getAttributes() {
      return null;
   }

   
   public ContentType getContentType() {
      return new ContentTypeParser(type);
   }
   
   public long getContentLength() {
      String value = getValue("Content-Length");
      
      if(value != null) {
         return new Long(value);
      }
      return -1;
   }
   
   public String getTransferEncoding() {
      List<String> list = getValues("Transfer-Encoding");
      
      if(list.size() > 0) {
         return list.get(0);
      }
      return null;
   }
   
   public ContentDisposition getDisposition() {
      String value = getValue("Content-Disposition");
      
      if(value == null) {
         return null;
      }
      return new ContentDispositionParser(value);
   }
   
   public List<String> getValues(String name) {
      return message.getValues(name);
   }
   
   public String getValue(String name) {
      return message.getValue(name);
   }

   public Object getAttribute(Object key) {
      return null;
   }

   public boolean isKeepAlive() {
      return true;
   }

   public InetSocketAddress getClientAddress() {
      return null;
   }

   public ReadableByteChannel getByteChannel() throws IOException {   
      return null;
   }

   public long getRequestTime() {
      return 0;
   }

   public Channel getChannel() {
      return channel;
   }
}