use of org.folio.inventory.dataimport.handlers.actions.HoldingsUpdateDelegate in project mod-inventory by folio-org.
the class UpdateHoldingsQuickMarcEventHandlerTest method setUp.
@Before
public void setUp() throws IOException {
existingHoldingsRecord = new JsonObject(TestUtil.readFileFromPath(INSTANCE_PATH)).mapTo(HoldingsRecord.class);
holdingsUpdateDelegate = Mockito.spy(new HoldingsUpdateDelegate(storage));
updateHoldingsQuickMarcEventHandler = new UpdateHoldingsQuickMarcEventHandler(holdingsUpdateDelegate, context);
when(storage.getHoldingsRecordCollection(any())).thenReturn(holdingsRecordCollection);
doAnswer(invocationOnMock -> {
Consumer<Success<HoldingsRecord>> successHandler = invocationOnMock.getArgument(1);
successHandler.accept(new Success<>(existingHoldingsRecord));
return null;
}).when(holdingsRecordCollection).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(holdingsRecordCollection).update(any(), any(), any());
when(context.getTenantId()).thenReturn("dummy");
when(context.getToken()).thenReturn("token");
when(context.getOkapiLocation()).thenReturn("http://localhost");
mappingRules = new JsonObject(TestUtil.readFileFromPath(MAPPING_RULES_PATH));
record = new JsonObject(TestUtil.readFileFromPath(RECORD_PATH));
}
use of org.folio.inventory.dataimport.handlers.actions.HoldingsUpdateDelegate in project mod-inventory by folio-org.
the class MarcHridSetConsumerVerticle method start.
@Override
public void start(Promise<Void> startPromise) {
JsonObject config = vertx.getOrCreateContext().config();
KafkaConfig kafkaConfig = KafkaConfig.builder().envId(config.getString(KAFKA_ENV)).kafkaHost(config.getString(KAFKA_HOST)).kafkaPort(config.getString(KAFKA_PORT)).okapiUrl(config.getString(OKAPI_URL)).replicationFactor(Integer.parseInt(config.getString(KAFKA_REPLICATION_FACTOR))).maxRequestSize(Integer.parseInt(config.getString(KAFKA_MAX_REQUEST_SIZE))).build();
LOGGER.info("kafkaConfig: {}", kafkaConfig);
marcBibConsumerWrapper = createConsumerByEvent(kafkaConfig, DI_SRS_MARC_BIB_INSTANCE_HRID_SET);
marcHoldingsConsumerWrapper = createConsumerByEvent(kafkaConfig, DI_SRS_MARC_HOLDINGS_HOLDING_HRID_SET);
HttpClient client = vertx.createHttpClient();
Storage storage = Storage.basedUpon(vertx, config, client);
InstanceUpdateDelegate instanceUpdateDelegate = new InstanceUpdateDelegate(storage);
HoldingsUpdateDelegate holdingsRecordUpdateDelegate = new HoldingsUpdateDelegate(storage);
String mappingMetadataExpirationTime = getCacheEnvVariable(config, "inventory.mapping-metadata-cache.expiration.time.seconds");
MappingMetadataCache mappingMetadataCache = new MappingMetadataCache(vertx, client, Long.parseLong(mappingMetadataExpirationTime));
MarcBibInstanceHridSetKafkaHandler marcBibInstanceHridSetKafkaHandler = new MarcBibInstanceHridSetKafkaHandler(instanceUpdateDelegate, mappingMetadataCache);
MarcHoldingsRecordHridSetKafkaHandler marcHoldingsRecordHridSetKafkaHandler = new MarcHoldingsRecordHridSetKafkaHandler(holdingsRecordUpdateDelegate, mappingMetadataCache);
CompositeFuture.all(marcBibConsumerWrapper.start(marcBibInstanceHridSetKafkaHandler, constructModuleName()), marcHoldingsConsumerWrapper.start(marcHoldingsRecordHridSetKafkaHandler, constructModuleName())).onFailure(startPromise::fail).onSuccess(ar -> startPromise.complete());
}
use of org.folio.inventory.dataimport.handlers.actions.HoldingsUpdateDelegate 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()));
}
Aggregations