-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Visitor test cases and addressed comments
Signed-off-by: Varun Jain <[email protected]>
- Loading branch information
1 parent
d0b70c7
commit c9ada83
Showing
3 changed files
with
64 additions
and
6 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
57 changes: 57 additions & 0 deletions
57
src/test/java/org/opensearch/neuralsearch/query/visitor/NeuralSearchQueryVisitorTests.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,57 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.neuralsearch.query.visitor; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.apache.lucene.search.BooleanClause; | ||
import org.opensearch.neuralsearch.query.NeuralQueryBuilder; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
public class NeuralSearchQueryVisitorTests extends OpenSearchTestCase { | ||
|
||
public void testAccept_whenNeuralQueryBuilderWithoutModelId_thenSetModelId() { | ||
String modelId = "bdcvjkcdjvkddcjxdjsc"; | ||
NeuralQueryBuilder neuralQueryBuilder = new NeuralQueryBuilder(); | ||
neuralQueryBuilder.fieldName("passage_text"); | ||
neuralQueryBuilder.k(768); | ||
|
||
NeuralSearchQueryVisitor neuralSearchQueryVisitor = new NeuralSearchQueryVisitor(modelId, null); | ||
neuralSearchQueryVisitor.accept(neuralQueryBuilder); | ||
|
||
assertEquals(modelId, neuralQueryBuilder.modelId()); | ||
} | ||
|
||
public void testAccept_whenNeuralQueryBuilderWithoutFieldModelId_thenSetFieldModelId() { | ||
Map<String, Object> neuralInfoMap = new HashMap<>(); | ||
neuralInfoMap.put("passage_text", "bdcvjkcdjvkddcjxdjsc"); | ||
NeuralQueryBuilder neuralQueryBuilder = new NeuralQueryBuilder(); | ||
neuralQueryBuilder.fieldName("passage_text"); | ||
neuralQueryBuilder.k(768); | ||
|
||
NeuralSearchQueryVisitor neuralSearchQueryVisitor = new NeuralSearchQueryVisitor(null, neuralInfoMap); | ||
neuralSearchQueryVisitor.accept(neuralQueryBuilder); | ||
|
||
assertEquals("bdcvjkcdjvkddcjxdjsc", neuralQueryBuilder.modelId()); | ||
} | ||
|
||
public void testAccept_whenNullValuesInVisitor_thenFail() { | ||
NeuralQueryBuilder neuralQueryBuilder = new NeuralQueryBuilder(); | ||
NeuralSearchQueryVisitor neuralSearchQueryVisitor = new NeuralSearchQueryVisitor(null, null); | ||
|
||
expectThrows(IllegalArgumentException.class, () -> neuralSearchQueryVisitor.accept(neuralQueryBuilder)); | ||
} | ||
|
||
public void testGetChildVisitor() { | ||
NeuralSearchQueryVisitor neuralSearchQueryVisitor = new NeuralSearchQueryVisitor(null, null); | ||
|
||
NeuralSearchQueryVisitor subVisitor = (NeuralSearchQueryVisitor) neuralSearchQueryVisitor.getChildVisitor(BooleanClause.Occur.MUST); | ||
|
||
assertEquals(subVisitor, neuralSearchQueryVisitor); | ||
|
||
} | ||
} |
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