Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for Scanner Name in Peripherals Endpoint #46

Merged
merged 5 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ public DeviceHealth findDevStatus(String devName) {
switch (devName){
case "flatbedscanner":
if(deviceAvailabilitySingleton.getScannerManager() != null) {
healthStatus = deviceAvailabilitySingleton.getScannerManager().getStatus().get(0).getHealthStatus();
healthStatus = deviceAvailabilitySingleton.getScannerManager().getScannerHealthStatus("FLATBED");
} else {
LOGGER.trace("Failed to Connect to " + devName);
}
break;
case "handscanner":
if(deviceAvailabilitySingleton.getScannerManager() != null) {
healthStatus = deviceAvailabilitySingleton.getScannerManager().getStatus().get(1).getHealthStatus();
healthStatus = deviceAvailabilitySingleton.getScannerManager().getScannerHealthStatus("HANDHELD");
} else {
LOGGER.trace("Failed to Connect to " + devName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,20 @@ public List<DeviceHealthResponse> getStatus() {
}
}

public DeviceHealth getScannerHealthStatus(String scannerName) {
public DeviceHealth getScannerHealthStatus(String scannerType) {
String scannerName = "";
for (ScannerDevice scanner : scanners) {
switch (scannerType) {
case "FLATBED":
case "HANDHELD":
if (scanner.getScannerType().equals(scannerType)) {
scannerName = scanner.getDeviceName();
}
break;
default:
scannerName = "";
}
}
for(DeviceHealthResponse deviceHealthResponse: getStatus()) {
if(deviceHealthResponse.getDeviceName().equals(scannerName)) {
return deviceHealthResponse.getHealthStatus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ void Test_findDevStatus_Scale() {
assertEquals(DeviceHealth.READY, deviceAvailabilityService.findDevStatus("scale"));
}

// These tests fail because of a known issue, we will revert back when a permanent solution is found
/*@Test
@Test
void Test_findDevStatus_FlatbedScanner() {
//arrange
DeviceHealth expected = new DeviceHealthResponse("FLATBED", DeviceHealth.NOTREADY).getHealthStatus();
Expand All @@ -98,7 +97,7 @@ void Test_findDevStatus_HandScanner() {

//assert
assertEquals(expected, actual);
}*/
}

@Test
void Test_findDevStatus_LineDisplay() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,12 +605,16 @@ public void getStatus_WhenCacheNull_CheckHealth() {
void getScannerHealthStatus_FlatbedScanner() {
//arrange
List<DeviceHealthResponse> devReady = new ArrayList<>();
devReady.add(new DeviceHealthResponse("FLATBED", DeviceHealth.READY));
devReady.add(new DeviceHealthResponse("HANDHELD", DeviceHealth.READY));
devReady.add(new DeviceHealthResponse("Zebra", DeviceHealth.READY));
devReady.add(new DeviceHealthResponse("Honeywell", DeviceHealth.READY));
Mockito.doReturn(devReady).when(scannerManagerCache).getStatus();
Mockito.doReturn("Honeywell").when(mockHandheldScannerDevice).getDeviceName();
Mockito.doReturn("HANDHELD").when(mockHandheldScannerDevice).getScannerType();
Mockito.doReturn("Zebra").when(mockFlatbedScannerDevice).getDeviceName();
Mockito.doReturn("FLATBED").when(mockFlatbedScannerDevice).getScannerType();

//act
DeviceHealth actual = scannerManagerCache.getScannerHealthStatus("HANDHELD");
DeviceHealth actual = scannerManagerCache.getScannerHealthStatus("FLATBED");

//assert
assertEquals(DeviceHealth.READY, actual);
Expand All @@ -620,9 +624,14 @@ void getScannerHealthStatus_FlatbedScanner() {
void getScannerHealthStatus_HandScanner() {
//arrange
List<DeviceHealthResponse> devReady = new ArrayList<>();
devReady.add(new DeviceHealthResponse("FLATBED", DeviceHealth.READY));
devReady.add(new DeviceHealthResponse("HANDHELD", DeviceHealth.READY));
devReady.add(new DeviceHealthResponse("Zebra", DeviceHealth.READY));
devReady.add(new DeviceHealthResponse("Honeywell", DeviceHealth.READY));
Mockito.doReturn(devReady).when(scannerManagerCache).getStatus();
Mockito.doReturn("Honeywell").when(mockHandheldScannerDevice).getDeviceName();
Mockito.doReturn("HANDHELD").when(mockHandheldScannerDevice).getScannerType();
Mockito.doReturn("Zebra").when(mockFlatbedScannerDevice).getDeviceName();
Mockito.doReturn("FLATBED").when(mockFlatbedScannerDevice).getScannerType();


//act
DeviceHealth actual = scannerManagerCache.getScannerHealthStatus("HANDHELD");
Expand All @@ -634,9 +643,12 @@ void getScannerHealthStatus_HandScanner() {
@Test
void getScannerHealthStatus_HandheldScanner_missing() {
//arrange
scannerDevices.remove(mockHandheldScannerDevice);
List<DeviceHealthResponse> devReady = new ArrayList<>();
devReady.add(new DeviceHealthResponse("FLATBED", DeviceHealth.READY));
devReady.add(new DeviceHealthResponse("Zebra", DeviceHealth.READY));
Mockito.doReturn(devReady).when(scannerManagerCache).getStatus();
Mockito.doReturn("Zebra").when(mockFlatbedScannerDevice).getDeviceName();
Mockito.doReturn("FLATBED").when(mockFlatbedScannerDevice).getScannerType();

//act
DeviceHealth actual = scannerManagerCache.getScannerHealthStatus("HANDHELD");
Expand Down