Skip to content

Commit

Permalink
added one more test
Browse files Browse the repository at this point in the history
Signed-off-by: Petar Dzepina <[email protected]>
  • Loading branch information
petardz committed Jan 6, 2023
1 parent 601f60d commit 254d155
Showing 1 changed file with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,41 @@ public void testGetMappingsViewSuccess() throws IOException {
assertEquals(2, unmappedFieldAliases.size());
}

public void testGetMappingsView_index_pattern_two_indices_Success() throws IOException {

String testIndexName1 = "get_mappings_view_index11";
String testIndexName2 = "get_mappings_view_index22";
String indexPattern = "get_mappings_view_index*";
createSampleIndex(testIndexName1);
createSampleIndex(testIndexName2);
indexDoc(testIndexName2, "987654", "{ \"extra_field\": 12345 }");

// Execute CreateMappingsAction to add alias mapping for index
Request request = new Request("GET", SecurityAnalyticsPlugin.MAPPINGS_VIEW_BASE_URI);
// both req params and req body are supported
request.addParameter("index_name", indexPattern);
request.addParameter("rule_topic", "netflow");
Response response = client().performRequest(request);
assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
Map<String, Object> respMap = responseAsMap(response);
// Verify alias mappings
Map<String, Object> props = (Map<String, Object>) respMap.get("properties");
assertEquals(4, props.size());
assertTrue(props.containsKey("source.ip"));
assertTrue(props.containsKey("destination.ip"));
assertTrue(props.containsKey("source.port"));
assertTrue(props.containsKey("destination.port"));
// Verify unmapped index fields
List<String> unmappedIndexFields = (List<String>) respMap.get("unmapped_index_fields");
assertEquals(7, unmappedIndexFields.size());
// Verify that we got Mappings View of concrete index testIndexName2 because it is newest of all under this alias
Optional<String> extraField = unmappedIndexFields.stream().filter(e -> e.equals("extra_field")).findFirst();
assertTrue(extraField.isPresent());
// Verify unmapped field aliases
List<String> unmappedFieldAliases = (List<String>) respMap.get("unmapped_field_aliases");
assertEquals(2, unmappedFieldAliases.size());
}

public void testGetMappingsView_alias_without_writeindex_Success() throws IOException {

String testIndexName1 = "get_mappings_view_index11";
Expand Down Expand Up @@ -600,7 +635,7 @@ public void testCreateMappings_withIndexPattern_oneNoMappings_failure() throws I
}

private void createSampleIndex(String indexName) throws IOException {
createSampleIndex(indexName, null, null);
createSampleIndex(indexName, Settings.EMPTY, null);
}

private void createSampleIndex(String indexName, Settings settings, String aliases) throws IOException {
Expand Down

0 comments on commit 254d155

Please sign in to comment.