Skip to content

Commit 39170a4

Browse files
authored
Merge pull request #39 from target/PNA-2041
PNA-2041: Withdraw check if MICR insertion fails
2 parents 162374e + ca98e1f commit 39170a4

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/main/java/com/target/devicemanager/components/check/MicrController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public MicrController(PrinterManager printerManager, MicrManager micrManager) {
7070
content = @Content(schema = @Schema(implementation = DeviceError.class)))
7171
})
7272
public void print(@Parameter(description = "Check Print Data") @Valid @RequestBody List<PrinterContent> contents) throws PrinterException {
73-
String url = "/v1/check";
73+
String url = "POST /v1/check";
7474
LOGGER.info("request: " + url);
7575
if(contents.size() < PRINT_CONTENT_SIZE){
7676
try {
@@ -97,7 +97,7 @@ public void print(@Parameter(description = "Check Print Data") @Valid @RequestBo
9797
content = @Content(schema = @Schema(implementation = MicrError.class)))
9898
})
9999
public MicrData readCheck() throws MicrException {
100-
String url = "/v1/check";
100+
String url = "GET /v1/check";
101101
LOGGER.info("request: " + url);
102102
CompletableFuture<MicrData> micrDataClient = new CompletableFuture<>();
103103
try {

src/main/java/com/target/devicemanager/components/check/MicrDevice.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ void insertCheck() throws MicrException {
189189
this.micrEventListeners.forEach(listener -> listener
190190
.micrErrorEventOccurred(new MicrErrorEvent(this, jposException)));
191191
setCheckCancelReceived(true);
192+
try {
193+
// Insert may fail if a check is already inserted from a previous MICR read,
194+
// calling withdraw to return the printer to a state that is ready for the next MICR read
195+
withdrawCheck();
196+
} catch (JposException jposException1) {
197+
// withdrawCheck() logs exceptions within the method, throwing original insertion exception
198+
}
192199
throw new MicrException(jposException);
193200
}
194201
}

src/test/java/com/target/devicemanager/components/check/MicrDeviceTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.target.devicemanager.components.check;
22

33
import com.target.devicemanager.common.DynamicDevice;
4+
import com.target.devicemanager.common.entities.DeviceError;
45
import com.target.devicemanager.common.entities.DeviceException;
56
import com.target.devicemanager.common.events.ConnectionEvent;
67
import com.target.devicemanager.common.events.ConnectionEventListener;
@@ -588,6 +589,24 @@ public void insertCheck_BeginEndInsertion_UntilDone() throws JposException, Micr
588589
verify(mockMicr).endInsertion();
589590
}
590591

592+
@Test
593+
public void insertCheck_InsertionExceptionAndWithdrawException() throws JposException {
594+
//arrange
595+
doThrow(new JposException(JposConst.JPOS_E_FAILURE)).when(mockMicr).endInsertion();
596+
doThrow(new JposException(MICRConst.JPOS_EMICR_COVEROPEN)).when(mockMicr).endRemoval();
597+
598+
//act
599+
try {
600+
micrDevice.insertCheck();
601+
} catch (MicrException micrException) {
602+
assertEquals(micrException.getDeviceError(), DeviceError.UNEXPECTED_ERROR);
603+
return;
604+
}
605+
606+
//assert
607+
fail("Expected exception, but got none");
608+
}
609+
591610
@Test
592611
public void withdrawCheck_BeginEndRemoval() throws JposException{
593612
//arrange

0 commit comments

Comments
 (0)