當前位置: 首頁>>代碼示例>>Java>>正文


Java Response.getEntityTag方法代碼示例

本文整理匯總了Java中javax.ws.rs.core.Response.getEntityTag方法的典型用法代碼示例。如果您正苦於以下問題:Java Response.getEntityTag方法的具體用法?Java Response.getEntityTag怎麽用?Java Response.getEntityTag使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.ws.rs.core.Response的用法示例。


在下文中一共展示了Response.getEntityTag方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testGetLdprs

import javax.ws.rs.core.Response; //導入方法依賴的package包/類
@Test
public void testGetLdprs() {
    when(mockHeaders.getAcceptableMediaTypes()).thenReturn(singletonList(TEXT_TURTLE_TYPE));

    final GetHandler getHandler = new GetHandler(mockLdpRequest, mockResourceService,
            mockIoService, mockBinaryService, null);

    final Response res = getHandler.getRepresentation(mockResource).build();
    assertEquals(OK, res.getStatusInfo());
    assertTrue(res.getLinks().stream().anyMatch(hasType(LDP.Resource)));
    assertTrue(res.getLinks().stream().anyMatch(hasType(LDP.RDFSource)));
    assertFalse(res.getLinks().stream().anyMatch(hasType(LDP.Container)));
    assertNull(res.getHeaderString(ACCEPT_POST));
    assertEquals(APPLICATION_SPARQL_UPDATE, res.getHeaderString(ACCEPT_PATCH));
    assertNull(res.getHeaderString(PREFERENCE_APPLIED));
    assertNull(res.getHeaderString(ACCEPT_RANGES));
    assertTrue(TEXT_TURTLE_TYPE.isCompatible(res.getMediaType()));
    assertTrue(res.getMediaType().isCompatible(TEXT_TURTLE_TYPE));
    assertEquals(from(time), res.getLastModified());

    final String allow = res.getHeaderString(ALLOW);
    assertTrue(allow.contains(GET));
    assertTrue(allow.contains(HEAD));
    assertTrue(allow.contains(OPTIONS));
    assertTrue(allow.contains(PUT));
    assertTrue(allow.contains(DELETE));
    assertTrue(allow.contains(PATCH));
    assertFalse(allow.contains(POST));

    final EntityTag etag = res.getEntityTag();
    assertTrue(etag.isWeak());
    assertEquals(md5Hex(time + baseUrl), etag.getValue());

    final List<Object> varies = res.getHeaders().get(VARY);
    assertFalse(varies.contains(RANGE));
    assertFalse(varies.contains(WANT_DIGEST));
    assertTrue(varies.contains(ACCEPT_DATETIME));
    assertTrue(varies.contains(PREFER));
}
 
開發者ID:trellis-ldp,項目名稱:trellis,代碼行數:40,代碼來源:GetHandlerTest.java

示例2: testMinimalLdprs

import javax.ws.rs.core.Response; //導入方法依賴的package包/類
@Test
public void testMinimalLdprs() {
    when(mockHeaders.getAcceptableMediaTypes()).thenReturn(singletonList(APPLICATION_LD_JSON_TYPE));
    when(mockLdpRequest.getPrefer()).thenReturn(Prefer.valueOf("return=minimal"));

    final GetHandler getHandler = new GetHandler(mockLdpRequest, mockResourceService,
            mockIoService, mockBinaryService, baseUrl);

    final Response res = getHandler.getRepresentation(mockResource).build();
    assertEquals(NO_CONTENT, res.getStatusInfo());
    assertTrue(res.getLinks().stream().anyMatch(hasType(LDP.Resource)));
    assertTrue(res.getLinks().stream().anyMatch(hasType(LDP.RDFSource)));
    assertFalse(res.getLinks().stream().anyMatch(hasType(LDP.Container)));
    assertNull(res.getHeaderString(ACCEPT_POST));
    assertEquals(APPLICATION_SPARQL_UPDATE, res.getHeaderString(ACCEPT_PATCH));
    assertEquals("return=minimal", res.getHeaderString(PREFERENCE_APPLIED));
    assertNull(res.getHeaderString(ACCEPT_RANGES));
    assertTrue(APPLICATION_LD_JSON_TYPE.isCompatible(res.getMediaType()));
    assertTrue(res.getMediaType().isCompatible(APPLICATION_LD_JSON_TYPE));
    assertEquals(from(time), res.getLastModified());

    final String allow = res.getHeaderString(ALLOW);
    assertTrue(allow.contains(GET));
    assertTrue(allow.contains(HEAD));
    assertTrue(allow.contains(OPTIONS));
    assertTrue(allow.contains(PUT));
    assertTrue(allow.contains(DELETE));
    assertTrue(allow.contains(PATCH));
    assertFalse(allow.contains(POST));

    final EntityTag etag = res.getEntityTag();
    assertTrue(etag.isWeak());
    assertEquals(md5Hex(time + baseUrl), etag.getValue());

    final List<Object> varies = res.getHeaders().get(VARY);
    assertFalse(varies.contains(RANGE));
    assertFalse(varies.contains(WANT_DIGEST));
    assertTrue(varies.contains(ACCEPT_DATETIME));
    assertTrue(varies.contains(PREFER));
}
 
開發者ID:trellis-ldp,項目名稱:trellis,代碼行數:41,代碼來源:GetHandlerTest.java

示例3: testGetVersionedLdprs

import javax.ws.rs.core.Response; //導入方法依賴的package包/類
@Test
public void testGetVersionedLdprs() {
    when(mockResource.isMemento()).thenReturn(true);
    when(mockHeaders.getAcceptableMediaTypes()).thenReturn(singletonList(TEXT_TURTLE_TYPE));

    final GetHandler getHandler = new GetHandler(mockLdpRequest, mockResourceService,
            mockIoService, mockBinaryService, null);

    final Response res = getHandler.getRepresentation(mockResource).build();
    assertEquals(OK, res.getStatusInfo());
    assertTrue(res.getLinks().stream().anyMatch(hasType(LDP.Resource)));
    assertTrue(res.getLinks().stream().anyMatch(hasType(LDP.RDFSource)));
    assertFalse(res.getLinks().stream().anyMatch(hasType(LDP.Container)));
    assertNull(res.getHeaderString(ACCEPT_POST));
    assertNull(res.getHeaderString(ACCEPT_PATCH));
    assertNull(res.getHeaderString(PREFERENCE_APPLIED));
    assertNull(res.getHeaderString(ACCEPT_RANGES));
    assertTrue(TEXT_TURTLE_TYPE.isCompatible(res.getMediaType()));
    assertTrue(res.getMediaType().isCompatible(TEXT_TURTLE_TYPE));
    assertEquals(from(time), res.getLastModified());
    assertEquals(ofInstant(time, UTC).format(RFC_1123_DATE_TIME), res.getHeaderString(MEMENTO_DATETIME));

    final String allow = res.getHeaderString(ALLOW);
    assertTrue(allow.contains(GET));
    assertTrue(allow.contains(HEAD));
    assertTrue(allow.contains(OPTIONS));
    assertFalse(allow.contains(PUT));
    assertFalse(allow.contains(DELETE));
    assertFalse(allow.contains(PATCH));
    assertFalse(allow.contains(POST));

    final EntityTag etag = res.getEntityTag();
    assertTrue(etag.isWeak());
    assertEquals(md5Hex(time + baseUrl), etag.getValue());

    final List<Object> varies = res.getHeaders().get(VARY);
    assertFalse(varies.contains(RANGE));
    assertFalse(varies.contains(WANT_DIGEST));
    assertFalse(varies.contains(ACCEPT_DATETIME));
    assertTrue(varies.contains(PREFER));
}
 
開發者ID:trellis-ldp,項目名稱:trellis,代碼行數:42,代碼來源:GetHandlerTest.java

示例4: testGetLdpc

import javax.ws.rs.core.Response; //導入方法依賴的package包/類
@Test
public void testGetLdpc() {
    when(mockResource.getInteractionModel()).thenReturn(LDP.Container);
    when(mockHeaders.getAcceptableMediaTypes()).thenReturn(singletonList(
                MediaType.valueOf(APPLICATION_LD_JSON + "; profile=\"" + compacted.getIRIString() + "\"")));

    final GetHandler getHandler = new GetHandler(mockLdpRequest, mockResourceService,
            mockIoService, mockBinaryService, null);

    final Response res = getHandler.getRepresentation(mockResource).build();
    assertEquals(OK, res.getStatusInfo());
    assertTrue(res.getLinks().stream().anyMatch(hasType(LDP.Resource)));
    assertTrue(res.getLinks().stream().anyMatch(hasType(LDP.RDFSource)));
    assertTrue(res.getLinks().stream().anyMatch(hasType(LDP.Container)));
    assertEquals(APPLICATION_SPARQL_UPDATE, res.getHeaderString(ACCEPT_PATCH));
    assertNull(res.getHeaderString(PREFERENCE_APPLIED));
    assertNull(res.getHeaderString(ACCEPT_RANGES));
    assertTrue(APPLICATION_LD_JSON_TYPE.isCompatible(res.getMediaType()));
    assertTrue(res.getMediaType().isCompatible(APPLICATION_LD_JSON_TYPE));
    assertEquals(from(time), res.getLastModified());
    assertFalse(res.getLinks().stream().anyMatch(link -> link.getRel().equals("describes")));
    assertFalse(res.getLinks().stream().anyMatch(link -> link.getRel().equals("describedby")));
    assertFalse(res.getLinks().stream().anyMatch(link -> link.getRel().equals("canonical")));

    final String acceptPost = res.getHeaderString(ACCEPT_POST);
    assertNotNull(acceptPost);
    assertTrue(acceptPost.contains("text/turtle"));
    assertTrue(acceptPost.contains(APPLICATION_LD_JSON));
    assertTrue(acceptPost.contains(APPLICATION_N_TRIPLES));

    final String allow = res.getHeaderString(ALLOW);
    assertTrue(allow.contains(GET));
    assertTrue(allow.contains(HEAD));
    assertTrue(allow.contains(OPTIONS));
    assertTrue(allow.contains(PUT));
    assertTrue(allow.contains(DELETE));
    assertTrue(allow.contains(PATCH));
    assertTrue(allow.contains(POST));

    final EntityTag etag = res.getEntityTag();
    assertTrue(etag.isWeak());
    assertEquals(md5Hex(time + baseUrl), etag.getValue());

    final List<Object> varies = res.getHeaders().get(VARY);
    assertFalse(varies.contains(RANGE));
    assertFalse(varies.contains(WANT_DIGEST));
    assertTrue(varies.contains(ACCEPT_DATETIME));
    assertTrue(varies.contains(PREFER));
}
 
開發者ID:trellis-ldp,項目名稱:trellis,代碼行數:50,代碼來源:GetHandlerTest.java


注:本文中的javax.ws.rs.core.Response.getEntityTag方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。