Skip to content

Commit

Permalink
馃懏 #17 Misc. clean-up;
Browse files Browse the repository at this point in the history
* Showing more meaningful error message
* Avoiding Commons Lang dependency
* Updating versions
  • Loading branch information
gunnarmorling committed Oct 8, 2021
1 parent 098b1b4 commit aa2dcef
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 14 deletions.
6 changes: 3 additions & 3 deletions docker-compose.basic-auth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
version: '2'
services:
zookeeper:
image: debezium/zookeeper:1.6
image: debezium/zookeeper:1.7
ports:
- 2181:2181
- 2888:2888
- 3888:3888
kafka:
image: debezium/kafka:1.6
image: debezium/kafka:1.7
ports:
- 9092:9092
links:
- zookeeper
environment:
- ZOOKEEPER_CONNECT=zookeeper:2181
connect:
image: debezium/connect-base:1.6
image: debezium/connect-base:1.7
ports:
- 8083:8083
links:
Expand Down
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,6 @@
<version>2.28.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>

</dependencies>

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/dev/morling/kccli/service/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

import java.net.URI;

import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

import dev.morling.kccli.util.Strings;

public class Context {
private final URI cluster;
private final String bootstrapServers;
Expand Down Expand Up @@ -64,8 +64,8 @@ public String getPassword() {

@JsonIgnore
public boolean isUsingBasicAuthentication() {
return StringUtils.isNotBlank(this.getUsername()) &&
StringUtils.isNotBlank(this.getPassword());
return !Strings.isBlank(this.getUsername()) &&
!Strings.isBlank(this.getPassword());
}

public static Context defaultContext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@

public class KafkaConnectException extends RuntimeException {

private int errorCode;
private final int errorCode;

public KafkaConnectException(String message, int errorCode) {
super(message);
this.errorCode = errorCode;
}

public KafkaConnectException(ErrorResponse error) {
super(getMessage(error.message));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@
package dev.morling.kccli.service;

import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

import org.eclipse.microprofile.rest.client.ext.ResponseExceptionMapper;

public class KafkaConnectResponseExceptionMapper implements ResponseExceptionMapper<RuntimeException> {

@Override
public RuntimeException toThrowable(Response response) {
if (response.getStatusInfo() == Status.UNAUTHORIZED) {
return new KafkaConnectException(response.readEntity(String.class), Status.UNAUTHORIZED.getStatusCode());
}

ErrorResponse error = response.readEntity(ErrorResponse.class);
return new KafkaConnectException(error);
}
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/dev/morling/kccli/util/Strings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2021 The original authors
*
* Licensed 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 dev.morling.kccli.util;

public class Strings {

private Strings() {
}

public static boolean isBlank(String string) {
if (string == null) {
return true;
}

return string.trim().isEmpty();
}
}
49 changes: 49 additions & 0 deletions src/test/java/dev/morling/kccli/util/StringsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2021 The original authors
*
* Licensed 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 dev.morling.kccli.util;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class StringsTest {

@Test
public void nullIsBlank() {
assertTrue(Strings.isBlank(null));
}

@Test
public void emptyIsBlank() {
assertTrue(Strings.isBlank(""));
}

@Test
public void whitespaceIsBlank() {
assertTrue(Strings.isBlank(" "));
}

@Test
public void bobIsNotBlank() {
assertFalse(Strings.isBlank("bob"));
}

@Test
public void bobWithWhitespaceIsNotBlank() {
assertFalse(Strings.isBlank(" bob "));
}
}

0 comments on commit aa2dcef

Please sign in to comment.