use of org.kie.kogito.jobs.service.model.job.Recipient in project kogito-apps by kiegroup.
the class BaseJobRepositoryTest method createAndSaveJob.
private void createAndSaveJob(String id) throws Exception {
job = JobDetails.builder().id(id).trigger(//
new PointInTimeTrigger(System.currentTimeMillis(), null, null)).priority(1).recipient(new Recipient.HTTPRecipient("url")).build();
tested().save(job).toCompletableFuture().get();
}
use of org.kie.kogito.jobs.service.model.job.Recipient in project kogito-apps by kiegroup.
the class RecipientMarshallerTest method unmarshall.
@Test
void unmarshall() {
JsonObject jsonObject = new JsonObject().put("endpoint", "test").put("classType", Recipient.HTTPRecipient.class.getName());
Recipient recipient = marshaller.unmarshall(jsonObject);
assertEquals(new Recipient.HTTPRecipient("test"), recipient);
}
use of org.kie.kogito.jobs.service.model.job.Recipient in project kogito-apps by kiegroup.
the class JobDetailsMarshaller method readFrom.
@Override
public JobDetails readFrom(ProtoStreamReader reader) throws IOException {
String id = reader.readString("id");
String correlationId = reader.readString("correlationId");
JobStatus status = mapString(reader.readString("status"), JobStatus.class);
ZonedDateTime lastUpdate = instantToZonedDateTime(reader.readInstant("lastUpdate"));
Integer retries = reader.readInt("retries");
Integer priority = reader.readInt("priority");
Integer executionCounter = reader.readInt("executionCounter");
String scheduledId = reader.readString("scheduledId");
// serialize payload
String payload = reader.readString("payload");
Recipient recipient = reader.readObject("recipient", Recipient.class);
Trigger trigger = reader.readObject("trigger", Trigger.class);
JobDetails.Type type = mapString(reader.readString("type"), JobDetails.Type.class);
return JobDetails.builder().id(id).correlationId(correlationId).status(status).lastUpdate(lastUpdate).retries(retries).priority(priority).executionCounter(executionCounter).scheduledId(scheduledId).payload(payload).recipient(recipient).trigger(trigger).type(type).build();
}
use of org.kie.kogito.jobs.service.model.job.Recipient in project kogito-apps by kiegroup.
the class MongoDBJobRepositoryTest method setUp.
@BeforeEach
void setUp() {
mongoClient = mock(ReactiveMongoClient.class);
collection = mock(ReactiveMongoCollection.class);
ReactiveMongoDatabase mongoDatabase = mock(ReactiveMongoDatabase.class);
when(mongoClient.getDatabase(anyString())).thenReturn(mongoDatabase);
when(mongoDatabase.getCollection(anyString())).thenReturn(collection);
Uni uni = mock(Uni.class);
Multi multi = mock(Multi.class);
when(collection.findOneAndReplace(any(Bson.class), any(), any(FindOneAndReplaceOptions.class))).thenReturn(uni);
when(collection.find(any(Bson.class))).thenReturn(multi);
when(collection.findOneAndDelete(any(Bson.class))).thenReturn(uni);
when(collection.find()).thenReturn(multi);
when(collection.find(any(Bson.class), any(FindOptions.class))).thenReturn(multi);
when(collection.createIndex(any())).thenReturn(uni);
when(uni.map(any())).thenAnswer(invocationOnMock -> {
jobDetailsMarshaller.unmarshall(marshalled);
return uni;
});
when(uni.await()).thenReturn(mock(UniAwait.class));
MultiCollect multiCollect = mock(MultiCollect.class);
when(multi.collect()).thenReturn(multiCollect);
when(multiCollect.first()).thenReturn(uni);
when(multiCollect.with(any())).thenReturn(uni);
when(multi.map(any())).thenAnswer(invocationOnMock -> {
jobDetailsMarshaller.unmarshall(marshalled);
return multi;
});
MultiConvert convertMulti = mock(MultiConvert.class);
when(multi.emitOn(any())).thenReturn(multi);
when(multi.convert()).thenReturn(convertMulti);
Publisher publisher = mock(Publisher.class);
when(convertMulti.toPublisher()).thenReturn(publisher);
completableFuture = mock(CompletableFuture.class);
UniConvert convert = mock(UniConvert.class);
when(uni.emitOn(any())).thenReturn(uni);
when(uni.convert()).thenReturn(convert);
when(convert.toCompletionStage()).thenReturn(completableFuture);
ZonedDateTime time = ZonedDateTime.now(DEFAULT_ZONE);
PointInTimeTrigger trigger = new PointInTimeTrigger(time.toInstant().getEpochSecond(), null, null);
Recipient recipient = new Recipient.HTTPRecipient("test");
unmarshalled = new JobDetailsBuilder().id("test").trigger(trigger).recipient(recipient).build();
marshalled = new JsonObject().put("id", "test");
jobDetailsMarshaller = mock(JobDetailsMarshaller.class);
when(jobDetailsMarshaller.marshall(any(JobDetails.class))).thenReturn(marshalled);
when(jobDetailsMarshaller.unmarshall(any(JsonObject.class))).thenReturn(unmarshalled);
mongoDBJobRepository = new MongoDBJobRepository(null, null, mongoClient, "test", jobDetailsMarshaller);
}
use of org.kie.kogito.jobs.service.model.job.Recipient in project kogito-apps by kiegroup.
the class BaseJobRepositoryTest method testMergeCallbackEndpoint.
@Test
void testMergeCallbackEndpoint() throws Exception {
String id = UUID.randomUUID().toString();
createAndSaveJob(id);
final String newCallbackEndpoint = "http://localhost/newcallback";
final Recipient.HTTPRecipient recipient = new Recipient.HTTPRecipient(newCallbackEndpoint);
final JobDetails toMerge = JobDetails.builder().id(id).recipient(recipient).build();
JobDetails merged = tested().merge(id, toMerge).toCompletableFuture().get();
assertThat(merged.getRecipient()).isEqualTo(recipient);
assertThat(merged.getId()).isEqualTo(job.getId());
assertThat(merged.getTrigger().hasNextFireTime()).isEqualTo(job.getTrigger().hasNextFireTime());
}
Aggregations