AcceptHeader { public List<Accept> getAccepts() { return accepts; } AcceptHeader(final String headerValue); List<Accept> getAccepts();  }
@Test public void singleMediaRange() { final String appXml = "application/xml"; final AcceptHeader acceptHeader = new AcceptHeader(appXml); assertEquals(1, acceptHeader.getAccepts().size()); assertEquals(appXml, acceptHeader.getAccepts().get(0).getMediaRange()); }
@Test public void singleWildcardMediaRange() { final String any = ANY.getMediaType(); final AcceptHeader acceptHeader = new AcceptHeader(any); assertEquals(1, acceptHeader.getAccepts().size()); assertEquals(any, acceptHeader.getAccepts().get(0).getMediaRange()); }
@Test public void singleSubtypeWildcardMediaRange() { final String anySubtype = APPLICATION_ANY.getMediaType(); final AcceptHeader acceptHeader = new AcceptHeader(anySubtype); assertEquals(1, acceptHeader.getAccepts().size()); assertEquals(anySubtype, acceptHeader.getAccepts().get(0).getMediaRange()); }
@Test public void multipleMediaRanges_withoutWhiteSpace() { final String appXml = APPLICATION_XML.getMediaType(); final String appXhtml = APPLICATION_XHTML_XML.getMediaType(); final String appPdf = APPLICATION_PDF.getMediaType(); final AcceptHeader acceptHeader = new AcceptHeader(appXml + "," + appXhtml + "," + appPdf); assertEquals(3, acceptHeader.getAccepts().size()); assertEquals(appPdf, acceptHeader.getAccepts().get(0).getMediaRange()); assertEquals(appXhtml, acceptHeader.getAccepts().get(1).getMediaRange()); assertEquals(appXml, acceptHeader.getAccepts().get(2).getMediaRange()); }
@Test public void multipleMediaRanges_withWhiteSpace() { final String appXml = APPLICATION_XML.getMediaType(); final String appXhtml = APPLICATION_XHTML_XML.getMediaType(); final String appPdf = APPLICATION_PDF.getMediaType(); final AcceptHeader acceptHeader = new AcceptHeader(appXml + ", " + appXhtml + ", " + appPdf); assertEquals(3, acceptHeader.getAccepts().size()); assertEquals(appPdf, acceptHeader.getAccepts().get(0).getMediaRange()); assertEquals(appXhtml, acceptHeader.getAccepts().get(1).getMediaRange()); assertEquals(appXml, acceptHeader.getAccepts().get(2).getMediaRange()); }
@Test public void multipleMediaRangesWith_withQualityFactors() { final Accept appXml = new Accept(APPLICATION_XML); final Accept appXhtml = new Accept(APPLICATION_XHTML_XML, 0.9f); final Accept appPdf = new Accept(APPLICATION_PDF, 0.4f); final String headerValue = appXml.toString() + "," + appXhtml.toString() + "," + appPdf.toString(); final AcceptHeader acceptHeader = new AcceptHeader(headerValue); assertEquals(3, acceptHeader.getAccepts().size()); assertEquals(appXml, acceptHeader.getAccepts().get(0)); assertEquals(appXhtml, acceptHeader.getAccepts().get(1)); assertEquals(appPdf, acceptHeader.getAccepts().get(2)); }
@Test public void mediaRangesWith_acceptExts() { final Accept appXml = new Accept(APPLICATION_XML); final Accept appXhtml = new Accept(APPLICATION_XHTML_XML, new Accept.Weight(0.9f, new Accept.AcceptExt[] { new Accept.AcceptExt("a"), new Accept.AcceptExt("x", "y")})); final Accept appPdf = new Accept(APPLICATION_PDF, new Accept.Weight(0.4f, new Accept.AcceptExt[] { new Accept.AcceptExt("1", "2") })); final String headerValue = appXml.toString() + "," + appXhtml.toString() + "," + appPdf.toString(); final AcceptHeader acceptHeader = new AcceptHeader(headerValue); assertEquals(3, acceptHeader.getAccepts().size()); assertEquals(appXml, acceptHeader.getAccepts().get(0)); assertEquals(appXhtml, acceptHeader.getAccepts().get(1)); assertEquals(appPdf, acceptHeader.getAccepts().get(2)); }
@Test public void mediaRangesWith_parameters() { final Accept appXml = new Accept(APPLICATION_XML, new Accept.Parameter[] { new Accept.Parameter("x", "y"), new Accept.Parameter("a", "b") }); final Accept appXhtml = new Accept(APPLICATION_XHTML_XML, new Accept.Parameter[] { new Accept.Parameter("y", "x"), new Accept.Parameter("b", "a") }, new Accept.Weight(0.9f)); final String headerValue = appXml.toString() + "," + appXhtml.toString(); final AcceptHeader acceptHeader = new AcceptHeader(headerValue); assertEquals(2, acceptHeader.getAccepts().size()); assertEquals(appXml, acceptHeader.getAccepts().get(0)); assertEquals(appXhtml, acceptHeader.getAccepts().get(1)); }