com.github.tomakehurst.wiremock.matching.RequestPatternBuilder Java Examples

The following examples show how to use com.github.tomakehurst.wiremock.matching.RequestPatternBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CityServiceErrorTest.java    From http-api-invoker with MIT License 6 votes vote down vote up
/**
 * 测试方法上加的重试注解
 */
@Test
public void testMethodAnnotatedRetry() {
    long start = System.currentTimeMillis();
    wireMockRule.stubFor(get(urlPathEqualTo("/city/allCities")).willReturn(serverError()));
    try {
        cityService.getAllCities();
        fail("前面应该报异常");
    } catch (Exception e) {
        e.printStackTrace();
        assertEquals(e.getCause().getClass(), IOException.class);
    }
    long timeConsume = System.currentTimeMillis() - start;
    assertTrue("重试之前会休眠3000秒,因此2次请求,需要重试1次,即需要在3-6秒完成测试",
            timeConsume > 3000 && timeConsume < 6000);
    // 前面报错后重试 2 次
    wireMockRule.verify(2, RequestPatternBuilder.allRequests().withUrl("/city/allCities"));
}
 
Example #2
Source File: AbstractClientApplicationTest.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
@Test
public void test_context() throws InterruptedException, UnknownHostException {
	cdl.await();
	Thread.sleep(2500);
	String hostName = InetAddress.getLocalHost().getCanonicalHostName();
	String serviceHost = "http://" + hostName + ":" + getServerPort();
	String managementHost = "http://" + hostName + ":" + getManagementPort();
	RequestPatternBuilder request = postRequestedFor(urlEqualTo("/instances"));
	request.withHeader("Content-Type", equalTo("application/json"))
			.withRequestBody(matchingJsonPath("$.name", equalTo("Test-Client")))
			.withRequestBody(matchingJsonPath("$.healthUrl", equalTo(managementHost + "/mgmt/health")))
			.withRequestBody(matchingJsonPath("$.managementUrl", equalTo(managementHost + "/mgmt")))
			.withRequestBody(matchingJsonPath("$.serviceUrl", equalTo(serviceHost + "/")))
			.withRequestBody(matchingJsonPath("$.metadata.startup", matching(".+")));

	wireMock.verify(request);
}
 
Example #3
Source File: BoxAPIRequestTest.java    From box-java-sdk with Apache License 2.0 6 votes vote down vote up
@Test
@Category(UnitTest.class)
public void requestSendsXBoxUAHeader() throws MalformedURLException {

    stubFor(get(urlEqualTo("/")).willReturn(aResponse().withStatus(200)));
    BoxAPIConnection api = new BoxAPIConnection("");

    URL url = new URL("http://localhost:53620/");
    BoxAPIRequest request = new BoxAPIRequest(api, url, "GET");

    request.send();

    String headerRegex = "agent=box-java-sdk/\\d\\.\\d+\\.\\d+; env=Java/\\d\\.\\d+\\.\\d+_\\d+";
    RequestPatternBuilder requestPatternBuilder = RequestPatternBuilder.newRequestPattern().withHeader("X-Box-UA",
            matching(headerRegex));
    verify(requestPatternBuilder);
}
 
Example #4
Source File: SdkHttpClientTestSuite.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
private void validateResponse(HttpExecuteResponse response, int returnCode, SdkHttpMethod method) throws IOException {
    RequestMethod requestMethod = RequestMethod.fromString(method.name());

    RequestPatternBuilder patternBuilder = RequestPatternBuilder.newRequestPattern(requestMethod, urlMatching("/"))
                                                                       .withHeader("Host", containing("localhost"))
                                                                       .withHeader("User-Agent", equalTo("hello-world!"));

    if (method == SdkHttpMethod.HEAD) {
        patternBuilder.withRequestBody(equalTo(""));
    } else {
        patternBuilder.withRequestBody(equalTo("Body"));
    }

    mockServer.verify(1, patternBuilder);

    if (method == SdkHttpMethod.HEAD) {
        assertThat(response.responseBody()).isEmpty();
    } else {
        assertThat(IoUtils.toUtf8String(response.responseBody().orElse(null))).isEqualTo("hello");
    }

    assertThat(response.httpResponse().firstMatchingHeader("Some-Header")).contains("With Value");
    assertThat(response.httpResponse().statusCode()).isEqualTo(returnCode);
    mockServer.resetMappings();
}
 
Example #5
Source File: SwaggerHubClientTest.java    From swaggerhub-maven-plugin with Apache License 2.0 6 votes vote down vote up
private RequestPatternBuilder putRequestPattern(String url){
    return putRequestedFor(urlPathEqualTo(String.format(url, API_OWNER, API_NAME, API_VERSION, SCM_INTEGRATION_PROVIDER_GITHUB)))
            .withQueryParam("oas", equalTo(OAS3))
            .withRequestBody(matchingJsonPath("$.branch", equalTo(SCM_BRANCH)))
            .withRequestBody(matchingJsonPath("$.enabled", equalTo("true")))
            .withRequestBody(matchingJsonPath("$.outputFile", equalTo(SCM_INTEGRATION_OUTPUT_FILE)))
            .withRequestBody(matchingJsonPath("$.repository", equalTo(SCM_INTEGRATION_REPOSITORY)))
            .withRequestBody(matchingJsonPath("$.owner", equalTo(SCM_REPOSITORY_OWNER)))
            .withRequestBody(matchingJsonPath("$.syncMethod", equalTo(SCM_INTEGRATION_SYNC_METHOD)))
            .withRequestBody(matchingJsonPath("$.target", equalTo(SCM_INTEGRATION_TARGET)))
            .withRequestBody(matchingJsonPath("$.outputFolder", equalTo(SCM_INTEGRATION_OUTPUT_FOLDER)))
            .withRequestBody(matchingJsonPath("$.managedPaths", equalToJson("[\"" + SCM_INTEGRATION_OUTPUT_FILE + "\"]")))
            .withRequestBody(matchingJsonPath("$.name", equalTo(SCM_INTEGRATION_NAME)))
            .withRequestBody(matchingJsonPath("$.username", equalTo(SCM_USERNAME)))
            .withRequestBody(matchingJsonPath("$.password", equalTo(SCM_PASSWORD)))
            .withRequestBody(matchingJsonPath("$.account", equalTo(SCM_ACCOUNT)))
            .withRequestBody(matchingJsonPath("$.project", equalTo(SCM_PROJECT)))
            .withRequestBody(matchingJsonPath("$.personalAccessToken", equalTo(SCM_PERSONAL_ACCESS_TOKEN)))
            .withRequestBody(matchingJsonPath("$.url", equalTo(SCM_URL)))
            .withRequestBody(matchingJsonPath("$.projectCollection", equalTo(SCM_PROJECT_COLLECTION)))
            .withRequestBody(matchingJsonPath("$.host", equalTo(SCM_HOST)));
}
 
Example #6
Source File: SwaggerHubClientTest.java    From swaggerhub-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * This test defines the expected request format to be made to SwaggerHub to create an Integration plugin
 * The values defined as part of the request matcher are what is expected to be set due to the users configuration.
 * @throws JsonProcessingException
 */
@Test
public void verifySaveIntegrationPluginOfType_postsExpectedRequestBodyWithBasePath() throws JsonProcessingException {
    //Given
    swaggerHubClient = buildSwaggerHubClient("basePath");
    SaveSCMPluginConfigRequest.Builder requestBuilder = requestBuilder();
    SaveSCMPluginConfigRequest saveSCMPluginConfigRequest = requestBuilder.build();
    String requestUrl = String.format("/basePath/plugins/configurations/%s/%s/%s/%s?oas=%s", API_OWNER, API_NAME, API_VERSION, SCM_INTEGRATION_PROVIDER_GITHUB, OAS3);
    stubFor(put(requestUrl).willReturn(created()));
    RequestPatternBuilder putRequestPattern = putRequestPattern("/basePath/plugins/configurations/%s/%s/%s/%s");

    //When
    Optional<Response> response = swaggerHubClient.saveIntegrationPluginOfType(saveSCMPluginConfigRequest);

    //Then
    verify(1, putRequestPattern);
    response.ifPresent( x -> assertEquals(201, response.get().code()));
    if(!response.isPresent()){
        fail();
    }
}
 
Example #7
Source File: SwaggerHubClientTest.java    From swaggerhub-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * This test defines the expected request format to be made to SwaggerHub to create an Integration plugin
 * The values defined as part of the request matcher are what is expected to be set due to the users configuration.
 * @throws JsonProcessingException
 */
@Test
public void verifySaveIntegrationPluginOfType_postsExpectedRequestBody() throws JsonProcessingException {
    //Given
    swaggerHubClient = buildSwaggerHubClient( null);
    SaveSCMPluginConfigRequest.Builder requestBuilder = requestBuilder();
    SaveSCMPluginConfigRequest saveSCMPluginConfigRequest = requestBuilder.build();
    String requestUrl = String.format("/plugins/configurations/%s/%s/%s/%s?oas=%s", API_OWNER, API_NAME, API_VERSION, SCM_INTEGRATION_PROVIDER_GITHUB, OAS3);
    stubFor(put(requestUrl).willReturn(created()));
    RequestPatternBuilder putRequestPattern = putRequestPattern("/plugins/configurations/%s/%s/%s/%s");

    //When
    Optional<Response> response = swaggerHubClient.saveIntegrationPluginOfType(saveSCMPluginConfigRequest);

    //Then
    verify(1, putRequestPattern);
    response.ifPresent( x -> assertEquals(201, response.get().code()));
    if(!response.isPresent()){
        fail();
    }
}
 
Example #8
Source File: SwaggerHubUploadTest.java    From swaggerhub-maven-plugin with Apache License 2.0 6 votes vote down vote up
private RequestPatternBuilder createPutSCMConfigRequestPatternBase(String owner, String api, String version, String oasVersion, String branch,
                                                                                   String enabled, String repository, String repositoryOwner, String outputFile,
                                                                                   String target, String outputFolder){

    return putRequestedFor(urlPathEqualTo(String.format("/plugins/configurations/%s/%s/%s/GITHUB", owner, api, version)))
            .withQueryParam("oas", equalTo(oasVersion))
            .withRequestBody(matchingJsonPath("$.branch", equalTo(branch)))
            .withRequestBody(matchingJsonPath("$.enabled", equalTo(enabled)))
            .withRequestBody(matchingJsonPath("$.repository", equalTo(repository)))
            .withRequestBody(matchingJsonPath("$.owner", equalTo(repositoryOwner)))
            .withRequestBody(matchingJsonPath("$.syncMethod", equalTo("Advanced Sync")))
            .withRequestBody(matchingJsonPath("$.target", equalTo(target)))
            .withRequestBody(matchingJsonPath("$.outputFolder", equalTo(outputFolder)))
            .withRequestBody(matchingJsonPath("$.managedPaths", equalToJson("[\""+outputFile+"\"]")))
            .withRequestBody(matchingJsonPath("$.providedPaths", equalToJson("[]")))
            .withRequestBody(matchingJsonPath("$.ignoredPaths", equalToJson("[]")));
}
 
Example #9
Source File: SwaggerHubUploadTest.java    From swaggerhub-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testInputFileIsUploaded_andSCMSaveRequestMadeWithUrlAndProjectCollection() throws Exception {
    //GIVEN
    UrlPathPattern saveDefinitionRequest = stubSaveDefinitionRequest(API_OWNER, INPUT_FILE_API, INPUT_FILE_API_VERSION, IS_PRIVATE, OAS2, JSON, SWAGGERHUB_API_TOKEN);
    UrlPathPattern saveSCMPluginConfigurationRequest = stubSaveSCMPluginConfigurationRequest(API_OWNER, INPUT_FILE_API, INPUT_FILE_API_VERSION, OAS2, SWAGGERHUB_API_TOKEN);

    RequestPatternBuilder saveSCMConfigRequest = createPutSCMConfigRequestPatternWithUrlAndProjectCollection(API_OWNER, INPUT_FILE_API, INPUT_FILE_API_VERSION, OAS2, SCM_BRANCH,
            SCM_ENABLE_INTEGRATION, SCM_REPOSITORY, SCM_REPOSITORY_OWNER, INPUT_FILE_FILENAME,
            DefinitionFileFormat.JSON.getLanguageTarget(), TEST_RESOURCES_DIRECTORY, SCM_PERSONAL_ACCESS_TOKEN, SCM_PROJECT, SCM_URL, SCM_PROJECT_COLLECTION);

    //WHEN
    getSwaggerUpload("src/test/resources/testProjects/upload-input-filesave-scm-plugin-with-url-and-project-collection.xml").execute();

    //THEN
    verify(1, postRequestedFor(saveDefinitionRequest));
    verify(1, putRequestedFor(saveSCMPluginConfigurationRequest));
    verify(1, saveSCMConfigRequest);
}
 
Example #10
Source File: SwaggerHubUploadTest.java    From swaggerhub-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testInputFileIsUploaded_andSCMSaveRequestMadeWithToken() throws Exception {
    //Given
    UrlPathPattern saveDefinitionRequest = stubSaveDefinitionRequest(API_OWNER, INPUT_FILE_API, INPUT_FILE_API_VERSION, IS_PRIVATE, OAS2, JSON, SWAGGERHUB_API_TOKEN);
    UrlPathPattern saveSCMPluginConfigurationRequest = stubSaveSCMPluginConfigurationRequest(API_OWNER, INPUT_FILE_API, INPUT_FILE_API_VERSION, OAS2, SWAGGERHUB_API_TOKEN);

    RequestPatternBuilder putRequestPattern1 = createPutSCMConfigRequestPatternWithToken(API_OWNER, INPUT_FILE_API, INPUT_FILE_API_VERSION, OAS2, SCM_BRANCH,
            SCM_ENABLE_INTEGRATION, SCM_REPOSITORY, SCM_REPOSITORY_OWNER, INPUT_FILE_FILENAME, DefinitionFileFormat.JSON.getLanguageTarget(), TEST_RESOURCES_DIRECTORY, SCM_TOKEN);

    //When
    getSwaggerUpload("src/test/resources/testProjects/upload-input-file-save-github-plugin.xml").execute();

    //Then
    verify(1, postRequestedFor(saveDefinitionRequest));
    verify(1, putRequestedFor(saveSCMPluginConfigurationRequest));
    verify(1, putRequestPattern1);
}
 
Example #11
Source File: SwaggerHubUploadTest.java    From swaggerhub-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testInputFileIsUploaded_andSCMSaveRequestMadeWithUsernamePassword() throws Exception {
    //Given
    UrlPathPattern saveDefinitionRequest = stubSaveDefinitionRequest(API_OWNER, INPUT_FILE_API, INPUT_FILE_API_VERSION, IS_PRIVATE, OAS2, JSON, SWAGGERHUB_API_TOKEN);
    UrlPathPattern saveSCMPluginConfigurationRequest = stubSaveSCMPluginConfigurationRequest(API_OWNER, INPUT_FILE_API, INPUT_FILE_API_VERSION, OAS2, SWAGGERHUB_API_TOKEN);

    RequestPatternBuilder saveSCMConfigRequest = createPutSCMConfigRequestPatternWithUsernamePassword(API_OWNER, INPUT_FILE_API, INPUT_FILE_API_VERSION, OAS2, SCM_BRANCH,
            SCM_ENABLE_INTEGRATION, SCM_REPOSITORY, SCM_REPOSITORY_OWNER, INPUT_FILE_FILENAME,
            DefinitionFileFormat.JSON.getLanguageTarget(), TEST_RESOURCES_DIRECTORY, SCM_USERNAME,SCM_PASSWORD);

    //When
    getSwaggerUpload("src/test/resources/testProjects/upload-input-file-save-scm-plugin-with-username-password.xml").execute();

    //Then
    verify(1, postRequestedFor(saveDefinitionRequest));
    verify(1, putRequestedFor(saveSCMPluginConfigurationRequest));
    verify(1, saveSCMConfigRequest);
}
 
Example #12
Source File: SwaggerHubUploadTest.java    From swaggerhub-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testInputFileIsUploaded_andSCMSaveRequestMadeWithAccountPATAndProject() throws Exception {
    //Given
    UrlPathPattern saveDefinitionRequest = stubSaveDefinitionRequest(API_OWNER, INPUT_FILE_API, INPUT_FILE_API_VERSION, IS_PRIVATE, OAS2, JSON, SWAGGERHUB_API_TOKEN);
    UrlPathPattern saveSCMPluginConfigurationRequest = stubSaveSCMPluginConfigurationRequest(API_OWNER, INPUT_FILE_API, INPUT_FILE_API_VERSION, OAS2, SWAGGERHUB_API_TOKEN);

    RequestPatternBuilder saveSCMConfigRequest = createPutSCMConfigRequestPatternWithAccountPATandProject(API_OWNER, INPUT_FILE_API, INPUT_FILE_API_VERSION, OAS2, SCM_BRANCH,
            SCM_ENABLE_INTEGRATION, SCM_REPOSITORY, SCM_REPOSITORY_OWNER, INPUT_FILE_FILENAME,
            DefinitionFileFormat.JSON.getLanguageTarget(), TEST_RESOURCES_DIRECTORY, SCM_ACCOUNT, SCM_PERSONAL_ACCESS_TOKEN, SCM_PROJECT);

    //When
    getSwaggerUpload("src/test/resources/testProjects/upload-input-file-save-scm-plugin-with-account-pat-project.xml").execute();

    //Then
    verify(1, postRequestedFor(saveDefinitionRequest));
    verify(1, putRequestedFor(saveSCMPluginConfigurationRequest));
    verify(1, saveSCMConfigRequest);
}
 
Example #13
Source File: SwaggerHubUploadTest.java    From swaggerhub-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultiDefinitionsAreUploadedWithCorrectPath_WhenUsingWindowsSupportedFilePath() throws Exception {
    //Given
    UrlPathPattern definition1Request = stubSaveDefinitionRequest(API_OWNER, MULTI_UPLOAD_API_1_TITLE, MULTI_UPLOAD_API_1_VERSION, IS_PRIVATE, OAS3, YAML, SWAGGERHUB_API_TOKEN);
    UrlPathPattern definition2Request = stubSaveDefinitionRequest(API_OWNER, MULTI_UPLOAD_API_2_TITLE, MULTI_UPLOAD_API_2_VERSION, IS_PRIVATE, OAS2, JSON, SWAGGERHUB_API_TOKEN);
    UrlPathPattern definition3Request = stubSaveDefinitionRequest(API_OWNER, MULTI_UPLOAD_API_3_TITLE, MULTI_UPLOAD_API_3_VERSION, IS_PRIVATE, OAS3, YAML, SWAGGERHUB_API_TOKEN);


    UrlPathPattern saveSCMPluginConfigurationRequest1 = stubSaveSCMPluginConfigurationRequest(API_OWNER, MULTI_UPLOAD_API_1_TITLE, MULTI_UPLOAD_API_1_VERSION, OAS3, SWAGGERHUB_API_TOKEN);
    UrlPathPattern saveSCMPluginConfigurationRequest2 = stubSaveSCMPluginConfigurationRequest(API_OWNER, MULTI_UPLOAD_API_2_TITLE, MULTI_UPLOAD_API_2_VERSION, OAS2, SWAGGERHUB_API_TOKEN);
    UrlPathPattern saveSCMPluginConfigurationRequest3 = stubSaveSCMPluginConfigurationRequest(API_OWNER, MULTI_UPLOAD_API_3_TITLE, MULTI_UPLOAD_API_3_VERSION, OAS3, SWAGGERHUB_API_TOKEN);

    RequestPatternBuilder putRequestPattern1 = createPutSCMConfigRequestPatternWithToken(API_OWNER, MULTI_UPLOAD_API_1_TITLE, MULTI_UPLOAD_API_1_VERSION, OAS3, SCM_BRANCH,
            SCM_ENABLE_INTEGRATION, SCM_REPOSITORY, SCM_REPOSITORY_OWNER, MULTI_UPLOAD_API_1_FILENAME, DefinitionFileFormat.YAML.getLanguageTarget(), FILE_FINDER_DIRECTORY, SCM_TOKEN);
    RequestPatternBuilder putRequestPattern2 = createPutSCMConfigRequestPatternWithToken(API_OWNER, MULTI_UPLOAD_API_2_TITLE, MULTI_UPLOAD_API_2_VERSION, OAS2, SCM_BRANCH,
            SCM_ENABLE_INTEGRATION, SCM_REPOSITORY, SCM_REPOSITORY_OWNER, MULTI_UPLOAD_API_2_FILENAME, DefinitionFileFormat.JSON.getLanguageTarget(), FILE_FINDER_DIRECTORY, SCM_TOKEN);
    RequestPatternBuilder putRequestPattern3 = createPutSCMConfigRequestPatternWithToken(API_OWNER, MULTI_UPLOAD_API_3_TITLE, MULTI_UPLOAD_API_3_VERSION, OAS3, SCM_BRANCH,
            SCM_ENABLE_INTEGRATION, SCM_REPOSITORY, SCM_REPOSITORY_OWNER, MULTI_UPLOAD_API_3_FILENAME, DefinitionFileFormat.YAML.getLanguageTarget(), FILE_FINDER_DIRECTORY, SCM_TOKEN);

    //When
    getSwaggerUpload("src/test/resources/testProjects/upload-multi-definitions-windows.xml").execute();

    //Then
    verify(1, postRequestedFor(definition1Request));
    verify(1, postRequestedFor(definition2Request));
    verify(1, postRequestedFor(definition3Request));

    verify(1, putRequestedFor(saveSCMPluginConfigurationRequest1));
    verify(putRequestPattern1);

    verify(1, putRequestedFor(saveSCMPluginConfigurationRequest2));
    verify(putRequestPattern2);

    verify(1, putRequestedFor(saveSCMPluginConfigurationRequest3));
    verify(putRequestPattern3);
}
 
Example #14
Source File: WireMockTestUtils.java    From junit-servers with MIT License 5 votes vote down vote up
/**
 * Verify that a given request has been triggered.
 *
 * @param endpoint Request endpoint.
 * @param method Request method.
 * @param cookies Cookies sent in HTTP request.
 */
static void assertRequestWithCookies(String endpoint, HttpMethod method, Iterable<Pair> cookies) {
	UrlPattern urlPattern = urlEqualTo(endpoint);
	RequestMethod rqMethod = new RequestMethod(method.name());
	RequestPatternBuilder rq = new RequestPatternBuilder(rqMethod, urlPattern);

	for (Pair cookie : cookies) {
		String cookieName = cookie.getO1();
		String cookieValue = cookie.getO2().get(0);
		rq.withCookie(cookieName, equalTo(cookieValue));
	}

	WireMock.verify(1, rq);
}
 
Example #15
Source File: WireMockTestUtils.java    From junit-servers with MIT License 5 votes vote down vote up
/**
 * Verify that a given request has been triggered.
 *
 * @param endpoint Request endpoint.
 * @param method Request method.
 * @param body Request body.
 */
static void assertRequestWithBody(String endpoint, HttpMethod method, String body) {
	UrlPattern urlPattern = urlEqualTo(endpoint);
	RequestMethod rqMethod = new RequestMethod(method.name());
	RequestPatternBuilder rq = new RequestPatternBuilder(rqMethod, urlPattern);
	rq.withRequestBody(equalTo(body));
	WireMock.verify(1, rq);
}
 
Example #16
Source File: WireMockTestUtils.java    From junit-servers with MIT License 5 votes vote down vote up
/**
 * Verify that a given request has been triggered.
 *
 * @param endpoint Request endpoint.
 * @param method Request method.
 */
static void assertUploadRequest(String endpoint, HttpMethod method, File file) {
	UrlPattern urlPattern = urlEqualTo(endpoint);
	RequestMethod rqMethod = new RequestMethod(method.name());
	RequestPatternBuilder rq = new RequestPatternBuilder(rqMethod, urlPattern)
		.withAllRequestBodyParts(new MultipartValuePatternBuilder()
			.withName(file.getName())
			.withBody(new BinaryEqualToPattern(TestUtils.readFile(file)))
		);

	WireMock.verify(1, rq);
}
 
Example #17
Source File: WireMockTestUtils.java    From junit-servers with MIT License 5 votes vote down vote up
/**
 * Verify that a given request has been triggered.
 *
 * @param endpoint Request endpoint.
 * @param method Request method.
 */
static void assertRequest(String endpoint, HttpMethod method) {
	UrlPattern urlPattern = urlEqualTo(endpoint);
	RequestMethod rqMethod = new RequestMethod(method.name());
	RequestPatternBuilder rq = new RequestPatternBuilder(rqMethod, urlPattern);
	WireMock.verify(1, rq);
}
 
Example #18
Source File: AbstractRegistrationClientTest.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@Test
public void register_should_return_id_when_successful() {
	ResponseDefinitionBuilder response = created().withHeader("Content-Type", "application/json")
			.withHeader("Location", this.wireMock.url("/instances/abcdef")).withBody("{ \"id\" : \"-id-\" }");
	this.wireMock.stubFor(post(urlEqualTo("/instances")).willReturn(response));

	assertThat(this.registrationClient.register(this.wireMock.url("/instances"), this.application))
			.isEqualTo("-id-");

	RequestPatternBuilder expectedRequest = postRequestedFor(urlEqualTo("/instances"))
			.withHeader("Accept", equalTo("application/json"))
			.withHeader("Content-Type", equalTo("application/json"));
	this.wireMock.verify(expectedRequest);
}
 
Example #19
Source File: CityServiceErrorTest.java    From http-api-invoker with MIT License 5 votes vote down vote up
/**
 * 测试类上面加的重试注解
 */
@Test
public void testClassAnnotatedRetry() {
    wireMockRule.stubFor(get(urlPathEqualTo("/city/getById")).willReturn(notFound()));
    try {
        cityService.getCity(1);
        fail("前面应该报异常");
    } catch (Exception e) {
        e.printStackTrace();
        assertEquals(e.getCause().getClass(), IOException.class);
    }
    // 前面报错后重试 3 次
    wireMockRule.verify(3, RequestPatternBuilder.allRequests().withUrl("/city/getById?id=1"));
}
 
Example #20
Source File: HttpClientTesting.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
private static <T> T sendServiceCallToWireMock(
    final ServiceCallArgs<T> args, final int returnCode) {

  args.wireMockServer.stubFor(
      post(urlEqualTo(args.expectedRequestPath))
          .withHeader(HttpHeaders.ACCEPT, equalTo(HttpClientTesting.CONTENT_TYPE_JSON))
          .willReturn(
              aResponse()
                  .withStatus(returnCode)
                  .withHeader(HttpHeaders.CONTENT_TYPE, HttpClientTesting.CONTENT_TYPE_JSON)
                  .withBody(args.serverReturnValue)));

  WireMock.configureFor("localhost", args.wireMockServer.port());
  final URI hostUri = URI.create(args.wireMockServer.url(""));

  final T response = args.serviceCall.apply(hostUri);

  RequestPatternBuilder requestPatternBuilder =
      postRequestedFor(urlMatching(args.expectedRequestPath));

  for (final String content : args.expectedBodyContents) {
    requestPatternBuilder = requestPatternBuilder.withRequestBody(containing(content));
  }

  verify(
      requestPatternBuilder.withHeader(
          HttpHeaders.CONTENT_TYPE, matching(HttpClientTesting.CONTENT_TYPE_JSON)));

  return response;
}
 
Example #21
Source File: AutoConfigureWireMockRandomPortApplicationTests.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Test
public void contextLoads() throws Exception {
	wireMockServer.verify(0, RequestPatternBuilder.allRequests());
	WireMock.verify(0, RequestPatternBuilder.allRequests());

	stubFor(get(urlEqualTo("/test")).willReturn(aResponse()
			.withHeader("Content-Type", "text/plain").withBody("Hello World!")));
	assertThat(this.service.go()).isEqualTo("Hello World!");

	wireMockServer.verify(1, RequestPatternBuilder.allRequests());
	WireMock.verify(1, RequestPatternBuilder.allRequests());
}
 
Example #22
Source File: SwaggerHubUploadTest.java    From swaggerhub-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultiDefinitionsAreUploaded_andSCMSaveRequestMadeWithTokenMade() throws Exception {
    //Given
    UrlPathPattern uploadDefinitionRequest1 = stubSaveDefinitionRequest(API_OWNER, MULTI_UPLOAD_API_1_TITLE, MULTI_UPLOAD_API_1_VERSION, IS_PRIVATE, OAS3, YAML, SWAGGERHUB_API_TOKEN);
    UrlPathPattern uploadDefinitionRequest2 = stubSaveDefinitionRequest(API_OWNER, MULTI_UPLOAD_API_2_TITLE, MULTI_UPLOAD_API_2_VERSION, IS_PRIVATE, OAS2, JSON, SWAGGERHUB_API_TOKEN);
    UrlPathPattern uploadDefinitionRequest3 = stubSaveDefinitionRequest(API_OWNER, MULTI_UPLOAD_API_3_TITLE, MULTI_UPLOAD_API_3_VERSION, IS_PRIVATE, OAS3, YAML, SWAGGERHUB_API_TOKEN);

    UrlPathPattern saveSCMPluginConfigurationRequest1 = stubSaveSCMPluginConfigurationRequest(API_OWNER, MULTI_UPLOAD_API_1_TITLE, MULTI_UPLOAD_API_1_VERSION, OAS3, SWAGGERHUB_API_TOKEN);
    UrlPathPattern saveSCMPluginConfigurationRequest2 = stubSaveSCMPluginConfigurationRequest(API_OWNER, MULTI_UPLOAD_API_2_TITLE, MULTI_UPLOAD_API_2_VERSION, OAS2, SWAGGERHUB_API_TOKEN);
    UrlPathPattern saveSCMPluginConfigurationRequest3 = stubSaveSCMPluginConfigurationRequest(API_OWNER, MULTI_UPLOAD_API_3_TITLE, MULTI_UPLOAD_API_3_VERSION, OAS3, SWAGGERHUB_API_TOKEN);

    RequestPatternBuilder putRequestPattern1 = createPutSCMConfigRequestPatternWithToken(API_OWNER, MULTI_UPLOAD_API_1_TITLE, MULTI_UPLOAD_API_1_VERSION, OAS3, SCM_BRANCH,
            SCM_ENABLE_INTEGRATION, SCM_REPOSITORY, SCM_REPOSITORY_OWNER, MULTI_UPLOAD_API_1_FILENAME, DefinitionFileFormat.YAML.getLanguageTarget(), FILE_FINDER_DIRECTORY, SCM_TOKEN);
    RequestPatternBuilder putRequestPattern2 = createPutSCMConfigRequestPatternWithToken(API_OWNER, MULTI_UPLOAD_API_2_TITLE, MULTI_UPLOAD_API_2_VERSION, OAS2, SCM_BRANCH,
            SCM_ENABLE_INTEGRATION, SCM_REPOSITORY, SCM_REPOSITORY_OWNER, MULTI_UPLOAD_API_2_FILENAME, DefinitionFileFormat.JSON.getLanguageTarget(), FILE_FINDER_DIRECTORY, SCM_TOKEN);
    RequestPatternBuilder putRequestPattern3 = createPutSCMConfigRequestPatternWithToken(API_OWNER, MULTI_UPLOAD_API_3_TITLE, MULTI_UPLOAD_API_3_VERSION, OAS3, SCM_BRANCH,
            SCM_ENABLE_INTEGRATION, SCM_REPOSITORY, SCM_REPOSITORY_OWNER, MULTI_UPLOAD_API_3_FILENAME, DefinitionFileFormat.YAML.getLanguageTarget(), FILE_FINDER_DIRECTORY, SCM_TOKEN);

    //When
    getSwaggerUpload("src/test/resources/testProjects/upload-multi-definitions-save-github-plugins.xml").execute();

    //Then
    verify(1, postRequestedFor(uploadDefinitionRequest1));
    verify(1, postRequestedFor(uploadDefinitionRequest2));
    verify(1, postRequestedFor(uploadDefinitionRequest3));

    verify(1, putRequestedFor(saveSCMPluginConfigurationRequest1));
    verify(putRequestPattern1);

    verify(1, putRequestedFor(saveSCMPluginConfigurationRequest2));
    verify(putRequestPattern2);

    verify(1, putRequestedFor(saveSCMPluginConfigurationRequest3));
    verify(putRequestPattern3);

}
 
Example #23
Source File: SwaggerHubUploadTest.java    From swaggerhub-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultiDefinitionsAreUploaded_andSCMSaveRequestMadeWithUrlAndProjectCollection() throws Exception {
    //GIVEN
    UrlPathPattern uploadDefinitionRequest1 = stubSaveDefinitionRequest(API_OWNER, MULTI_UPLOAD_API_1_TITLE, MULTI_UPLOAD_API_1_VERSION, IS_PRIVATE, OAS3, YAML, SWAGGERHUB_API_TOKEN);
    UrlPathPattern uploadDefinitionRequest2 = stubSaveDefinitionRequest(API_OWNER, MULTI_UPLOAD_API_2_TITLE, MULTI_UPLOAD_API_2_VERSION, IS_PRIVATE, OAS2, JSON, SWAGGERHUB_API_TOKEN);
    UrlPathPattern uploadDefinitionRequest3 = stubSaveDefinitionRequest(API_OWNER, MULTI_UPLOAD_API_3_TITLE, MULTI_UPLOAD_API_3_VERSION, IS_PRIVATE, OAS3, YAML, SWAGGERHUB_API_TOKEN);

    UrlPathPattern saveSCMPluginConfigurationRequest1 = stubSaveSCMPluginConfigurationRequest(API_OWNER, MULTI_UPLOAD_API_1_TITLE, MULTI_UPLOAD_API_1_VERSION, OAS3, SWAGGERHUB_API_TOKEN);
    UrlPathPattern saveSCMPluginConfigurationRequest2 = stubSaveSCMPluginConfigurationRequest(API_OWNER, MULTI_UPLOAD_API_2_TITLE, MULTI_UPLOAD_API_2_VERSION, OAS2, SWAGGERHUB_API_TOKEN);
    UrlPathPattern saveSCMPluginConfigurationRequest3 = stubSaveSCMPluginConfigurationRequest(API_OWNER, MULTI_UPLOAD_API_3_TITLE, MULTI_UPLOAD_API_3_VERSION, OAS3, SWAGGERHUB_API_TOKEN);

    RequestPatternBuilder saveSCMPluginRequestPattern1 = createPutSCMConfigRequestPatternWithUrlAndProjectCollection(API_OWNER, MULTI_UPLOAD_API_1_TITLE, MULTI_UPLOAD_API_1_VERSION, OAS3, SCM_BRANCH,
            SCM_ENABLE_INTEGRATION, SCM_REPOSITORY, SCM_REPOSITORY_OWNER, MULTI_UPLOAD_API_1_FILENAME, DefinitionFileFormat.YAML.getLanguageTarget(), FILE_FINDER_DIRECTORY, SCM_PERSONAL_ACCESS_TOKEN,
            SCM_PROJECT, SCM_URL, SCM_PROJECT_COLLECTION);
    RequestPatternBuilder saveSCMPluginRequestPattern2 = createPutSCMConfigRequestPatternWithUrlAndProjectCollection(API_OWNER, MULTI_UPLOAD_API_2_TITLE, MULTI_UPLOAD_API_2_VERSION, OAS2, SCM_BRANCH,
            SCM_ENABLE_INTEGRATION, SCM_REPOSITORY, SCM_REPOSITORY_OWNER, MULTI_UPLOAD_API_2_FILENAME, DefinitionFileFormat.JSON.getLanguageTarget(), FILE_FINDER_DIRECTORY, SCM_PERSONAL_ACCESS_TOKEN,
            SCM_PROJECT, SCM_URL, SCM_PROJECT_COLLECTION);
    RequestPatternBuilder saveSCMPluginRequestPattern3 = createPutSCMConfigRequestPatternWithUrlAndProjectCollection(API_OWNER, MULTI_UPLOAD_API_3_TITLE, MULTI_UPLOAD_API_3_VERSION, OAS3, SCM_BRANCH,
            SCM_ENABLE_INTEGRATION, SCM_REPOSITORY, SCM_REPOSITORY_OWNER, MULTI_UPLOAD_API_3_FILENAME, DefinitionFileFormat.YAML.getLanguageTarget(), FILE_FINDER_DIRECTORY, SCM_PERSONAL_ACCESS_TOKEN,
            SCM_PROJECT, SCM_URL, SCM_PROJECT_COLLECTION);

    //WHEN
    getSwaggerUpload("src/test/resources/testProjects/upload-multi-definitions-save-scm-plugins-with-url-and-project-collection.xml").execute();

    //THEN
    verify(1, postRequestedFor(uploadDefinitionRequest1));
    verify(1, postRequestedFor(uploadDefinitionRequest2));
    verify(1, postRequestedFor(uploadDefinitionRequest3));

    verify(1, putRequestedFor(saveSCMPluginConfigurationRequest1));
    verify(saveSCMPluginRequestPattern1);

    verify(1, putRequestedFor(saveSCMPluginConfigurationRequest2));
    verify(saveSCMPluginRequestPattern2);

    verify(1, putRequestedFor(saveSCMPluginConfigurationRequest3));
    verify(saveSCMPluginRequestPattern3);
}
 
Example #24
Source File: SwaggerHubUploadTest.java    From swaggerhub-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultiDefinitionsAreUploaded_andSCMSaveRequestMadeWithHost() throws Exception {
    //GIVEN
    UrlPathPattern uploadDefinitionRequest1 = stubSaveDefinitionRequest(API_OWNER, MULTI_UPLOAD_API_1_TITLE, MULTI_UPLOAD_API_1_VERSION, IS_PRIVATE, OAS3, YAML, SWAGGERHUB_API_TOKEN);
    UrlPathPattern uploadDefinitionRequest2 = stubSaveDefinitionRequest(API_OWNER, MULTI_UPLOAD_API_2_TITLE, MULTI_UPLOAD_API_2_VERSION, IS_PRIVATE, OAS2, JSON, SWAGGERHUB_API_TOKEN);
    UrlPathPattern uploadDefinitionRequest3 = stubSaveDefinitionRequest(API_OWNER, MULTI_UPLOAD_API_3_TITLE, MULTI_UPLOAD_API_3_VERSION, IS_PRIVATE, OAS3, YAML, SWAGGERHUB_API_TOKEN);

    UrlPathPattern saveSCMPluginConfigurationRequest1 = stubSaveSCMPluginConfigurationRequest(API_OWNER, MULTI_UPLOAD_API_1_TITLE, MULTI_UPLOAD_API_1_VERSION, OAS3, SWAGGERHUB_API_TOKEN);
    UrlPathPattern saveSCMPluginConfigurationRequest2 = stubSaveSCMPluginConfigurationRequest(API_OWNER, MULTI_UPLOAD_API_2_TITLE, MULTI_UPLOAD_API_2_VERSION, OAS2, SWAGGERHUB_API_TOKEN);
    UrlPathPattern saveSCMPluginConfigurationRequest3 = stubSaveSCMPluginConfigurationRequest(API_OWNER, MULTI_UPLOAD_API_3_TITLE, MULTI_UPLOAD_API_3_VERSION, OAS3, SWAGGERHUB_API_TOKEN);

    RequestPatternBuilder saveSCMPluginRequestPattern1 = createPutSCMConfigRequestWithHost(API_OWNER, MULTI_UPLOAD_API_1_TITLE, MULTI_UPLOAD_API_1_VERSION, OAS3, SCM_BRANCH,
            SCM_ENABLE_INTEGRATION, SCM_REPOSITORY, SCM_REPOSITORY_OWNER, MULTI_UPLOAD_API_1_FILENAME, DefinitionFileFormat.YAML.getLanguageTarget(), FILE_FINDER_DIRECTORY, SCM_HOST);
    RequestPatternBuilder saveSCMPluginRequestPattern2 = createPutSCMConfigRequestWithHost(API_OWNER, MULTI_UPLOAD_API_2_TITLE, MULTI_UPLOAD_API_2_VERSION, OAS2, SCM_BRANCH,
            SCM_ENABLE_INTEGRATION, SCM_REPOSITORY, SCM_REPOSITORY_OWNER, MULTI_UPLOAD_API_2_FILENAME, DefinitionFileFormat.JSON.getLanguageTarget(), FILE_FINDER_DIRECTORY, SCM_HOST);
    RequestPatternBuilder saveSCMPluginRequestPattern3 = createPutSCMConfigRequestWithHost(API_OWNER, MULTI_UPLOAD_API_3_TITLE, MULTI_UPLOAD_API_3_VERSION, OAS3, SCM_BRANCH,
            SCM_ENABLE_INTEGRATION, SCM_REPOSITORY, SCM_REPOSITORY_OWNER, MULTI_UPLOAD_API_3_FILENAME, DefinitionFileFormat.YAML.getLanguageTarget(), FILE_FINDER_DIRECTORY, SCM_HOST);

    //WHEN
    getSwaggerUpload("src/test/resources/testProjects/upload-multi-definitions-save-scm-plugins-with-host.xml").execute();

    //THEN
    verify(1, postRequestedFor(uploadDefinitionRequest1));
    verify(1, postRequestedFor(uploadDefinitionRequest2));
    verify(1, postRequestedFor(uploadDefinitionRequest3));

    verify(1, putRequestedFor(saveSCMPluginConfigurationRequest1));
    verify(saveSCMPluginRequestPattern1);

    verify(1, putRequestedFor(saveSCMPluginConfigurationRequest2));
    verify(saveSCMPluginRequestPattern2);

    verify(1, putRequestedFor(saveSCMPluginConfigurationRequest3));
    verify(saveSCMPluginRequestPattern3);
}
 
Example #25
Source File: SwaggerHubUploadTest.java    From swaggerhub-maven-plugin with Apache License 2.0 5 votes vote down vote up
private RequestPatternBuilder createPutSCMConfigRequestPatternWithToken(String owner, String api, String version, String oasVersion, String branch,
                                                                        String enabled, String repository, String repositoryOwner, String outputFile,
                                                                        String target, String outputFolder, String scmToken){

    return createPutSCMConfigRequestPatternBase(owner, api, version, oasVersion, branch, enabled, repository, repositoryOwner, outputFile, target, outputFolder)
            .withRequestBody(matchingJsonPath("$.token", equalTo(scmToken)));
}
 
Example #26
Source File: SwaggerHubUploadTest.java    From swaggerhub-maven-plugin with Apache License 2.0 5 votes vote down vote up
private RequestPatternBuilder createPutSCMConfigRequestPatternWithUsernamePassword(String owner, String api, String version, String oasVersion, String branch,
                                                                        String enabled, String repository, String repositoryOwner, String outputFile,
                                                                        String target, String outputFolder, String username, String password){

    return createPutSCMConfigRequestPatternBase(owner, api, version, oasVersion, branch, enabled, repository, repositoryOwner, outputFile, target, outputFolder)
            .withRequestBody(matchingJsonPath("$.username", equalTo(username)))
            .withRequestBody(matchingJsonPath("$.password", equalTo(password)));

}
 
Example #27
Source File: SwaggerHubUploadTest.java    From swaggerhub-maven-plugin with Apache License 2.0 5 votes vote down vote up
private RequestPatternBuilder createPutSCMConfigRequestPatternWithAccountPATandProject(String owner, String api, String version, String oasVersion, String branch,
                                                                                   String enabled, String repository, String repositoryOwner, String outputFile,
                                                                                   String target, String outputFolder, String account, String personalAccessToken, String project){

    return createPutSCMConfigRequestPatternBase(owner, api, version, oasVersion, branch, enabled, repository, repositoryOwner, outputFile, target, outputFolder)
            .withRequestBody(matchingJsonPath("$.account", equalTo(account)))
            .withRequestBody(matchingJsonPath("$.personalAccessToken", equalTo(personalAccessToken)))
            .withRequestBody(matchingJsonPath("$.project", equalTo(project)));

}
 
Example #28
Source File: SwaggerHubUploadTest.java    From swaggerhub-maven-plugin with Apache License 2.0 5 votes vote down vote up
private RequestPatternBuilder createPutSCMConfigRequestPatternWithUrlAndProjectCollection(String owner, String api,String version, String oasVersion, String branch,
                                                                                          String enabled, String repository, String repositoryOwner, String outputFile,
                                                                                          String target, String outputFolder, String personalAccessToken, String project,
                                                                                          String url, String projectCollection){
    return createPutSCMConfigRequestPatternBase(owner, api, version, oasVersion, branch, enabled, repository, repositoryOwner, outputFile, target, outputFolder)
            .withRequestBody(matchingJsonPath("$.personalAccessToken", equalTo(personalAccessToken)))
            .withRequestBody(matchingJsonPath("$.project", equalTo(project)))
            .withRequestBody(matchingJsonPath("$.url", equalTo(url)))
            .withRequestBody(matchingJsonPath("$.projectCollection", equalTo(projectCollection)));
}
 
Example #29
Source File: SwaggerHubUploadTest.java    From swaggerhub-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultiDefinitionsAreUploaded_andSCMSaveRequestMadeWithAccountPATAndProject() throws Exception {
    //Given
    UrlPathPattern uploadDefinitionRequest1 = stubSaveDefinitionRequest(API_OWNER, MULTI_UPLOAD_API_1_TITLE, MULTI_UPLOAD_API_1_VERSION, IS_PRIVATE, OAS3, YAML, SWAGGERHUB_API_TOKEN);
    UrlPathPattern uploadDefinitionRequest2 = stubSaveDefinitionRequest(API_OWNER, MULTI_UPLOAD_API_2_TITLE, MULTI_UPLOAD_API_2_VERSION, IS_PRIVATE, OAS2, JSON, SWAGGERHUB_API_TOKEN);
    UrlPathPattern uploadDefinitionRequest3 = stubSaveDefinitionRequest(API_OWNER, MULTI_UPLOAD_API_3_TITLE, MULTI_UPLOAD_API_3_VERSION, IS_PRIVATE, OAS3, YAML, SWAGGERHUB_API_TOKEN);

    UrlPathPattern saveSCMPluginConfigurationRequest1 = stubSaveSCMPluginConfigurationRequest(API_OWNER, MULTI_UPLOAD_API_1_TITLE, MULTI_UPLOAD_API_1_VERSION, OAS3, SWAGGERHUB_API_TOKEN);
    UrlPathPattern saveSCMPluginConfigurationRequest2 = stubSaveSCMPluginConfigurationRequest(API_OWNER, MULTI_UPLOAD_API_2_TITLE, MULTI_UPLOAD_API_2_VERSION, OAS2, SWAGGERHUB_API_TOKEN);
    UrlPathPattern saveSCMPluginConfigurationRequest3 = stubSaveSCMPluginConfigurationRequest(API_OWNER, MULTI_UPLOAD_API_3_TITLE, MULTI_UPLOAD_API_3_VERSION, OAS3, SWAGGERHUB_API_TOKEN);

    RequestPatternBuilder saveSCMPluginRequestPattern1 = createPutSCMConfigRequestPatternWithAccountPATandProject(API_OWNER, MULTI_UPLOAD_API_1_TITLE, MULTI_UPLOAD_API_1_VERSION, OAS3, SCM_BRANCH,
            SCM_ENABLE_INTEGRATION, SCM_REPOSITORY, SCM_REPOSITORY_OWNER, MULTI_UPLOAD_API_1_FILENAME, DefinitionFileFormat.YAML.getLanguageTarget(), FILE_FINDER_DIRECTORY, SCM_ACCOUNT, SCM_PERSONAL_ACCESS_TOKEN, SCM_PROJECT);
    RequestPatternBuilder saveSCMPluginRequestPattern2 = createPutSCMConfigRequestPatternWithAccountPATandProject(API_OWNER, MULTI_UPLOAD_API_2_TITLE, MULTI_UPLOAD_API_2_VERSION, OAS2, SCM_BRANCH,
            SCM_ENABLE_INTEGRATION, SCM_REPOSITORY, SCM_REPOSITORY_OWNER, MULTI_UPLOAD_API_2_FILENAME, DefinitionFileFormat.JSON.getLanguageTarget(), FILE_FINDER_DIRECTORY, SCM_ACCOUNT, SCM_PERSONAL_ACCESS_TOKEN, SCM_PROJECT);
    RequestPatternBuilder saveSCMPluginRequestPattern3 = createPutSCMConfigRequestPatternWithAccountPATandProject(API_OWNER, MULTI_UPLOAD_API_3_TITLE, MULTI_UPLOAD_API_3_VERSION, OAS3, SCM_BRANCH,
            SCM_ENABLE_INTEGRATION, SCM_REPOSITORY, SCM_REPOSITORY_OWNER, MULTI_UPLOAD_API_3_FILENAME, DefinitionFileFormat.YAML.getLanguageTarget(), FILE_FINDER_DIRECTORY, SCM_ACCOUNT, SCM_PERSONAL_ACCESS_TOKEN, SCM_PROJECT);

    //When
    getSwaggerUpload("src/test/resources/testProjects/upload-multi-definitions-save-scm-plugins-with-account-pat-project.xml").execute();

    //Then
    verify(1, postRequestedFor(uploadDefinitionRequest1));
    verify(1, postRequestedFor(uploadDefinitionRequest2));
    verify(1, postRequestedFor(uploadDefinitionRequest3));

    verify(1, putRequestedFor(saveSCMPluginConfigurationRequest1));
    verify(saveSCMPluginRequestPattern1);

    verify(1, putRequestedFor(saveSCMPluginConfigurationRequest2));
    verify(saveSCMPluginRequestPattern2);

    verify(1, putRequestedFor(saveSCMPluginConfigurationRequest3));
    verify(saveSCMPluginRequestPattern3);
}
 
Example #30
Source File: SwaggerHubUploadTest.java    From swaggerhub-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultiDefinitionsAreUploaded_andSCMSaveRequestMadeWithUsernamePassword() throws Exception {
    //Given
    UrlPathPattern uploadDefinitionRequest1 = stubSaveDefinitionRequest(API_OWNER, MULTI_UPLOAD_API_1_TITLE, MULTI_UPLOAD_API_1_VERSION, IS_PRIVATE, OAS3, YAML, SWAGGERHUB_API_TOKEN);
    UrlPathPattern uploadDefinitionRequest2 = stubSaveDefinitionRequest(API_OWNER, MULTI_UPLOAD_API_2_TITLE, MULTI_UPLOAD_API_2_VERSION, IS_PRIVATE, OAS2, JSON, SWAGGERHUB_API_TOKEN);
    UrlPathPattern uploadDefinitionRequest3 = stubSaveDefinitionRequest(API_OWNER, MULTI_UPLOAD_API_3_TITLE, MULTI_UPLOAD_API_3_VERSION, IS_PRIVATE, OAS3, YAML, SWAGGERHUB_API_TOKEN);

    UrlPathPattern saveSCMPluginConfigurationRequest1 = stubSaveSCMPluginConfigurationRequest(API_OWNER, MULTI_UPLOAD_API_1_TITLE, MULTI_UPLOAD_API_1_VERSION, OAS3, SWAGGERHUB_API_TOKEN);
    UrlPathPattern saveSCMPluginConfigurationRequest2 = stubSaveSCMPluginConfigurationRequest(API_OWNER, MULTI_UPLOAD_API_2_TITLE, MULTI_UPLOAD_API_2_VERSION, OAS2, SWAGGERHUB_API_TOKEN);
    UrlPathPattern saveSCMPluginConfigurationRequest3 = stubSaveSCMPluginConfigurationRequest(API_OWNER, MULTI_UPLOAD_API_3_TITLE, MULTI_UPLOAD_API_3_VERSION, OAS3, SWAGGERHUB_API_TOKEN);

    RequestPatternBuilder saveSCMPluginRequestPattern1 = createPutSCMConfigRequestPatternWithUsernamePassword(API_OWNER, MULTI_UPLOAD_API_1_TITLE, MULTI_UPLOAD_API_1_VERSION, OAS3, SCM_BRANCH,
            SCM_ENABLE_INTEGRATION, SCM_REPOSITORY, SCM_REPOSITORY_OWNER, MULTI_UPLOAD_API_1_FILENAME, DefinitionFileFormat.YAML.getLanguageTarget(), FILE_FINDER_DIRECTORY, SCM_USERNAME, SCM_PASSWORD);
    RequestPatternBuilder saveSCMPluginRequestPattern2 = createPutSCMConfigRequestPatternWithUsernamePassword(API_OWNER, MULTI_UPLOAD_API_2_TITLE, MULTI_UPLOAD_API_2_VERSION, OAS2, SCM_BRANCH,
            SCM_ENABLE_INTEGRATION, SCM_REPOSITORY, SCM_REPOSITORY_OWNER, MULTI_UPLOAD_API_2_FILENAME, DefinitionFileFormat.JSON.getLanguageTarget(), FILE_FINDER_DIRECTORY, SCM_USERNAME, SCM_PASSWORD);
    RequestPatternBuilder saveSCMPluginRequestPattern3 = createPutSCMConfigRequestPatternWithUsernamePassword(API_OWNER, MULTI_UPLOAD_API_3_TITLE, MULTI_UPLOAD_API_3_VERSION, OAS3, SCM_BRANCH,
            SCM_ENABLE_INTEGRATION, SCM_REPOSITORY, SCM_REPOSITORY_OWNER, MULTI_UPLOAD_API_3_FILENAME, DefinitionFileFormat.YAML.getLanguageTarget(), FILE_FINDER_DIRECTORY, SCM_USERNAME, SCM_PASSWORD);

    //When
    getSwaggerUpload("src/test/resources/testProjects/upload-multi-definitions-save-scm-plugins-with-username-password.xml").execute();

    //Then
    verify(1, postRequestedFor(uploadDefinitionRequest1));
    verify(1, postRequestedFor(uploadDefinitionRequest2));
    verify(1, postRequestedFor(uploadDefinitionRequest3));

    verify(1, putRequestedFor(saveSCMPluginConfigurationRequest1));
    verify(saveSCMPluginRequestPattern1);

    verify(1, putRequestedFor(saveSCMPluginConfigurationRequest2));
    verify(saveSCMPluginRequestPattern2);

    verify(1, putRequestedFor(saveSCMPluginConfigurationRequest3));
    verify(saveSCMPluginRequestPattern3);
}