Skip to content

Commit f48ced3

Browse files
committed
Add test support classes for passive package
- Add TestTrackableValue implementation with Jackson support - Add AnotherTestTrackableValue for mixed type testing - Add TestState class for StatExtractor testing - Add TestStatExtractor concrete implementation
1 parent 1fea790 commit f48ced3

File tree

4 files changed

+140
-0
lines changed

4 files changed

+140
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Scanner Core - A Modular Framework for Probe Definition, Execution, and Result Analysis.
3+
*
4+
* Copyright 2017-2023 Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH
5+
*
6+
* Licensed under Apache License, Version 2.0
7+
* http://www.apache.org/licenses/LICENSE-2.0.txt
8+
*/
9+
package de.rub.nds.scanner.core.passive;
10+
11+
import com.fasterxml.jackson.annotation.JsonCreator;
12+
import com.fasterxml.jackson.annotation.JsonProperty;
13+
import java.util.Objects;
14+
15+
public class AnotherTestTrackableValue implements TrackableValue {
16+
private final int number;
17+
18+
@JsonCreator
19+
public AnotherTestTrackableValue(@JsonProperty("number") int number) {
20+
this.number = number;
21+
}
22+
23+
public int getNumber() {
24+
return number;
25+
}
26+
27+
@Override
28+
public boolean equals(Object o) {
29+
if (this == o) return true;
30+
if (o == null || getClass() != o.getClass()) return false;
31+
AnotherTestTrackableValue that = (AnotherTestTrackableValue) o;
32+
return number == that.number;
33+
}
34+
35+
@Override
36+
public int hashCode() {
37+
return Objects.hash(number);
38+
}
39+
40+
@Override
41+
public String toString() {
42+
return "AnotherTestTrackableValue{" + "number=" + number + '}';
43+
}
44+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Scanner Core - A Modular Framework for Probe Definition, Execution, and Result Analysis.
3+
*
4+
* Copyright 2017-2023 Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH
5+
*
6+
* Licensed under Apache License, Version 2.0
7+
* http://www.apache.org/licenses/LICENSE-2.0.txt
8+
*/
9+
package de.rub.nds.scanner.core.passive;
10+
11+
public class TestStatExtractor extends StatExtractor<TestState, TestTrackableValue> {
12+
13+
private boolean shouldExtractNull = false;
14+
15+
public TestStatExtractor() {
16+
super(new TestTrackableValue("type"));
17+
}
18+
19+
public void setShouldExtractNull(boolean shouldExtractNull) {
20+
this.shouldExtractNull = shouldExtractNull;
21+
}
22+
23+
@Override
24+
public void extract(TestState state) {
25+
if (shouldExtractNull) {
26+
put(null);
27+
} else if (state != null && state.getValue() != null) {
28+
put(new TestTrackableValue(state.getValue()));
29+
}
30+
}
31+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Scanner Core - A Modular Framework for Probe Definition, Execution, and Result Analysis.
3+
*
4+
* Copyright 2017-2023 Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH
5+
*
6+
* Licensed under Apache License, Version 2.0
7+
* http://www.apache.org/licenses/LICENSE-2.0.txt
8+
*/
9+
package de.rub.nds.scanner.core.passive;
10+
11+
public class TestState {
12+
private final String value;
13+
14+
public TestState(String value) {
15+
this.value = value;
16+
}
17+
18+
public String getValue() {
19+
return value;
20+
}
21+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Scanner Core - A Modular Framework for Probe Definition, Execution, and Result Analysis.
3+
*
4+
* Copyright 2017-2023 Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH
5+
*
6+
* Licensed under Apache License, Version 2.0
7+
* http://www.apache.org/licenses/LICENSE-2.0.txt
8+
*/
9+
package de.rub.nds.scanner.core.passive;
10+
11+
import com.fasterxml.jackson.annotation.JsonCreator;
12+
import com.fasterxml.jackson.annotation.JsonProperty;
13+
import java.util.Objects;
14+
15+
public class TestTrackableValue implements TrackableValue {
16+
private final String value;
17+
18+
@JsonCreator
19+
public TestTrackableValue(@JsonProperty("value") String value) {
20+
this.value = value;
21+
}
22+
23+
public String getValue() {
24+
return value;
25+
}
26+
27+
@Override
28+
public boolean equals(Object o) {
29+
if (this == o) return true;
30+
if (o == null || getClass() != o.getClass()) return false;
31+
TestTrackableValue that = (TestTrackableValue) o;
32+
return Objects.equals(value, that.value);
33+
}
34+
35+
@Override
36+
public int hashCode() {
37+
return Objects.hash(value);
38+
}
39+
40+
@Override
41+
public String toString() {
42+
return "TestTrackableValue{" + "value='" + value + '\'' + '}';
43+
}
44+
}

0 commit comments

Comments
 (0)