|
1 | 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
2 | 2 | // SPDX-License-Identifier: Apache-2.0 |
3 | 3 |
|
| 4 | +import com.java.inspector.InspectorScenario; |
4 | 5 | import org.slf4j.Logger; |
5 | 6 | import org.slf4j.LoggerFactory; |
6 | 7 | import com.java.inspector.HelloInspector; |
|
15 | 16 | import software.amazon.awssdk.regions.Region; |
16 | 17 | import software.amazon.awssdk.services.inspector2.Inspector2Client; |
17 | 18 |
|
| 19 | +import java.io.ByteArrayInputStream; |
| 20 | +import java.io.ByteArrayOutputStream; |
| 21 | +import java.io.InputStream; |
| 22 | +import java.io.PrintStream; |
| 23 | +import java.util.Collections; |
| 24 | + |
18 | 25 | import static org.junit.jupiter.api.Assertions.*; |
19 | 26 |
|
20 | 27 | @TestInstance(TestInstance.Lifecycle.PER_METHOD) |
@@ -101,4 +108,40 @@ public void testInspectorActionsIntegration() { |
101 | 108 |
|
102 | 109 | logger.info("Test 2 passed"); |
103 | 110 | } |
| 111 | + |
| 112 | + |
| 113 | + @Test |
| 114 | + @Tag("IntegrationTest") |
| 115 | + @Order(3) |
| 116 | + public void testInspectorScenarioEndToEnd() { |
| 117 | + assertDoesNotThrow(() -> { |
| 118 | + |
| 119 | + // The scenario calls scanner.nextLine() repeatedly. |
| 120 | + // We simulate user input by providing many "c" lines. |
| 121 | + String simulatedInput = String.join("\n", |
| 122 | + Collections.nCopies(20, "c")) + "\n"; |
| 123 | + |
| 124 | + InputStream originalIn = System.in; |
| 125 | + PrintStream originalOut = System.out; |
| 126 | + |
| 127 | + try { |
| 128 | + // Redirect System.in to simulated input |
| 129 | + ByteArrayInputStream testIn = new ByteArrayInputStream(simulatedInput.getBytes()); |
| 130 | + System.setIn(testIn); |
| 131 | + |
| 132 | + // Capture System.out so logs don’t spam the console |
| 133 | + System.setOut(new PrintStream(new ByteArrayOutputStream())); |
| 134 | + |
| 135 | + // Run the scenario |
| 136 | + InspectorScenario.main(new String[]{}); |
| 137 | + |
| 138 | + } finally { |
| 139 | + // Restore original I/O streams |
| 140 | + System.setIn(originalIn); |
| 141 | + System.setOut(originalOut); |
| 142 | + } |
| 143 | + }); |
| 144 | + |
| 145 | + logger.info("Test 3 (Scenario end-to-end) passed"); |
| 146 | + } |
104 | 147 | } |
0 commit comments