|
Java example source code file (XmlFrameDecoderTest.java)
The XmlFrameDecoderTest.java Java example source code/* * Copyright 2013 The Netty Project * * The Netty Project 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 io.netty.handler.codec.xml; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.embedded.EmbeddedChannel; import io.netty.handler.codec.CorruptedFrameException; import io.netty.handler.codec.TooLongFrameException; import io.netty.util.CharsetUtil; import org.junit.Test; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; public class XmlFrameDecoderTest { private final List<String> xmlSamples; public XmlFrameDecoderTest() throws IOException, URISyntaxException { xmlSamples = Arrays.asList( sample("01"), sample("02"), sample("03"), sample("04"), sample("05"), sample("06") ); } @Test(expected = IllegalArgumentException.class) public void testConstructorWithIllegalArgs01() { new XmlFrameDecoder(0); } @Test(expected = IllegalArgumentException.class) public void testConstructorWithIllegalArgs02() { new XmlFrameDecoder(-23); } @Test(expected = TooLongFrameException.class) public void testDecodeWithFrameExceedingMaxLength() { XmlFrameDecoder decoder = new XmlFrameDecoder(3); EmbeddedChannel ch = new EmbeddedChannel(decoder); ch.writeInbound(Unpooled.copiedBuffer("<v/>", CharsetUtil.UTF_8)); } @Test(expected = CorruptedFrameException.class) public void testDecodeWithInvalidInput() { XmlFrameDecoder decoder = new XmlFrameDecoder(1048576); EmbeddedChannel ch = new EmbeddedChannel(decoder); ch.writeInbound(Unpooled.copiedBuffer("invalid XML", CharsetUtil.UTF_8)); } @Test(expected = CorruptedFrameException.class) public void testDecodeWithInvalidContentBeforeXml() { XmlFrameDecoder decoder = new XmlFrameDecoder(1048576); EmbeddedChannel ch = new EmbeddedChannel(decoder); ch.writeInbound(Unpooled.copiedBuffer("invalid XML<foo/>", CharsetUtil.UTF_8)); } @Test public void testDecodeShortValidXml() { testDecodeWithXml("<xxx/>", " |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.