use of org.apache.hc.core5.http.copied.NameValuePair in project httpcomponents-core by apache.
the class TestBasicHeaderValueFormatter method testElementsFormatting.
@Test
public void testElementsFormatting() throws Exception {
final NameValuePair param1 = new BasicNameValuePair("param", "regular_stuff");
final NameValuePair param2 = new BasicNameValuePair("param", "this\\that");
final NameValuePair param3 = new BasicNameValuePair("param", "this,that");
final NameValuePair param4 = new BasicNameValuePair("param", null);
final HeaderElement element1 = new BasicHeaderElement("name1", "value1", new NameValuePair[] { param1 });
final HeaderElement element2 = new BasicHeaderElement("name2", "value2", new NameValuePair[] { param2 });
final HeaderElement element3 = new BasicHeaderElement("name3", "value3", new NameValuePair[] { param3 });
final HeaderElement element4 = new BasicHeaderElement("name4", "value4", new NameValuePair[] { param4 });
final HeaderElement element5 = new BasicHeaderElement("name5", null);
final HeaderElement[] elements = new HeaderElement[] { element1, element2, element3, element4, element5 };
final CharArrayBuffer buf = new CharArrayBuffer(64);
this.formatter.formatElements(buf, elements, false);
Assertions.assertEquals("name1=value1; param=regular_stuff, name2=value2; " + "param=\"this\\\\that\", name3=value3; param=\"this,that\", " + "name4=value4; param, name5", buf.toString());
}
use of org.apache.hc.core5.http.copied.NameValuePair in project httpcomponents-core by apache.
the class TestBasicHeaderValueFormatter method testParamsFormatting.
@Test
public void testParamsFormatting() throws Exception {
final NameValuePair param1 = new BasicNameValuePair("param", "regular_stuff");
final NameValuePair param2 = new BasicNameValuePair("param", "this\\that");
final NameValuePair param3 = new BasicNameValuePair("param", "this,that");
final NameValuePair[] params = new NameValuePair[] { param1, param2, param3 };
final CharArrayBuffer buf = new CharArrayBuffer(64);
buf.clear();
this.formatter.formatParameters(buf, params, false);
Assertions.assertEquals("param=regular_stuff; param=\"this\\\\that\"; param=\"this,that\"", buf.toString());
buf.clear();
this.formatter.formatParameters(buf, params, true);
Assertions.assertEquals("param=\"regular_stuff\"; param=\"this\\\\that\"; param=\"this,that\"", buf.toString());
}
use of org.apache.hc.core5.http.copied.NameValuePair in project httpcomponents-core by apache.
the class TestBasicHeaderValueParser method testNVParseEscaped.
@Test
public void testNVParseEscaped() {
final String headerValue = "test1 = \"\\\"stuff\\\"\"; test2= \"\\\\\"; test3 = \"stuff; stuff\"";
final CharArrayBuffer buf = new CharArrayBuffer(64);
buf.append(headerValue);
final ParserCursor cursor = new ParserCursor(0, buf.length());
final NameValuePair[] params = this.parser.parseParameters(buf, cursor);
Assertions.assertEquals(3, params.length);
Assertions.assertEquals("test1", params[0].getName());
Assertions.assertEquals("\"stuff\"", params[0].getValue());
Assertions.assertEquals("test2", params[1].getName());
Assertions.assertEquals("\\", params[1].getValue());
Assertions.assertEquals("test3", params[2].getName());
Assertions.assertEquals("stuff; stuff", params[2].getValue());
}
use of org.apache.hc.core5.http.copied.NameValuePair in project httpcomponents-core by apache.
the class TestBasicHeaderValueParser method testNVParseAll.
@Test
public void testNVParseAll() {
String s = "test; test1 = stuff ; test2 = \"stuff; stuff\"; test3=\"stuff";
CharArrayBuffer buffer = new CharArrayBuffer(16);
buffer.append(s);
ParserCursor cursor = new ParserCursor(0, s.length());
NameValuePair[] params = this.parser.parseParameters(buffer, cursor);
Assertions.assertEquals("test", params[0].getName());
Assertions.assertNull(params[0].getValue());
Assertions.assertEquals("test1", params[1].getName());
Assertions.assertEquals("stuff", params[1].getValue());
Assertions.assertEquals("test2", params[2].getName());
Assertions.assertEquals("stuff; stuff", params[2].getValue());
Assertions.assertEquals("test3", params[3].getName());
Assertions.assertEquals("stuff", params[3].getValue());
Assertions.assertEquals(s.length(), cursor.getPos());
Assertions.assertTrue(cursor.atEnd());
s = "test; test1 = stuff ; test2 = \"stuff; stuff\"; test3=\"stuff\",123";
buffer = new CharArrayBuffer(16);
buffer.append(s);
cursor = new ParserCursor(0, s.length());
params = this.parser.parseParameters(buffer, cursor);
Assertions.assertEquals("test", params[0].getName());
Assertions.assertNull(params[0].getValue());
Assertions.assertEquals("test1", params[1].getName());
Assertions.assertEquals("stuff", params[1].getValue());
Assertions.assertEquals("test2", params[2].getName());
Assertions.assertEquals("stuff; stuff", params[2].getValue());
Assertions.assertEquals("test3", params[3].getName());
Assertions.assertEquals("stuff", params[3].getValue());
Assertions.assertEquals(s.length() - 3, cursor.getPos());
Assertions.assertFalse(cursor.atEnd());
s = " ";
buffer = new CharArrayBuffer(16);
buffer.append(s);
cursor = new ParserCursor(0, s.length());
params = this.parser.parseParameters(buffer, cursor);
Assertions.assertEquals(0, params.length);
}
use of org.apache.hc.core5.http.copied.NameValuePair in project httpcomponents-core by apache.
the class TestURIBuilder method createParameterList.
private List<NameValuePair> createParameterList() {
final List<NameValuePair> parameters = new ArrayList<>();
parameters.add(new BasicNameValuePair("parameter1", "value1"));
parameters.add(new BasicNameValuePair("parameter2", "\"1\u00aa position\""));
parameters.add(new BasicNameValuePair("parameter3", "Jos\u00e9 Abra\u00e3o"));
return parameters;
}
Aggregations