JobBuildService { @Transactional public Optional<BuildOrder> peekBuildFor(String workerName) { workerService.onHeartbeat(workerName); Worker worker = workerDao.findByName(workerName).get(); Optional<JobBuild> jobBuildOptional = jobBuildDao.findByStatusAndWorker(JobBuild.Status.READY, worker); return jobBuildOptional.map(jobBuild -> prepareBuildOrder(jobBuild, worker)); }  @Transactional void prepareJobs(Build build, Dickfile dickfile); @Transactional void buildStage(Build build, Dickfile dickfile, Stage stage); @Transactional Optional<BuildOrder> peekBuildFor(String workerName); boolean isStopped(Long id); @Transactional void reportProgress(Long id, String partialLog); @Transactional void reportFailure(Long id, String fullLog); @Transactional void reportSuccess(Long id, String fullLog); Build.Status updateBuildStatus(Build build); @Transactional void stop(Build build); @Transactional List<LogChunkModel> getLogChunks(Long id, Date creationDate); @Transactional OutputModel getOutput(Long id); @Transactional void deleteJobBuilds(Build build);  }
@Test public void shouldReturnBuildOrder() { Worker worker = produceWorker(Worker.Status.READY); Build build = produceBuild(); JobBuild jobBuild = produceJobBuild(worker, build, JobBuild.Status.READY); BuildOrder buildOrder = jobBuildService.peekBuildFor("testingWorker").get(); assertThat(buildOrder).isNotNull(); assertThat(buildOrder.getBuildId()).isEqualTo(jobBuild.getId()); assertThat(buildOrder.getCommands()).containsExactly("echo bar"); assertThat(buildOrder.getDockerImage()).isEqualTo("centos"); assertThat(buildOrder.getEnvironment()).extracting("name", "value") .contains(Tuple.tuple("FOO", "bar")); Optional<BuildOrder> optional = jobBuildService.peekBuildFor("testingWorker"); assertThat(optional.isPresent()).isFalse(); }