Search in sources :

Example 1 with QueryParameter

use of org.springframework.cloud.contract.spec.internal.QueryParameter in project spring-cloud-contract by spring-cloud.

the class CustomModeQueryParamsGiven method addQueryParameters.

private void addQueryParameters(Url buildUrl) {
    List<QueryParameter> queryParameters = buildUrl.getQueryParameters().getParameters().stream().filter(this::allowedQueryParameter).collect(Collectors.toList());
    Iterator<QueryParameter> iterator = queryParameters.iterator();
    while (iterator.hasNext()) {
        QueryParameter parameter = iterator.next();
        String text = addQueryParameter(parameter);
        if (iterator.hasNext()) {
            this.blockBuilder.addLine(text);
        } else {
            this.blockBuilder.addIndented(text);
        }
    }
}
Also used : QueryParameter(org.springframework.cloud.contract.spec.internal.QueryParameter)

Example 2 with QueryParameter

use of org.springframework.cloud.contract.spec.internal.QueryParameter in project spring-cloud-contract by spring-cloud.

the class JaxRsUrlPathWhen method appendQueryParams.

private void appendQueryParams(QueryParameters queryParameters) {
    if (queryParameters == null || queryParameters.getParameters().isEmpty()) {
        return;
    }
    this.blockBuilder.addEmptyLine();
    Iterator<QueryParameter> iterator = queryParameters.getParameters().stream().filter(this::allowedQueryParameter).iterator();
    while (iterator.hasNext()) {
        QueryParameter param = iterator.next();
        String queryParamValue = getQueryParamValue(param);
        String text = ".queryParam(\"" + param.getName() + "\", " + queryParamValue + ")";
        if (iterator.hasNext()) {
            this.blockBuilder.addLine(text);
        } else {
            this.blockBuilder.addIndented(text);
        }
    }
}
Also used : QueryParameter(org.springframework.cloud.contract.spec.internal.QueryParameter)

Example 3 with QueryParameter

use of org.springframework.cloud.contract.spec.internal.QueryParameter in project spring-cloud-contract by spring-cloud.

the class MockMvcQueryParamsWhen method addQueryParameters.

private void addQueryParameters(Url buildUrl) {
    List<QueryParameter> queryParameters = buildUrl.getQueryParameters().getParameters().stream().filter(this::allowedQueryParameter).collect(Collectors.toList());
    Iterator<QueryParameter> iterator = queryParameters.iterator();
    while (iterator.hasNext()) {
        QueryParameter parameter = iterator.next();
        String text = addQueryParameter(parameter);
        if (iterator.hasNext()) {
            this.blockBuilder.addLine(text);
        } else {
            this.blockBuilder.addIndented(text);
        }
    }
}
Also used : QueryParameter(org.springframework.cloud.contract.spec.internal.QueryParameter)

Example 4 with QueryParameter

use of org.springframework.cloud.contract.spec.internal.QueryParameter in project spring-cloud-contract by spring-cloud.

the class ContractDslSnippetTests method should_create_contract_template_and_doc_without_body_and_headers.

@Test
public void should_create_contract_template_and_doc_without_body_and_headers() throws Exception {
    this.mockMvc.perform(MockMvcRequestBuilders.get("/foo").param("one", "newValueOne").param("two", "newValueTwo")).andExpect(status().isOk()).andDo(document("empty", dslContract()));
    then(file("/contracts/empty.groovy")).exists();
    then(file("/empty/dsl-contract.adoc")).exists();
    Collection<Contract> parsedContracts = ContractVerifierDslConverter.convertAsCollection(new File("/"), file("/contracts/empty.groovy"));
    Contract parsedContract = parsedContracts.iterator().next();
    then(parsedContract.getRequest().getHeaders()).isNull();
    then(parsedContract.getRequest().getMethod().getClientValue()).isNotNull();
    then(parsedContract.getRequest().getUrlPath().getClientValue()).isNotNull();
    then(parsedContract.getRequest().getUrlPath().getClientValue().toString()).startsWith("/");
    List<QueryParameter> parameters = parsedContract.getRequest().getUrlPath().getQueryParameters().getParameters();
    QueryParameter one = parameter(parameters, "one");
    QueryParameter two = parameter(parameters, "two");
    then(one.getClientValue()).isEqualTo("newValueOne");
    then(two.getClientValue()).isEqualTo("newValueTwo");
    then(parsedContract.getRequest().getBody()).isNull();
    then(parsedContract.getResponse().getStatus().getClientValue()).isNotNull();
    then(parsedContract.getResponse().getHeaders()).isNull();
    then(parsedContract.getResponse().getBody()).isNull();
    then(parsedContract.getResponse().getBodyMatchers()).isNull();
}
Also used : QueryParameter(org.springframework.cloud.contract.spec.internal.QueryParameter) Contract(org.springframework.cloud.contract.spec.Contract) SpringCloudContractRestDocs.dslContract(org.springframework.cloud.contract.wiremock.restdocs.SpringCloudContractRestDocs.dslContract) File(java.io.File) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

QueryParameter (org.springframework.cloud.contract.spec.internal.QueryParameter)4 File (java.io.File)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 Contract (org.springframework.cloud.contract.spec.Contract)1 SpringCloudContractRestDocs.dslContract (org.springframework.cloud.contract.wiremock.restdocs.SpringCloudContractRestDocs.dslContract)1