ListenersConvertor { static GenericKafkaListener convertTlsListener(KafkaListenerTls tls) { GenericKafkaListenerConfiguration configuration = null; if (tls.getConfiguration() != null) { configuration = new GenericKafkaListenerConfigurationBuilder() .withBrokerCertChainAndKey(tls.getConfiguration().getBrokerCertChainAndKey()) .build(); } return new GenericKafkaListenerBuilder() .withName("tls") .withPort(9093) .withType(KafkaListenerType.INTERNAL) .withTls(true) .withAuth(tls.getAuth()) .withNetworkPolicyPeers(tls.getNetworkPolicyPeers()) .withConfiguration(configuration) .build(); }  @SuppressWarnings("deprecation") static List<GenericKafkaListener> convertToNewFormat(KafkaListeners oldListeners);  }
@Test public void testConvertSimpleTlsListener() { KafkaListenerTls oldTls = new KafkaListenerTlsBuilder() .build(); GenericKafkaListener newTls = ListenersConvertor.convertTlsListener(oldTls); assertThat(newTls.getName(), is("tls")); assertThat(newTls.getPort(), is(9093)); assertThat(newTls.getType(), is(KafkaListenerType.INTERNAL)); assertThat(newTls.getAuth(), is(nullValue())); assertThat(newTls.isTls(), is(true)); assertThat(newTls.getNetworkPolicyPeers(), is(nullValue())); assertThat(newTls.getConfiguration(), is(nullValue())); }
@Test public void testConvertTlsListener() { KafkaListenerTls oldTls = new KafkaListenerTlsBuilder() .withAuth(new KafkaListenerAuthenticationScramSha512()) .withNetworkPolicyPeers(NETWORK_POLICY_PEER_1, NETWORK_POLICY_PEER_2) .withNewConfiguration() .withNewBrokerCertChainAndKey() .withCertificate("cert") .withKey("key") .withSecretName("secretName") .endBrokerCertChainAndKey() .endConfiguration() .build(); GenericKafkaListener newTls = ListenersConvertor.convertTlsListener(oldTls); assertThat(newTls.getName(), is("tls")); assertThat(newTls.getPort(), is(9093)); assertThat(newTls.getType(), is(KafkaListenerType.INTERNAL)); assertThat(newTls.getAuth().getType(), is(KafkaListenerAuthenticationScramSha512.SCRAM_SHA_512)); assertThat(newTls.isTls(), is(true)); assertThat(newTls.getNetworkPolicyPeers().size(), is(2)); assertThat(newTls.getNetworkPolicyPeers(), hasItems(NETWORK_POLICY_PEER_1, NETWORK_POLICY_PEER_2)); assertThat(newTls.getConfiguration(), is(notNullValue())); assertThat(newTls.getConfiguration().getBrokerCertChainAndKey().getCertificate(), is("cert")); assertThat(newTls.getConfiguration().getBrokerCertChainAndKey().getKey(), is("key")); assertThat(newTls.getConfiguration().getBrokerCertChainAndKey().getSecretName(), is("secretName")); }