gnodet-bot commented on code in PR #30604: URL: https://github.com/apache/camel/pull/30604#discussion_r4659028644
########## 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: 💬 **Nit (carried over):** `throws Exception` is unnecessary — `template.send()`, `assertThat()`, and `verify()` do not throw checked exceptions. The other two test methods correctly omit it. ```suggestion void testDeleteMessage() { ``` -- 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]
