use of org.apache.hc.core5.util.CharArrayBuffer in project httpcomponents-core by apache.
the class TestBasicHeaderValueParser method testNVParse.
@Test
public void testNVParse() {
String s = "test";
CharArrayBuffer buffer = new CharArrayBuffer(64);
buffer.append(s);
ParserCursor cursor = new ParserCursor(0, s.length());
NameValuePair param = this.parser.parseNameValuePair(buffer, cursor);
Assertions.assertEquals("test", param.getName());
Assertions.assertNull(param.getValue());
Assertions.assertEquals(s.length(), cursor.getPos());
Assertions.assertTrue(cursor.atEnd());
s = "test;";
buffer = new CharArrayBuffer(16);
buffer.append(s);
cursor = new ParserCursor(0, s.length());
param = this.parser.parseNameValuePair(buffer, cursor);
Assertions.assertEquals("test", param.getName());
Assertions.assertNull(param.getValue());
Assertions.assertEquals(s.length(), cursor.getPos());
Assertions.assertTrue(cursor.atEnd());
s = "test ,12";
buffer = new CharArrayBuffer(16);
buffer.append(s);
cursor = new ParserCursor(0, s.length());
param = this.parser.parseNameValuePair(buffer, cursor);
Assertions.assertEquals("test", param.getName());
Assertions.assertNull(param.getValue());
Assertions.assertEquals(s.length() - 2, cursor.getPos());
Assertions.assertFalse(cursor.atEnd());
s = "test=stuff";
buffer = new CharArrayBuffer(16);
buffer.append(s);
cursor = new ParserCursor(0, s.length());
param = this.parser.parseNameValuePair(buffer, cursor);
Assertions.assertEquals("test", param.getName());
Assertions.assertEquals("stuff", param.getValue());
Assertions.assertEquals(s.length(), cursor.getPos());
Assertions.assertTrue(cursor.atEnd());
s = " test = stuff ";
buffer = new CharArrayBuffer(16);
buffer.append(s);
cursor = new ParserCursor(0, s.length());
param = this.parser.parseNameValuePair(buffer, cursor);
Assertions.assertEquals("test", param.getName());
Assertions.assertEquals("stuff", param.getValue());
Assertions.assertEquals(s.length(), cursor.getPos());
Assertions.assertTrue(cursor.atEnd());
s = " test = stuff ;1234";
buffer = new CharArrayBuffer(16);
buffer.append(s);
cursor = new ParserCursor(0, s.length());
param = this.parser.parseNameValuePair(buffer, cursor);
Assertions.assertEquals("test", param.getName());
Assertions.assertEquals("stuff", param.getValue());
Assertions.assertEquals(s.length() - 4, cursor.getPos());
Assertions.assertFalse(cursor.atEnd());
s = "test = \"stuff\"";
buffer = new CharArrayBuffer(16);
buffer.append(s);
cursor = new ParserCursor(0, s.length());
param = this.parser.parseNameValuePair(buffer, cursor);
Assertions.assertEquals("test", param.getName());
Assertions.assertEquals("stuff", param.getValue());
s = "test = \" stuff\\\"\"";
buffer = new CharArrayBuffer(16);
buffer.append(s);
cursor = new ParserCursor(0, s.length());
param = this.parser.parseNameValuePair(buffer, cursor);
Assertions.assertEquals("test", param.getName());
Assertions.assertEquals(" stuff\"", param.getValue());
s = " test";
buffer = new CharArrayBuffer(16);
buffer.append(s);
cursor = new ParserCursor(0, s.length());
param = this.parser.parseNameValuePair(buffer, cursor);
Assertions.assertEquals("test", param.getName());
Assertions.assertNull(param.getValue());
s = " ";
buffer = new CharArrayBuffer(16);
buffer.append(s);
cursor = new ParserCursor(0, s.length());
param = this.parser.parseNameValuePair(buffer, cursor);
Assertions.assertEquals("", param.getName());
Assertions.assertNull(param.getValue());
s = " = stuff ";
buffer = new CharArrayBuffer(16);
buffer.append(s);
cursor = new ParserCursor(0, s.length());
param = this.parser.parseNameValuePair(buffer, cursor);
Assertions.assertEquals("", param.getName());
Assertions.assertEquals("stuff", param.getValue());
}
use of org.apache.hc.core5.util.CharArrayBuffer in project httpcomponents-core by apache.
the class TestBasicLineFormatter method testRLFormattingInvalidInput.
@Test
public void testRLFormattingInvalidInput() throws Exception {
final CharArrayBuffer buf = new CharArrayBuffer(64);
final RequestLine requestline = new RequestLine(Method.GET.name(), "/stuff", HttpVersion.HTTP_1_1);
Assertions.assertThrows(NullPointerException.class, () -> formatter.formatRequestLine(null, requestline));
Assertions.assertThrows(NullPointerException.class, () -> formatter.formatRequestLine(buf, null));
}
use of org.apache.hc.core5.util.CharArrayBuffer in project httpcomponents-core by apache.
the class TestBasicLineFormatter method testSLFormattingInvalidInput.
@Test
public void testSLFormattingInvalidInput() throws Exception {
final CharArrayBuffer buf = new CharArrayBuffer(64);
final StatusLine statusline = new StatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
Assertions.assertThrows(NullPointerException.class, () -> formatter.formatStatusLine(null, statusline));
Assertions.assertThrows(NullPointerException.class, () -> formatter.formatStatusLine(buf, null));
}
use of org.apache.hc.core5.util.CharArrayBuffer in project httpcomponents-core by apache.
the class TestBufferedHeader method testBasicConstructor.
@Test
public void testBasicConstructor() throws Exception {
final CharArrayBuffer buf = new CharArrayBuffer(32);
buf.append("name: value");
final BufferedHeader header = new BufferedHeader(buf, false);
Assertions.assertEquals("name", header.getName());
Assertions.assertEquals("value", header.getValue());
Assertions.assertSame(buf, header.getBuffer());
Assertions.assertEquals(5, header.getValuePos());
}
use of org.apache.hc.core5.util.CharArrayBuffer in project httpcomponents-core by apache.
the class TestBufferedHeader method testSerialization.
@Test
public void testSerialization() throws Exception {
final CharArrayBuffer buf = new CharArrayBuffer(32);
buf.append("name: value");
final BufferedHeader orig = new BufferedHeader(buf, false);
final ByteArrayOutputStream outbuffer = new ByteArrayOutputStream();
final ObjectOutputStream outStream = new ObjectOutputStream(outbuffer);
outStream.writeObject(orig);
outStream.close();
final byte[] raw = outbuffer.toByteArray();
final ByteArrayInputStream inBuffer = new ByteArrayInputStream(raw);
final ObjectInputStream inStream = new ObjectInputStream(inBuffer);
final BufferedHeader clone = (BufferedHeader) inStream.readObject();
Assertions.assertEquals(orig.getName(), clone.getName());
Assertions.assertEquals(orig.getValue(), clone.getValue());
}
Aggregations