@Test public void testGetVersionList() { when(mockRequest.selectVariant(POSSIBLE_RDF_VARIANTS)).thenReturn(mockVariant); when(mockNodes.find(any(Session.class), anyString())).thenReturn(mockResource); when(mockResource.getTriples(any(IdentifierConverter.class), eq(VersionsRdfContext.class))) .thenReturn(mockRdfStream); when(mockResource.isVersioned()).thenReturn(true); when(mockVariant.getMediaType()).thenReturn(new MediaType("text", "turtle")); final RdfStream response = testObj.getVersionList(); assertEquals("Got wrong RdfStream!", mockRdfStream, response); }
@Test public void testGetVersionList() throws RepositoryException { final String pid = "FedoraVersioningTest"; when(mockRequest.selectVariant(POSSIBLE_RDF_VARIANTS)).thenReturn(mockVariant); when(mockNodes.getObject(any(Session.class), anyString())).thenReturn(mockResource); when(mockResource.getVersionTriples(any(HttpIdentifierTranslator.class))) .thenReturn(mockRdfStream); when(mockVariant.getMediaType()).thenReturn(new MediaType("text", "turtle")); final RdfStream response = testObj.getVersionList(createPathList(pid), mockRequest, getUriInfoImpl()); assertEquals("Got wrong RdfStream!", mockRdfStream, response); }
public Object getTasks( Request request, UriInfo uriInfo, Integer firstResult, Integer maxResults) { Variant variant = request.selectVariant(VARIANTS); if (variant != null) { if (MediaType.APPLICATION_JSON_TYPE.equals(variant.getMediaType())) { return getJsonTasks(uriInfo, firstResult, maxResults); } else if (Hal.APPLICATION_HAL_JSON_TYPE.equals(variant.getMediaType())) { return getHalTasks(uriInfo, firstResult, maxResults); } } throw new InvalidRequestException( Response.Status.NOT_ACCEPTABLE, "No acceptable content-type found"); }
public static boolean isPaged(HttpServletRequest httpRequest, Request request) { String accept = httpRequest.getHeader("Accept"); if (StringHelper.containsNonWhitespace(accept)) { MediaType requestMediaType = MediaType.valueOf(accept); if (APPLICATION_JSON_PAGED.equals(requestMediaType) || APPLICATION_XML_PAGED.equals(requestMediaType)) { return true; } } Variant variant = request.selectVariant(variants); return (variant != null && (variant.equals(APPLICATION_JSON_PAGED) || variant.equals(APPLICATION_XML_PAGED))); }
@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); }