-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated default plugin mapper and added unit tests
Signed-off-by: Asif Sohail Mohammed <[email protected]>
- Loading branch information
1 parent
ddf7729
commit fa9dd0c
Showing
11 changed files
with
213 additions
and
18 deletions.
There are no files selected for viewing
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
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
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
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
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
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
...on/src/test/java/org/opensearch/dataprepper/logstash/mapping/DefaultPluginMapperTest.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.dataprepper.logstash.mapping; | ||
|
||
import com.amazon.dataprepper.model.configuration.PluginModel; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.opensearch.dataprepper.logstash.exception.LogstashMappingException; | ||
import org.opensearch.dataprepper.logstash.model.LogstashPlugin; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.Assert.assertThrows; | ||
|
||
class DefaultPluginMapperTest { | ||
|
||
private DefaultPluginMapper defaultPluginMapper; | ||
|
||
@BeforeEach | ||
void createObjectUnderTest() { | ||
defaultPluginMapper = new DefaultPluginMapper(); | ||
} | ||
|
||
@Test | ||
void mapPlugin_without_mapping_file_throws_logstash_mapping_exception_Test() { | ||
LogstashPlugin logstashPlugin = TestDataProvider.invalidMappingResourceNameData(); | ||
String mappingResourceName = logstashPlugin.getPluginName() + ".mapping.yaml"; | ||
|
||
Exception exception = assertThrows(LogstashMappingException.class, () -> | ||
defaultPluginMapper.mapPlugin(logstashPlugin)); | ||
|
||
String expectedMessage = "Unable to find mapping resource " + mappingResourceName; | ||
String actualMessage = exception.getMessage(); | ||
|
||
assertThat(expectedMessage, equalTo(actualMessage)); | ||
} | ||
|
||
@Test | ||
void mapPlugin_with_incorrect_mapping_file_throws_logstash_mapping_exception_Test() { | ||
LogstashPlugin logstashPlugin = TestDataProvider.invalidMappingResourceData(); | ||
String mappingResourceName = logstashPlugin.getPluginName() + ".mapping.yaml"; | ||
|
||
Exception exception = assertThrows(LogstashMappingException.class, () -> | ||
defaultPluginMapper.mapPlugin(logstashPlugin)); | ||
|
||
String expectedMessage = "Unable to parse mapping file " + mappingResourceName; | ||
String actualMessage = exception.getMessage(); | ||
|
||
assertThat(expectedMessage, equalTo(actualMessage)); | ||
} | ||
|
||
@Test | ||
void mapPlugin_without_plugin_name_in_mapping_file_throws_logstash_mapping_exception_Test() { | ||
LogstashPlugin logstashPlugin = TestDataProvider.noPluginNameMappingResourceData(); | ||
String mappingResourceName = logstashPlugin.getPluginName() + ".mapping.yaml"; | ||
|
||
Exception exception = assertThrows(LogstashMappingException.class, () -> | ||
defaultPluginMapper.mapPlugin(logstashPlugin)); | ||
|
||
String expectedMessage = "The mapping file " + mappingResourceName + " has a null value for 'pluginName'."; | ||
String actualMessage = exception.getMessage(); | ||
|
||
assertThat(expectedMessage, equalTo(actualMessage)); | ||
} | ||
|
||
@Test | ||
void mapPlugin_returns_plugin_model_Test() { | ||
LogstashPlugin logstashPlugin = TestDataProvider.pluginData(); | ||
|
||
PluginModel actualPluginModel = defaultPluginMapper.mapPlugin(logstashPlugin); | ||
PluginModel expectedPluginModel = TestDataProvider.getSamplePluginModel(); | ||
|
||
assertThat(expectedPluginModel.getPluginName(), equalTo(actualPluginModel.getPluginName())); | ||
assertThat(expectedPluginModel.getPluginSettings(), equalTo(actualPluginModel.getPluginSettings())); | ||
} | ||
|
||
} |
71 changes: 71 additions & 0 deletions
71
...iguration/src/test/java/org/opensearch/dataprepper/logstash/mapping/TestDataProvider.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,71 @@ | ||
package org.opensearch.dataprepper.logstash.mapping; | ||
|
||
import com.amazon.dataprepper.model.configuration.PluginModel; | ||
import org.opensearch.dataprepper.logstash.model.LogstashAttribute; | ||
import org.opensearch.dataprepper.logstash.model.LogstashAttributeValue; | ||
import org.opensearch.dataprepper.logstash.model.LogstashPlugin; | ||
import org.opensearch.dataprepper.logstash.model.LogstashValueType; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
public class TestDataProvider { | ||
|
||
public static LogstashPlugin invalidMappingResourceNameData() { | ||
return LogstashPlugin.builder() | ||
.pluginName("amazon_elasticsearch") | ||
.attributes(Collections.singletonList(getArrayTypeAttribute())).build(); | ||
} | ||
|
||
public static LogstashPlugin invalidMappingResourceData() { | ||
return LogstashPlugin.builder() | ||
.pluginName("invalid") | ||
.attributes(Collections.singletonList(getArrayTypeAttribute())).build(); | ||
} | ||
|
||
public static LogstashPlugin noPluginNameMappingResourceData() { | ||
return LogstashPlugin.builder() | ||
.pluginName("no_plugin_name") | ||
.attributes(Collections.singletonList(getArrayTypeAttribute())).build(); | ||
} | ||
|
||
public static LogstashPlugin pluginData() { | ||
return LogstashPlugin.builder() | ||
.pluginName("amazon_es") | ||
.attributes(Arrays.asList(getArrayTypeAttribute(), getStringTypeAttribute())).build(); | ||
} | ||
|
||
public static PluginModel getSamplePluginModel() { | ||
Map<String, Object> attributes = new LinkedHashMap<>(); | ||
attributes.put("aws_sigv4", true); | ||
attributes.put("insecure", false); | ||
attributes.put("aws_region", "us-west-2"); | ||
attributes.put("hosts", Collections.singletonList("https://localhost:9200")); | ||
return new PluginModel("opensearch", attributes); | ||
} | ||
|
||
private static LogstashAttribute getArrayTypeAttribute() { | ||
LogstashAttributeValue logstashAttributeValue = LogstashAttributeValue.builder() | ||
.attributeValueType(LogstashValueType.ARRAY) | ||
.value(Collections.singletonList("https://localhost:9200")) | ||
.build(); | ||
return LogstashAttribute.builder() | ||
.attributeName("hosts") | ||
.attributeValue(logstashAttributeValue) | ||
.build(); | ||
} | ||
|
||
private static LogstashAttribute getStringTypeAttribute() { | ||
LogstashAttributeValue logstashAttributeValue = LogstashAttributeValue.builder() | ||
.attributeValueType(LogstashValueType.STRING) | ||
.value("us-west-2") | ||
.build(); | ||
return LogstashAttribute.builder() | ||
.attributeName("region") | ||
.attributeValue(logstashAttributeValue) | ||
.build(); | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
data-prepper-logstash-configuration/src/test/resources/amazon_es.mapping.yaml
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,8 @@ | ||
pluginName: opensearch | ||
mappedAttributeNames: | ||
hosts: hosts | ||
index: index | ||
region: aws_region | ||
additionalAttributes: | ||
aws_sigv4: true | ||
insecure: false |
8 changes: 8 additions & 0 deletions
8
data-prepper-logstash-configuration/src/test/resources/invalid.mapping.yaml
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,8 @@ | ||
pluginName: | ||
mappedAttributeNames: | ||
hosts: hosts | ||
cacert: cert | ||
user: username | ||
password: password | ||
index: index | ||
proxy: proxy |
7 changes: 7 additions & 0 deletions
7
data-prepper-logstash-configuration/src/test/resources/no_plugin_name.mapping.yaml
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,7 @@ | ||
mappedAttributeNames: | ||
hosts: hosts | ||
index: index | ||
region: aws_region | ||
additionalAttributes: | ||
aws_sigv4: true | ||
insecure: false |