当前位置: 首页>>代码示例>>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;未经允许,请勿转载。