Skip to content

Commit

Permalink
Merge branch 'OF-2559_mina-to-netty' of https://github.com/surevine/O…
Browse files Browse the repository at this point in the history
…penfire into OF-2559_mina-to-netty
  • Loading branch information
AlexGidman committed Jun 29, 2023
2 parents dd18ccb + d2fd098 commit 306a3bf
Showing 1 changed file with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@
package org.jivesoftware.openfire.nio;

import org.apache.mina.core.buffer.IoBuffer;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import java.nio.CharBuffer;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CodingErrorAction;
import java.nio.charset.StandardCharsets;

import static org.junit.Assert.assertEquals;
Expand All @@ -30,6 +35,27 @@
*/
public class XMLLightweightParserTest {

private CharsetDecoder encoder;
private XMLLightweightParser parser;

@Before
public void setUp() throws Exception {
parser = new XMLLightweightParser();

encoder = StandardCharsets.UTF_8.newDecoder()
.onMalformedInput(CodingErrorAction.REPLACE)
.onUnmappableCharacter(CodingErrorAction.REPLACE);
}

private char[] ioBufferToChars(IoBuffer buffer) {
CharBuffer charBuffer = CharBuffer.allocate(buffer.capacity());
encoder.decode(buffer.buf(), charBuffer, false);
char[] buf = new char[charBuffer.position()];
charBuffer.flip();
charBuffer.get(buf);
return buf;
}

/**
* Asserts that a start-tag name can be parsed when it is followed by a space character.
*
Expand All @@ -45,10 +71,9 @@ public void testOF2329OpenAndCloseWithSpace() throws Exception
final IoBuffer buffer = IoBuffer.allocate(input.length(), false);
buffer.putString(input, StandardCharsets.UTF_8.newEncoder());
buffer.flip();
final XMLLightweightParser parser = new XMLLightweightParser(StandardCharsets.UTF_8);

// Execute system under test.
parser.read(buffer);
parser.read(ioBufferToChars(buffer));
final String[] result = parser.getMsgs();

// Verify results.
Expand All @@ -74,7 +99,7 @@ public void testOF2329OpenAndCloseWithSpaceAndNewline() throws Exception
final XMLLightweightParser parser = new XMLLightweightParser();

// Execute system under test.
parser.read(buffer);
parser.read(ioBufferToChars(buffer));
final String[] result = parser.getMsgs();

// Verify results.
Expand All @@ -100,7 +125,7 @@ public void testOF2329OpenAndCloseWithNewline() throws Exception
final XMLLightweightParser parser = new XMLLightweightParser();

// Execute system under test.
parser.read(buffer);
parser.read(ioBufferToChars(buffer));
final String[] result = parser.getMsgs();

// Verify results.
Expand All @@ -126,7 +151,7 @@ public void testOF2329SelfTerminatingWithSpace() throws Exception
final XMLLightweightParser parser = new XMLLightweightParser();

// Execute system under test.
parser.read(buffer);
parser.read(ioBufferToChars(buffer));
final String[] result = parser.getMsgs();

// Verify results.
Expand All @@ -152,7 +177,7 @@ public void testOF2329SelfTerminatingWithSpaceAndNewline() throws Exception
final XMLLightweightParser parser = new XMLLightweightParser();

// Execute system under test.
parser.read(buffer);
parser.read(ioBufferToChars(buffer));
final String[] result = parser.getMsgs();

// Verify results.
Expand All @@ -178,7 +203,7 @@ public void testOF2329SelfTerminatingWithNewline() throws Exception
final XMLLightweightParser parser = new XMLLightweightParser();

// Execute system under test.
parser.read(buffer);
parser.read(ioBufferToChars(buffer));
final String[] result = parser.getMsgs();

// Verify results.
Expand Down

0 comments on commit 306a3bf

Please sign in to comment.