saravanakumar1987 commented on code in PR #30604:
URL: https://github.com/apache/camel/pull/30604#discussion_r4659030544


##########
components/camel-alibaba/camel-alibaba-mns/src/test/java/org/apache/camel/component/alibaba/mns/MNSProducerWithoutKeysTest.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.alibaba.mns;
+
+import com.aliyun.mns.client.CloudQueue;
+import com.aliyun.mns.client.CloudTopic;
+import com.aliyun.mns.client.MNSClient;
+import com.aliyun.mns.model.Message;
+import com.aliyun.mns.model.TopicMessage;
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.alibaba.mns.constants.MNSHeaders;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+class MNSProducerWithoutKeysTest extends CamelTestSupport {
+
+    private final TestConfiguration testConfiguration = new 
TestConfiguration();
+
+    @BindToRegistry("mnsClient")
+    MNSClient mnsClient = mock(MNSClient.class);
+
+    CloudQueue cloudQueue = mock(CloudQueue.class);
+
+    CloudTopic cloudTopic = mock(CloudTopic.class);
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("direct:send")
+                        .to("alibaba-mns:" + 
testConfiguration.getProperty("queue") + "?mnsClient=#mnsClient");
+                from("direct:publish")
+                        .to("alibaba-mns:topic:" + 
testConfiguration.getProperty("topic") + "?mnsClient=#mnsClient");
+                from("direct:delete")
+                        .to("alibaba-mns:" + 
testConfiguration.getProperty("queue")
+                            + "?operation=deleteMessage&mnsClient=#mnsClient");
+            }
+        };
+    }
+
+    @Test
+    void testSendMessage() {
+        
when(mnsClient.getQueueRef(testConfiguration.getProperty("queue"))).thenReturn(cloudQueue);
+
+        Exchange exchange = template.send("direct:send", e -> 
e.getMessage().setBody("hello mns"));
+
+        assertThat(exchange.getException()).isNull();
+        verify(cloudQueue).putMessage(any(Message.class));
+    }
+
+    @Test
+    void testPublishMessage() {
+        
when(mnsClient.getTopicRef(testConfiguration.getProperty("topic"))).thenReturn(cloudTopic);
+
+        Exchange exchange = template.send("direct:publish", e -> 
e.getMessage().setBody("hello topic"));
+
+        assertThat(exchange.getException()).isNull();
+        verify(cloudTopic).publishMessage(any(TopicMessage.class));
+    }
+
+    @Test
+    void testDeleteMessage() throws Exception {

Review Comment:
   Kept as it is. `verify(cloudQueue).deleteMessage(...)` calls 
`CloudQueue.deleteMessage`, which declares `ServiceHandlingRequiredException` 
in aliyun-sdk-mns 2.0.0. That exception is checked. Without the throws clause, 
javac fails at that line with "unreported exception 
com.aliyun.mns.common.ServiceHandlingRequiredException". `putMessage` and 
`publishMessage` declare only unchecked exceptions, so the other two tests need 
none.
   
   _Claude Code on behalf of saravanakumar1987_



-- 
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