sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tma...@apache.org
Subject [sling-org-apache-sling-distribution-journal-kafka] branch master updated: SLING-8451 - Document KafkaEndpoint configuration properties and use Kafka default
Date Fri, 31 May 2019 14:11:26 GMT
This is an automated email from the ASF dual-hosted git repository.

tmaret pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-distribution-journal-kafka.git


The following commit(s) were added to refs/heads/master by this push:
     new 0ff8c5f  SLING-8451 - Document KafkaEndpoint configuration properties and use Kafka
default
0ff8c5f is described below

commit 0ff8c5f26ac95df049d562172ea973c4e593acae
Author: tmaret <tmaret@adobe.com>
AuthorDate: Fri May 31 16:11:17 2019 +0200

    SLING-8451 - Document KafkaEndpoint configuration properties and use Kafka default
    
    * Build KafkaEndpoint using a custom converter instead of the ad-hoc mock
---
 pom.xml                                            |  2 +-
 .../journal/kafka/util/KafkaEndpointBuilder.java   | 31 +++++++++-------------
 2 files changed, 14 insertions(+), 19 deletions(-)

diff --git a/pom.xml b/pom.xml
index a72608b..eb819fe 100644
--- a/pom.xml
+++ b/pom.xml
@@ -125,7 +125,7 @@
         <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.converter</artifactId>
-            <version>1.0.0</version>
+            <version>1.0.8</version>
         </dependency>
         <dependency>
             <groupId>ch.qos.logback</groupId>
diff --git a/src/test/java/org/apache/sling/distribution/journal/kafka/util/KafkaEndpointBuilder.java
b/src/test/java/org/apache/sling/distribution/journal/kafka/util/KafkaEndpointBuilder.java
index be5dde9..3579274 100644
--- a/src/test/java/org/apache/sling/distribution/journal/kafka/util/KafkaEndpointBuilder.java
+++ b/src/test/java/org/apache/sling/distribution/journal/kafka/util/KafkaEndpointBuilder.java
@@ -21,29 +21,24 @@ package org.apache.sling.distribution.journal.kafka.util;
 import java.util.Map;
 
 import org.apache.sling.distribution.journal.kafka.KafkaEndpoint;
+import org.osgi.util.converter.Converter;
 
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 import static org.osgi.util.converter.Converters.standardConverter;
 
 public class KafkaEndpointBuilder {
 
-    public static KafkaEndpoint buildKafkaEndpoint(Map<String, Object> props) {
+    /**
+     * Custom converter that return null instead of throwing ConversionException
+     * for properties with null default. See FELIX-6137.
+     */
+    private static final Converter CONVERTER = standardConverter()
+            .newConverterBuilder()
+            .errorHandler((o,t) -> null)
+            .build();
 
-        /*
-         * The standardConverter does not support null default
-         * Until FELIX-6137 is fixed, we use this 'creative' way
-         * to build KafkaEndpoint.
-         */
-
-        KafkaEndpoint proxy = standardConverter().convert(props).to(KafkaEndpoint.class);
-        KafkaEndpoint endpoint = mock(KafkaEndpoint.class);
-        when(endpoint.saslJaasConfig()).thenReturn(null);
-        when(endpoint.securityProtocol()).thenReturn(proxy.securityProtocol());
-        when(endpoint.kafkaBootstrapServers()).thenReturn(proxy.kafkaBootstrapServers());
-        when(endpoint.kafkaDefaultApiTimeout()).thenReturn(proxy.kafkaDefaultApiTimeout());
-        when(endpoint.kafkaRequestTimeout()).thenReturn(proxy.kafkaRequestTimeout());
-        when(endpoint.saslMechanism()).thenReturn(proxy.saslMechanism());
-        return endpoint;
+    public static KafkaEndpoint buildKafkaEndpoint(Map<String, Object> props) {
+        return CONVERTER.convert(props).to(KafkaEndpoint.class);
     }
+
+
 }


Mime
View raw message