Search in sources :

Example 6 with QualitySourceMediaType

use of org.glassfish.jersey.message.internal.QualitySourceMediaType in project jersey by jersey.

the class QualitySourceMediaTypeProviderTest method testMediaTypeSpecifityHTTPExample2.

@Test
public void testMediaTypeSpecifityHTTPExample2() throws Exception {
    final String header = "text/*, text/html;level=1, text/html, */*";
    final List<QualitySourceMediaType> l = HttpHeaderReader.readQualitySourceMediaType(header);
    MediaType m;
    m = l.get(0);
    assertEquals("text", m.getType());
    assertEquals("html", m.getSubtype());
    assertEquals(1, m.getParameters().size());
    m = l.get(1);
    assertEquals("text", m.getType());
    assertEquals("html", m.getSubtype());
    assertEquals(0, m.getParameters().size());
    m = l.get(2);
    assertEquals("text", m.getType());
    assertEquals("*", m.getSubtype());
    assertEquals(0, m.getParameters().size());
    m = l.get(3);
    assertEquals("*", m.getType());
    assertEquals("*", m.getSubtype());
    assertEquals(0, m.getParameters().size());
}
Also used : MediaType(javax.ws.rs.core.MediaType) QualitySourceMediaType(org.glassfish.jersey.message.internal.QualitySourceMediaType) QualitySourceMediaType(org.glassfish.jersey.message.internal.QualitySourceMediaType) Test(org.junit.Test)

Example 7 with QualitySourceMediaType

use of org.glassfish.jersey.message.internal.QualitySourceMediaType in project jersey by jersey.

the class QualitySourceMediaTypeProviderTest method testOneMediaTypeWithParameters.

@Test
public void testOneMediaTypeWithParameters() throws Exception {
    final String header = "application/xml;charset=utf8";
    final List<QualitySourceMediaType> l = HttpHeaderReader.readQualitySourceMediaType(header);
    assertEquals(1, l.size());
    final MediaType m = l.get(0);
    assertEquals("application", m.getType());
    assertEquals("xml", m.getSubtype());
    assertEquals(1, m.getParameters().size());
    assertTrue(m.getParameters().containsKey("charset"));
    assertEquals("utf8", m.getParameters().get("charset"));
}
Also used : MediaType(javax.ws.rs.core.MediaType) QualitySourceMediaType(org.glassfish.jersey.message.internal.QualitySourceMediaType) QualitySourceMediaType(org.glassfish.jersey.message.internal.QualitySourceMediaType) Test(org.junit.Test)

Example 8 with QualitySourceMediaType

use of org.glassfish.jersey.message.internal.QualitySourceMediaType in project jersey by jersey.

the class QualitySourceMediaTypeProviderTest method testMediaTypeSpecifity.

@Test
public void testMediaTypeSpecifity() throws Exception {
    final String header = "*/*, text/*, text/plain";
    final List<QualitySourceMediaType> l = HttpHeaderReader.readQualitySourceMediaType(header);
    assertEquals(3, l.size());
    MediaType m;
    m = l.get(0);
    assertEquals("text", m.getType());
    assertEquals("plain", m.getSubtype());
    assertEquals(0, m.getParameters().size());
    m = l.get(1);
    assertEquals("text", m.getType());
    assertEquals("*", m.getSubtype());
    assertEquals(0, m.getParameters().size());
    m = l.get(2);
    assertEquals("*", m.getType());
    assertEquals("*", m.getSubtype());
    assertEquals(0, m.getParameters().size());
}
Also used : MediaType(javax.ws.rs.core.MediaType) QualitySourceMediaType(org.glassfish.jersey.message.internal.QualitySourceMediaType) QualitySourceMediaType(org.glassfish.jersey.message.internal.QualitySourceMediaType) Test(org.junit.Test)

Example 9 with QualitySourceMediaType

use of org.glassfish.jersey.message.internal.QualitySourceMediaType in project jersey by jersey.

the class QualitySourceMediaTypeProviderTest method testHttpURLConnectionAcceptHeader.

@Test
public void testHttpURLConnectionAcceptHeader() throws Exception {
    final String header = "text/html, image/gif, image/jpeg, */*; qs=.2";
    final List<QualitySourceMediaType> l = HttpHeaderReader.readQualitySourceMediaType(header);
    assertEquals(4, l.size());
    MediaType m;
    m = l.get(0);
    assertEquals("text", m.getType());
    assertEquals("html", m.getSubtype());
    assertEquals(0, m.getParameters().size());
    m = l.get(1);
    assertEquals("image", m.getType());
    assertEquals("gif", m.getSubtype());
    assertEquals(0, m.getParameters().size());
    m = l.get(2);
    assertEquals("image", m.getType());
    assertEquals("jpeg", m.getSubtype());
    assertEquals(0, m.getParameters().size());
    m = l.get(3);
    assertEquals("*", m.getType());
    assertEquals("*", m.getSubtype());
    assertEquals(1, m.getParameters().size());
}
Also used : MediaType(javax.ws.rs.core.MediaType) QualitySourceMediaType(org.glassfish.jersey.message.internal.QualitySourceMediaType) QualitySourceMediaType(org.glassfish.jersey.message.internal.QualitySourceMediaType) Test(org.junit.Test)

Example 10 with QualitySourceMediaType

use of org.glassfish.jersey.message.internal.QualitySourceMediaType in project jersey by jersey.

the class QualitySourceMediaTypeProviderTest method testMultipleMediaType.

@Test
public void testMultipleMediaType() throws Exception {
    final String header = "application/xml, text/xml, text/html";
    final List<QualitySourceMediaType> l = HttpHeaderReader.readQualitySourceMediaType(header);
    assertEquals(3, l.size());
    MediaType m;
    m = l.get(0);
    assertEquals("application", m.getType());
    assertEquals("xml", m.getSubtype());
    assertEquals(0, m.getParameters().size());
    m = l.get(1);
    assertEquals("text", m.getType());
    assertEquals("xml", m.getSubtype());
    assertEquals(0, m.getParameters().size());
    m = l.get(2);
    assertEquals("text", m.getType());
    assertEquals("html", m.getSubtype());
    assertEquals(0, m.getParameters().size());
}
Also used : MediaType(javax.ws.rs.core.MediaType) QualitySourceMediaType(org.glassfish.jersey.message.internal.QualitySourceMediaType) QualitySourceMediaType(org.glassfish.jersey.message.internal.QualitySourceMediaType) Test(org.junit.Test)

Aggregations

MediaType (javax.ws.rs.core.MediaType)11 QualitySourceMediaType (org.glassfish.jersey.message.internal.QualitySourceMediaType)11 Test (org.junit.Test)11