Search in sources :

Example 71 with HttpHeaders

use of javax.ws.rs.core.HttpHeaders in project cxf by apache.

the class HttpHeadersImplTest method testGetCookieWithAttributes.

@Test
public void testGetCookieWithAttributes() throws Exception {
    Message m = createMessage(createHeader(HttpHeaders.COOKIE, "$Version=1;a=b"));
    HttpHeaders h = new HttpHeadersImpl(m);
    Map<String, Cookie> cookies = h.getCookies();
    assertEquals(1, cookies.size());
    Cookie cookie = cookies.get("a");
    assertEquals("b", cookie.getValue());
    assertEquals(1, cookie.getVersion());
}
Also used : Cookie(javax.ws.rs.core.Cookie) HttpHeaders(javax.ws.rs.core.HttpHeaders) Message(org.apache.cxf.message.Message) Test(org.junit.Test)

Example 72 with HttpHeaders

use of javax.ws.rs.core.HttpHeaders in project cxf by apache.

the class HttpHeadersImplTest method testMultipleAcceptableLanguages.

@Test
public void testMultipleAcceptableLanguages() throws Exception {
    MetadataMap<String, String> headers = createHeader(HttpHeaders.ACCEPT_LANGUAGE, "en;q=0.7, en-gb;q=0.8, da, zh-Hans-SG;q=0.9");
    Message m = createMessage(headers);
    HttpHeaders h = new HttpHeadersImpl(m);
    List<Locale> languages = h.getAcceptableLanguages();
    assertEquals(4, languages.size());
    assertEquals(new Locale("da"), languages.get(0));
    assertEquals(new Locale("zh", "Hans-SG"), languages.get(1));
    assertEquals(new Locale("en", "GB"), languages.get(2));
    assertEquals(new Locale("en"), languages.get(3));
}
Also used : Locale(java.util.Locale) HttpHeaders(javax.ws.rs.core.HttpHeaders) Message(org.apache.cxf.message.Message) Test(org.junit.Test)

Example 73 with HttpHeaders

use of javax.ws.rs.core.HttpHeaders in project cxf by apache.

the class HttpHeadersImplTest method testNoRequestHeader.

@Test
public void testNoRequestHeader() throws Exception {
    Message m = createMessage(createHeader("COMPLEX_HEADER", "b=c; param=c, a=b;param=b"));
    HttpHeaders h = new HttpHeadersImpl(m);
    List<String> values = h.getRequestHeader("HEADER");
    assertNull(values);
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) Message(org.apache.cxf.message.Message) Test(org.junit.Test)

Example 74 with HttpHeaders

use of javax.ws.rs.core.HttpHeaders in project cxf by apache.

the class HttpHeadersImplTest method testGetNoMediaTypes.

@Test
public void testGetNoMediaTypes() throws Exception {
    Message m = new MessageImpl();
    m.put(Message.PROTOCOL_HEADERS, Collections.emptyMap());
    HttpHeaders h = new HttpHeadersImpl(m);
    List<MediaType> acceptValues = h.getAcceptableMediaTypes();
    assertEquals(1, acceptValues.size());
    assertEquals("*/*", acceptValues.get(0).toString());
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) Message(org.apache.cxf.message.Message) MediaType(javax.ws.rs.core.MediaType) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 75 with HttpHeaders

use of javax.ws.rs.core.HttpHeaders in project cxf by apache.

the class HttpHeadersImplTest method testGetEmptyHeader.

@Test
public void testGetEmptyHeader() throws Exception {
    Message m = new MessageImpl();
    // this is what happens at runtime and is tested in the system tests
    Map<String, List<String>> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
    headers.put("A", Collections.<String>emptyList());
    m.put(Message.PROTOCOL_HEADERS, headers);
    HttpHeaders h = new HttpHeadersImpl(m);
    List<String> values = h.getRequestHeader("A");
    assertTrue(values.isEmpty());
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) Message(org.apache.cxf.message.Message) List(java.util.List) TreeMap(java.util.TreeMap) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Aggregations

HttpHeaders (javax.ws.rs.core.HttpHeaders)87 Test (org.junit.Test)57 Message (org.apache.cxf.message.Message)31 HttpServletRequest (javax.servlet.http.HttpServletRequest)13 Optional (java.util.Optional)11 CatalogFramework (ddf.catalog.CatalogFramework)10 MultipartBody (org.apache.cxf.jaxrs.ext.multipart.MultipartBody)10 JsonObject (com.google.gson.JsonObject)9 Locale (java.util.Locale)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 Response (javax.ws.rs.core.Response)8 UriInfo (javax.ws.rs.core.UriInfo)8 IOException (java.io.IOException)7 WebApplicationException (javax.ws.rs.WebApplicationException)7 MediaType (javax.ws.rs.core.MediaType)7 RequestInfo (com.liferay.apio.architect.request.RequestInfo)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 Conditions (com.liferay.apio.architect.test.util.json.Conditions)5 OutputStream (java.io.OutputStream)5 Annotation (java.lang.annotation.Annotation)5