Skip to content

Commit

Permalink
Add tests to reproduce mapping error
Browse files Browse the repository at this point in the history
Adds tests to reproduce Mapping Parsing Error when the parameters take
the value null. Confirmed that both tests fail.

Signed-off-by: John Mazanec <[email protected]>
  • Loading branch information
jmazanec15 committed Apr 5, 2022
1 parent d9a9f59 commit ecb6633
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/test/java/org/opensearch/knn/index/KNNMethodContextTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,21 @@ public void testParse_invalid() throws IOException {
expectThrows(MapperParsingException.class, () -> MethodComponentContext.parse(in7));
}

/**
* Test context method parsing when parameters are set to null
*/
public void testParse_nullParameters() throws IOException {
String methodName = "test-method";
XContentBuilder xContentBuilder = XContentFactory.jsonBuilder()
.startObject()
.field(NAME, methodName)
.field(PARAMETERS, (String) null)
.endObject();
Map<String, Object> in = xContentBuilderToMap(xContentBuilder);
KNNMethodContext knnMethodContext = KNNMethodContext.parse(in);
assertTrue(knnMethodContext.getMethodComponent().getParameters().isEmpty());
}

/**
* Test context method parsing when input is valid
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,21 @@ public void testGetParameters() throws IOException {
assertEquals(paramVal2, methodContext.getParameters().get(paramKey2));
}

/**
* Test method component context parsing when parameters are set to null
*/
public void testParse_nullParameters() throws IOException {
String name = "test-name";
XContentBuilder xContentBuilder = XContentFactory.jsonBuilder()
.startObject()
.field(NAME, name)
.field(PARAMETERS, (String) null)
.endObject();
Map<String, Object> in = xContentBuilderToMap(xContentBuilder);
MethodComponentContext methodComponentContext = MethodComponentContext.parse(in);
assertTrue(methodComponentContext.getParameters().isEmpty());
}

/**
* Test parse where input is valid
*/
Expand Down

0 comments on commit ecb6633

Please sign in to comment.