use of org.folio.HoldingsType in project mod-inventory by folio-org.
the class QuickMarcKafkaHandlerTest method shouldSendHoldingsUpdatedEvent.
@Test
public void shouldSendHoldingsUpdatedEvent(TestContext context) throws InterruptedException {
List<HoldingsType> holdings = new ArrayList<>();
holdings.add(new HoldingsType().withName("testingnote$a"));
MappingParameters mappingParameters = new MappingParameters();
mappingParameters.withHoldingsTypes(holdings);
// given
Async async = context.async();
Map<String, String> payload = new HashMap<>();
payload.put("RECORD_TYPE", "MARC_HOLDING");
payload.put("MARC_HOLDING", Json.encode(holdingsRecord));
payload.put("MAPPING_RULES", holdingsMappingRules.encode());
payload.put("MAPPING_PARAMS", Json.encode(mappingParameters));
payload.put("PARSED_RECORD_DTO", Json.encode(new ParsedRecordDto().withRecordType(ParsedRecordDto.RecordType.MARC_HOLDING).withRelatedRecordVersion("1")));
Event event = new Event().withId("01").withEventPayload(Json.encode(payload));
String expectedKafkaRecordKey = "test_key";
when(kafkaRecord.key()).thenReturn(expectedKafkaRecordKey);
when(kafkaRecord.value()).thenReturn(Json.encode(event));
// when
Future<String> future = handler.handle(kafkaRecord);
// then
String observeTopic = formatTopicName(kafkaConfig.getEnvId(), getDefaultNameSpace(), TENANT_ID, QM_INVENTORY_HOLDINGS_UPDATED.name());
cluster.observeValues(ObserveKeyValues.on(observeTopic, 1).observeFor(30, TimeUnit.SECONDS).build());
future.onComplete(ar -> {
context.assertTrue(ar.succeeded());
context.assertEquals(expectedKafkaRecordKey, ar.result());
async.complete();
});
}
use of org.folio.HoldingsType in project mod-source-record-manager by folio-org.
the class MappingParametersProvider method getHoldingsTypes.
private Future<List<HoldingsType>> getHoldingsTypes(OkapiConnectionParams params) {
Promise<List<HoldingsType>> promise = Promise.promise();
String holdingsTypesUrl = "/holdings-types?limit=" + settingsLimit;
RestUtil.doRequest(params, holdingsTypesUrl, HttpMethod.GET, null).onComplete(ar -> {
if (RestUtil.validateAsyncResult(ar, promise)) {
JsonObject response = ar.result().getJson();
if (response != null && response.containsKey(HOLDINGS_TYPES_RESPONSE_PARAM)) {
List<HoldingsType> holdingsTypes = response.mapTo(Holdingstypes.class).getHoldingsTypes();
promise.complete(holdingsTypes);
} else {
promise.complete(Collections.emptyList());
}
}
});
return promise.future();
}
use of org.folio.HoldingsType in project mod-inventory by folio-org.
the class MarcHoldingsRecordHridSetKafkaHandlerTest method setUp.
@Before
public void setUp() throws IOException {
mappingRules = new JsonObject(TestUtil.readFileFromPath(MAPPING_RULES_PATH));
existingHoldingsRecord = new JsonObject(TestUtil.readFileFromPath(HOLDINGS_PATH)).mapTo(HoldingsRecord.class);
record = Json.decodeValue(TestUtil.readFileFromPath(RECORD_PATH), Record.class);
record.getParsedRecord().withContent(JsonObject.mapFrom(record.getParsedRecord().getContent()).encode());
mocks = MockitoAnnotations.openMocks(this);
when(mockedStorage.getHoldingsRecordCollection(any(Context.class))).thenReturn(mockedHoldingsCollection);
doAnswer(invocationOnMock -> {
Consumer<Success<HoldingsRecord>> successHandler = invocationOnMock.getArgument(1);
successHandler.accept(new Success<>(existingHoldingsRecord));
return null;
}).when(mockedHoldingsCollection).findById(anyString(), any(), any());
doAnswer(invocationOnMock -> {
HoldingsRecord holdingsRecord = invocationOnMock.getArgument(0);
Consumer<Success<HoldingsRecord>> successHandler = invocationOnMock.getArgument(1);
successHandler.accept(new Success<>(holdingsRecord));
return null;
}).when(mockedHoldingsCollection).update(any(HoldingsRecord.class), any(), any());
List<HoldingsType> holdings = new ArrayList<>();
holdings.add(new HoldingsType().withName("testingnote$a").withId("5f694a63-1bd4-4002-9f38-09170eb7aa62"));
MappingParameters mappingParameters = new MappingParameters();
mappingParameters.withHoldingsTypes(holdings);
WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(MAPPING_METADATA_URL + "/.*"), true)).willReturn(WireMock.ok().withBody(Json.encode(new MappingMetadataDto().withMappingParams(Json.encode(mappingParameters)).withMappingRules(mappingRules.encode())))));
MappingMetadataCache mappingMetadataCache = new MappingMetadataCache(vertx, vertx.createHttpClient(), 3600);
marcHoldingsRecordHridSetKafkaHandler = new MarcHoldingsRecordHridSetKafkaHandler(new HoldingsUpdateDelegate(mockedStorage), mappingMetadataCache);
this.okapiHeaders = List.of(KafkaHeader.header(OKAPI_TENANT_HEADER, "diku"), KafkaHeader.header(OKAPI_URL_HEADER, mockServer.baseUrl()));
}
use of org.folio.HoldingsType in project mod-inventory by folio-org.
the class UpdateHoldingsQuickMarcEventHandlerTest method shouldProcessEvent.
@Test
public void shouldProcessEvent() {
List<HoldingsType> holdings = new ArrayList<>();
holdings.add(new HoldingsType().withName("testingnote$a").withId("fe19bae4-da28-472b-be90-d442e2428eadx"));
MappingParameters mappingParameters = new MappingParameters();
mappingParameters.withHoldingsTypes(holdings);
HashMap<String, String> eventPayload = new HashMap<>();
eventPayload.put("RECORD_TYPE", "MARC_HOLDING");
eventPayload.put("MARC_HOLDING", record.encode());
eventPayload.put("MAPPING_RULES", mappingRules.encode());
eventPayload.put("MAPPING_PARAMS", Json.encode(mappingParameters));
eventPayload.put("RELATED_RECORD_VERSION", HOLDINGS_VERSION.toString());
Future<HoldingsRecord> future = updateHoldingsQuickMarcEventHandler.handle(eventPayload);
HoldingsRecord updatedHoldings = future.result();
Assert.assertNotNull(updatedHoldings);
Assert.assertEquals(HOLDINGS_ID, updatedHoldings.getId());
Assert.assertEquals(HOLDINGS_VERSION, updatedHoldings.getVersion());
Assert.assertNull(updatedHoldings.getHoldingsTypeId());
Assert.assertNotNull(updatedHoldings.getHoldingsStatements());
Assert.assertEquals(21, updatedHoldings.getHoldingsStatements().size());
Assert.assertNotNull(updatedHoldings.getNotes());
Assert.assertEquals("testingnote$a ; testingnote$u ; testingnote$3 ; testingnote$5 ; testingnote$6 ; testingnote$8", updatedHoldings.getNotes().get(0).getNote());
ArgumentCaptor<Context> argument = ArgumentCaptor.forClass(Context.class);
verify(holdingsUpdateDelegate).handle(any(), any(), argument.capture());
Assert.assertEquals("token", argument.getValue().getToken());
Assert.assertEquals("dummy", argument.getValue().getTenantId());
Assert.assertEquals("http://localhost", argument.getValue().getOkapiLocation());
}
use of org.folio.HoldingsType in project mod-inventory by folio-org.
the class UpdateHoldingsQuickMarcEventHandlerTest method shouldSendError.
@Test
public void shouldSendError() {
doAnswer(invocationOnMock -> {
Consumer<Failure> failureHandler = invocationOnMock.getArgument(2);
failureHandler.accept(new Failure("Internal Server Error", 500));
return null;
}).when(holdingsRecordCollection).update(any(), any(), any());
List<HoldingsType> holdings = new ArrayList<>();
holdings.add(new HoldingsType().withName("testingnote$a").withId("fe19bae4-da28-472b-be90-d442e2428eadx"));
MappingParameters mappingParameters = new MappingParameters();
mappingParameters.withHoldingsTypes(holdings);
HashMap<String, String> eventPayload = new HashMap<>();
eventPayload.put("RECORD_TYPE", "MARC_HOLDING");
eventPayload.put("MARC_HOLDING", record.encode());
eventPayload.put("MAPPING_RULES", mappingRules.encode());
eventPayload.put("MAPPING_PARAMS", Json.encode(mappingParameters));
Future<HoldingsRecord> future = updateHoldingsQuickMarcEventHandler.handle(eventPayload);
Assert.assertTrue(future.failed());
}
Aggregations