diff --git a/lib3270j/src/test/java/haus/nightmare/lib3270j/integration/LiveHostHeadlessTest.java b/lib3270j/src/test/java/haus/nightmare/lib3270j/integration/LiveHostHeadlessTest.java index f17f6ac..1bd58ef 100644 --- a/lib3270j/src/test/java/haus/nightmare/lib3270j/integration/LiveHostHeadlessTest.java +++ b/lib3270j/src/test/java/haus/nightmare/lib3270j/integration/LiveHostHeadlessTest.java @@ -54,11 +54,12 @@ public class LiveHostHeadlessTest { CountDownLatch connectedLatch = new CountDownLatch(1); CountDownLatch screenLatch = new CountDownLatch(1); + java.util.concurrent.atomic.AtomicReference screenContentRef = new java.util.concurrent.atomic.AtomicReference<>(); client.addConnectionListener(new ConnectionListener() { @Override public void onConnectionStateChanged(ConnectionState oldState, ConnectionState newState) { - if (newState == ConnectionState.CONNECTED_3270) { + if (newState.is3270()) { connectedLatch.countDown(); } } @@ -72,7 +73,11 @@ public class LiveHostHeadlessTest { public void onScreenUpdated() { ScreenBuffer sb = client.getScreenBuffer(); if (sb != null && sb.isFormatted()) { - screenLatch.countDown(); + String text = sb.getText().trim(); + if (!text.isEmpty()) { + screenContentRef.set(text); + screenLatch.countDown(); + } } } }); @@ -80,21 +85,20 @@ public class LiveHostHeadlessTest { try { client.connect(); - boolean connected = connectedLatch.await(5, TimeUnit.SECONDS); - assertTrue(connected, "Client must establish CONNECTED_3270 state"); + boolean connected = connectedLatch.await(8, TimeUnit.SECONDS); + assertTrue(connected, "Client must establish 3270 connected state"); - boolean screenReceived = screenLatch.await(5, TimeUnit.SECONDS); + boolean screenReceived = screenLatch.await(8, TimeUnit.SECONDS); assertTrue(screenReceived, "Client must receive formatted screen from live MVS host"); - ScreenBuffer sb = client.getScreenBuffer(); - assertNotNull(sb); - - StringBuilder fullText = new StringBuilder(); - for (int i = 0; i < sb.getSize(); i++) { - char c = sb.getCell(i).ucs4; - fullText.append(c > ' ' ? c : ' '); + String screenContent = screenContentRef.get(); + if (screenContent == null || screenContent.isEmpty()) { + ScreenBuffer sb = client.getScreenBuffer(); + if (sb != null) { + screenContent = sb.getText().trim(); + } } - String screenContent = fullText.toString().trim(); + assertNotNull(screenContent, "Screen content should not be null"); assertFalse(screenContent.isEmpty(), "Screen buffer text should not be empty"); // Verify headless graphics plane is initialized without AWT