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

findingsDto assign detectorId bug #102

Merged
merged 2 commits into from
Nov 3, 2022
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
Expand Up @@ -45,7 +45,7 @@ public FindingDto(
Instant timestamp,
List<FindingDocument> documents
) {
this.detectorId = id;
this.detectorId = detectorId;
this.id = id;
this.relatedDocIds = relatedDocIds;
this.index = index;
Expand Down Expand Up @@ -89,4 +89,31 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeList(documents);
}

public String getId() {
return id;
}

public List<String> getRelatedDocIds() {
return relatedDocIds;
}

public String getIndex() {
return index;
}

public List<DocLevelQuery> getDocLevelQueries() {
return docLevelQueries;
}

public Instant getTimestamp() {
return timestamp;
}

public List<FindingDocument> getDocuments() {
return documents;
}

public String getDetectorId() {
return detectorId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
package org.opensearch.securityanalytics.findings;

import java.time.Instant;
import java.util.List;
import org.opensearch.commons.alerting.model.DocLevelQuery;
import org.opensearch.commons.alerting.model.FindingDocument;
import org.opensearch.securityanalytics.action.FindingDto;
import org.opensearch.test.OpenSearchTestCase;

public class FindingDtoTests extends OpenSearchTestCase {


public void testFindingDTO_creation() {

FindingDocument findingDocument1 = new FindingDocument("test_index1", "doc1", true, "document 1 payload");
FindingDocument findingDocument2 = new FindingDocument("test_index1", "doc2", true, "document 2 payload");
FindingDocument findingDocument3 = new FindingDocument("test_index1", "doc3", true, "document 3 payload");

Instant now = Instant.now();

FindingDto findingDto = new FindingDto(
"detectorId",
"findingId",
List.of("doc1", "doc2", "doc3"),
"my_index",
List.of(new DocLevelQuery("1","myQuery","fieldA:valABC", List.of())),
now,
List.of(findingDocument1, findingDocument2, findingDocument3)
);

assertEquals("detectorId", findingDto.getDetectorId());
assertEquals("findingId", findingDto.getId());
assertEquals(List.of("doc1", "doc2", "doc3"), findingDto.getRelatedDocIds());
assertEquals("my_index", findingDto.getIndex());
assertEquals(List.of(new DocLevelQuery("1","myQuery","fieldA:valABC", List.of())), findingDto.getDocLevelQueries());
assertEquals(now, findingDto.getTimestamp());
assertEquals(List.of(findingDocument1, findingDocument2, findingDocument3), findingDto.getDocuments());
}

}