MongoJobRepository extends AbstractMongoRepository<String, JobInfo> implements JobRepository { @Override protected final JobInfo decode(final Document document) { return newJobInfo( document.getString(JobStructure.ID.key()), document.getString(JobStructure.JOB_TYPE.key()), toOffsetDateTime(document.getDate(JobStructure.STARTED.key())), toOffsetDateTime(document.getDate(JobStructure.LAST_UPDATED.key())), ofNullable(toOffsetDateTime(document.getDate(JobStructure.STOPPED.key()))), JobStatus.valueOf(document.getString(JobStructure.STATUS.key())), getMessagesFrom(document), clock, document.getString(JobStructure.HOSTNAME.key())); } MongoJobRepository(final MongoDatabase mongoDatabase,
                              final String jobInfoCollectionName,
                              final MongoProperties mongoProperties); @Override JobStatus findStatus(final String jobId); @Override void removeIfStopped(final String id); @Override void appendMessage(final String jobId, final JobMessage jobMessage); @Override void setJobStatus(final String jobId, final JobStatus jobStatus); @Override void setLastUpdate(final String jobId, final OffsetDateTime lastUpdate); @Override List<JobInfo> findLatest(final int maxCount); @Override List<JobInfo> findLatestJobsDistinct(); List<String> findAllJobIdsDistinct(); @Override List<JobInfo> findLatestBy(final String type, final int maxCount); @Override List<JobInfo> findByType(final String type); @Override List<JobInfo> findRunningWithoutUpdateSince(final OffsetDateTime timeOffset); @Override List<JobInfo> findAllJobInfoWithoutMessages(); @Override void keepJobMessagesWithinMaximumSize(String jobId); static final String ID; }
@Test public void shouldNotFailInCaseLogMessageHasNoText() throws Exception { final Map<String, Object> infoLog = new HashMap<String, Object>() {{ put(MSG_LEVEL.key(), "INFO"); put(MSG_TEXT.key(), "Some text"); put(MSG_TS.key(), new Date()); }}; final Map<String, Object> errorLog = new HashMap<String, Object>() {{ put(MSG_LEVEL.key(), "ERROR"); put(MSG_TEXT.key(), null); put(MSG_TS.key(), new Date()); }}; final Document infoLogDocument = new Document(infoLog); final Document errorLogDocument = new Document(errorLog); final Map<String, Object> jobLogs = new HashMap<String, Object>() {{ put(MESSAGES.key(), asList(infoLogDocument, errorLogDocument)); put(JOB_TYPE.key(), "SomeType"); put(ID.key(), "/SomeType/ID"); put(STATUS.key(), ERROR.toString()); }}; final JobInfo jobInfo = repo.decode(new Document(jobLogs)); assertThat(jobInfo.getMessages().size(), is(2)); }