Skip to content

Commit 9e1df72

Browse files
committed
adding code for faults
1 parent 08f1e20 commit 9e1df72

3 files changed

Lines changed: 116 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.webfuzzing.commons.faults;
2+
3+
import java.util.Objects;
4+
5+
public enum DefinedFaultCategory implements FaultCategory {
6+
7+
/*
8+
TODO
9+
code label are still up to discussion and re-arrangement...
10+
*/
11+
12+
//1xx: HTTP
13+
14+
HTTP_STATUS_500(100, "HTTP Status 500", "causes500_internalServerError",
15+
"TODO"),
16+
SCHEMA_INVALID_RESPONSE(101, "Received A Response From API That Is Not Valid According To Its Schema", "returnsSchemaInvalidResponse",
17+
"TODO"),
18+
19+
20+
;
21+
22+
private final int code;
23+
24+
private final String name;
25+
26+
private final String testCaseLabel;
27+
28+
private final String fullDescription;
29+
30+
DefinedFaultCategory(int code, String name, String testCaseLabel, String fullDescription) {
31+
this.code = code;
32+
this.name = Objects.requireNonNull(name);
33+
this.testCaseLabel = Objects.requireNonNull(testCaseLabel);
34+
this.fullDescription = Objects.requireNonNull(fullDescription);
35+
}
36+
37+
@Override
38+
public int getCode() {
39+
return code;
40+
}
41+
42+
@Override
43+
public String getDescriptiveName() {
44+
return name;
45+
}
46+
47+
@Override
48+
public String getTestCaseLabel() {
49+
return testCaseLabel;
50+
}
51+
52+
@Override
53+
public String getFullDescription() {
54+
return fullDescription;
55+
}
56+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.webfuzzing.commons.faults;
2+
3+
public interface FaultCategory {
4+
5+
6+
/**
7+
* A unique code identifying this fault category
8+
*/
9+
public int getCode();
10+
11+
/**
12+
* A short descriptive name to explain the category
13+
*/
14+
public String getDescriptiveName();
15+
16+
/**
17+
* A short label that can be used in test case naming
18+
*/
19+
public String getTestCaseLabel();
20+
21+
/**
22+
* A full, lengthy description of this fault category.
23+
* It should not contain any special formatting, as this field will be used for documentation
24+
* in different context, eg, markdown and HTML.
25+
*/
26+
public String getFullDescription();
27+
28+
/**
29+
* A descriptive identifier for this category.
30+
* Not a full, lengthy description.
31+
* For example based on code and name
32+
*/
33+
public default String getLabel() {
34+
return "F" + getCode() + ":" + getDescriptiveName();
35+
}
36+
37+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.webfuzzing.commons.faults;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.util.Arrays;
6+
import java.util.stream.Collectors;
7+
8+
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
10+
class FaultCategoryTest {
11+
12+
@Test
13+
public void testUniqueCodes() {
14+
15+
int total = DefinedFaultCategory.values().length;
16+
int unique = Arrays.stream(DefinedFaultCategory.values())
17+
.map(c -> c.getCode())
18+
.collect(Collectors.toSet())
19+
.size();
20+
21+
assertEquals(total, unique, "Mismatch: " + total + " != " + unique);
22+
}
23+
}

0 commit comments

Comments
 (0)