### Question:
DelfiInitialIngestService implements InitialIngestService { @Override public IngestResult ingestManifest(LoadManifest loadManifest, MessageHeaders headers) { log.debug("Request to ingest file with following parameters: {}, and headers : {}", loadManifest, headers); checkPreconditions(headers); IngestHeaders ingestHeaders = ingestHeadersMapper.toIngestHeaders(headers); log.debug("Parse ingest headers. Headers: {}", ingestHeaders); authenticationService .checkAuthentication(ingestHeaders.getAuthorizationToken(), ingestHeaders.getPartition()); loadManifestValidationService.validateManifest(loadManifest); String jobId = jobStatusService.initInjectJob(); IngestMessage ingestMessage = IngestMessage.builder() .ingestJobId(jobId) .loadManifest(loadManifest) .headers(ingestHeaders) .build(); log.debug("Send ingest message for processing. Message: {}", ingestMessage); ingestGateway.sendIngestToPubSub(ingestMessage); log.debug("Request to ingest with parameters : {}, init the injection jobId: {}", loadManifest, jobId); return IngestResult.builder() .jobId(jobId) .build(); }  @Override IngestResult ingestManifest(LoadManifest loadManifest,
      MessageHeaders headers);  }### Answer:
@Test public void shouldInitiateIngestAndSendMessageToGateway() { LoadManifest loadManifest = LoadManifest.builder().build(); MessageHeaders headers = getMessageHeaders(); given(jobStatusService.initInjectJob()).willReturn(INGEST_JOB_ID); IngestResult ingestResult = initialIngestService.ingestManifest(loadManifest, headers); then(ingestResult).isEqualTo(IngestResult.builder() .jobId(INGEST_JOB_ID) .build()); InOrder inOrder = inOrder(jobStatusService, loadManifestValidationService, ingestGateway, authenticationService, ingestHeadersMapper); inOrder.verify(ingestHeadersMapper).toIngestHeaders(headers); inOrder.verify(authenticationService).checkAuthentication(AUTHORIZATION_TOKEN, PARTITION); inOrder.verify(loadManifestValidationService).validateManifest(loadManifest); inOrder.verify(jobStatusService).initInjectJob(); inOrder.verify(ingestGateway).sendIngestToPubSub(ingestMessageCaptor.capture()); inOrder.verifyNoMoreInteractions(); then(ingestMessageCaptor.getValue()).isEqualTo(getIngestMessage(loadManifest)); }
@Test public void shouldThrowUnauthorizedExceptionWhenCheckAuthorizationIsFailed() { LoadManifest loadManifest = LoadManifest.builder().build(); MessageHeaders headers = getMessageHeaders(); willThrow(OsduUnauthorizedException.class) .given(authenticationService).checkAuthentication(AUTHORIZATION_TOKEN, PARTITION); Throwable thrown = catchThrowable(() -> initialIngestService.ingestManifest(loadManifest, headers)); then(thrown).isInstanceOf(OsduUnauthorizedException.class); InOrder inOrder = inOrder(jobStatusService, loadManifestValidationService, ingestGateway, authenticationService, ingestHeadersMapper); inOrder.verify(ingestHeadersMapper).toIngestHeaders(headers); inOrder.verify(authenticationService).checkAuthentication(AUTHORIZATION_TOKEN, PARTITION); inOrder.verify(loadManifestValidationService, never()).validateManifest(any()); inOrder.verify(jobStatusService, never()).initInjectJob(); inOrder.verify(ingestGateway, never()).sendIngestToPubSub(any()); inOrder.verifyNoMoreInteractions(); }
@Test public void shouldThrowIngestExceptionWhenManifestIsInvalid() { LoadManifest loadManifest = LoadManifest.builder().build(); MessageHeaders headers = getMessageHeaders(); willThrow(IngestException.class).given(loadManifestValidationService).validateManifest(loadManifest); Throwable thrown = catchThrowable(() -> initialIngestService.ingestManifest(loadManifest, headers)); then(thrown).isInstanceOf(IngestException.class); InOrder inOrder = inOrder(jobStatusService, loadManifestValidationService, ingestGateway, authenticationService, ingestHeadersMapper); inOrder.verify(ingestHeadersMapper).toIngestHeaders(headers); inOrder.verify(authenticationService).checkAuthentication(AUTHORIZATION_TOKEN, PARTITION); inOrder.verify(loadManifestValidationService).validateManifest(loadManifest); inOrder.verify(jobStatusService, never()).initInjectJob(); inOrder.verify(ingestGateway, never()).sendIngestToPubSub(any()); inOrder.verifyNoMoreInteractions(); }