Skip to content

Commit bf48f99

Browse files
authored
Revert Text Block changes from "Enhance validation for create connector API" opensearch-project#3260 (opensearch-project#3329)
Text Blcok changes introduced in JDK15. Eventhough our main release is based on JDK21, 2.x is still based on JDK11. So to support autoi bot backport of these test files in the future, reverting Text Block related changes from test cases. Signed-off-by: Abdul Muneer Kolarkunnu <[email protected]>
1 parent b5dd5a1 commit bf48f99

File tree

2 files changed

+38
-40
lines changed

2 files changed

+38
-40
lines changed

common/src/test/java/org/opensearch/ml/common/connector/ConnectorActionTest.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ public void toXContent_NullValue() throws IOException {
100100
XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent());
101101
action.toXContent(builder, ToXContent.EMPTY_PARAMS);
102102
String content = TestHelper.xContentBuilderToString(builder);
103-
String expctedContent = """
104-
{"action_type":"PREDICT","method":"http","url":"https://test.com",\
105-
"request_body":"{\\"input\\": \\"${parameters.input}\\"}"}\
106-
""";
107-
assertEquals(expctedContent, content);
103+
assertEquals(
104+
"{\"action_type\":\"PREDICT\",\"method\":\"http\",\"url\":\"https://test.com\","
105+
+ "\"request_body\":\"{\\\"input\\\": \\\"${parameters.input}\\\"}\"}",
106+
content
107+
);
108108
}
109109

110110
@Test
@@ -127,23 +127,21 @@ public void toXContent() throws IOException {
127127
XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent());
128128
action.toXContent(builder, ToXContent.EMPTY_PARAMS);
129129
String content = TestHelper.xContentBuilderToString(builder);
130-
String expctedContent = """
131-
{"action_type":"PREDICT","method":"http","url":"https://test.com","headers":{"key1":"value1"},\
132-
"request_body":"{\\"input\\": \\"${parameters.input}\\"}",\
133-
"pre_process_function":"connector.pre_process.openai.embedding",\
134-
"post_process_function":"connector.post_process.openai.embedding"}\
135-
""";
136-
assertEquals(expctedContent, content);
130+
assertEquals(
131+
"{\"action_type\":\"PREDICT\",\"method\":\"http\",\"url\":\"https://test.com\","
132+
+ "\"headers\":{\"key1\":\"value1\"},\"request_body\":\"{\\\"input\\\": \\\"${parameters.input}\\\"}\","
133+
+ "\"pre_process_function\":\"connector.pre_process.openai.embedding\","
134+
+ "\"post_process_function\":\"connector.post_process.openai.embedding\"}",
135+
content
136+
);
137137
}
138138

139139
@Test
140140
public void parse() throws IOException {
141-
String jsonStr = """
142-
{"action_type":"PREDICT","method":"http","url":"https://test.com","headers":{"key1":"value1"},\
143-
"request_body":"{\\"input\\": \\"${parameters.input}\\"}",\
144-
"pre_process_function":"connector.pre_process.openai.embedding",\
145-
"post_process_function":"connector.post_process.openai.embedding"}"\
146-
""";
141+
String jsonStr = "{\"action_type\":\"PREDICT\",\"method\":\"http\",\"url\":\"https://test.com\","
142+
+ "\"headers\":{\"key1\":\"value1\"},\"request_body\":\"{\\\"input\\\": \\\"${parameters.input}\\\"}\","
143+
+ "\"pre_process_function\":\"connector.pre_process.openai.embedding\","
144+
+ "\"post_process_function\":\"connector.post_process.openai.embedding\"}";
147145
XContentParser parser = XContentType.JSON
148146
.xContent()
149147
.createParser(

common/src/test/java/org/opensearch/ml/common/transport/connector/MLCreateConnectorInputTests.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,18 @@ public class MLCreateConnectorInputTests {
5555
private static final String TEST_CREDENTIAL_VALUE = "test_key_value";
5656
private static final String TEST_ROLE1 = "role1";
5757
private static final String TEST_ROLE2 = "role2";
58-
private final String expectedInputStr = """
59-
{"name":"test_connector_name","description":"this is a test connector","version":"1","protocol":"http",\
60-
"parameters":{"input":"test input value"},"credential":{"key":"test_key_value"},\
61-
"actions":[{"action_type":"PREDICT","method":"POST","url":"https://test.com",\
62-
"headers":{"api_key":"${credential.key}"},\
63-
"request_body":"{\\"input\\": \\"${parameters.input}\\"}",\
64-
"pre_process_function":"connector.pre_process.openai.embedding",\
65-
"post_process_function":"connector.post_process.openai.embedding"}],\
66-
"backend_roles":["role1","role2"],"add_all_backend_roles":false,\
67-
"access_mode":"PUBLIC","client_config":{"max_connection":20,\
68-
"connection_timeout":10000,"read_timeout":10000,\
69-
"retry_backoff_millis":10,"retry_timeout_seconds":10,"max_retry_times":-1,"retry_backoff_policy":"constant"}}\
70-
""";
58+
private final String expectedInputStr = "{\"name\":\"test_connector_name\","
59+
+ "\"description\":\"this is a test connector\",\"version\":\"1\",\"protocol\":\"http\","
60+
+ "\"parameters\":{\"input\":\"test input value\"},\"credential\":{\"key\":\"test_key_value\"},"
61+
+ "\"actions\":[{\"action_type\":\"PREDICT\",\"method\":\"POST\",\"url\":\"https://test.com\","
62+
+ "\"headers\":{\"api_key\":\"${credential.key}\"},"
63+
+ "\"request_body\":\"{\\\"input\\\": \\\"${parameters.input}\\\"}\","
64+
+ "\"pre_process_function\":\"connector.pre_process.openai.embedding\","
65+
+ "\"post_process_function\":\"connector.post_process.openai.embedding\"}],"
66+
+ "\"backend_roles\":[\"role1\",\"role2\"],\"add_all_backend_roles\":false,"
67+
+ "\"access_mode\":\"PUBLIC\",\"client_config\":{\"max_connection\":20,"
68+
+ "\"connection_timeout\":10000,\"read_timeout\":10000,"
69+
+ "\"retry_backoff_millis\":10,\"retry_timeout_seconds\":10,\"max_retry_times\":-1,\"retry_backoff_policy\":\"constant\"}}";
7170

7271
@Before
7372
public void setUp() {
@@ -238,15 +237,16 @@ public void testParse() throws Exception {
238237

239238
@Test
240239
public void testParse_ArrayParameter() throws Exception {
241-
String expectedInputStr = """
242-
{"name":"test_connector_name","description":"this is a test connector","version":"1",\
243-
"protocol":"http","parameters":{"input":["test input value"]},"credential":{"key":"test_key_value"},\
244-
"actions":[{"action_type":"PREDICT","method":"POST","url":"https://test.com",\
245-
"headers":{"api_key":"${credential.key}"},"request_body":"{\\"input\\": \\"${parameters.input}\\"}",\
246-
"pre_process_function":"connector.pre_process.openai.embedding",\
247-
"post_process_function":"connector.post_process.openai.embedding"}],\
248-
"backend_roles":["role1","role2"],"add_all_backend_roles":false,"access_mode":"PUBLIC"};\
249-
""";
240+
String expectedInputStr = "{\"name\":\"test_connector_name\","
241+
+ "\"description\":\"this is a test connector\",\"version\":\"1\",\"protocol\":\"http\","
242+
+ "\"parameters\":{\"input\":[\"test input value\"]},\"credential\":{\"key\":\"test_key_value\"},"
243+
+ "\"actions\":[{\"action_type\":\"PREDICT\",\"method\":\"POST\",\"url\":\"https://test.com\","
244+
+ "\"headers\":{\"api_key\":\"${credential.key}\"},"
245+
+ "\"request_body\":\"{\\\"input\\\": \\\"${parameters.input}\\\"}\","
246+
+ "\"pre_process_function\":\"connector.pre_process.openai.embedding\","
247+
+ "\"post_process_function\":\"connector.post_process.openai.embedding\"}],"
248+
+ "\"backend_roles\":[\"role1\",\"role2\"],\"add_all_backend_roles\":false,"
249+
+ "\"access_mode\":\"PUBLIC\"}";
250250
testParseFromJsonString(expectedInputStr, parsedInput -> {
251251
assertEquals(TEST_CONNECTOR_NAME, parsedInput.getName());
252252
assertEquals(1, parsedInput.getParameters().size());

0 commit comments

Comments
 (0)