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

mxsm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/eventmesh.git


The following commit(s) were added to refs/heads/master by this push:
     new cf16cf60d [ISSUE#4508] Add unit test for SpringSourceConnector. (#4509)
cf16cf60d is described below

commit cf16cf60d570844d06198db6b3dd034551368a58
Author: yanrongzhen <[email protected]>
AuthorDate: Wed Oct 25 21:27:49 2023 +0800

    [ISSUE#4508] Add unit test for SpringSourceConnector. (#4509)
    
    * Add unit test for SpringSourceConnector.
    
    * fix build.gradle
---
 .../eventmesh-connector-spring/build.gradle        |  4 ++
 .../connector/SpringSourceConnectorTest.java       | 59 ++++++++++++++++++++++
 2 files changed, 63 insertions(+)

diff --git a/eventmesh-connectors/eventmesh-connector-spring/build.gradle 
b/eventmesh-connectors/eventmesh-connector-spring/build.gradle
index 06057096a..33e01d7c3 100644
--- a/eventmesh-connectors/eventmesh-connector-spring/build.gradle
+++ b/eventmesh-connectors/eventmesh-connector-spring/build.gradle
@@ -18,6 +18,7 @@
 configurations {
     implementation.exclude group: 'ch.qos.logback', module: 'logback-classic'
     implementation.exclude group: 'log4j', module: 'log4j'
+    testImplementation.exclude group: 'org.apache.logging.log4j', module: 
'log4j-to-slf4j'
 }
 
 dependencies {
@@ -28,4 +29,7 @@ dependencies {
     implementation "org.springframework:spring-messaging:$spring_version"
     compileOnly 'org.projectlombok:lombok'
     annotationProcessor 'org.projectlombok:lombok'
+
+    testImplementation "org.mockito:mockito-core"
+    testImplementation "org.mockito:mockito-junit-jupiter"
 }
\ No newline at end of file
diff --git 
a/eventmesh-connectors/eventmesh-connector-spring/src/test/java/org/apache/eventmesh/connector/spring/source/connector/SpringSourceConnectorTest.java
 
b/eventmesh-connectors/eventmesh-connector-spring/src/test/java/org/apache/eventmesh/connector/spring/source/connector/SpringSourceConnectorTest.java
new file mode 100644
index 000000000..35e4accbc
--- /dev/null
+++ 
b/eventmesh-connectors/eventmesh-connector-spring/src/test/java/org/apache/eventmesh/connector/spring/source/connector/SpringSourceConnectorTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.eventmesh.connector.spring.source.connector;
+
+import org.apache.eventmesh.connector.spring.source.config.SpringSourceConfig;
+import org.apache.eventmesh.openconnect.offsetmgmt.api.data.ConnectRecord;
+
+import java.util.List;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Spy;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+@ExtendWith(MockitoExtension.class)
+public class SpringSourceConnectorTest {
+
+    @Spy
+    private SpringSourceConnector connector;
+
+    @Test
+    public void testSpringSourceConnector() throws Exception {
+        SpringSourceConfig sourceConfig = new SpringSourceConfig();
+        connector.init(sourceConfig);
+        connector.start();
+        final int count = 5;
+        final String message = "testMessage";
+        writeMockedRecords(count, message);
+        List<ConnectRecord> connectRecords = connector.poll();
+        Assertions.assertEquals(count, connectRecords.size());
+        for (int i = 0; i < connectRecords.size(); i++) {
+            Object actualMessage = 
String.valueOf(connectRecords.get(i).getData());
+            String expectedMessage = "testMessage" + i;
+            Assertions.assertEquals(expectedMessage, actualMessage);
+        }
+    }
+
+    private void writeMockedRecords(int count, String message) throws 
Exception {
+        for (int i = 0; i < count; i++) {
+            connector.send(message + i);
+        }
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to