-
Notifications
You must be signed in to change notification settings - Fork 202
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: George Chen <qchea@amazon.com>
- Loading branch information
1 parent
0387808
commit d587b54
Showing
12 changed files
with
93 additions
and
36 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
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
18 changes: 18 additions & 0 deletions
18
...-parser/src/main/java/org/opensearch/dataprepper/validation/PluginErrorsConsolidator.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,18 @@ | ||
package org.opensearch.dataprepper.validation; | ||
|
||
import javax.inject.Named; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
|
||
@Named | ||
public class PluginErrorsConsolidator { | ||
public String consolidatedErrorMessage(final List<PluginError> pluginErrors) { | ||
final List<String> allErrorMessages = pluginErrors.stream() | ||
.map(PluginError::getErrorMessage) | ||
.collect(Collectors.toList()); | ||
return IntStream.range(0, allErrorMessages.size()) | ||
.mapToObj(i -> (i + 1) + ". " + allErrorMessages.get(i)) | ||
.collect(Collectors.joining("\n")); | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
...ser/src/test/java/org/opensearch/dataprepper/validation/PluginErrorsConsolidatorTest.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,28 @@ | ||
package org.opensearch.dataprepper.validation; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
class PluginErrorsConsolidatorTest { | ||
|
||
@Test | ||
void testWithPluginErrors() { | ||
final PluginErrorsConsolidator objectUnderTest = new PluginErrorsConsolidator(); | ||
final String testErrorMessage1 = "test error message 1"; | ||
final String testErrorMessage2 = "test error message 2"; | ||
final PluginError pluginError1 = mock(PluginError.class); | ||
when(pluginError1.getErrorMessage()).thenReturn(testErrorMessage1); | ||
final PluginError pluginError2 = mock(PluginError.class); | ||
when(pluginError2.getErrorMessage()).thenReturn(testErrorMessage2); | ||
final String consolidatedErrorMessage = objectUnderTest.consolidatedErrorMessage( | ||
List.of(pluginError1, pluginError2)); | ||
assertThat(consolidatedErrorMessage, equalTo( | ||
String.format("1. %s\n2. %s", testErrorMessage1, testErrorMessage2))); | ||
} | ||
} |
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