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

fix test #4

Merged
merged 1 commit into from
Jun 12, 2024
Merged
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 @@ -9,6 +9,7 @@
import org.opensearch.commons.alerting.model.DocLevelMonitorInput;
import org.opensearch.commons.alerting.model.IntervalSchedule;
import org.opensearch.commons.alerting.model.Monitor;
import org.opensearch.commons.alerting.model.ScheduledJob;
import org.opensearch.commons.alerting.model.remote.monitors.RemoteDocLevelMonitorInput;
import org.opensearch.core.common.bytes.BytesReference;
import org.opensearch.core.common.io.stream.StreamInput;
Expand All @@ -25,6 +26,7 @@

import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static org.opensearch.common.xcontent.XContentFactory.jsonBuilder;

public class ThreatIntelInputTests extends OpenSearchTestCase {

Expand All @@ -33,8 +35,15 @@ public void testThreatInputSerde() throws IOException {
BytesStreamOutput out = new BytesStreamOutput();
threatIntelInput.writeTo(out);
BytesReference bytes = out.bytes();
RemoteDocLevelMonitorInput remoteDocLevelMonitorInput = new RemoteDocLevelMonitorInput(
bytes,
new DocLevelMonitorInput("threat intel input",
List.of("index1", "index2"),
emptyList()
)
);
Monitor monitor = new Monitor(
randomAlphaOfLength(10),
Monitor.NO_ID,
Monitor.NO_VERSION,
randomAlphaOfLength(10),
true,
Expand All @@ -45,13 +54,7 @@ public void testThreatInputSerde() throws IOException {
null,
4,
List.of(
new RemoteDocLevelMonitorInput(
bytes,
new DocLevelMonitorInput("threat intel input",
List.of("index1", "index2"),
emptyList()
)
)
remoteDocLevelMonitorInput
),
emptyList(),
emptyMap(),
Expand All @@ -61,11 +64,8 @@ public void testThreatInputSerde() throws IOException {
BytesStreamOutput monitorOut = new BytesStreamOutput();
monitor.writeTo(monitorOut);

StreamInput sin = StreamInput.wrap(monitorOut.bytes().toBytesRef().bytes);
Monitor monitor1 = new Monitor(sin);

String monitorString = toJsonString(monitor);
Monitor parsedMonitor = Monitor.parse(getParser(monitorString));
String monitorString = BytesReference.bytes(monitor.toXContentWithUser(jsonBuilder(), ToXContent.EMPTY_PARAMS)).utf8ToString();
Monitor parsedMonitor = Monitor.parse(getParser(monitorString), Monitor.NO_ID, Monitor.NO_VERSION);
assertEquals(((RemoteDocLevelMonitorInput) parsedMonitor.getInputs().get(0)).getInput(), ((RemoteDocLevelMonitorInput) parsedMonitor.getInputs().get(0)).getInput());
}

Expand All @@ -88,7 +88,7 @@ public XContentParser getParser(String xc) throws IOException {
}

public String toJsonString(Monitor monitor) throws IOException {
XContentBuilder builder = XContentFactory.jsonBuilder();
XContentBuilder builder = jsonBuilder();
return monitor.toXContent(builder, ToXContent.EMPTY_PARAMS).toString();

}
Expand Down
Loading