package de.timroes;
import static org.junit.Assert.*;
import de.timroes.axmlrpc.*;
import de.timroes.axmlrpc.serializer.SerializerHandler;
import org.junit.Test;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.Map;
import java.util.TreeMap;
public class TestResponseParser {
public final static String xmlDecl = "";
public final static SerializerHandler sh = new SerializerHandler(XMLRPCClient.FLAGS_NONE);
@Test
public void testSimpleResponse() throws Exception {
ResponseParser sut = new ResponseParser();
Object actual = sut.parse(sh, strToStream(xmlDecl +
"" +
" " +
" " +
" toto" +
" " +
" " +
""), false);
assertEquals("toto", actual);
}
@Test
public void testWithTrailingWhitespaceInTags() throws Exception {
ResponseParser sut = new ResponseParser();
Object actual = sut.parse(sh, strToStream(xmlDecl +
"" +
" " +
" " +
" toto" +
" " +
" " +
""), false);
assertEquals("toto", actual);
}
@Test
public void testWithTrailingEndlineInTags() throws Exception {
ResponseParser sut = new ResponseParser();
Object actual = sut.parse(sh, strToStream(xmlDecl +
"" +
" " +
" " +
" toto" +
" " +
" " +
""), false);
assertEquals("toto", actual);
}
@Test
public void testWithTrailingTabInTags() throws Exception {
ResponseParser sut = new ResponseParser();
Object actual = sut.parse(sh, strToStream(xmlDecl +
"" +
" " +
" " +
" toto" +
" " +
" " +
""), false);
assertEquals("toto", actual);
}
@Test
public void testResponseWithNonAsciiCharacter() throws Exception {
ResponseParser sut = new ResponseParser();
Object actual = sut.parse(sh, strToStream(xmlDecl +
"" +
" " +
" " +
" Aéris" +
" " +
" " +
""), false);
assertEquals("Aéris", actual);
}
@Test
public void testUTF16Response() throws Exception {
ResponseParser sut = new ResponseParser();
Object actual = sut.parse(sh, bytesToStream((xmlDecl +
"" +
" " +
" " +
" toto" +
" " +
" " +
"").getBytes(StandardCharsets.UTF_16)), false);
assertEquals("toto", actual);
}
@Test
public void testResponseWithComplexValue() throws Exception {
ResponseParser sut = new ResponseParser();
Object actual = sut.parse(sh, strToStream(xmlDecl +
"" +
" " +
" " +
" " +
" " +
" intValue12" +
" otherIntValue13" +
" boolValue1" +
" strValuetoto" +
" doubleValue12.4" +
" dateValue20200908T0440Z" +
// Don't test base64 because it seems assertEqual will do a reference equals on arrray of bytes so it's not easily testable here
// so we test it in a test below
//" base64ValueQWVyaXM=" +
" nestedValue " +
" innerStrValueinner" +
" " +
" " +
" " +
" " +
" " +
""), false);
Map