Search in sources :

Example 1 with Record

use of eu.europeana.metis.sandbox.domain.Record in project metis-sandbox by europeana.

the class EnrichedConsumerTest method processMedia_serviceThrowException_expectFailStatus.

@Test
void processMedia_serviceThrowException_expectFailStatus() {
    Record record = Record.builder().datasetId("1").datasetName("").country(Country.ITALY).language(Language.IT).content("".getBytes()).recordId("").build();
    Event recordEvent = new Event(new RecordInfo(record), Step.ENRICH, Status.SUCCESS);
    when(service.processMedia(record)).thenThrow(new RecordProcessingException("1", new Exception()));
    consumer.processMedia(recordEvent);
    verify(service).processMedia(record);
    verify(amqpTemplate).convertAndSend(any(), captor.capture());
    assertEquals(Status.FAIL, captor.getValue().getStatus());
}
Also used : RecordProcessingException(eu.europeana.metis.sandbox.common.exception.RecordProcessingException) RecordInfo(eu.europeana.metis.sandbox.domain.RecordInfo) Event(eu.europeana.metis.sandbox.domain.Event) Record(eu.europeana.metis.sandbox.domain.Record) RecordProcessingException(eu.europeana.metis.sandbox.common.exception.RecordProcessingException) Test(org.junit.jupiter.api.Test)

Example 2 with Record

use of eu.europeana.metis.sandbox.domain.Record in project metis-sandbox by europeana.

the class EnrichedConsumerTest method processMedia_expectSuccess.

@Test
void processMedia_expectSuccess() {
    Record record = Record.builder().datasetId("1").datasetName("").country(Country.ITALY).language(Language.IT).content("".getBytes()).recordId("").build();
    Event recordEvent = new Event(new RecordInfo(record), Step.ENRICH, Status.SUCCESS);
    when(service.processMedia(record)).thenReturn(new RecordInfo(record));
    consumer.processMedia(recordEvent);
    verify(service).processMedia(record);
    verify(amqpTemplate).convertAndSend(any(), captor.capture());
    assertEquals(Step.MEDIA_PROCESS, captor.getValue().getStep());
}
Also used : RecordInfo(eu.europeana.metis.sandbox.domain.RecordInfo) Event(eu.europeana.metis.sandbox.domain.Event) Record(eu.europeana.metis.sandbox.domain.Record) Test(org.junit.jupiter.api.Test)

Example 3 with Record

use of eu.europeana.metis.sandbox.domain.Record in project metis-sandbox by europeana.

the class StepExecutorTest method consumeEventStatusSuccess_expectEventSuccess.

@Test
void consumeEventStatusSuccess_expectEventSuccess() {
    final String routingKey = "routingKey";
    final Record myTestRecord = getTestRecord(1L);
    final RecordProcessEvent myEvent = new RecordProcessEvent(new RecordInfo(myTestRecord), Step.HARVEST_ZIP, Status.SUCCESS);
    stepExecutor.consume(routingKey, myEvent, Step.HARVEST_ZIP, () -> getRecordInfo());
    verify(amqpTemplate).convertAndSend(eq(routingKey), captor.capture());
    assertRecordId_CreatedStepAndStatus(getRecordInfo().getRecord().getRecordId(), Status.SUCCESS);
}
Also used : RecordInfo(eu.europeana.metis.sandbox.domain.RecordInfo) RecordProcessEvent(eu.europeana.metis.sandbox.domain.RecordProcessEvent) Record(eu.europeana.metis.sandbox.domain.Record) Test(org.junit.jupiter.api.Test)

Example 4 with Record

use of eu.europeana.metis.sandbox.domain.Record in project metis-sandbox by europeana.

the class StepExecutorTest method consumeEventStatusFailQueueNeverCalled_expectException.

@Test
void consumeEventStatusFailQueueNeverCalled_expectException() {
    final String routingKey = "routingKey";
    final Record myTestRecord = getTestRecord(1L);
    final RecordProcessEvent myEvent = new RecordProcessEvent(new RecordInfo(myTestRecord), Step.HARVEST_ZIP, Status.FAIL);
    stepExecutor.consume(routingKey, myEvent, Step.HARVEST_ZIP, () -> getRecordInfo());
    verify(amqpTemplate, never()).convertAndSend(eq(routingKey), captor.capture());
    assertThrows(MockitoException.class, () -> captor.getValue());
}
Also used : RecordInfo(eu.europeana.metis.sandbox.domain.RecordInfo) RecordProcessEvent(eu.europeana.metis.sandbox.domain.RecordProcessEvent) Record(eu.europeana.metis.sandbox.domain.Record) Test(org.junit.jupiter.api.Test)

Example 5 with Record

use of eu.europeana.metis.sandbox.domain.Record in project metis-sandbox by europeana.

the class StepExecutorTest method consumeEventStatusSuccessThrowsRuntimeException_expectEventFail.

@Test
void consumeEventStatusSuccessThrowsRuntimeException_expectEventFail() {
    final String routingKey = "routingKey";
    final Long expectedRecordId = 1L;
    final Record myTestRecord = getTestRecord(expectedRecordId);
    final RecordProcessEvent myEvent = new RecordProcessEvent(new RecordInfo(myTestRecord), Step.HARVEST_ZIP, Status.SUCCESS);
    stepExecutor.consume(routingKey, myEvent, Step.HARVEST_ZIP, () -> {
        throw new RuntimeException("General Failure");
    });
    verify(amqpTemplate).convertAndSend(eq(routingKey), captor.capture());
    assertRecordId_CreatedStepAndStatus(expectedRecordId, Status.FAIL);
}
Also used : RecordInfo(eu.europeana.metis.sandbox.domain.RecordInfo) RecordProcessEvent(eu.europeana.metis.sandbox.domain.RecordProcessEvent) Record(eu.europeana.metis.sandbox.domain.Record) Test(org.junit.jupiter.api.Test)

Aggregations

Record (eu.europeana.metis.sandbox.domain.Record)16 RecordInfo (eu.europeana.metis.sandbox.domain.RecordInfo)14 Test (org.junit.jupiter.api.Test)11 RecordProcessEvent (eu.europeana.metis.sandbox.domain.RecordProcessEvent)9 RecordError (eu.europeana.metis.sandbox.domain.RecordError)4 OaiRecord (eu.europeana.metis.harvesting.oaipmh.OaiRecord)3 RecordProcessingException (eu.europeana.metis.sandbox.common.exception.RecordProcessingException)3 RecordEntity (eu.europeana.metis.sandbox.entity.RecordEntity)3 RecordErrorLogEntity (eu.europeana.metis.sandbox.entity.RecordErrorLogEntity)3 ArrayList (java.util.ArrayList)3 OaiRepository (eu.europeana.metis.harvesting.oaipmh.OaiRepository)2 Step (eu.europeana.metis.sandbox.common.Step)2 Event (eu.europeana.metis.sandbox.domain.Event)2 IOException (java.io.IOException)2 List (java.util.List)2 MessageProperties (org.springframework.amqp.core.MessageProperties)2 HarvesterException (eu.europeana.metis.harvesting.HarvesterException)1 OaiHarvest (eu.europeana.metis.harvesting.oaipmh.OaiHarvest)1 OaiRecordHeader (eu.europeana.metis.harvesting.oaipmh.OaiRecordHeader)1 OaiRecordHeaderIterator (eu.europeana.metis.harvesting.oaipmh.OaiRecordHeaderIterator)1