Skip to content

Commit

Permalink
DBZ-3720 Error with debezium.sink.pulsar.client.serviceUrl and debezi…
Browse files Browse the repository at this point in the history
…um-server
  • Loading branch information
gustavolira authored and jpechane committed Dec 16, 2024
1 parent b1ffeba commit d17fba6
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
38 changes: 38 additions & 0 deletions debezium-core/src/main/java/io/debezium/util/Strings.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import java.util.stream.Collectors;

import io.debezium.annotation.ThreadSafe;
import io.debezium.text.ParsingException;
Expand Down Expand Up @@ -1253,4 +1254,41 @@ else if (c == ',') {
tokens.addToken(input.position(tokenStart), tokenStart, input.index() + 1);
}
}

/**
* Converts a string with separators (e.g., dots, underscores) into camelCase format using Stream API.
*
* @param input the input string containing separators such as dots or underscores
* @return the converted string in camelCase format, or an empty string if the input is null or empty
*/
public static String convertDotAndUnderscoreStringToCamelCase(String input) {
if (input == null || input.isEmpty()) {
return "";
}

String[] words = input.split("[._]+");
if (words.length == 0) {
return ""; // Handle edge case where input contains only separators
}

return java.util.stream.IntStream.range(0, words.length)
.filter(i -> !words[i].isEmpty()) // Skip empty segments caused by consecutive separators
.mapToObj(i -> i == 0
? words[i].toLowerCase() // Ensure the first word starts with lowercase
: capitalizeFirstLetter(words[i])) // Capitalize the first letter of subsequent words
.collect(java.util.stream.Collectors.joining());
}

/**
* Capitalizes the first letter of a word and converts the rest to lowercase.
*
* @param word the word to capitalize
* @return the word with the first letter capitalized
*/
private static String capitalizeFirstLetter(String word) {
if (word.isEmpty()) {
return "";
}
return Character.toUpperCase(word.charAt(0)) + word.substring(1).toLowerCase();
}
}
48 changes: 48 additions & 0 deletions debezium-core/src/test/java/io/debezium/util/StringsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -426,4 +426,52 @@ protected void assertRegexList(String patterns, String... matches) {
.map(Pattern::pattern)
.collect(Collectors.toList())).isEqualTo(Arrays.asList((Object[]) matches));
}

@Test
public void convertDotAndUnderscoreStringToCamelCaseShouldReturnEmptyForNullInput() {
assertThat(Strings.convertDotAndUnderscoreStringToCamelCase(null))
.isEqualTo("");
}

@Test
public void convertDotAndUnderscoreStringToCamelCaseShouldReturnEmptyForEmptyInput() {
assertThat(Strings.convertDotAndUnderscoreStringToCamelCase(""))
.isEqualTo("");
}

@Test
public void convertDotAndUnderscoreStringToCamelCaseShouldHandleNoSeparators() {
assertThat(Strings.convertDotAndUnderscoreStringToCamelCase("hello"))
.isEqualTo("hello");
}

@Test
public void convertDotAndUnderscoreStringToCamelCaseShouldHandleUnderscores() {
assertThat(Strings.convertDotAndUnderscoreStringToCamelCase("hello_world"))
.isEqualTo("helloWorld");
}

@Test
public void convertDotAndUnderscoreStringToCamelCaseShouldHandleDots() {
assertThat(Strings.convertDotAndUnderscoreStringToCamelCase("hello.world"))
.isEqualTo("helloWorld");
}

@Test
public void convertDotAndUnderscoreStringToCamelCaseShouldHandleDotsAndUnderscores() {
assertThat(Strings.convertDotAndUnderscoreStringToCamelCase("hello.world_and_universe"))
.isEqualTo("helloWorldAndUniverse");
}

@Test
public void convertDotAndUnderscoreStringToCamelCaseShouldConvertUpperCaseInput() {
assertThat(Strings.convertDotAndUnderscoreStringToCamelCase("HELLO_WORLD"))
.isEqualTo("helloWorld");
}

@Test
public void convertDotAndUnderscoreStringToCamelCaseShouldHandleMultipleConsecutiveSeparators() {
assertThat(Strings.convertDotAndUnderscoreStringToCamelCase("hello__world..universe"))
.isEqualTo("helloWorldUniverse");
}
}

0 comments on commit d17fba6

Please sign in to comment.