Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE#4508] Add unit test for SpringSourceConnector. #4509

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions eventmesh-connectors/eventmesh-connector-spring/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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"
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Loading