|
| 1 | +// Jest Snapshot v1, https://goo.gl/fbAQLP |
| 2 | + |
| 3 | +exports[`ClientConnector component (integration with AsyncAPI document) renders with default path when pathName is null 1`] = ` |
| 4 | +"@Startup |
| 5 | +@Singleton |
| 6 | +public class WebSocketClientConnector{ |
| 7 | +
|
| 8 | + @Inject |
| 9 | + WebSocketConnector<WebSocketClient> connector; |
| 10 | +
|
| 11 | +
|
| 12 | + @Inject |
| 13 | + @ConfigProperty(name = \\"com.asyncapi.WebSocketClient.base-uri\\") |
| 14 | + String baseURI; |
| 15 | +
|
| 16 | +
|
| 17 | + @PostConstruct |
| 18 | + void openAndSendMessagesWithDelay() { |
| 19 | + new Thread(() -> { |
| 20 | + try { |
| 21 | + Log.info(\\"Starting WebSocket connection attempt...\\"); |
| 22 | + // URI parameters |
| 23 | + String query = \\"\\"; |
| 24 | + |
| 25 | + String heartbeat = System.getenv(\\"HEARTBEAT\\"); |
| 26 | + if(heartbeat == null || heartbeat.isEmpty()){ |
| 27 | + throw new IllegalArgumentException(\\"Required environment variable HEARTBEAT is missing or empty\\"); |
| 28 | + } |
| 29 | + query += \\"heartbeat=\\" + URLEncoder.encode(heartbeat, StandardCharsets.UTF_8); |
| 30 | +
|
| 31 | + String bids = System.getenv(\\"BIDS\\"); |
| 32 | + if(bids == null || bids.isEmpty()){ |
| 33 | + throw new IllegalArgumentException(\\"Required environment variable BIDS is missing or empty\\"); |
| 34 | + } |
| 35 | + query += \\"&bids=\\" + URLEncoder.encode(bids, StandardCharsets.UTF_8); |
| 36 | +
|
| 37 | + String sessionId = System.getenv(\\"SESSIONID\\"); |
| 38 | + if(sessionId == null || sessionId.isEmpty()){ |
| 39 | + throw new IllegalArgumentException(\\"Required environment variable SESSIONID is missing or empty\\"); |
| 40 | + } |
| 41 | + query += \\"&sessionId=\\" + URLEncoder.encode(sessionId, StandardCharsets.UTF_8); |
| 42 | +
|
| 43 | +
|
| 44 | + String queryUri = baseURI + \\"/\\" + \\"?\\" + query; |
| 45 | + WebSocketClientConnection connection = connector.baseUri(queryUri).connectAndAwait(); |
| 46 | + Thread.sleep(120000); // Keep the connection open for 2 minutes |
| 47 | + |
| 48 | +
|
| 49 | + // Calling to close the WebSocket connection |
| 50 | + |
| 51 | +
|
| 52 | + connection.closeAndAwait(); |
| 53 | + Log.info(\\"Connection closed gracefully.\\"); |
| 54 | + Thread.sleep(1000); // Wait for a second before exiting |
| 55 | + System.exit(0); |
| 56 | + } catch (Exception e) { |
| 57 | + Log.error(\\"Error during WebSocket communication\\", e); |
| 58 | + System.exit(1); |
| 59 | + } |
| 60 | + }).start(); |
| 61 | + } |
| 62 | +}" |
| 63 | +`; |
| 64 | +
|
| 65 | +exports[`ClientConnector component (integration with AsyncAPI document) renders with default path when pathName is undefined 1`] = ` |
| 66 | +"@Startup |
| 67 | +@Singleton |
| 68 | +public class WebSocketClientConnector{ |
| 69 | +
|
| 70 | + @Inject |
| 71 | + WebSocketConnector<WebSocketClient> connector; |
| 72 | +
|
| 73 | +
|
| 74 | + @Inject |
| 75 | + @ConfigProperty(name = \\"com.asyncapi.WebSocketClient.base-uri\\") |
| 76 | + String baseURI; |
| 77 | +
|
| 78 | +
|
| 79 | + @PostConstruct |
| 80 | + void openAndSendMessagesWithDelay() { |
| 81 | + new Thread(() -> { |
| 82 | + try { |
| 83 | + Log.info(\\"Starting WebSocket connection attempt...\\"); |
| 84 | + // URI parameters |
| 85 | + String query = \\"\\"; |
| 86 | + |
| 87 | + String heartbeat = System.getenv(\\"HEARTBEAT\\"); |
| 88 | + if(heartbeat == null || heartbeat.isEmpty()){ |
| 89 | + throw new IllegalArgumentException(\\"Required environment variable HEARTBEAT is missing or empty\\"); |
| 90 | + } |
| 91 | + query += \\"heartbeat=\\" + URLEncoder.encode(heartbeat, StandardCharsets.UTF_8); |
| 92 | +
|
| 93 | + String bids = System.getenv(\\"BIDS\\"); |
| 94 | + if(bids == null || bids.isEmpty()){ |
| 95 | + throw new IllegalArgumentException(\\"Required environment variable BIDS is missing or empty\\"); |
| 96 | + } |
| 97 | + query += \\"&bids=\\" + URLEncoder.encode(bids, StandardCharsets.UTF_8); |
| 98 | +
|
| 99 | + String sessionId = System.getenv(\\"SESSIONID\\"); |
| 100 | + if(sessionId == null || sessionId.isEmpty()){ |
| 101 | + throw new IllegalArgumentException(\\"Required environment variable SESSIONID is missing or empty\\"); |
| 102 | + } |
| 103 | + query += \\"&sessionId=\\" + URLEncoder.encode(sessionId, StandardCharsets.UTF_8); |
| 104 | +
|
| 105 | +
|
| 106 | + String queryUri = baseURI + \\"/\\" + \\"?\\" + query; |
| 107 | + WebSocketClientConnection connection = connector.baseUri(queryUri).connectAndAwait(); |
| 108 | + Thread.sleep(120000); // Keep the connection open for 2 minutes |
| 109 | + |
| 110 | +
|
| 111 | + // Calling to close the WebSocket connection |
| 112 | + |
| 113 | +
|
| 114 | + connection.closeAndAwait(); |
| 115 | + Log.info(\\"Connection closed gracefully.\\"); |
| 116 | + Thread.sleep(1000); // Wait for a second before exiting |
| 117 | + System.exit(0); |
| 118 | + } catch (Exception e) { |
| 119 | + Log.error(\\"Error during WebSocket communication\\", e); |
| 120 | + System.exit(1); |
| 121 | + } |
| 122 | + }).start(); |
| 123 | + } |
| 124 | +}" |
| 125 | +`; |
| 126 | +
|
| 127 | +exports[`ClientConnector component (integration with AsyncAPI document) renders with path from fixture 1`] = ` |
| 128 | +"@Startup |
| 129 | +@Singleton |
| 130 | +public class WebSocketClientConnector{ |
| 131 | +
|
| 132 | + @Inject |
| 133 | + WebSocketConnector<WebSocketClient> connector; |
| 134 | +
|
| 135 | +
|
| 136 | + @Inject |
| 137 | + @ConfigProperty(name = \\"com.asyncapi.WebSocketClient.base-uri\\") |
| 138 | + String baseURI; |
| 139 | +
|
| 140 | +
|
| 141 | + @PostConstruct |
| 142 | + void openAndSendMessagesWithDelay() { |
| 143 | + new Thread(() -> { |
| 144 | + try { |
| 145 | + Log.info(\\"Starting WebSocket connection attempt...\\"); |
| 146 | + // URI parameters |
| 147 | + String query = \\"\\"; |
| 148 | + |
| 149 | + String heartbeat = System.getenv(\\"HEARTBEAT\\"); |
| 150 | + if(heartbeat == null || heartbeat.isEmpty()){ |
| 151 | + throw new IllegalArgumentException(\\"Required environment variable HEARTBEAT is missing or empty\\"); |
| 152 | + } |
| 153 | + query += \\"heartbeat=\\" + URLEncoder.encode(heartbeat, StandardCharsets.UTF_8); |
| 154 | +
|
| 155 | + String bids = System.getenv(\\"BIDS\\"); |
| 156 | + if(bids == null || bids.isEmpty()){ |
| 157 | + throw new IllegalArgumentException(\\"Required environment variable BIDS is missing or empty\\"); |
| 158 | + } |
| 159 | + query += \\"&bids=\\" + URLEncoder.encode(bids, StandardCharsets.UTF_8); |
| 160 | +
|
| 161 | + String sessionId = System.getenv(\\"SESSIONID\\"); |
| 162 | + if(sessionId == null || sessionId.isEmpty()){ |
| 163 | + throw new IllegalArgumentException(\\"Required environment variable SESSIONID is missing or empty\\"); |
| 164 | + } |
| 165 | + query += \\"&sessionId=\\" + URLEncoder.encode(sessionId, StandardCharsets.UTF_8); |
| 166 | +
|
| 167 | +
|
| 168 | + String queryUri = baseURI + \\"/ws\\" + \\"?\\" + query; |
| 169 | + WebSocketClientConnection connection = connector.baseUri(queryUri).connectAndAwait(); |
| 170 | + Thread.sleep(120000); // Keep the connection open for 2 minutes |
| 171 | + |
| 172 | +
|
| 173 | + // Calling to close the WebSocket connection |
| 174 | + |
| 175 | +
|
| 176 | + connection.closeAndAwait(); |
| 177 | + Log.info(\\"Connection closed gracefully.\\"); |
| 178 | + Thread.sleep(1000); // Wait for a second before exiting |
| 179 | + System.exit(0); |
| 180 | + } catch (Exception e) { |
| 181 | + Log.error(\\"Error during WebSocket communication\\", e); |
| 182 | + System.exit(1); |
| 183 | + } |
| 184 | + }).start(); |
| 185 | + } |
| 186 | +}" |
| 187 | +`; |
0 commit comments