forked from opensearch-project/security-analytics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Riya Saxena <[email protected]>
- Loading branch information
1 parent
362f0d6
commit 2a5cd34
Showing
7 changed files
with
781 additions
and
326 deletions.
There are no files selected for viewing
350 changes: 335 additions & 15 deletions
350
src/test/java/org/opensearch/securityanalytics/SecurityAnalyticsRestTestCase.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
303 changes: 0 additions & 303 deletions
303
src/test/java/org/opensearch/securityanalytics/correlation/CorrelationEngineRestApiIT.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...ava/org/opensearch/securityanalytics/correlation/alerts/CorrelationAlertServiceTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package org.opensearch.securityanalytics.correlation.alerts; | ||
|
||
import org.opensearch.client.Client; | ||
import org.opensearch.commons.alerting.model.Alert; | ||
import org.opensearch.commons.alerting.model.CorrelationAlert; | ||
import org.opensearch.core.action.ActionListener; | ||
import org.opensearch.core.xcontent.NamedXContentRegistry; | ||
import org.opensearch.securityanalytics.correlation.alert.CorrelationAlertService; | ||
import org.opensearch.securityanalytics.correlation.alert.CorrelationAlertsList; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
import java.time.Instant; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.spy; | ||
|
||
public class CorrelationAlertServiceTests extends OpenSearchTestCase { | ||
|
||
public void testGetActiveAlerts() { | ||
// Mock setup | ||
Client client = mock(Client.class); | ||
NamedXContentRegistry xContentRegistry = mock(NamedXContentRegistry.class); | ||
CorrelationAlertService alertsService = spy(new CorrelationAlertService(client, xContentRegistry)); | ||
|
||
|
||
// Fake data | ||
String ruleId = "correlation_rule_id_123"; | ||
long currentTime = System.currentTimeMillis(); | ||
|
||
// Define a fake correlation alert | ||
CorrelationAlert correlationAlert = new CorrelationAlert( | ||
Collections.emptyList(), | ||
ruleId, | ||
"mock-rule", | ||
UUID.randomUUID().toString(), | ||
1L, | ||
1, | ||
null, | ||
"mock-trigger", | ||
Alert.State.ACTIVE, | ||
Instant.ofEpochMilli(currentTime).minusMillis(1000L), | ||
Instant.ofEpochMilli(currentTime).plusMillis(1000L), | ||
null, | ||
null, | ||
"high", | ||
new ArrayList<>() | ||
); | ||
|
||
List<CorrelationAlert> correlationAlerts = Collections.singletonList(correlationAlert); | ||
|
||
// Call getActiveAlerts | ||
alertsService.getActiveAlerts(ruleId, currentTime, new ActionListener<CorrelationAlertsList>() { | ||
@Override | ||
public void onResponse(CorrelationAlertsList correlationAlertsList) { | ||
// Assertion | ||
assertEquals(correlationAlerts.size(), correlationAlertsList.getCorrelationAlertList().size()); | ||
|
||
// Additional assertions can be added here to verify specific fields or states | ||
CorrelationAlert returnedAlert = correlationAlertsList.getCorrelationAlertList().get(0); | ||
assertEquals(correlationAlert.getId(), returnedAlert.getId()); | ||
assertEquals(correlationAlert.getCorrelationRuleId(), returnedAlert.getCorrelationRuleId()); | ||
assertEquals(correlationAlert.getStartTime(), returnedAlert.getStartTime()); | ||
assertEquals(correlationAlert.getEndTime(), returnedAlert.getEndTime()); | ||
} | ||
|
||
@Override | ||
public void onFailure(Exception e) { | ||
|
||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.