davsclaus commented on code in PR #24961:
URL: https://github.com/apache/camel/pull/24961#discussion_r3619701136


##########
components/camel-ai/camel-openai/src/test/java/org/apache/camel/component/openai/OpenAIAudioSpeechMockTest.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.camel.component.openai;
+
+import java.nio.charset.StandardCharsets;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.infra.openai.mock.OpenAIMock;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+

Review Comment:
   Convention: new test code should use AssertJ assertions (`assertThat(...)`) 
instead of JUnit assertions. Consider migrating these imports to:
   ```java
   import static org.assertj.core.api.Assertions.assertThat;
   ```
   and replacing `assertEquals`/`assertTrue`/`assertNotNull`/`assertNull` with 
fluent AssertJ equivalents.



##########
components/camel-ai/camel-openai/src/test/java/org/apache/camel/component/openai/OpenAIAudioTranslationMockTest.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.camel.component.openai;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.infra.openai.mock.OpenAIMock;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;

Review Comment:
   Same as above — new test code should use AssertJ assertions per project 
conventions.



##########
components/camel-ai/camel-openai/src/test/java/org/apache/camel/component/openai/OpenAIAudioSpeechMockTest.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.camel.component.openai;
+
+import java.nio.charset.StandardCharsets;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.infra.openai.mock.OpenAIMock;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class OpenAIAudioSpeechMockTest extends CamelTestSupport {
+
+    private static final byte[] AUDIO_DATA = 
"FAKE-MP3-AUDIO-BYTES".getBytes(StandardCharsets.UTF_8);
+
+    @RegisterExtension
+    public OpenAIMock openAIMock = new OpenAIMock().builder()
+            .whenSpeech()
+            .replyWithSpeech(AUDIO_DATA)
+            .end()
+            .build();
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("direct:speak")
+                        
.to("openai:audio-speech?speechModel=tts-1&speechVoice=alloy&apiKey=dummy&baseUrl="
+                            + openAIMock.getBaseUrl() + "/v1");
+
+                from("direct:speak-no-model")
+                        
.to("openai:audio-speech?speechVoice=alloy&apiKey=dummy&baseUrl="
+                            + openAIMock.getBaseUrl() + "/v1");
+
+                from("direct:speak-wav")
+                        
.to("openai:audio-speech?speechModel=tts-1&speechVoice=nova&speechResponseFormat=wav&apiKey=dummy&baseUrl="
+                            + openAIMock.getBaseUrl() + "/v1");
+            }
+        };
+    }
+
+    @Test
+    void testSpeechReturnsAudioBytes() {
+        Exchange result = template.request("direct:speak", e -> 
e.getIn().setBody("Hello from Apache Camel"));
+
+        assertNotNull(result);
+        assertNull(result.getException());
+        assertArrayEquals(AUDIO_DATA, 
result.getMessage().getBody(byte[].class));
+    }
+
+    @Test
+    void testSpeechSetsContentType() {
+        Exchange result = template.request("direct:speak", e -> 
e.getIn().setBody("Hello"));
+
+        assertNotNull(result);
+        assertNull(result.getException());
+        assertEquals("audio/mpeg", 
result.getMessage().getHeader(Exchange.CONTENT_TYPE));
+    }
+
+    @Test
+    void testSpeechWavContentType() {
+        Exchange result = template.request("direct:speak-wav", e -> 
e.getIn().setBody("Hello"));
+
+        assertNotNull(result);
+        assertNull(result.getException());
+        assertEquals("audio/wav", 
result.getMessage().getHeader(Exchange.CONTENT_TYPE));
+        assertArrayEquals(AUDIO_DATA, 
result.getMessage().getBody(byte[].class));
+    }
+
+    @Test
+    void testSpeechWithHeaderOverrides() {
+        Exchange result = template.request("direct:speak", e -> {
+            e.getIn().setBody("Hello");
+            e.getIn().setHeader(OpenAIConstants.SPEECH_MODEL, 
"gpt-4o-mini-tts");
+            e.getIn().setHeader(OpenAIConstants.SPEECH_VOICE, "shimmer");
+            e.getIn().setHeader(OpenAIConstants.SPEECH_RESPONSE_FORMAT, 
"flac");
+            e.getIn().setHeader(OpenAIConstants.SPEECH_SPEED, 1.25);
+            e.getIn().setHeader(OpenAIConstants.SPEECH_INSTRUCTIONS, "Speak 
cheerfully");
+        });
+
+        assertNotNull(result);
+        assertNull(result.getException());
+        assertArrayEquals(AUDIO_DATA, 
result.getMessage().getBody(byte[].class));
+        assertEquals("audio/flac", 
result.getMessage().getHeader(Exchange.CONTENT_TYPE));
+    }
+
+    @Test
+    void testSpeechMissingModel() {
+        Exchange result = template.request("direct:speak-no-model", e -> 
e.getIn().setBody("Hello"));
+
+        assertNotNull(result);
+        assertNotNull(result.getException());
+        assertTrue(result.getException() instanceof IllegalArgumentException);
+        assertTrue(result.getException().getMessage().contains("Speech model 
must be specified"));

Review Comment:
   This `assertTrue(... instanceof ...)` + `assertTrue(... .contains(...))` 
pattern is more readable and provides better failure messages with AssertJ:
   ```suggestion
           assertThat(result.getException())
                   .isInstanceOf(IllegalArgumentException.class)
                   .hasMessageContaining("Speech model must be specified");
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to