|
11 | 11 |
|
12 | 12 | import com.fasterxml.jackson.databind.ObjectMapper; |
13 | 13 | import com.smartbear.har.model.HarRequest; |
| 14 | +import org.apache.commons.lang3.SystemUtils; |
14 | 15 |
|
15 | 16 | @Slf4j |
16 | | -@NoArgsConstructor(access = AccessLevel.PRIVATE) |
17 | 17 | public class FixtureBuilder { |
18 | 18 | private static final ObjectMapper objectMapper = new ObjectMapper(); |
19 | 19 | private final List<FixtureType> fixtureTypes = new ArrayList<>(); |
20 | 20 |
|
21 | | - private static final String currentPath = |
22 | | - Fixture.class.getProtectionDomain().getCodeSource().getLocation().getPath(); |
23 | | - public static final Path FIXTURES_INPUT_PATH = Paths.get(currentPath, "fixtures"); |
24 | | - public static final Path FIXTURES_OUTPUT_PATH = Paths.get(currentPath, "output"); |
| 21 | + private final Path input; |
| 22 | + private final Path output; |
| 23 | + |
| 24 | + private FixtureBuilder(){ |
| 25 | + String currentPath = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); |
| 26 | + currentPath = SystemUtils.IS_OS_WINDOWS? currentPath.substring(1) : currentPath; |
| 27 | + this.input = Paths.get(currentPath, "fixtures"); |
| 28 | + this.output = Paths.get(currentPath, "output"); |
| 29 | + } |
25 | 30 |
|
26 | 31 | public static FixtureBuilder builder() { |
27 | 32 | return new FixtureBuilder(); |
28 | 33 | } |
29 | 34 |
|
| 35 | + |
| 36 | + public Path getInput() { |
| 37 | + return input; |
| 38 | + } |
| 39 | + |
| 40 | + public Path getOutput() { |
| 41 | + return output; |
| 42 | + } |
| 43 | + |
30 | 44 | public FixtureBuilder applicationFormEncoded() { |
31 | 45 | this.fixtureTypes.add(FixtureType.APPLICATION_FORM_ENCODED); |
32 | 46 | return this; |
@@ -101,8 +115,7 @@ public List<Fixture> build() throws Exception { |
101 | 115 | List<Fixture> fixtures = new ArrayList<>(); |
102 | 116 | for (FixtureType fixtureType : fixtureTypes) { |
103 | 117 | Path filePath = |
104 | | - Paths.get( |
105 | | - FIXTURES_INPUT_PATH.toString(), String.format("%s.json", fixtureType.getName())); |
| 118 | + Paths.get(input.toString(), String.format("%s.json", fixtureType.getName())); |
106 | 119 | HarRequest harRequest = objectMapper.readValue(filePath.toFile(), HarRequest.class); |
107 | 120 | fixtures.add(new Fixture(fixtureType, harRequest)); |
108 | 121 | } |
|
0 commit comments