Skip to content

Commit 196748e

Browse files
committed
restructure tests
Signed-off-by: Kaushal Kumar <[email protected]>
1 parent 402bf1a commit 196748e

File tree

7 files changed

+17
-20
lines changed

7 files changed

+17
-20
lines changed

modules/autotagging-commons/src/test/java/org/opensearch/rule/action/GetRuleRequestTests.java renamed to modules/autotagging-commons/common/src/test/java/org/opensearch/rule/action/GetRuleRequestTests.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,22 @@
1111
import org.opensearch.common.io.stream.BytesStreamOutput;
1212
import org.opensearch.core.common.io.stream.StreamInput;
1313
import org.opensearch.rule.GetRuleRequest;
14-
import org.opensearch.rule.InMemoryRuleProcessingServiceTests;
1514
import org.opensearch.rule.autotagging.Attribute;
1615
import org.opensearch.rule.autotagging.Rule;
16+
import org.opensearch.rule.utils.RuleTestUtils;
1717
import org.opensearch.test.OpenSearchTestCase;
1818

1919
import java.io.IOException;
2020
import java.util.HashMap;
2121
import java.util.Map;
2222
import java.util.Set;
2323

24-
import static org.opensearch.rule.InMemoryRuleProcessingServiceTests.WLMFeatureType;
25-
2624
public class GetRuleRequestTests extends OpenSearchTestCase {
2725
/**
2826
* Test case to verify the serialization and deserialization of GetRuleRequest
2927
*/
3028
public void testSerialization() throws IOException {
31-
GetRuleRequest request = new GetRuleRequest(_ID_ONE, ATTRIBUTE_MAP, null, WLMFeatureType.WLM);
29+
GetRuleRequest request = new GetRuleRequest(_ID_ONE, ATTRIBUTE_MAP, null, RuleTestUtils.MockRuleFeatureType.INSTANCE);
3230
assertEquals(_ID_ONE, request.getId());
3331
BytesStreamOutput out = new BytesStreamOutput();
3432
request.writeTo(out);
@@ -42,7 +40,12 @@ public void testSerialization() throws IOException {
4240
* Test case to verify the serialization and deserialization of GetRuleRequest when name is null
4341
*/
4442
public void testSerializationWithNull() throws IOException {
45-
GetRuleRequest request = new GetRuleRequest((String) null, new HashMap<>(), SEARCH_AFTER, WLMFeatureType.WLM);
43+
GetRuleRequest request = new GetRuleRequest(
44+
(String) null,
45+
new HashMap<>(),
46+
SEARCH_AFTER,
47+
RuleTestUtils.MockRuleFeatureType.INSTANCE
48+
);
4649
assertNull(request.getId());
4750
BytesStreamOutput out = new BytesStreamOutput();
4851
request.writeTo(out);
@@ -64,23 +67,23 @@ public void testSerializationWithNull() throws IOException {
6467
public static final String TIMESTAMP_ONE = "2024-01-26T08:58:57.558Z";
6568
public static final String TIMESTAMP_TWO = "2023-01-26T08:58:57.558Z";
6669
public static final Map<Attribute, Set<String>> ATTRIBUTE_MAP = Map.of(
67-
InMemoryRuleProcessingServiceTests.TestAttribute.TEST_ATTRIBUTE,
70+
RuleTestUtils.MockRuleAttributes.MOCK_RULE_ATTRIBUTE_ONE,
6871
Set.of(ATTRIBUTE_VALUE_ONE)
6972
);
7073

7174
public static final Rule ruleOne = Rule.builder()
7275
.description(DESCRIPTION_ONE)
73-
.featureType(WLMFeatureType.WLM)
76+
.featureType(RuleTestUtils.MockRuleFeatureType.INSTANCE)
7477
.featureValue(FEATURE_VALUE_ONE)
7578
.attributeMap(ATTRIBUTE_MAP)
7679
.updatedAt(TIMESTAMP_ONE)
7780
.build();
7881

7982
public static final Rule ruleTwo = Rule.builder()
8083
.description(DESCRIPTION_TWO)
81-
.featureType(WLMFeatureType.WLM)
84+
.featureType(RuleTestUtils.MockRuleFeatureType.INSTANCE)
8285
.featureValue(FEATURE_VALUE_TWO)
83-
.attributeMap(Map.of(InMemoryRuleProcessingServiceTests.TestAttribute.TEST_ATTRIBUTE, Set.of(ATTRIBUTE_VALUE_TWO)))
86+
.attributeMap(Map.of(RuleTestUtils.MockRuleAttributes.MOCK_RULE_ATTRIBUTE_TWO, Set.of(ATTRIBUTE_VALUE_TWO)))
8487
.updatedAt(TIMESTAMP_TWO)
8588
.build();
8689

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
import org.opensearch.core.xcontent.ToXContent;
1515
import org.opensearch.core.xcontent.XContentBuilder;
1616
import org.opensearch.rule.GetRuleResponse;
17-
import org.opensearch.rule.InMemoryRuleProcessingServiceTests;
1817
import org.opensearch.rule.autotagging.Attribute;
1918
import org.opensearch.rule.autotagging.Rule;
19+
import org.opensearch.rule.utils.RuleTestUtils;
2020
import org.opensearch.test.OpenSearchTestCase;
2121

2222
import java.io.IOException;
@@ -36,13 +36,13 @@ public class GetRuleResponseTests extends OpenSearchTestCase {
3636
public static final String DESCRIPTION_ONE = "description_1";
3737
public static final String TIMESTAMP_ONE = "2024-01-26T08:58:57.558Z";
3838
static final Map<Attribute, Set<String>> ATTRIBUTE_MAP = Map.of(
39-
InMemoryRuleProcessingServiceTests.TestAttribute.TEST_ATTRIBUTE,
39+
RuleTestUtils.MockRuleAttributes.MOCK_RULE_ATTRIBUTE_ONE,
4040
Set.of(ATTRIBUTE_VALUE_ONE)
4141
);
4242

4343
public static final Rule ruleOne = Rule.builder()
4444
.description(DESCRIPTION_ONE)
45-
.featureType(InMemoryRuleProcessingServiceTests.WLMFeatureType.WLM)
45+
.featureType(RuleTestUtils.MockRuleFeatureType.INSTANCE)
4646
.featureValue(FEATURE_VALUE_ONE)
4747
.attributeMap(ATTRIBUTE_MAP)
4848
.updatedAt(TIMESTAMP_ONE)
@@ -111,10 +111,10 @@ public void testToXContentGetSingleRule() throws IOException {
111111
+ " {\n"
112112
+ " \"_id\" : \"id_1\",\n"
113113
+ " \"description\" : \"description_1\",\n"
114-
+ " \"test_attribute\" : [\n"
114+
+ " \"mock_attribute_one\" : [\n"
115115
+ " \"mock_attribute_one\"\n"
116116
+ " ],\n"
117-
+ " \"wlm\" : \"feature_value_one\",\n"
117+
+ " \"mock_feature_type\" : \"feature_value_one\",\n"
118118
+ " \"updated_at\" : \"2024-01-26T08:58:57.558Z\"\n"
119119
+ " }\n"
120120
+ " ],\n"

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,9 @@
1717

1818
public class RuleTestUtils {
1919
public static final String _ID_ONE = "AgfUO5Ja9yfvhdONlYi3TQ==";
20-
public static final String _ID_TWO = "G5iIq84j7eK1qIAAAAIH53=1";
21-
public static final String FEATURE_VALUE_ONE = "feature_value_one";
22-
public static final String FEATURE_VALUE_TWO = "feature_value_two";
2320
public static final String ATTRIBUTE_VALUE_ONE = "mock_attribute_one";
2421
public static final String ATTRIBUTE_VALUE_TWO = "mock_attribute_two";
2522
public static final String DESCRIPTION_ONE = "description_1";
26-
public static final String DESCRIPTION_TWO = "description_2";
27-
public static final String TIMESTAMP_ONE = "2024-01-26T08:58:57.558Z";
28-
public static final String TIMESTAMP_TWO = "2023-01-26T08:58:57.558Z";
2923
public static final String FEATURE_TYPE_NAME = "mock_feature_type";
3024
public static final String TEST_INDEX_NAME = ".test_index_for_rule";
3125
public static final Map<Attribute, Set<String>> ATTRIBUTE_MAP = Map.of(

0 commit comments

Comments
 (0)