Author: sjlee
Date: Wed Jun 24 22:29:51 2009
New Revision: 788200
URL: http://svn.apache.org/viewvc?rev=788200&view=rev
Log:
ASYNCWEB-31
added support for multiple values for a given query parameter.
Added:
mina/asyncweb/branches/1.0-mina1/client/src/test/java/org/apache/asyncweb/client/FakeProtocolEncoderOutput.java
(with props)
mina/asyncweb/branches/1.0-mina1/client/src/test/java/org/apache/asyncweb/client/RequestEncodingTest.java
(with props)
Added:
mina/asyncweb/branches/1.0-mina1/client/src/test/java/org/apache/asyncweb/client/FakeProtocolEncoderOutput.java
URL:
http://svn.apache.org/viewvc/mina/asyncweb/branches/1.0-mina1/client/src/test/java/org/apache/asyncweb/client/FakeProtocolEncoderOutput.java?rev=788200&view=auto
==============================================================================
---
mina/asyncweb/branches/1.0-mina1/client/src/test/java/org/apache/asyncweb/client/FakeProtocolEncoderOutput.java
(added)
+++
mina/asyncweb/branches/1.0-mina1/client/src/test/java/org/apache/asyncweb/client/FakeProtocolEncoderOutput.java
Wed Jun 24 22:29:51 2009
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.asyncweb.client;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.WriteFuture;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+
+public class FakeProtocolEncoderOutput implements ProtocolEncoderOutput {
+ private final List<ByteBuffer> buffers = new LinkedList<ByteBuffer>();
+
+ public void write(ByteBuffer buffer) {
+ buffers.add(buffer);
+ }
+
+ public WriteFuture flush() {
+ return null;
+ }
+
+ public void mergeAll() {}
+
+ /**
+ * Gathers bytes from all buffers.
+ */
+ public byte[] getBytes() {
+ int size = 0;
+ for (ByteBuffer b : buffers) {
+ size += b.limit();
+ }
+ byte[] result = new byte[size];
+ int position = 0;
+ for (ByteBuffer b : buffers) {
+ int length = b.limit();
+ System.arraycopy(b.array(), 0, result, position, length);
+ position += length;
+ }
+ return result;
+ }
+}
Propchange:
mina/asyncweb/branches/1.0-mina1/client/src/test/java/org/apache/asyncweb/client/FakeProtocolEncoderOutput.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
mina/asyncweb/branches/1.0-mina1/client/src/test/java/org/apache/asyncweb/client/RequestEncodingTest.java
URL:
http://svn.apache.org/viewvc/mina/asyncweb/branches/1.0-mina1/client/src/test/java/org/apache/asyncweb/client/RequestEncodingTest.java?rev=788200&view=auto
==============================================================================
---
mina/asyncweb/branches/1.0-mina1/client/src/test/java/org/apache/asyncweb/client/RequestEncodingTest.java
(added)
+++
mina/asyncweb/branches/1.0-mina1/client/src/test/java/org/apache/asyncweb/client/RequestEncodingTest.java
Wed Jun 24 22:29:51 2009
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.asyncweb.client;
+
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.apache.asyncweb.client.codec.HttpMessage;
+import org.apache.asyncweb.client.codec.HttpRequestEncoder;
+import org.apache.asyncweb.client.codec.HttpRequestMessage;
+
+public class RequestEncodingTest extends TestCase {
+ public void testMultiValueParam() throws Exception {
+ HttpRequestMessage request = new HttpRequestMessage(new
URL("http://www.foo.com"), null);
+ request.setParameter("name", "value1");
+ request.setParameter("name", "value2");
+
+ FakeProtocolEncoderOutput out = new FakeProtocolEncoderOutput();
+ HttpRequestEncoder encoder = new HttpRequestEncoder();
+ encoder.encode(null, request, out);
+
+ byte[] bytes = out.getBytes();
+ String str = new String(bytes, HttpMessage.HTTP_ELEMENT_CHARSET);
+ // check both parameters are encoded into the request
+ assertTrue(str.contains("name=value1"));
+ assertTrue(str.contains("name=value2"));
+ }
+}
Propchange:
mina/asyncweb/branches/1.0-mina1/client/src/test/java/org/apache/asyncweb/client/RequestEncodingTest.java
------------------------------------------------------------------------------
svn:eol-style = native