@Test public void testPreconditionsNoneMatch() { MutableRequest mr = new MutableRequest("", "http://example.org/app/resource", "GET"); mr.header(HttpHeaders.IF_NONE_MATCH, "\"686897696a7c876b7e\""); Request r = mr.toJaxrsRequest(); assertEquals( r.evaluatePreconditions(new EntityTag("686897696a7c876b7e")).build().getStatus(), Status.NOT_MODIFIED.getStatusCode()); assertNull(r.evaluatePreconditions(new EntityTag("000000000000000000"))); }
@Test public void testPreconditionsModified() throws ParseException { MutableRequest mr = new MutableRequest("", "http://example.org/app/resource", "GET"); mr.header(HttpHeaders.IF_MODIFIED_SINCE, "Sat, 29 Oct 2011 19:43:31 GMT"); Request r = mr.toJaxrsRequest(); SimpleDateFormat f = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z", Locale.ENGLISH); Date date = f.parse("Sat, 29 Oct 2011 19:43:31 GMT"); assertEquals( r.evaluatePreconditions(date).build().getStatus(), Status.NOT_MODIFIED.getStatusCode()); date = f.parse("Sat, 30 Oct 2011 19:43:31 GMT"); assertNull(r.evaluatePreconditions(date)); }
@Test public void testSelectVariant() { MutableRequest mr = new MutableRequest("", "http://example.org/app/resource", "GET"); mr.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON); mr.header(HttpHeaders.ACCEPT_LANGUAGE, "en"); Request r = mr.toJaxrsRequest(); List<Variant> lv = Variant.mediaTypes(MediaType.APPLICATION_XML_TYPE, MediaType.APPLICATION_JSON_TYPE) .languages(Locale.ENGLISH, Locale.FRENCH) .add() .build(); assertEquals(r.selectVariant(lv).getMediaType(), MediaType.APPLICATION_JSON_TYPE); assertEquals(r.selectVariant(lv).getLanguage(), Locale.ENGLISH); }
@Test public void testUri() throws URISyntaxException { MutableRequest r = new MutableRequest("", "http://example.org/app/resource", "GET"); Request v = r.toJaxrsRequest(); assertEquals(v.getUri(), URI.create("http://example.org/app/resource")); }
@Test public void testMethod() { MutableRequest r = new MutableRequest("", "http://example.org/app/resource", "GET"); Request v = r.toJaxrsRequest(); assertEquals(v.getMethod(), "GET"); }