Skip to content

Commit

Permalink
Merge pull request #39 from target/PNA-2041
Browse files Browse the repository at this point in the history
PNA-2041: Withdraw check if MICR insertion fails
  • Loading branch information
rrenkor authored Mar 28, 2024
2 parents 162374e + ca98e1f commit 39170a4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public MicrController(PrinterManager printerManager, MicrManager micrManager) {
content = @Content(schema = @Schema(implementation = DeviceError.class)))
})
public void print(@Parameter(description = "Check Print Data") @Valid @RequestBody List<PrinterContent> contents) throws PrinterException {
String url = "/v1/check";
String url = "POST /v1/check";
LOGGER.info("request: " + url);
if(contents.size() < PRINT_CONTENT_SIZE){
try {
Expand All @@ -97,7 +97,7 @@ public void print(@Parameter(description = "Check Print Data") @Valid @RequestBo
content = @Content(schema = @Schema(implementation = MicrError.class)))
})
public MicrData readCheck() throws MicrException {
String url = "/v1/check";
String url = "GET /v1/check";
LOGGER.info("request: " + url);
CompletableFuture<MicrData> micrDataClient = new CompletableFuture<>();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ void insertCheck() throws MicrException {
this.micrEventListeners.forEach(listener -> listener
.micrErrorEventOccurred(new MicrErrorEvent(this, jposException)));
setCheckCancelReceived(true);
try {
// Insert may fail if a check is already inserted from a previous MICR read,
// calling withdraw to return the printer to a state that is ready for the next MICR read
withdrawCheck();
} catch (JposException jposException1) {
// withdrawCheck() logs exceptions within the method, throwing original insertion exception
}
throw new MicrException(jposException);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.target.devicemanager.components.check;

import com.target.devicemanager.common.DynamicDevice;
import com.target.devicemanager.common.entities.DeviceError;
import com.target.devicemanager.common.entities.DeviceException;
import com.target.devicemanager.common.events.ConnectionEvent;
import com.target.devicemanager.common.events.ConnectionEventListener;
Expand Down Expand Up @@ -588,6 +589,24 @@ public void insertCheck_BeginEndInsertion_UntilDone() throws JposException, Micr
verify(mockMicr).endInsertion();
}

@Test
public void insertCheck_InsertionExceptionAndWithdrawException() throws JposException {
//arrange
doThrow(new JposException(JposConst.JPOS_E_FAILURE)).when(mockMicr).endInsertion();
doThrow(new JposException(MICRConst.JPOS_EMICR_COVEROPEN)).when(mockMicr).endRemoval();

//act
try {
micrDevice.insertCheck();
} catch (MicrException micrException) {
assertEquals(micrException.getDeviceError(), DeviceError.UNEXPECTED_ERROR);
return;
}

//assert
fail("Expected exception, but got none");
}

@Test
public void withdrawCheck_BeginEndRemoval() throws JposException{
//arrange
Expand Down

0 comments on commit 39170a4

Please sign in to comment.