Skip to content

Commit 90b2397

Browse files
committed
adding json representation for fault categories
1 parent 46d307f commit 90b2397

6 files changed

Lines changed: 110 additions & 0 deletions

File tree

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,11 @@
244244
</execution>
245245
</executions>
246246
</plugin>
247+
<plugin>
248+
<groupId>org.apache.maven.surefire</groupId>
249+
<artifactId>surefire</artifactId>
250+
<version>3.5.3</version>
251+
</plugin>
247252
</plugins>
248253
</build>
249254

src/main/java/com/webfuzzing/commons/faults/DefinedFaultCategory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.webfuzzing.commons.faults;
22

3+
import com.fasterxml.jackson.annotation.JsonFormat;
4+
35
import java.util.Objects;
46

7+
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
58
public enum DefinedFaultCategory implements FaultCategory {
69

710
/*
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[ {
2+
"code" : 100,
3+
"testCaseLabel" : "causes500_internalServerError",
4+
"fullDescription" : "TODO",
5+
"descriptiveName" : "HTTP Status 500",
6+
"label" : "F100:HTTP Status 500"
7+
}, {
8+
"code" : 101,
9+
"testCaseLabel" : "returnsSchemaInvalidResponse",
10+
"fullDescription" : "TODO",
11+
"descriptiveName" : "Received A Response From API That Is Not Valid According To Its Schema",
12+
"label" : "F101:Received A Response From API That Is Not Valid According To Its Schema"
13+
} ]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.webfuzzing.commons.faults;
2+
3+
import com.fasterxml.jackson.core.JsonProcessingException;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
6+
import java.io.IOException;
7+
import java.nio.file.Files;
8+
import java.nio.file.Paths;
9+
import java.util.Arrays;
10+
import java.util.Comparator;
11+
import java.util.List;
12+
import java.util.stream.Collectors;
13+
14+
public class FaultsToJson {
15+
16+
public static final String JSON_OUTPUT_FILEPATH = "src/main/resources/wfc/faults/fault_categories.json";
17+
18+
public static void main(String[] args) throws Exception {
19+
20+
String json = getJsonFromClass();
21+
22+
Files.write(Paths.get(JSON_OUTPUT_FILEPATH), json.getBytes());
23+
}
24+
25+
public static String getJsonFromClass(){
26+
ObjectMapper mapper = new ObjectMapper();
27+
28+
List<DefinedFaultCategory> faults = Arrays.stream(DefinedFaultCategory.values())
29+
.sorted(Comparator.comparingInt(DefinedFaultCategory::getCode))
30+
.collect(Collectors.toList());
31+
32+
String json = null;
33+
try {
34+
json = mapper
35+
.writerWithDefaultPrettyPrinter()
36+
.writeValueAsString(faults);
37+
} catch (JsonProcessingException e) {
38+
throw new RuntimeException(e);
39+
}
40+
41+
return json;
42+
}
43+
44+
public static String getJsonFromFile(){
45+
46+
String json = null;
47+
try {
48+
json = new String(Files.readAllBytes(Paths.get(JSON_OUTPUT_FILEPATH)));
49+
} catch (IOException e) {
50+
throw new RuntimeException(e);
51+
}
52+
return json;
53+
}
54+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.webfuzzing.commons.faults;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
7+
public class FaultsToJsonTest {
8+
9+
10+
@Test
11+
public void testUpdatedJson() {
12+
13+
/*
14+
if this method fails, need to recreate JSON file with FaultsToJson
15+
*/
16+
String current = FaultsToJson.getJsonFromClass();
17+
String file = FaultsToJson.getJsonFromFile();
18+
assertEquals(current, file);
19+
}
20+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.webfuzzing.commons.report;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertNotNull;
6+
7+
public class ReportTest {
8+
9+
@Test
10+
public void testGeneratedReportClasses() {
11+
12+
Report report = new Report();
13+
assertNotNull(report);
14+
}
15+
}

0 commit comments

Comments
 (0)