ListenersConvertor { @SuppressWarnings("deprecation") public static List<GenericKafkaListener> convertToNewFormat(KafkaListeners oldListeners) { List<GenericKafkaListener> newListeners = new ArrayList<>(3); if (oldListeners != null) { if (oldListeners.getPlain() != null) { newListeners.add(convertPlainListener(oldListeners.getPlain())); } if (oldListeners.getTls() != null) { newListeners.add(convertTlsListener(oldListeners.getTls())); } if (oldListeners.getExternal() != null) { newListeners.add(convertExternalListener(oldListeners.getExternal())); } } return newListeners; }  @SuppressWarnings("deprecation") static List<GenericKafkaListener> convertToNewFormat(KafkaListeners oldListeners);  }
@Test public void testConvertToNewFormat() { KafkaListeners oldListeners = new KafkaListenersBuilder() .withNewPlain() .withAuth(new KafkaListenerAuthenticationScramSha512()) .endPlain() .withNewTls() .withAuth(new KafkaListenerAuthenticationTls()) .endTls() .withNewKafkaListenerExternalRoute() .withAuth(new KafkaListenerAuthenticationTls()) .endKafkaListenerExternalRoute() .build(); List<GenericKafkaListener> newListners = ListenersConvertor.convertToNewFormat(oldListeners); assertThat(newListners, is(notNullValue())); assertThat(newListners.size(), is(3)); GenericKafkaListener plain = newListners.stream().filter(list -> "plain".equals(list.getName())).findFirst().orElseThrow(() -> new RuntimeException()); assertThat(plain.getAuth().getType(), is(KafkaListenerAuthenticationScramSha512.SCRAM_SHA_512)); GenericKafkaListener tls = newListners.stream().filter(list -> "tls".equals(list.getName())).findFirst().orElseThrow(() -> new RuntimeException()); assertThat(tls.getAuth().getType(), is(KafkaListenerAuthenticationTls.TYPE_TLS)); GenericKafkaListener external = newListners.stream().filter(list -> "external".equals(list.getName())).findFirst().orElseThrow(() -> new RuntimeException()); assertThat(external.getType(), is(KafkaListenerType.ROUTE)); assertThat(external.getAuth().getType(), is(KafkaListenerAuthenticationTls.TYPE_TLS)); }
@Test public void testConvertToNewFormatSingle() { KafkaListeners oldListeners = new KafkaListenersBuilder() .withNewPlain() .withAuth(new KafkaListenerAuthenticationScramSha512()) .endPlain() .build(); List<GenericKafkaListener> newListners = ListenersConvertor.convertToNewFormat(oldListeners); assertThat(newListners, is(notNullValue())); assertThat(newListners.size(), is(1)); GenericKafkaListener plain = newListners.stream().filter(list -> "plain".equals(list.getName())).findFirst().orElseThrow(() -> new RuntimeException()); assertThat(plain.getAuth().getType(), is(KafkaListenerAuthenticationScramSha512.SCRAM_SHA_512)); }
@Test public void testConvertToNewFormatEmpty() { KafkaListeners oldListeners = new KafkaListenersBuilder() .build(); List<GenericKafkaListener> newListners = ListenersConvertor.convertToNewFormat(oldListeners); assertThat(newListners, is(notNullValue())); assertThat(newListners.size(), is(0)); }
@Test public void testConvertToNewFormatNull() { List<GenericKafkaListener> newListners = ListenersConvertor.convertToNewFormat(null); assertThat(newListners, is(notNullValue())); assertThat(newListners.size(), is(0)); }