本文整理汇总了Java中org.springframework.restdocs.hypermedia.LinksSnippet类的典型用法代码示例。如果您正苦于以下问题:Java LinksSnippet类的具体用法?Java LinksSnippet怎么用?Java LinksSnippet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LinksSnippet类属于org.springframework.restdocs.hypermedia包,在下文中一共展示了LinksSnippet类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSimple
import org.springframework.restdocs.hypermedia.LinksSnippet; //导入依赖的package包/类
@Test
public void getSimple() {
LinksSnippet links = HypermediaDocumentation.links(new HyperschemaLinkExtractor(), //
HypermediaDocumentation.linkWithRel(FactsRel.FACT_IDS.getRelation().getName())
.description(
"The link for the eventstream of fact ids, links to the <<_sse_stream_of_fact_ids, facts resource>>"), //
HypermediaDocumentation.linkWithRel(FactsRel.FULL_FACTS.getRelation().getName())
.description(
"The link for the eventstream, links to the <<_sse_stream_of_facts, facts resource>>"), //
HypermediaDocumentation.linkWithRel(FactsRel.CREATE_TRANSACTIONAL.getRelation()
.getName()).description(
"Creating a new transaction links to the <<resources-transactions, transaction resource>>"));
final Response response = target("/").register(documentationConfiguration(
this.documentation))
.register(document("root", preprocessRequest(removeHeaders(
"User-Agent")), preprocessResponse(prettyPrint()), links))
.request()
.get();
assertThat(response.getStatus(), is(200));
}
示例2: linksForSkipper
import org.springframework.restdocs.hypermedia.LinksSnippet; //导入依赖的package包/类
/**
* {@link LinksSnippet} for common links. Common links are set to be ignored.
*
* @param descriptors Provide addition link descriptors
* @return the link snipped
*/
public static LinksSnippet linksForSkipper(LinkDescriptor... descriptors) {
return HypermediaDocumentation.links(
linkWithRel("self").ignored(),
linkWithRel("profile").ignored(),
linkWithRel("search").ignored(),
linkWithRel("deployer").ignored().optional(),
linkWithRel("curies").ignored().optional()).and(descriptors);
}
示例3: extract
import org.springframework.restdocs.hypermedia.LinksSnippet; //导入依赖的package包/类
public static List<LinkDescriptor> extract(LinksSnippet snippet) {
try {
Method getDescriptorsByRel = LinksSnippet.class.getDeclaredMethod("getDescriptorsByRel");
getDescriptorsByRel.setAccessible(true);
return new ArrayList<>(((Map<String, LinkDescriptor>) getDescriptorsByRel.invoke(snippet)).values());
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
}
return emptyList();
}
示例4: should_extract_link_descriptors
import org.springframework.restdocs.hypermedia.LinksSnippet; //导入依赖的package包/类
@Test
public void should_extract_link_descriptors() {
// given
LinksSnippet snippet = links(
linkWithRel("self").description("Is documented!")
);
// when
List<LinkDescriptor> descriptors = extract(snippet);
then(descriptors).hasSize(1);
then(descriptors.get(0).getRel()).isEqualTo("self");
then(descriptors.get(0).getDescription()).isEqualTo("Is documented!");
}
示例5: getSimpleFact
import org.springframework.restdocs.hypermedia.LinksSnippet; //导入依赖的package包/类
@Test
public void getSimpleFact() {
// links
LinksSnippet links = HypermediaDocumentation.links(new HyperschemaLinkExtractor(), //
HypermediaDocumentation.linkWithRel(Rel.SELF.getRelation().getName()).description(
"The link to that specific resource"));
// payload
List<FieldDescriptor> factFieldDescriptors = Descriptors.getFactFieldDescriptors("",
new ConstrainedFields(FactJson.class));
factFieldDescriptors.add(PayloadDocumentation.fieldWithPath("_schema").description(
"Schemainformation"));
Snippet responseDoc = PayloadDocumentation.responseFields(factFieldDescriptors);
// header
ResponseHeadersSnippet headerDoc = responseHeaders(headerWithName(HttpHeaders.CACHE_CONTROL)
.description("Caching for 1000000 seconds."));
final Response response = target("/facts/" + TestFacts.one.id().toString()).register(
documentationConfiguration(this.documentation))
.register(document("fact",
preprocessRequest(removeHeaders("User-Agent")), preprocessResponse(
prettyPrint()), links, responseDoc, headerDoc))
.request()
.get();
assertThat(response.getStatus(), is(200));
assertThat(response.getHeaderString(HttpHeaders.CACHE_CONTROL), is(
"max-age=1000000, s-maxage=1000000, public"));
}
示例6: enhanceSnippetsWithRaml
import org.springframework.restdocs.hypermedia.LinksSnippet; //导入依赖的package包/类
protected static Snippet[] enhanceSnippetsWithRaml(String description,
boolean privateResource,
Function<List<Snippet>, List<Snippet>> snippetFilter,
Snippet... snippets) {
List<RequestFieldsSnippet> requestFieldsSnippets = new ArrayList<>();
List<ResponseFieldsSnippet> responseFieldsSnippets = new ArrayList<>();
List<LinksSnippet> linkSnippets = new ArrayList<>();
List<RequestParametersSnippet> requestParametersSnippets = new ArrayList<>();
List<PathParametersSnippet> pathParametersSnippets = new ArrayList<>();
List<Snippet> ramlSnippets = new ArrayList<>();
List<Snippet> otherSnippets = new ArrayList<>();
for (Snippet snippet : snippets) {
if (snippet instanceof RequestFieldsSnippet) {
requestFieldsSnippets.add((RequestFieldsSnippet) snippet);
} else if (snippet instanceof ResponseFieldsSnippet) {
responseFieldsSnippets.add((ResponseFieldsSnippet) snippet);
} else if (snippet instanceof LinksSnippet) {
linkSnippets.add((LinksSnippet) snippet);
} else if (snippet instanceof RequestParametersSnippet) {
requestParametersSnippets.add((RequestParametersSnippet) snippet);
} else if (snippet instanceof PathParametersSnippet) {
pathParametersSnippets.add((PathParametersSnippet) snippet);
} else if (snippet instanceof RamlResourceSnippet) {
ramlSnippets.add(snippet);
} else {
otherSnippets.add(snippet);
}
}
List<Snippet> enhancedSnippets = new ArrayList<>();
enhancedSnippets.addAll(requestFieldsSnippets);
enhancedSnippets.addAll(responseFieldsSnippets);
enhancedSnippets.addAll(linkSnippets);
enhancedSnippets.addAll(requestParametersSnippets);
enhancedSnippets.addAll(pathParametersSnippets);
enhancedSnippets.addAll(otherSnippets);
if (ramlSnippets.isEmpty()) { // No RamlResourceSnippet, so we configure our own based on the info of the other snippets
RamlResourceSnippetParameters ramlParameters = RamlResourceSnippetParameters.builder()
.description(description)
.privateResource(privateResource)
.requestFields(requestFieldsSnippets.stream().map(DescriptorExtractor::extract).flatMap(List::stream).toArray(FieldDescriptor[]::new))
.responseFields(responseFieldsSnippets.stream().map(DescriptorExtractor::extract).flatMap(List::stream).toArray(FieldDescriptor[]::new))
.links(linkSnippets.stream().map(DescriptorExtractor::extract).flatMap(List::stream).toArray(LinkDescriptor[]::new))
.requestParameters(requestParametersSnippets.stream().map(DescriptorExtractor::extract).flatMap(List::stream).toArray(ParameterDescriptor[]::new))
.pathParameters(pathParametersSnippets.stream().map(DescriptorExtractor::extract).flatMap(List::stream).toArray(ParameterDescriptor[]::new))
.build();
enhancedSnippets.add(ramlResource(ramlParameters));
} else {
enhancedSnippets.addAll(ramlSnippets);
}
enhancedSnippets = snippetFilter.apply(enhancedSnippets);
return enhancedSnippets.toArray(new Snippet[0]);
}
示例7: linksInPath
import org.springframework.restdocs.hypermedia.LinksSnippet; //导入依赖的package包/类
protected LinksSnippet linksInPath(String jsonPath, LinkDescriptor... linkDescriptors) {
return new JsonPathLinksSnippet(jsonPath, linkDescriptors);
}