Search in sources :

Example 76 with RegexPattern

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

the class RecordProcessedEventHandlingServiceImplTest method setUp.

@Before
public void setUp() throws IOException {
    String[] hostAndPort = kafkaCluster.getBrokerList().split(":");
    kafkaConfig = KafkaConfig.builder().kafkaHost(hostAndPort[0]).kafkaPort(hostAndPort[1]).envId(KAFKA_ENV_ID).build();
    String rules = TestUtil.readFileFromPath(RULES_PATH);
    MockitoAnnotations.openMocks(this);
    mappingRuleCache = new MappingRuleCache(mappingRuleDao, vertx);
    marcRecordAnalyzer = new MarcRecordAnalyzer();
    mappingRuleService = new MappingRuleServiceImpl(mappingRuleDao, mappingRuleCache);
    mappingRuleDao = when(mock(MappingRuleDaoImpl.class).get(any(), anyString())).thenReturn(Future.succeededFuture(Optional.of(new JsonObject(rules)))).getMock();
    mappingParametersProvider = when(mock(MappingParametersProvider.class).get(anyString(), any(OkapiConnectionParams.class))).thenReturn(Future.succeededFuture(new MappingParameters())).getMock();
    mappingMetadataService = new MappingMetadataServiceImpl(mappingParametersProvider, mappingRuleService, mappingRulesSnapshotDao, mappingParamsSnapshotDao);
    changeEngineService = new ChangeEngineServiceImpl(jobExecutionSourceChunkDao, jobExecutionService, marcRecordAnalyzer, hrIdFieldService, recordsPublishingService, mappingMetadataService, kafkaConfig);
    ReflectionTestUtils.setField(changeEngineService, "maxDistributionNum", 10);
    ReflectionTestUtils.setField(changeEngineService, "batchSize", 100);
    chunkProcessingService = new EventDrivenChunkProcessingServiceImpl(jobExecutionSourceChunkDao, jobExecutionService, changeEngineService, jobExecutionProgressService);
    recordProcessedEventHandlingService = new RecordProcessedEventHandlingServiceImpl(jobExecutionProgressService, jobExecutionService, journalService, jobMonitoringService);
    HashMap<String, String> headers = new HashMap<>();
    headers.put(OKAPI_URL_HEADER, "http://localhost:" + snapshotMockServer.port());
    headers.put(OKAPI_TENANT_HEADER, TENANT_ID);
    headers.put(OKAPI_TOKEN_HEADER, "token");
    params = new OkapiConnectionParams(headers, vertx);
    WireMock.stubFor(post(RECORDS_SERVICE_URL).willReturn(created().withTransformers(RequestToResponseTransformer.NAME)));
    WireMock.stubFor(get(new UrlPathPattern(new RegexPattern("/data-import-profiles/jobProfiles/" + ".*"), true)).willReturn(ok().withBody(JsonObject.mapFrom(jobProfile).encode())));
}
Also used : HashMap(java.util.HashMap) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) MappingRuleDaoImpl(org.folio.dao.MappingRuleDaoImpl) JsonObject(io.vertx.core.json.JsonObject) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) OkapiConnectionParams(org.folio.dataimport.util.OkapiConnectionParams) MappingParametersProvider(org.folio.services.mappers.processor.MappingParametersProvider) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) MarcRecordAnalyzer(org.folio.dataimport.util.marc.MarcRecordAnalyzer) Before(org.junit.Before)

Example 77 with RegexPattern

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

the class AbstractRestTest method setUp.

@Before
public void setUp(TestContext context) throws IOException {
    clearTable(context);
    spec = new RequestSpecBuilder().setContentType(ContentType.JSON).addHeader(OKAPI_URL_HEADER, "http://localhost:" + snapshotMockServer.port()).addHeader(OKAPI_TENANT_HEADER, TENANT_ID).addHeader(RestVerticle.OKAPI_USERID_HEADER, okapiUserIdHeader).addHeader("Accept", "text/plain, application/json").setBaseUri("http://localhost:" + port).build();
    String record = TestUtil.readFileFromPath(RECORD_PATH);
    WireMock.stubFor(WireMock.post(SNAPSHOT_SERVICE_URL).willReturn(WireMock.created().withBody(postedSnapshotResponseBody)));
    WireMock.stubFor(WireMock.post(RECORDS_SERVICE_URL).willReturn(WireMock.created()));
    WireMock.stubFor(WireMock.put(new UrlPathPattern(new RegexPattern(RECORD_SERVICE_URL + "/.*"), true)).willReturn(WireMock.ok()));
    WireMock.stubFor(WireMock.put(PARSED_RECORDS_COLLECTION_URL).willReturn(WireMock.ok()));
    WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(RECORD_SERVICE_URL + "/.*"), true)).willReturn(WireMock.ok().withBody(record)));
    WireMock.stubFor(WireMock.put(new UrlPathPattern(new RegexPattern(SNAPSHOT_SERVICE_URL + "/.*"), true)).willReturn(WireMock.ok()));
    WireMock.stubFor(post(new UrlPathPattern(new RegexPattern(PROFILE_SNAPSHOT_URL + "/.*"), true)).willReturn(WireMock.created().withBody(Json.encode(profileSnapshotWrapperResponse))));
    WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(PROFILE_SNAPSHOT_URL + "/.*"), true)).willReturn(WireMock.ok().withBody(Json.encode(profileSnapshotWrapperResponse))));
    WireMock.stubFor(post(PUBSUB_PUBLISH_URL).willReturn(WireMock.noContent()));
    WireMock.stubFor(get(GET_USER_URL + okapiUserIdHeader).willReturn(okJson(userResponse.toString())));
    WireMock.stubFor(get(IDENTIFIER_TYPES_URL).willReturn(okJson(new JsonObject().put("identifierTypes", new JsonArray()).toString())));
    WireMock.stubFor(get(INSTANCE_TYPES_URL).willReturn(okJson(new JsonObject().put("instanceTypes", new JsonArray()).toString())));
    WireMock.stubFor(get(CLASSIFICATION_TYPES_URL).willReturn(okJson(new JsonObject().put("classificationTypes", new JsonArray()).toString())));
    WireMock.stubFor(get(ELECTRONIC_ACCESS_URL).willReturn(okJson(new JsonObject().put("electronicAccessRelationships", new JsonArray()).toString())));
    WireMock.stubFor(get(INSTANCE_FORMATS_URL).willReturn(okJson(new JsonObject().put("instanceFormats", new JsonArray()).toString())));
    WireMock.stubFor(get(CONTRIBUTOR_NAME_TYPES_URL).willReturn(okJson(new JsonObject().put("contributorNameTypes", new JsonArray()).toString())));
    WireMock.stubFor(get(CONTRIBUTOR_TYPES_URL).willReturn(okJson(new JsonObject().put("contributorTypes", new JsonArray()).toString())));
    WireMock.stubFor(get(INSTANCE_NOTE_TYPES_URL).willReturn(okJson(new JsonObject().put("instanceNoteTypes", new JsonArray()).toString())));
    WireMock.stubFor(get(INSTANCE_ALTERNATIVE_TITLE_TYPES_URL).willReturn(okJson(new JsonObject().put("alternativeTitleTypes", new JsonArray()).toString())));
    WireMock.stubFor(get(MODE_OF_ISSUANCE_TYPES_URL).willReturn(okJson(new JsonObject().put("issuanceModes", new JsonArray()).toString())));
    WireMock.stubFor(get(INSTANCE_STATUSES_URL).willReturn(okJson(new JsonObject().put("instanceStatuses", new JsonArray()).toString())));
    WireMock.stubFor(get(NATURE_OF_CONTENT_TERMS_URL).willReturn(okJson(new JsonObject().put("natureOfContentTerms", new JsonArray()).toString())));
    WireMock.stubFor(get(INSTANCE_RELATIONSHIP_TYPES_URL).willReturn(okJson(new JsonObject().put("instanceRelationshipTypes", new JsonArray()).toString())));
    WireMock.stubFor(get(HOLDINGS_TYPES_URL).willReturn(okJson(new JsonObject().put("holdingsTypes", new JsonArray()).toString())));
    WireMock.stubFor(get(HOLDINGS_NOTE_TYPES_URL).willReturn(okJson(new JsonObject().put("holdingsNoteTypes", new JsonArray()).toString())));
    WireMock.stubFor(get(ILL_POLICIES_URL).willReturn(okJson(new JsonObject().put("illPolicies", new JsonArray()).toString())));
    WireMock.stubFor(get(CALL_NUMBER_TYPES_URL).willReturn(okJson(new JsonObject().put("callNumberTypes", new JsonArray()).toString())));
    WireMock.stubFor(get(STATISTICAL_CODES_URL).willReturn(okJson(new JsonObject().put("statisticalCodes", new JsonArray()).toString())));
    WireMock.stubFor(get(STATISTICAL_CODE_TYPES_URL).willReturn(okJson(new JsonObject().put("statisticalCodeTypes", new JsonArray()).toString())));
    WireMock.stubFor(get(LOCATIONS_URL).willReturn(okJson(new JsonObject().put("locations", new JsonArray()).toString())));
    WireMock.stubFor(get(MATERIAL_TYPES_URL).willReturn(okJson(new JsonObject().put("mtypes", new JsonArray()).toString())));
    WireMock.stubFor(get(ITEM_DAMAGED_STATUSES_URL).willReturn(okJson(new JsonObject().put("itemDamageStatuses", new JsonArray()).toString())));
    WireMock.stubFor(get(LOAN_TYPES_URL).willReturn(okJson(new JsonObject().put("loantypes", new JsonArray()).toString())));
    WireMock.stubFor(get(ITEM_NOTE_TYPES_URL).willReturn(okJson(new JsonObject().put("itemNoteTypes", new JsonArray()).toString())));
    WireMock.stubFor(get(AUTHORITY_NOTE_TYPES_URL).willReturn(okJson(new JsonObject().put("authorityNoteTypes", new JsonArray()).toString())));
    WireMock.stubFor(get(FIELD_PROTECTION_SETTINGS_URL).willReturn(okJson(new JsonObject().put("marcFieldProtectionSettings", new JsonArray()).toString())));
    WireMock.stubFor(get(TENANT_CONFIGURATIONS_SETTINGS_URL).willReturn(okJson(new JsonObject().put("configs", new JsonArray()).toString())));
    WireMock.stubFor(WireMock.delete(new UrlPathPattern(new RegexPattern("/source-storage/snapshots/.{36}/records"), true)).willReturn(WireMock.noContent()));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) JsonObject(io.vertx.core.json.JsonObject) RequestSpecBuilder(io.restassured.builder.RequestSpecBuilder) Before(org.junit.Before)

Example 78 with RegexPattern

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

the class ChangeManagerAPITest method shouldUpdateSingleParentOnPutWhenSnapshotUpdateFailed.

@Test
public void shouldUpdateSingleParentOnPutWhenSnapshotUpdateFailed() {
    WireMock.stubFor(WireMock.put(new UrlPathPattern(new RegexPattern(SNAPSHOT_SERVICE_URL + "/.*"), true)).willReturn(WireMock.serverError()));
    InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
    List<JobExecution> createdJobExecutions = response.getJobExecutions();
    assertThat(createdJobExecutions.size(), is(1));
    JobExecution singleParent = createdJobExecutions.get(0);
    assertThat(singleParent.getSubordinationType(), is(JobExecution.SubordinationType.PARENT_SINGLE));
    singleParent.setJobProfileInfo(new JobProfileInfo().withId(DEFAULT_JOB_PROFILE_ID).withName("Marc jobs profile"));
    RestAssured.given().spec(spec).body(JsonObject.mapFrom(singleParent).toString()).when().put(JOB_EXECUTION_PATH + singleParent.getId()).then().statusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
}
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) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 79 with RegexPattern

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

the class ChangeManagerAPITest method shouldMarkJobExecutionAsErrorAndDoNotDeleteRecordsIfDefaultJobProfileWasNotSet.

@Test
public void shouldMarkJobExecutionAsErrorAndDoNotDeleteRecordsIfDefaultJobProfileWasNotSet(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)));
    Async async = testContext.async();
    RestAssured.given().spec(spec).body(new JobProfileInfo().withName("MARC records").withId(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).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()));
    async.complete();
    verify(0, deleteRequestedFor(new UrlPathPattern(new RegexPattern("/source-storage/snapshots/.{36}"), true)));
}
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) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 80 with RegexPattern

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

the class ChangeManagerAPITest method shouldMarkJobExecutionAsErrorIfNoSourceChunksExist.

@Test
public void shouldMarkJobExecutionAsErrorIfNoSourceChunksExist(TestContext testContext) {
    InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
    List<JobExecution> createdJobExecutions = response.getJobExecutions();
    assertThat(createdJobExecutions.size(), is(1));
    JobExecution jobExec = createdJobExecutions.get(0);
    WireMock.stubFor(WireMock.delete(new UrlPathPattern(new RegexPattern("/source-storage/snapshots/.{36}"), 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).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)

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