This is an automated email from the ASF dual-hosted git repository.

wenjin272 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/flink-agents.git


The following commit(s) were added to refs/heads/main by this push:
     new 5a43f7b1 [hotfix][api][java] Add tests for enum value parsers (#1135)
5a43f7b1 is described below

commit 5a43f7b1e11de28bf2875455fd4fb63b57aac428
Author: william <[email protected]>
AuthorDate: Fri Sep 18 11:26:41 2026 +0800

    [hotfix][api][java] Add tests for enum value parsers (#1135)
    
    Add focused unit tests for the string parsers of EventLogLevel, LoggerType, 
ResourceType and MessageRole, which are the entry points for user supplied 
configuration and currently have no coverage. No production code is changed.
    
    Generated-by: CodeBuddy (Auto)
---
 .../agents/api/chat/messages/MessageRoleTest.java  | 70 ++++++++++++++++++++++
 .../flink/agents/api/logger/EventLogLevelTest.java | 62 +++++++++++++++++++
 .../flink/agents/api/logger/LoggerTypeTest.java    | 68 +++++++++++++++++++++
 .../agents/api/resource/ResourceTypeTest.java      | 61 +++++++++++++++++++
 4 files changed, 261 insertions(+)

diff --git 
a/api/src/test/java/org/apache/flink/agents/api/chat/messages/MessageRoleTest.java
 
b/api/src/test/java/org/apache/flink/agents/api/chat/messages/MessageRoleTest.java
new file mode 100644
index 00000000..f4f01cd4
--- /dev/null
+++ 
b/api/src/test/java/org/apache/flink/agents/api/chat/messages/MessageRoleTest.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.agents.api.chat.messages;
+
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/** Tests for {@link MessageRole}. */
+class MessageRoleTest {
+
+    @Test
+    @DisplayName("Resolve a message role from its serialized value")
+    void testFromValue() {
+        assertThat(MessageRole.fromValue("user")).isEqualTo(MessageRole.USER);
+        
assertThat(MessageRole.fromValue("assistant")).isEqualTo(MessageRole.ASSISTANT);
+        
assertThat(MessageRole.fromValue("system")).isEqualTo(MessageRole.SYSTEM);
+        assertThat(MessageRole.fromValue("tool")).isEqualTo(MessageRole.TOOL);
+    }
+
+    @Test
+    @DisplayName("Every declared role round-trips through its serialized 
value")
+    void testFromValueCoversEveryValue() {
+        for (MessageRole role : MessageRole.values()) {
+            assertThat(MessageRole.fromValue(role.getValue())).isEqualTo(role);
+        }
+    }
+
+    @Test
+    @DisplayName("The serialized value is what toString returns as well")
+    void testToStringReturnsValue() {
+        for (MessageRole role : MessageRole.values()) {
+            assertThat(role.toString()).isEqualTo(role.getValue());
+        }
+    }
+
+    @Test
+    @DisplayName("An unknown value is rejected and echoed back")
+    void testFromValueRejectsUnknownValue() {
+        assertThatThrownBy(() -> MessageRole.fromValue("admin"))
+                .isInstanceOf(IllegalArgumentException.class)
+                .hasMessageContaining("Invalid MessageRole value: admin");
+    }
+
+    @Test
+    @DisplayName("A null value is rejected rather than matching a role")
+    void testFromValueRejectsNull() {
+        assertThatThrownBy(() -> MessageRole.fromValue(null))
+                .isInstanceOf(IllegalArgumentException.class)
+                .hasMessageContaining("Invalid MessageRole value: null");
+    }
+}
diff --git 
a/api/src/test/java/org/apache/flink/agents/api/logger/EventLogLevelTest.java 
b/api/src/test/java/org/apache/flink/agents/api/logger/EventLogLevelTest.java
new file mode 100644
index 00000000..c340282d
--- /dev/null
+++ 
b/api/src/test/java/org/apache/flink/agents/api/logger/EventLogLevelTest.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.agents.api.logger;
+
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/** Tests for {@link EventLogLevel}. */
+class EventLogLevelTest {
+
+    @Test
+    @DisplayName("Parse a log level from its name, ignoring case")
+    void testFromStringIsCaseInsensitive() {
+        
assertThat(EventLogLevel.fromString("off")).isEqualTo(EventLogLevel.OFF);
+        
assertThat(EventLogLevel.fromString("STANDARD")).isEqualTo(EventLogLevel.STANDARD);
+        
assertThat(EventLogLevel.fromString("Verbose")).isEqualTo(EventLogLevel.VERBOSE);
+    }
+
+    @Test
+    @DisplayName("Every declared log level round-trips through its name")
+    void testFromStringCoversEveryValue() {
+        for (EventLogLevel level : EventLogLevel.values()) {
+            
assertThat(EventLogLevel.fromString(level.name())).isEqualTo(level);
+        }
+    }
+
+    @Test
+    @DisplayName("A null value is rejected with a message naming the enum")
+    void testFromStringRejectsNull() {
+        assertThatThrownBy(() -> EventLogLevel.fromString(null))
+                .isInstanceOf(IllegalArgumentException.class)
+                .hasMessageContaining("EventLogLevel value cannot be null");
+    }
+
+    @Test
+    @DisplayName("An unknown value is rejected with a message listing the 
valid values")
+    void testFromStringRejectsUnknownValue() {
+        assertThatThrownBy(() -> EventLogLevel.fromString("trace"))
+                .isInstanceOf(IllegalArgumentException.class)
+                .hasMessageContaining("Invalid EventLogLevel")
+                .hasMessageContaining("OFF, STANDARD, VERBOSE");
+    }
+}
diff --git 
a/api/src/test/java/org/apache/flink/agents/api/logger/LoggerTypeTest.java 
b/api/src/test/java/org/apache/flink/agents/api/logger/LoggerTypeTest.java
new file mode 100644
index 00000000..c4c15f56
--- /dev/null
+++ b/api/src/test/java/org/apache/flink/agents/api/logger/LoggerTypeTest.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.agents.api.logger;
+
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/** Tests for {@link LoggerType}. */
+class LoggerTypeTest {
+
+    @Test
+    @DisplayName("Resolve a logger type from its identifier, ignoring case")
+    void testFromTypeIsCaseInsensitive() {
+        assertThat(LoggerType.fromType("slf4j")).isEqualTo(LoggerType.SLF4J);
+        assertThat(LoggerType.fromType("SLF4J")).isEqualTo(LoggerType.SLF4J);
+        assertThat(LoggerType.fromType("File")).isEqualTo(LoggerType.FILE);
+    }
+
+    @Test
+    @DisplayName("Surrounding whitespace is trimmed before resolution")
+    void testFromTypeTrimsWhitespace() {
+        assertThat(LoggerType.fromType(" file ")).isEqualTo(LoggerType.FILE);
+        
assertThat(LoggerType.fromType("\tslf4j\n")).isEqualTo(LoggerType.SLF4J);
+    }
+
+    @Test
+    @DisplayName("Every declared type round-trips through its identifier")
+    void testFromTypeCoversEveryValue() {
+        for (LoggerType type : LoggerType.values()) {
+            assertThat(LoggerType.fromType(type.getType())).isEqualTo(type);
+        }
+    }
+
+    @Test
+    @DisplayName("A null identifier is rejected")
+    void testFromTypeRejectsNull() {
+        assertThatThrownBy(() -> LoggerType.fromType(null))
+                .isInstanceOf(IllegalArgumentException.class)
+                .hasMessageContaining("Logger type cannot be null");
+    }
+
+    @Test
+    @DisplayName("An unknown identifier is rejected and echoed back")
+    void testFromTypeRejectsUnknownType() {
+        assertThatThrownBy(() -> LoggerType.fromType("kafka"))
+                .isInstanceOf(IllegalArgumentException.class)
+                .hasMessageContaining("Unknown logger type: kafka");
+    }
+}
diff --git 
a/api/src/test/java/org/apache/flink/agents/api/resource/ResourceTypeTest.java 
b/api/src/test/java/org/apache/flink/agents/api/resource/ResourceTypeTest.java
new file mode 100644
index 00000000..374a9c6b
--- /dev/null
+++ 
b/api/src/test/java/org/apache/flink/agents/api/resource/ResourceTypeTest.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.agents.api.resource;
+
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/** Tests for {@link ResourceType}. */
+class ResourceTypeTest {
+
+    @Test
+    @DisplayName("Resolve a resource type from its string value")
+    void testFromValue() {
+        
assertThat(ResourceType.fromValue("chat_model")).isEqualTo(ResourceType.CHAT_MODEL);
+        
assertThat(ResourceType.fromValue("vector_store")).isEqualTo(ResourceType.VECTOR_STORE);
+        
assertThat(ResourceType.fromValue("mcp_server")).isEqualTo(ResourceType.MCP_SERVER);
+    }
+
+    @Test
+    @DisplayName("Every declared type round-trips through its string value")
+    void testFromValueCoversEveryValue() {
+        for (ResourceType type : ResourceType.values()) {
+            
assertThat(ResourceType.fromValue(type.getValue())).isEqualTo(type);
+        }
+    }
+
+    @Test
+    @DisplayName("An unknown value is rejected and echoed back")
+    void testFromValueRejectsUnknownValue() {
+        assertThatThrownBy(() -> 
ResourceType.fromValue("chat_model_connections"))
+                .isInstanceOf(IllegalArgumentException.class)
+                .hasMessageContaining("Unknown ResourceType value: 
chat_model_connections");
+    }
+
+    @Test
+    @DisplayName("A null value is rejected rather than matching a type")
+    void testFromValueRejectsNull() {
+        assertThatThrownBy(() -> ResourceType.fromValue(null))
+                .isInstanceOf(IllegalArgumentException.class)
+                .hasMessageContaining("Unknown ResourceType value: null");
+    }
+}

Reply via email to