-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MODEXPW-528] Add new tests for exporting EDI
- Loading branch information
1 parent
462fdda
commit 463fc94
Showing
8 changed files
with
240 additions
and
96 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
...n/java/org/folio/dew/batch/acquisitions/edifact/exceptions/EntitiesNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.folio.dew.batch.acquisitions.edifact.exceptions; | ||
|
||
public class EntitiesNotFoundException extends RuntimeException { | ||
|
||
private static final String EXCEPTION_MESSAGE = "Entities not found: %s"; | ||
|
||
public EntitiesNotFoundException(Class<?> entityClass) { | ||
super(EXCEPTION_MESSAGE.formatted(entityClass.getSimpleName()), null, false, false); | ||
} | ||
|
||
} |
9 changes: 0 additions & 9 deletions
9
...main/java/org/folio/dew/batch/acquisitions/edifact/exceptions/OrderNotFoundException.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
...est/java/org/folio/dew/batch/acquisitions/edifact/jobs/MapToEdifactClaimsTaskletTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package org.folio.dew.batch.acquisitions.edifact.jobs; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.folio.dew.utils.QueryUtils.convertIdsToCqlQuery; | ||
import static org.folio.dew.utils.TestUtils.getMockData; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyList; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.doReturn; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.folio.dew.domain.dto.Piece; | ||
import org.folio.dew.domain.dto.PieceCollection; | ||
import org.folio.dew.domain.dto.PoLine; | ||
import org.folio.dew.domain.dto.PoLineCollection; | ||
import org.folio.dew.domain.dto.PurchaseOrder; | ||
import org.folio.dew.domain.dto.PurchaseOrderCollection; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.batch.core.BatchStatus; | ||
import org.springframework.batch.core.ExitStatus; | ||
import org.springframework.batch.core.Job; | ||
import org.springframework.batch.core.JobExecution; | ||
import org.springframework.batch.test.JobLauncherTestUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
|
||
import lombok.SneakyThrows; | ||
|
||
class MapToEdifactClaimsTaskletTest extends MapToEdifactTaskletAbstractTest { | ||
|
||
private static final String SAMPLE_PIECES_PATH = "edifact/acquisitions/pieces_collection.json"; | ||
|
||
@Autowired | ||
Job edifactClaimsExportJob; | ||
|
||
private List<PurchaseOrder> orders; | ||
private List<PoLine> poLines; | ||
private List<Piece> pieces; | ||
private List<String> pieceIds; | ||
|
||
@BeforeEach | ||
@SneakyThrows | ||
protected void setUp() { | ||
super.setUp(); | ||
edifactExportJob = edifactClaimsExportJob; | ||
orders = objectMapper.readValue(getMockData(SAMPLE_PURCHASE_ORDERS_PATH), PurchaseOrderCollection.class).getPurchaseOrders(); | ||
poLines = objectMapper.readValue(getMockData(SAMPLE_PO_LINES_PATH), PoLineCollection.class).getPoLines(); | ||
pieces = objectMapper.readValue(getMockData(SAMPLE_PIECES_PATH), PieceCollection.class).getPieces(); | ||
|
||
pieceIds = pieces.stream().map(Piece::getId).toList(); | ||
doReturn(pieces).when(ordersService).getPiecesByIdsAndReceivingStatus(pieceIds, Piece.ReceivingStatusEnum.LATE); | ||
} | ||
|
||
@Test | ||
void testEdifactClaimsExport() throws Exception { | ||
JobLauncherTestUtils testLauncher = createTestLauncher(edifactExportJob); | ||
String poLineQuery = convertIdsToCqlQuery(pieces.stream().map(Piece::getPoLineId).toList()); | ||
|
||
doReturn(poLines).when(ordersService).getPoLinesByQuery(poLineQuery); | ||
doReturn(orders).when(ordersService).getPurchaseOrdersByIds(anyList()); | ||
doReturn("test1").when(purchaseOrdersToEdifactMapper).convertOrdersToEdifact(any(), any(), anyString()); | ||
|
||
var exportConfig = getEdifactExportConfig(SAMPLE_EDI_ORDERS_EXPORT, pieceIds); | ||
JobExecution jobExecution = testLauncher.launchStep(MAP_TO_EDIFACT_STEP, getJobParameters(exportConfig)); | ||
|
||
assertThat(jobExecution.getExitStatus()).isEqualTo(ExitStatus.COMPLETED); | ||
verify(ordersService).getPiecesByIdsAndReceivingStatus(pieceIds, Piece.ReceivingStatusEnum.LATE); | ||
verify(ordersService).getPoLinesByQuery(poLineQuery); | ||
verify(ordersService).getPurchaseOrdersByIds(anyList()); | ||
} | ||
|
||
@Test | ||
void testEdifactClaimsExportNoPiecesFound() throws Exception { | ||
JobLauncherTestUtils testLauncher = createTestLauncher(edifactExportJob); | ||
doReturn(List.of()).when(ordersService).getPiecesByIdsAndReceivingStatus(pieceIds, Piece.ReceivingStatusEnum.LATE); | ||
|
||
var exportConfig = getEdifactExportConfig(SAMPLE_EDI_ORDERS_EXPORT, pieceIds); | ||
JobExecution jobExecution = testLauncher.launchStep(MAP_TO_EDIFACT_STEP, getJobParameters(exportConfig)); | ||
|
||
assertThat(jobExecution.getExitStatus().getExitCode()).isEqualTo(ExitStatus.FAILED.getExitCode()); | ||
assertThat(jobExecution.getExitStatus().getExitDescription()).contains("Entities not found: Piece"); | ||
verify(ordersService).getPiecesByIdsAndReceivingStatus(pieceIds, Piece.ReceivingStatusEnum.LATE); | ||
} | ||
|
||
@Test | ||
void testEdifactClaimsExportMissingRequiredFields() throws Exception { | ||
JobLauncherTestUtils testLauncher = createTestLauncher(edifactExportJob); | ||
var exportConfig = getEdifactExportConfig(SAMPLE_EDI_ORDERS_EXPORT, List.of()); | ||
|
||
JobExecution jobExecution = testLauncher.launchStep(MAP_TO_EDIFACT_STEP, getJobParameters(exportConfig)); | ||
var status = new ArrayList<>(jobExecution.getStepExecutions()).get(0).getStatus(); | ||
|
||
assertEquals(BatchStatus.FAILED, status); | ||
assertThat(jobExecution.getExitStatus().getExitCode()).isEqualTo(ExitStatus.FAILED.getExitCode()); | ||
assertThat(jobExecution.getExitStatus().getExitDescription()).contains("Export configuration is incomplete, missing required fields: [claimPieceIds]"); | ||
} | ||
|
||
@Override | ||
protected ObjectNode getEdifactExportConfig(String path) throws IOException { | ||
return getEdifactExportConfig(path, pieceIds); | ||
} | ||
|
||
protected ObjectNode getEdifactExportConfig(String path, List<String> pieceIds) throws IOException { | ||
var exportConfig = super.getEdifactExportConfig(path); | ||
var arr = exportConfig.putArray("claimPieceIds"); | ||
pieceIds.forEach(arr::add); | ||
return exportConfig; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.