Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Summarizable and Detailed Results #25

Merged
merged 3 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Scanner Core - A modular framework for probe definition, execution, and result analysis.
*
* Copyright 2017-2023 Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH
*
* Licensed under Apache License, Version 2.0
* http://www.apache.org/licenses/LICENSE-2.0.txt
*/
package de.rub.nds.scanner.core.probe.result;

import java.io.Serializable;

public class DetailedResult<T extends Serializable> implements SummarizableTestResult {

public static <T extends Serializable> DetailedResult<T> TRUE() {
return new DetailedResult<>(TestResults.TRUE);
}

public static <T extends Serializable> DetailedResult<T> TRUE(T details) {
return new DetailedResult<>(TestResults.TRUE, details);
}

public static <T extends Serializable> DetailedResult<T> FALSE() {
return new DetailedResult<>(TestResults.FALSE);
}

public static <T extends Serializable> DetailedResult<T> FALSE(T details) {
return new DetailedResult<>(TestResults.FALSE, details);
}

private final T details;
private final TestResults summary;

public DetailedResult(TestResults summary, T details) {
this.details = details;
this.summary = summary;
}

public DetailedResult(TestResults summary) {
this(summary, null);
}

public T getDetails() {
return details;
}

@Override
public TestResults getSummarizedResult() {
return summary;
}

@Override
public boolean isExplicitSummary() {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Scanner Core - A modular framework for probe definition, execution, and result analysis.
*
* Copyright 2017-2023 Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH
*
* Licensed under Apache License, Version 2.0
* http://www.apache.org/licenses/LICENSE-2.0.txt
*/
package de.rub.nds.scanner.core.probe.result;

/**
* A complex test result that can still be summarized into a single TestResults. This summary might
* be generated on the fly (from the contained details), or set explicitly (e.g. in case of an
* error)
*/
public interface SummarizableTestResult extends TestResult {
TestResults getSummarizedResult();

/**
* @return Whether the summary was explicitly set instead of generated on the fly.
*/
boolean isExplicitSummary();

@Override
default boolean equalsExpectedResult(TestResult other) {
if (other instanceof TestResults) {
return getSummarizedResult().equals(other);
}
return this.equals(other);
}

@Override
default String getName() {
return getSummarizedResult().getName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
*/
package de.rub.nds.scanner.core.probe.result;

import java.io.Serializable;

/** The interface for TestResults */
public interface TestResult {
public interface TestResult extends Serializable {

/**
* @return the name of the TestResult.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
@JsonIncludeProperties({"type", "value"})
@JsonPropertyOrder({"type", "value"})
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum TestResults implements TestResult {
public enum TestResults implements SummarizableTestResult {
TRUE,
FALSE,
PARTIALLY,
Expand All @@ -48,4 +48,14 @@ public String getName() {
public static TestResults of(boolean value) {
return value ? TRUE : FALSE;
}

@Override
public TestResults getSummarizedResult() {
return this;
}

@Override
public boolean isExplicitSummary() {
return true;
}
}