gnodet-bot commented on code in PR #26499:
URL: https://github.com/apache/camel/pull/26499#discussion_r4024525037


##########
components/camel-huawei/camel-huaweicloud-smn/src/test/java/org/apache/camel/component/huaweicloud/smn/PublishTextMessageOperationViaPropertyTest.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.huaweicloud.smn;
+
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnOperations;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnProperties;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * When the operation is supplied only through the {@code 
CamelHwCloudSmnOperation} exchange property (with no
+ * {@code operation} endpoint parameter), an empty text-message body must fail 
with the clear
+ * {@code IllegalArgumentException} - not a {@code NullPointerException} from 
the guard testing the (null) endpoint
+ * operation, which was the behaviour before the operation was resolved ahead 
of the body check.
+ */
+public class PublishTextMessageOperationViaPropertyTest extends 
CamelTestSupport {
+
+    TestConfiguration testConfiguration = new TestConfiguration();
+
+    @BindToRegistry("smnClient")
+    SmnClientMock smnClientMock = new SmnClientMock(null);
+
+    protected RouteBuilder createRouteBuilder() {

Review Comment:
   ⚠️ **Missing test for the second bug scenario.** The PR description 
identifies two distinct bugs:
   
   1. Operation supplied **only via property** (null endpoint operation) + 
empty body → NPE. ✅ Covered by `emptyBodyReportsAClearErrorNotAnNpe()`.
   2. Endpoint operation = `publishAsTemplatedMessage`, property overrides to 
`publishAsTextMessage`, empty body → the old guard checks the endpoint 
operation (`publishAsTemplatedMessage`), doesn't fire, and publishes an empty 
text message. ❌ No test.
   
   The second scenario is entirely reachable in production (a route that sets 
`operation=publishAsTemplatedMessage` on the endpoint but dynamically overrides 
to `publishAsTextMessage` via property), and the fix in 
`SimpleNotificationProducer` covers it — but without a test, it can regress 
silently. Please add a test case, e.g.:
   
   ```java
   @Test
   public void endpointOperationOverriddenByPropertyEnforcesBodyCheck() {
       // endpoint has operation=publishAsTemplatedMessage, property overrides 
to publishAsTextMessage
       Exchange result = 
template.request("direct:publish_without_operation_param",
               e -> { e.getMessage().setHeader(/* or property */); 
e.getIn().setBody(null); });
       // expect the clear IllegalArgumentException, not a silent empty publish
       ...
   }
   ```
   
   (The exact setup depends on whether you reuse this class's route or add a 
second route — given the existing route already sets `SMN_OPERATION` to 
`PUBLISH_AS_TEXT_MESSAGE`, a separate route with 
`operation=publishAsTemplatedMessage` on the endpoint + property override is 
needed.)



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