01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: *
19: */
20: package org.apache.mina.filter.codec.textline;
21:
22: import java.nio.charset.Charset;
23:
24: import junit.framework.Assert;
25: import junit.framework.TestCase;
26:
27: import org.apache.mina.common.IoBuffer;
28: import org.apache.mina.filter.codec.ProtocolCodecSession;
29: import org.apache.mina.filter.codec.ProtocolEncoderOutput;
30:
31: /**
32: * Tests {@link TextLineEncoder}.
33: *
34: * @author The Apache MINA Project (dev@mina.apache.org)
35: * @version $Rev: 607166 $, $Date: 2007-12-27 20:43:04 -0700 (Thu, 27 Dec 2007) $
36: */
37: public class TextLineEncoderTest extends TestCase {
38: public static void main(String[] args) {
39: junit.textui.TestRunner.run(TextLineEncoderTest.class);
40: }
41:
42: public void testEncode() throws Exception {
43: TextLineEncoder encoder = new TextLineEncoder(Charset
44: .forName("UTF-8"), LineDelimiter.WINDOWS);
45: ProtocolCodecSession session = new ProtocolCodecSession();
46: ProtocolEncoderOutput out = session.getEncoderOutput();
47:
48: encoder.encode(session, "ABC", out);
49: Assert.assertEquals(1, session.getEncoderOutputQueue().size());
50: IoBuffer buf = (IoBuffer) session.getEncoderOutputQueue()
51: .poll();
52: Assert.assertEquals(5, buf.remaining());
53: Assert.assertEquals('A', buf.get());
54: Assert.assertEquals('B', buf.get());
55: Assert.assertEquals('C', buf.get());
56: Assert.assertEquals('\r', buf.get());
57: Assert.assertEquals('\n', buf.get());
58: }
59: }
|