|
7 | 7 |
|
8 | 8 | package org.elasticsearch.xpack.inference.services.azureaistudio.completion; |
9 | 9 |
|
| 10 | +import org.elasticsearch.TransportVersion; |
10 | 11 | import org.elasticsearch.common.Strings; |
11 | | -import org.elasticsearch.test.ESTestCase; |
| 12 | +import org.elasticsearch.common.io.stream.Writeable; |
12 | 13 | import org.elasticsearch.xcontent.XContentBuilder; |
13 | 14 | import org.elasticsearch.xcontent.XContentFactory; |
14 | 15 | import org.elasticsearch.xcontent.XContentType; |
| 16 | +import org.elasticsearch.xpack.core.ml.AbstractBWCWireSerializationTestCase; |
15 | 17 | import org.elasticsearch.xpack.inference.services.ConfigurationParseContext; |
16 | 18 | import org.elasticsearch.xpack.inference.services.azureaistudio.AzureAiStudioEndpointType; |
17 | 19 | import org.elasticsearch.xpack.inference.services.azureaistudio.AzureAiStudioProvider; |
18 | 20 | import org.elasticsearch.xpack.inference.services.settings.RateLimitSettings; |
| 21 | +import org.elasticsearch.xpack.inference.services.settings.RateLimitSettingsTests; |
19 | 22 | import org.hamcrest.CoreMatchers; |
20 | 23 |
|
21 | 24 | import java.io.IOException; |
|
27 | 30 | import static org.elasticsearch.xpack.inference.services.azureaistudio.AzureAiStudioConstants.TARGET_FIELD; |
28 | 31 | import static org.hamcrest.Matchers.is; |
29 | 32 |
|
30 | | -public class AzureAiStudioChatCompletionServiceSettingsTests extends ESTestCase { |
| 33 | +public class AzureAiStudioChatCompletionServiceSettingsTests extends AbstractBWCWireSerializationTestCase< |
| 34 | + AzureAiStudioChatCompletionServiceSettings> { |
31 | 35 | public void testFromMap_Request_CreatesSettingsCorrectly() { |
32 | 36 | var target = "http://sometarget.local"; |
33 | 37 | var provider = "openai"; |
@@ -119,4 +123,38 @@ public void testToFilteredXContent_WritesAllValues() throws IOException { |
119 | 123 | public static HashMap<String, Object> createRequestSettingsMap(String target, String provider, String endpointType) { |
120 | 124 | return new HashMap<>(Map.of(TARGET_FIELD, target, PROVIDER_FIELD, provider, ENDPOINT_TYPE_FIELD, endpointType)); |
121 | 125 | } |
| 126 | + |
| 127 | + @Override |
| 128 | + protected Writeable.Reader<AzureAiStudioChatCompletionServiceSettings> instanceReader() { |
| 129 | + return AzureAiStudioChatCompletionServiceSettings::new; |
| 130 | + } |
| 131 | + |
| 132 | + @Override |
| 133 | + protected AzureAiStudioChatCompletionServiceSettings createTestInstance() { |
| 134 | + return createRandom(); |
| 135 | + } |
| 136 | + |
| 137 | + @Override |
| 138 | + protected AzureAiStudioChatCompletionServiceSettings mutateInstance(AzureAiStudioChatCompletionServiceSettings instance) |
| 139 | + throws IOException { |
| 140 | + return randomValueOtherThan(instance, AzureAiStudioChatCompletionServiceSettingsTests::createRandom); |
| 141 | + } |
| 142 | + |
| 143 | + @Override |
| 144 | + protected AzureAiStudioChatCompletionServiceSettings mutateInstanceForVersion( |
| 145 | + AzureAiStudioChatCompletionServiceSettings instance, |
| 146 | + TransportVersion version |
| 147 | + ) { |
| 148 | + return instance; |
| 149 | + } |
| 150 | + |
| 151 | + private static AzureAiStudioChatCompletionServiceSettings createRandom() { |
| 152 | + return new AzureAiStudioChatCompletionServiceSettings( |
| 153 | + randomAlphaOfLength(10), |
| 154 | + randomFrom(AzureAiStudioProvider.values()), |
| 155 | + randomFrom(AzureAiStudioEndpointType.values()), |
| 156 | + RateLimitSettingsTests.createRandom() |
| 157 | + ); |
| 158 | + } |
| 159 | + |
122 | 160 | } |
0 commit comments