|
11 | 11 | import com.github.tomakehurst.wiremock.client.WireMock; |
12 | 12 | import com.github.tomakehurst.wiremock.junit.WireMockRule; |
13 | 13 | import edu.ohio.ais.rundeck.util.OAuthClientTest; |
| 14 | +import org.apache.tools.ant.util.FileUtils; |
| 15 | +import org.junit.After; |
14 | 16 | import org.junit.Before; |
15 | 17 | import org.junit.Rule; |
16 | 18 | import org.junit.Test; |
17 | 19 | import org.mockito.Mockito; |
18 | 20 |
|
| 21 | +import java.io.File; |
| 22 | +import java.io.IOException; |
| 23 | +import java.nio.file.Files; |
| 24 | +import java.nio.file.Path; |
| 25 | +import java.nio.file.Paths; |
19 | 26 | import java.util.HashMap; |
20 | 27 | import java.util.Map; |
21 | 28 |
|
@@ -46,6 +53,8 @@ public class HttpWorkflowNodeStepPluginTest { |
46 | 53 | protected PluginStepContext pluginContext; |
47 | 54 | protected PluginLogger pluginLogger; |
48 | 55 | protected INodeEntry node; |
| 56 | + protected File resourcePath = new File("src" + File.separator + "test" + File.separator + "resources"); |
| 57 | + protected File testResource = new File(resourcePath + File.separator + "example.json"); |
49 | 58 |
|
50 | 59 | /** |
51 | 60 | * Setup options for simple execution for the given method. |
@@ -92,9 +101,22 @@ public Map<String, Object> getOAuthOptions(String method) { |
92 | 101 | return options; |
93 | 102 | } |
94 | 103 |
|
| 104 | + private static String readFileAsString(String filePath) throws IOException { |
| 105 | + Path path = Paths.get(filePath); |
| 106 | + byte[] bytes = Files.readAllBytes(path); |
| 107 | + return new String(bytes); |
| 108 | + } |
| 109 | + |
95 | 110 | @Rule |
96 | 111 | public WireMockRule wireMockRule = new WireMockRule(18089); |
97 | 112 |
|
| 113 | + @After |
| 114 | + public void tearDown(){ |
| 115 | + if( Files.exists(this.testResource.toPath()) ){ |
| 116 | + FileUtils.delete(this.testResource); |
| 117 | + } |
| 118 | + } |
| 119 | + |
98 | 120 | @Before |
99 | 121 | public void setUp() { |
100 | 122 | plugin = new HttpWorkflowNodeStepPlugin(); |
@@ -346,4 +368,34 @@ public void canPrintNoContent() throws NodeStepException { |
346 | 368 |
|
347 | 369 | this.plugin.executeNodeStep(pluginContext, options, node ); |
348 | 370 | } |
| 371 | + |
| 372 | + @Test |
| 373 | + public void canPrintContentToFile() throws NodeStepException, IOException { |
| 374 | + Map<String, Object> options = new HashMap<>(); |
| 375 | + |
| 376 | + options.put("remoteUrl", OAuthClientTest.BASE_URI + NO_CONTENT_URL); |
| 377 | + options.put("method", "GET"); |
| 378 | + options.put("printResponse",true); |
| 379 | + options.put("printResponseToFile",true); |
| 380 | + options.put("file", testResource); |
| 381 | + |
| 382 | + assertNotNull(Paths.get(testResource.toString())); |
| 383 | + this.plugin.executeNodeStep(pluginContext, options, node ); |
| 384 | + assertNotNull(readFileAsString(testResource.toString())); |
| 385 | + } |
| 386 | + |
| 387 | + @Test |
| 388 | + public void canPrintContentToFileIfPrintResponseIsFalse() throws NodeStepException, IOException { |
| 389 | + Map<String, Object> options = new HashMap<>(); |
| 390 | + |
| 391 | + options.put("remoteUrl", OAuthClientTest.BASE_URI + NO_CONTENT_URL); |
| 392 | + options.put("method", "GET"); |
| 393 | + options.put("printResponse",false); |
| 394 | + options.put("printResponseToFile",true); |
| 395 | + options.put("file", testResource); |
| 396 | + |
| 397 | + assertNotNull(Paths.get(testResource.toString())); |
| 398 | + this.plugin.executeNodeStep(pluginContext, options, node ); |
| 399 | + assertNotNull(readFileAsString(testResource.toString())); |
| 400 | + } |
349 | 401 | } |
0 commit comments