### Question:
PDSCreateJobService { @UseCaseUserCreatesJob(@PDSStep(name="service call",description = "job will be created, serverId will be used to store new job",number=2)) public PDSJobCreateResult createJob(PDSJobConfiguration configuration) { configurationValidator.assertPDSConfigurationValid(configuration); PDSJob job = new PDSJob(); job.created = LocalDateTime.now(); job.state = PDSJobStatusState.CREATED; job.owner = userContextService.getUserId(); job.setServerId(serverConfigurationService.getServerId()); try { job.jsonConfiguration=configuration.toJSON(); } catch (PDSJSONConverterException e) { throw new PDSNotAcceptableException("Configuration conversion failure:"+e.getMessage()); } job = repository.save(job); return new PDSJobCreateResult(job.getUUID()); }  @UseCaseUserCreatesJob(@PDSStep(name="service call",description = "job will be created, serverId will be used to store new job",number=2)) PDSJobCreateResult createJob(PDSJobConfiguration configuration);  }### Answer:
@Test public void creating_a_job_returns_jobUUD_of_stored_job_in_repository() { PDSJobConfiguration configuration = new PDSJobConfiguration(); configuration.setSechubJobUUID(sechubJobUUID); PDSJobCreateResult result = serviceToTest.createJob(configuration); assertNotNull(result); UUID pdsJobUUID = result.getJobUUID(); assertEquals(createdJob1UUID, pdsJobUUID); }
@Test public void creating_a_job_sets_current_user_as_owner() { PDSJobConfiguration configuration = new PDSJobConfiguration(); PDSJobCreateResult result = serviceToTest.createJob(configuration); assertNotNull(result); ArgumentCaptor<PDSJob> jobCaptor = ArgumentCaptor.forClass(PDSJob.class); verify(repository).save(jobCaptor.capture()); assertEquals("callerName", jobCaptor.getValue().getOwner()); }
@Test public void creating_a_job_sets_configuration_as_json() throws Exception{ PDSJobConfiguration configuration = new PDSJobConfiguration(); serviceToTest.createJob(configuration); ArgumentCaptor<PDSJob> jobCaptor = ArgumentCaptor.forClass(PDSJob.class); verify(repository).save(jobCaptor.capture()); String json = configuration.toJSON(); assertEquals("{\"parameters\":[]}", json); assertEquals(json, jobCaptor.getValue().getJsonConfiguration()); }
@Test public void creating_a_job_calls_configurationValidator() { PDSJobConfiguration configuration = new PDSJobConfiguration(); serviceToTest.createJob(configuration); verify(configurationValidator).assertPDSConfigurationValid(configuration); }
@Test public void creating_a_job_fires_exception_thrown_by_validator() { PDSJobConfiguration configuration = new PDSJobConfiguration(); doThrow(new PDSNotAcceptableException("ups")).when(configurationValidator).assertPDSConfigurationValid(configuration); expected.expect(PDSNotAcceptableException.class); expected.expectMessage("ups"); serviceToTest.createJob(configuration); }