Search in sources :

Example 11 with HeaderGroup

use of org.apache.hc.core5.http.message.HeaderGroup in project httpcomponents-core by apache.

the class TestHeaderGroup method testUpdateHeader.

@Test
public void testUpdateHeader() {
    final HeaderGroup headergroup = new HeaderGroup();
    final Header header1 = new BasicHeader("name1", "value1");
    final Header header2 = new BasicHeader("name2", "value2");
    final Header header3 = new BasicHeader("name3", "value3");
    headergroup.addHeader(header1);
    headergroup.addHeader(header2);
    headergroup.addHeader(header3);
    headergroup.setHeader(new BasicHeader("name2", "newvalue"));
    headergroup.setHeader(new BasicHeader("name4", "value4"));
    headergroup.setHeader(null);
    Assertions.assertEquals(4, headergroup.getHeaders().length);
    Assertions.assertEquals("newvalue", headergroup.getFirstHeader("name2").getValue());
}
Also used : Header(org.apache.hc.core5.http.Header) Test(org.junit.jupiter.api.Test)

Example 12 with HeaderGroup

use of org.apache.hc.core5.http.message.HeaderGroup in project httpcomponents-core by apache.

the class TestHeaderGroup method testAddRemoveHeaders.

@Test
public void testAddRemoveHeaders() {
    final HeaderGroup headergroup = new HeaderGroup();
    final Header header = new BasicHeader("name", "value");
    headergroup.addHeader(header);
    headergroup.addHeader(header);
    Assertions.assertEquals(2, headergroup.getHeaders().length);
    Assertions.assertFalse(headergroup.removeHeaders((Header) null));
    Assertions.assertTrue(headergroup.removeHeaders(header));
    Assertions.assertFalse(headergroup.removeHeaders((Header) null));
    Assertions.assertEquals(0, headergroup.getHeaders().length);
}
Also used : Header(org.apache.hc.core5.http.Header) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)12 Header (org.apache.hc.core5.http.Header)11 HeaderGroup (org.apache.hc.core5.http.message.HeaderGroup)3 MessageHeaders (org.apache.hc.core5.http.MessageHeaders)2 BasicHeader (org.apache.hc.core5.http.message.BasicHeader)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 HashSet (java.util.HashSet)1