• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Snippet类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.restdocs.snippet.Snippet的典型用法代码示例。如果您正苦于以下问题:Java Snippet类的具体用法?Java Snippet怎么用?Java Snippet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Snippet类属于org.springframework.restdocs.snippet包,在下文中一共展示了Snippet类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: document

import org.springframework.restdocs.snippet.Snippet; //导入依赖的package包/类
public static RestDocumentationResultHandler document(String identifier,
                                                      String description,
                                                      boolean privateResource,
                                                      OperationRequestPreprocessor requestPreprocessor,
                                                      OperationResponsePreprocessor responsePreprocessor,
                                                      Function<List<Snippet>, List<Snippet>> snippetFilter,
                                                      Snippet... snippets) {

    Snippet[] enhancedSnippets = enhanceSnippetsWithRaml(description, privateResource, snippetFilter, snippets);

    if (requestPreprocessor != null && responsePreprocessor != null) {
        return MockMvcRestDocumentation.document(identifier, requestPreprocessor, responsePreprocessor, enhancedSnippets);
    } else if (requestPreprocessor != null) {
        return MockMvcRestDocumentation.document(identifier, requestPreprocessor, enhancedSnippets);
    } else if (responsePreprocessor != null) {
        return MockMvcRestDocumentation.document(identifier, responsePreprocessor, enhancedSnippets);
    }

    return MockMvcRestDocumentation.document(identifier, enhancedSnippets);
}
 
开发者ID:ePages-de,项目名称:restdocs-raml,代码行数:21,代码来源:RamlDocumentation.java


示例2: post

import org.springframework.restdocs.snippet.Snippet; //导入依赖的package包/类
@Test
public void post() throws Exception {

    ConstrainedFields fields = new ConstrainedFields(FactTransactionJson.class);
    List<FieldDescriptor> fieldDescriptors = Descriptors.getFactFieldDescriptors("facts[].",
            fields);
    fieldDescriptors.add(0, fields.withPath("facts").description(
            "Non empty list with the facts to commit in this transaction"));
    Snippet requestFieldSnippet = requestFields(//
            fieldDescriptors);

    FactTransactionJson factTransactionJson = objectMapper.readValue(this.getClass()
            .getResourceAsStream("TransactionJson.json"), FactTransactionJson.class);

    final Response response = target("/transactions").register(documentationConfiguration(
            this.documentation))
            .register(document("facts-transactions", preprocessRequest(
                    removeHeaders("User-Agent"), prettyPrint()), preprocessResponse(
                            prettyPrint()), requestFieldSnippet))
            .request()
            .post(Entity.entity(
                    factTransactionJson, MediaType.APPLICATION_JSON));
    assertThat(response.getStatus(), is(204));

}
 
开发者ID:uweschaefer,项目名称:factcast,代码行数:26,代码来源:TransactionDocumentation0Test.java


示例3: getSimpleFact

import org.springframework.restdocs.snippet.Snippet; //导入依赖的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"));
}
 
开发者ID:uweschaefer,项目名称:factcast,代码行数:29,代码来源:EventsDocumentation0Test.java


示例4: verifySnippetInvocation

import org.springframework.restdocs.snippet.Snippet; //导入依赖的package包/类
private void verifySnippetInvocation(Snippet snippet, Map<String, Object> attributes, int times)
		throws IOException {
	ArgumentCaptor<Operation> operation = ArgumentCaptor.forClass(Operation.class);
	verify(snippet, Mockito.times(times)).document(operation.capture());
	assertThat(this.operationRequest, is(equalTo(operation.getValue().getRequest())));
	assertThat(this.operationResponse, is(equalTo(operation.getValue().getResponse())));
	assertThat(attributes, is(equalTo(operation.getValue().getAttributes())));
}
 
开发者ID:ePages-de,项目名称:restdocs-wiremock,代码行数:9,代码来源:WireMockJsonSnippetTest.java


示例5: getSectionSnippet

import org.springframework.restdocs.snippet.Snippet; //导入依赖的package包/类
private SectionSupport getSectionSnippet(Operation operation, String snippetName) {
    for (Snippet snippet : getDefaultSnippets(operation)) {
        if (snippet instanceof SectionSupport) {
            SectionSupport sectionSnippet = (SectionSupport) snippet;
            if (snippetName.equals(sectionSnippet.getFileName())) {
                return sectionSnippet;
            }
        }
    }

    return SnippetRegistry.getClassicSnippet(snippetName);
}
 
开发者ID:ScaCap,项目名称:spring-auto-restdocs,代码行数:13,代码来源:SectionSnippet.java


示例6: enhanceSnippetsWithRaml

import org.springframework.restdocs.snippet.Snippet; //导入依赖的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]);
}
 
开发者ID:ePages-de,项目名称:restdocs-raml,代码行数:61,代码来源:RamlDocumentation.java


示例7: document

import org.springframework.restdocs.snippet.Snippet; //导入依赖的package包/类
/**
 * Wraps the static document() method of RestDocs and configures it to pretty print request and
 * response JSON structures.
 */
protected RestDocumentationResultHandler document(String identifier, Snippet... snippets) {
  return MockMvcRestDocumentation.document(
      identifier, preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()), snippets);
}
 
开发者ID:reflectoring,项目名称:infiniboard,代码行数:9,代码来源:ControllerTestTemplate.java


示例8: documentPrettyPrint

import org.springframework.restdocs.snippet.Snippet; //导入依赖的package包/类
public RestDocumentationResultHandler documentPrettyPrint( String useCase, Snippet... snippets )
{
    return document( useCase, preprocessRequest( prettyPrint() ), preprocessResponse( prettyPrint() ), snippets );
}
 
开发者ID:dhis2,项目名称:dhis2-core,代码行数:5,代码来源:DhisWebSpringTest.java


示例9: getDefaultSnippets

import org.springframework.restdocs.snippet.Snippet; //导入依赖的package包/类
public static List<Snippet> getDefaultSnippets(Operation operation) {
    return (List<Snippet>) operation.getAttributes().get(ATTRIBUTE_NAME_DEFAULT_SNIPPETS);
}
 
开发者ID:ScaCap,项目名称:spring-auto-restdocs,代码行数:4,代码来源:OperationAttributeHelper.java


示例10: section

import org.springframework.restdocs.snippet.Snippet; //导入依赖的package包/类
public static Snippet section() {
    return new SectionBuilder().build();
}
 
开发者ID:ScaCap,项目名称:spring-auto-restdocs,代码行数:4,代码来源:AutoDocumentation.java


示例11: authorization

import org.springframework.restdocs.snippet.Snippet; //导入依赖的package包/类
public static Snippet authorization(String defaultAuthorization) {
    return new AuthorizationSnippet(defaultAuthorization);
}
 
开发者ID:ScaCap,项目名称:spring-auto-restdocs,代码行数:4,代码来源:AutoDocumentation.java


示例12: wiremockJson

import org.springframework.restdocs.snippet.Snippet; //导入依赖的package包/类
/**
 * Returns a json {@code Snippet} that will generate the WireMock stub from
 * the API operation.
 *
 * @see {@see MockMvcRestDocumentation}
 * @return the json snippet
 */
public static Snippet wiremockJson() {
	return new WireMockJsonSnippet();
}
 
开发者ID:ePages-de,项目名称:restdocs-wiremock,代码行数:11,代码来源:WireMockDocumentation.java



注:本文中的org.springframework.restdocs.snippet.Snippet类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java HashSP800DRBG类代码示例发布时间:2022-05-23
下一篇:
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap