Search in sources :

Example 81 with RegexPattern

use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-source-record-manager by folio-org.

the class ChangeManagerAPITest method shouldMarkJobExecutionAsErrorAndDeleteAllAssociatedRecords.

@Test
public void shouldMarkJobExecutionAsErrorAndDeleteAllAssociatedRecords(TestContext testContext) {
    InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
    List<JobExecution> createdJobExecutions = response.getJobExecutions();
    assertThat(createdJobExecutions.size(), is(1));
    JobExecution jobExec = createdJobExecutions.get(0);
    WireMock.stubFor(post(RECORDS_SERVICE_URL).willReturn(created().withTransformers(RequestToResponseTransformer.NAME)));
    WireMock.stubFor(WireMock.delete(new UrlPathPattern(new RegexPattern(SNAPSHOT_SERVICE_URL + "/.*"), true)).willReturn(WireMock.noContent()));
    Async async = testContext.async();
    RestAssured.given().spec(spec).body(new JobProfileInfo().withName("MARC records").withId(DEFAULT_JOB_PROFILE_ID).withDataType(JobProfileInfo.DataType.MARC)).when().put(JOB_EXECUTION_PATH + jobExec.getId() + JOB_PROFILE_PATH).then().statusCode(HttpStatus.SC_OK);
    async.complete();
    async = testContext.async();
    RestAssured.given().spec(spec).body(rawRecordsDto.withId(UUID.randomUUID().toString())).when().post(JOB_EXECUTION_PATH + jobExec.getId() + RECORDS_PATH).then().statusCode(HttpStatus.SC_NO_CONTENT);
    async.complete();
    async = testContext.async();
    RestAssured.given().spec(spec).when().delete(JOB_EXECUTION_PATH + jobExec.getId() + RECORDS_PATH).then().statusCode(HttpStatus.SC_NO_CONTENT);
    async.complete();
    async = testContext.async();
    RestAssured.given().spec(spec).when().get(JOB_EXECUTION_PATH + jobExec.getId()).then().statusCode(HttpStatus.SC_OK).body("status", is(CANCELLED.value())).body("completedDate", notNullValue(Date.class));
    async.complete();
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) JobProfileInfo(org.folio.rest.jaxrs.model.JobProfileInfo) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Async(io.vertx.ext.unit.Async) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) Date(java.util.Date) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 82 with RegexPattern

use of com.github.tomakehurst.wiremock.matching.RegexPattern in project neow3j by neow3j.

the class WireMockTestHelper method setUpWireMockForCall.

public static void setUpWireMockForCall(String call, String responseFile, String... params) throws IOException {
    String responseBody = loadFile("/responses/" + responseFile);
    StringBuilder regexPattern = new StringBuilder().append(".*\"method\":\"").append(call).append("\".*").append(".*\"params\":.*");
    for (String param : params) {
        regexPattern.append(".*").append(param).append(".*");
    }
    WireMock.stubFor(WireMock.post(WireMock.urlEqualTo("/")).withRequestBody(new RegexPattern(regexPattern.toString())).willReturn(WireMock.aResponse().withStatus(200).withBody(responseBody)));
}
Also used : RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern)

Example 83 with RegexPattern

use of com.github.tomakehurst.wiremock.matching.RegexPattern in project neow3j by neow3j.

the class WireMockTestHelper method setUpWireMockForInvokeFunction.

public static void setUpWireMockForInvokeFunction(String contractFunction, String responseFile) throws IOException {
    String responseBody = loadFile("/responses/" + responseFile);
    WireMock.stubFor(WireMock.post(WireMock.urlEqualTo("/")).withRequestBody(new RegexPattern("" + ".*\"method\":\"invokefunction\"" + ".*\"params\":.*\"" + contractFunction + "\".*")).willReturn(WireMock.aResponse().withStatus(200).withBody(responseBody)));
}
Also used : RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern)

Example 84 with RegexPattern

use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-kb-ebsco-java by folio-org.

the class LoadHoldingsStatusImplTest method shouldReturnStatusCompleted.

@Test
public void shouldReturnStatusCompleted(TestContext context) throws IOException, URISyntaxException {
    setupDefaultLoadKBConfiguration();
    mockGet(new EqualToPattern(RMAPI_HOLDINGS_STATUS_URL), "responses/rmapi/holdings/status/get-status-completed-one-page.json");
    stubFor(post(new UrlPathPattern(new EqualToPattern(RMAPI_POST_HOLDINGS_URL), false)).willReturn(new ResponseDefinitionBuilder().withBody("").withStatus(202)));
    mockGet(new RegexPattern(RMAPI_POST_HOLDINGS_URL), "responses/rmapi/holdings/holdings/get-holdings.json");
    Async async = context.async();
    handleStatusChange(COMPLETED, holdingsStatusRepository, o -> async.complete());
    postWithStatus(HOLDINGS_LOAD_BY_ID_URL, "", SC_NO_CONTENT, STUB_TOKEN_HEADER);
    async.await(TIMEOUT);
    final HoldingsLoadingStatus status = getWithOk(STUB_HOLDINGS_LOAD_STATUS_BY_ID_URL, STUB_TOKEN_HEADER).body().as(HoldingsLoadingStatus.class);
    assertThat(status.getData().getType(), equalTo(LoadStatusData.Type.STATUS));
    assertThat(status.getData().getAttributes().getTotalCount(), equalTo(2));
    assertThat(status.getData().getAttributes().getStatus().getName(), equalTo(COMPLETED));
    assertTrue(parse(status.getData().getAttributes().getStarted(), POSTGRES_TIMESTAMP_FORMATTER).isBefore(parse(status.getData().getAttributes().getFinished(), POSTGRES_TIMESTAMP_FORMATTER)));
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) HoldingsLoadingStatus(org.folio.rest.jaxrs.model.HoldingsLoadingStatus) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Async(io.vertx.ext.unit.Async) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) Test(org.junit.Test)

Example 85 with RegexPattern

use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-kb-ebsco-java by folio-org.

the class UsersLookUpServiceTest method shouldReturn404WhenUserNotFound.

@Test
public void shouldReturn404WhenUserNotFound(TestContext context) {
    final String stubUserId = "xyz";
    final String stubUserIdEndpoint = GET_USER_ENDPOINT + stubUserId;
    Async async = context.async();
    OKAPI_HEADERS.put(XOkapiHeaders.TENANT, STUB_TENANT);
    OKAPI_HEADERS.put(XOkapiHeaders.URL, getWiremockUrl());
    OKAPI_HEADERS.put(XOkapiHeaders.USER_ID, stubUserId);
    stubFor(get(new UrlPathPattern(new RegexPattern(stubUserIdEndpoint), true)).willReturn(new ResponseDefinitionBuilder().withStatus(404).withStatusMessage("User Not Found")));
    CompletableFuture<User> info = usersLookUpService.lookUpUser(new OkapiParams(OKAPI_HEADERS));
    info.thenCompose(result -> {
        context.assertNull(result);
        async.complete();
        return null;
    }).exceptionally(exception -> {
        context.assertTrue(exception.getCause() instanceof NotFoundException);
        async.complete();
        return null;
    });
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) TestRule(org.junit.rules.TestRule) XOkapiHeaders(org.folio.okapi.common.XOkapiHeaders) URISyntaxException(java.net.URISyntaxException) WireMockConfiguration(com.github.tomakehurst.wiremock.core.WireMockConfiguration) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) WireMockRule(com.github.tomakehurst.wiremock.junit.WireMockRule) Map(java.util.Map) TestUtil(org.folio.test.util.TestUtil) WireMock.get(com.github.tomakehurst.wiremock.client.WireMock.get) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) Vertx(io.vertx.core.Vertx) IOException(java.io.IOException) Test(org.junit.Test) STUB_TENANT(org.folio.test.util.TestUtil.STUB_TENANT) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) OkapiParams(org.folio.common.OkapiParams) NotFoundException(javax.ws.rs.NotFoundException) TestStartLoggingRule(org.folio.test.junit.TestStartLoggingRule) Rule(org.junit.Rule) WireMock.stubFor(com.github.tomakehurst.wiremock.client.WireMock.stubFor) NotAuthorizedException(javax.ws.rs.NotAuthorizedException) Slf4jNotifier(com.github.tomakehurst.wiremock.common.Slf4jNotifier) OkapiParams(org.folio.common.OkapiParams) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Async(io.vertx.ext.unit.Async) NotFoundException(javax.ws.rs.NotFoundException) Test(org.junit.Test)

Aggregations

RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)148 Test (org.junit.Test)119 UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)79 Matchers.containsString (org.hamcrest.Matchers.containsString)46 Async (io.vertx.ext.unit.Async)33 JsonapiError (org.folio.rest.jaxrs.model.JsonapiError)31 ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)26 Before (org.junit.Before)22 JsonObject (io.vertx.core.json.JsonObject)18 MappingParameters (org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters)16 HashMap (java.util.HashMap)13 EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)12 AbstractRestTest (org.folio.rest.impl.AbstractRestTest)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 TestContext (io.vertx.ext.unit.TestContext)10 WireMockConfiguration (com.github.tomakehurst.wiremock.core.WireMockConfiguration)9 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)9 IOException (java.io.IOException)9 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)9 RunWith (org.junit.runner.RunWith)9