Skip to content

Commit 13c4c27

Browse files
committed
Adding an integration test for testing the usage of absolute paths in Scenario annotation
Adding an integration test for testing the usage of absolute paths in Scenario annotation
1 parent 9659ccd commit 13c4c27

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package org.jsmart.zerocode.testhelp.tests;
2+
3+
import java.io.ByteArrayOutputStream;
4+
import java.io.File;
5+
import java.io.FileNotFoundException;
6+
import java.io.IOException;
7+
import java.io.InputStream;
8+
import java.nio.charset.StandardCharsets;
9+
import java.nio.file.Files;
10+
import java.nio.file.Path;
11+
import java.nio.file.Paths;
12+
import java.nio.file.StandardOpenOption;
13+
14+
import org.jsmart.zerocode.core.domain.Scenario;
15+
import org.jsmart.zerocode.core.domain.TargetEnv;
16+
import org.jsmart.zerocode.core.runner.ZeroCodeUnitRunner;
17+
import org.junit.BeforeClass;
18+
import org.junit.Test;
19+
import org.junit.runner.RunWith;
20+
21+
@TargetEnv("github_host.properties")
22+
@RunWith(ZeroCodeUnitRunner.class)
23+
public class ScenarioAbsolutePathTest {
24+
25+
// Trying in target folder
26+
private static String folder1File1 = "target/temp/unit_test_files/cherry_pick_tests/folder_a/test_case_1.json";
27+
private static String sourceResourceFile = "helloworld/hello_world_status_ok_assertions.json";
28+
29+
@BeforeClass
30+
public static void start() {
31+
System.out.println("INSIDE BEFORE");
32+
Path path = Paths.get(folder1File1);
33+
try {
34+
Files.createDirectories(path.getParent());
35+
String absolutePath = path.toFile().getAbsolutePath();
36+
File f1 = new File(absolutePath);
37+
f1.createNewFile();
38+
39+
InputStream resourceStream = Thread.currentThread()
40+
.getContextClassLoader()
41+
.getResourceAsStream(sourceResourceFile);
42+
if (resourceStream == null) {
43+
throw new FileNotFoundException(
44+
"Resource file '" + sourceResourceFile + "' not found in test resources.");
45+
}
46+
47+
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
48+
byte[] buffer = new byte[1024];
49+
int length;
50+
51+
while ((length = resourceStream.read(buffer)) != -1) {
52+
outStream.write(buffer, 0, length);
53+
}
54+
55+
String contents = outStream.toString("UTF-8");
56+
57+
Files.write(path, contents.getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE,
58+
StandardOpenOption.TRUNCATE_EXISTING);
59+
60+
} catch (IOException exx) {
61+
throw new RuntimeException("Create file '" + folder1File1 + "' Exception" + exx);
62+
}
63+
}
64+
65+
@Test
66+
@Scenario("target/temp/unit_test_files/cherry_pick_tests/folder_a/test_case_1.json")
67+
public void testAbsolutePathGet() throws Exception {
68+
}
69+
}

0 commit comments

Comments
 (0)