Skip to content

Commit e2200ce

Browse files
committed
fix UT
Signed-off-by: Ruirui Zhang <[email protected]>
1 parent b0e1009 commit e2200ce

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

modules/autotagging-commons/common/src/test/java/org/opensearch/rule/service/IndexStoredRulePersistenceServiceTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.opensearch.rule.RulePersistenceService;
2727
import org.opensearch.rule.RuleQueryMapper;
2828
import org.opensearch.rule.autotagging.Rule;
29+
import org.opensearch.rule.utils.RuleTestUtils;
2930
import org.opensearch.search.SearchHit;
3031
import org.opensearch.search.SearchHits;
3132
import org.opensearch.test.OpenSearchTestCase;
@@ -90,6 +91,7 @@ public void testGetRuleByIdSuccess() {
9091
return null;
9192
}).when(searchRequestBuilder).execute(any(ActionListener.class));
9293

94+
when(getRuleRequest.getFeatureType()).thenReturn(RuleTestUtils.MockRuleFeatureType.INSTANCE);
9395
rulePersistenceService.getRule(getRuleRequest, listener);
9496

9597
ArgumentCaptor<GetRuleResponse> responseCaptor = ArgumentCaptor.forClass(GetRuleResponse.class);
@@ -132,6 +134,7 @@ public void testGetRuleByIdNotFound() {
132134
return null;
133135
}).when(searchRequestBuilder).execute(any(ActionListener.class));
134136

137+
when(getRuleRequest.getFeatureType()).thenReturn(RuleTestUtils.MockRuleFeatureType.INSTANCE);
135138
rulePersistenceService.getRule(getRuleRequest, listener);
136139

137140
ArgumentCaptor<Exception> exceptionCaptor = ArgumentCaptor.forClass(Exception.class);

modules/autotagging-commons/common/src/test/java/org/opensearch/rule/utils/RuleTestUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ public enum MockRuleAttributes implements Attribute {
7070
MOCK_RULE_ATTRIBUTE_ONE(ATTRIBUTE_VALUE_ONE),
7171
MOCK_RULE_ATTRIBUTE_TWO(ATTRIBUTE_VALUE_TWO),
7272
INVALID_ATTRIBUTE(RuleTestUtils.INVALID_ATTRIBUTE);
73-
;
7473

7574
private final String name;
7675

modules/autotagging-commons/src/test/java/org/opensearch/rule/InMemoryRuleProcessingServiceTests.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88

99
package org.opensearch.rule;
1010

11-
import org.opensearch.core.common.io.stream.StreamOutput;
1211
import org.opensearch.rule.attribute_extractor.AttributeExtractor;
1312
import org.opensearch.rule.autotagging.Attribute;
13+
import org.opensearch.rule.autotagging.AutoTaggingRegistry;
1414
import org.opensearch.rule.autotagging.FeatureType;
1515
import org.opensearch.rule.autotagging.Rule;
1616
import org.opensearch.rule.storage.DefaultAttributeValueStore;
1717
import org.opensearch.test.OpenSearchTestCase;
1818

19-
import java.io.IOException;
2019
import java.util.List;
2120
import java.util.Map;
2221
import java.util.Optional;
@@ -124,9 +123,13 @@ public Iterable<String> extract() {
124123
public enum WLMFeatureType implements FeatureType {
125124
WLM;
126125

126+
static {
127+
WLM.registerFeatureType();
128+
}
129+
127130
@Override
128131
public String getName() {
129-
return "";
132+
return "wlm";
130133
}
131134

132135
@Override
@@ -135,7 +138,9 @@ public Map<String, Attribute> getAllowedAttributesRegistry() {
135138
}
136139

137140
@Override
138-
public void registerFeatureType() {}
141+
public void registerFeatureType() {
142+
AutoTaggingRegistry.registerFeatureType(WLM);
143+
}
139144
}
140145

141146
public enum TestAttribute implements Attribute {
@@ -155,8 +160,5 @@ public String getName() {
155160

156161
@Override
157162
public void validateAttribute() {}
158-
159-
@Override
160-
public void writeTo(StreamOutput out) throws IOException {}
161163
}
162164
}

modules/autotagging-commons/src/test/java/org/opensearch/rule/action/GetRuleResponseTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,17 @@ public void testToXContentGetSingleRule() throws IOException {
109109
String expected = "{\n"
110110
+ " \"rules\" : [\n"
111111
+ " {\n"
112-
+ " \"_id\" : \"AgfUO5Ja9yfvhdONlYi3TQ==\",\n"
112+
+ " \"_id\" : \"id_1\",\n"
113113
+ " \"description\" : \"description_1\",\n"
114-
+ " \"mock_attribute_one\" : [\n"
114+
+ " \"test_attribute\" : [\n"
115115
+ " \"mock_attribute_one\"\n"
116116
+ " ],\n"
117-
+ " \"mock_feature_type\" : \"feature_value_one\",\n"
117+
+ " \"wlm\" : \"feature_value_one\",\n"
118118
+ " \"updated_at\" : \"2024-01-26T08:58:57.558Z\"\n"
119119
+ " }\n"
120120
+ " ],\n"
121121
+ " \"search_after\" : [\n"
122-
+ " \"search_after_id\"\n"
122+
+ " \"search_after\"\n"
123123
+ " ]\n"
124124
+ "}";
125125
assertEquals(expected, actual);

0 commit comments

Comments
 (0)