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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 9955251f909 CAMEL-21319: Added unit test
9955251f909 is described below

commit 9955251f90963e6b0c1108782e45258198935f7f
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Sun Oct 6 10:09:12 2024 +0200

    CAMEL-21319: Added unit test
---
 ...mppTRXProducerSupervisingRouteControllerIT.java | 132 +++++++++++++++++++++
 1 file changed, 132 insertions(+)

diff --git 
a/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppTRXProducerSupervisingRouteControllerIT.java
 
b/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppTRXProducerSupervisingRouteControllerIT.java
new file mode 100644
index 00000000000..08f78639b7b
--- /dev/null
+++ 
b/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppTRXProducerSupervisingRouteControllerIT.java
@@ -0,0 +1,132 @@
+/*
+ * 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.smpp.integration;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.smpp.SmppConstants;
+import org.apache.camel.component.smpp.SmppMessageType;
+import org.apache.camel.spi.SupervisingRouteController;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.jsmpp.examples.SMPPServerSimulator;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.parallel.Isolated;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+@Isolated
+class SmppTRXProducerSupervisingRouteControllerIT extends CamelTestSupport {
+    private static int PORT = 8100; // use private port to avoid reusing from 
previous tests
+    private static final CountDownLatch LATCH = new CountDownLatch(1);
+    private static final Thread SMPP_SERVER_SIMULATOR = new Thread(() -> {
+        try {
+            // timeout after 3 sec
+            LATCH.await(3, TimeUnit.SECONDS);
+        } catch (Exception e) {
+            // ignore
+        }
+        System.setProperty("jsmpp.simulator.port", "" + PORT);
+        SMPPServerSimulator.main(null);
+    });
+
+    @EndpointInject("mock:result")
+    private MockEndpoint result;
+
+    @EndpointInject("direct:start")
+    private Endpoint start;
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+
+        SupervisingRouteController src = 
context.getRouteController().supervising();
+        src.setBackOffDelay(500);
+        src.setBackOffMaxAttempts(20);
+        src.setInitialDelay(100);
+        src.setThreadPoolSize(2);
+
+        return context;
+    }
+
+    @BeforeAll
+    public static void runSMPPServerSimulator() {
+        PORT = AvailablePortFinder.getNextAvailable(8100, 9999);
+        SMPP_SERVER_SIMULATOR.start();
+    }
+
+    @AfterAll
+    public static void stopSMPPServerSimulator() {
+        SMPP_SERVER_SIMULATOR.interrupt();
+    }
+
+    @Test
+    void sendSubmitSMInOnly() throws Exception {
+        result.expectedMessageCount(1);
+
+        Exchange exchange = start.createExchange(ExchangePattern.InOnly);
+        exchange.getIn().setBody("Hello SMPP World!");
+
+        template.send(start, exchange);
+
+        MockEndpoint.assertIsSatisfied(context);
+        Exchange resultExchange = result.getExchanges().get(0);
+        assertEquals(SmppMessageType.DeliveryReceipt.toString(), 
resultExchange.getIn().getHeader(SmppConstants.MESSAGE_TYPE));
+        assertEquals("Hello SMPP World!", resultExchange.getIn().getBody());
+        assertNotNull(resultExchange.getIn().getHeader(SmppConstants.ID));
+        assertEquals(1, 
resultExchange.getIn().getHeader(SmppConstants.SUBMITTED));
+        assertEquals(1, 
resultExchange.getIn().getHeader(SmppConstants.DELIVERED));
+        
assertNotNull(resultExchange.getIn().getHeader(SmppConstants.DONE_DATE));
+        
assertNotNull(resultExchange.getIn().getHeader(SmppConstants.SUBMIT_DATE));
+        assertNull(resultExchange.getIn().getHeader(SmppConstants.ERROR));
+
+        assertNotNull(exchange.getIn().getHeader(SmppConstants.ID));
+        assertEquals(1, 
exchange.getIn().getHeader(SmppConstants.SENT_MESSAGE_COUNT));
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("direct:start")
+                        .to("smpp://j@localhost:" + PORT + 
"?password=jpwd&systemType=producer" +
+                            
"&messageReceiverRouteId=testMessageReceiverRouteId");
+
+                from("direct:messageReceiver").id("testMessageReceiverRouteId")
+                        .choice()
+                        .when(simple("${header.CamelSmppSourceAddr} == '555'"))
+                        .to("mock:garbage") // SMPPServerSimulator.run send a 
test message, ignore it
+                        .otherwise()
+                        .to("mock:result");
+            }
+        };
+    }
+}

Reply via email to