This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit 6a5b3e5e551307a123144f02f3df2f7cee454a07 Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Thu Dec 14 14:46:54 2023 +0100 CAMEL-18590 - Camel-Azure components: Define a unique configuration for authentication - Azure Servicebus - Tests Signed-off-by: Andrea Cosentino <anco...@gmail.com> --- .../azure/servicebus/ServiceBusComponent.java | 3 --- .../azure/servicebus/ServiceBusConfiguration.java | 3 +-- .../azure/servicebus/ServiceBusEndpointTest.java | 27 ++++++++++++++++++++-- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/components/camel-azure/camel-azure-servicebus/src/main/java/org/apache/camel/component/azure/servicebus/ServiceBusComponent.java b/components/camel-azure/camel-azure-servicebus/src/main/java/org/apache/camel/component/azure/servicebus/ServiceBusComponent.java index e4f38adccc4..5e314007743 100644 --- a/components/camel-azure/camel-azure-servicebus/src/main/java/org/apache/camel/component/azure/servicebus/ServiceBusComponent.java +++ b/components/camel-azure/camel-azure-servicebus/src/main/java/org/apache/camel/component/azure/servicebus/ServiceBusComponent.java @@ -20,7 +20,6 @@ import java.util.Map; import java.util.Set; import com.azure.core.credential.TokenCredential; -import com.azure.identity.DefaultAzureCredentialBuilder; import org.apache.camel.CamelContext; import org.apache.camel.Endpoint; import org.apache.camel.spi.Metadata; @@ -73,8 +72,6 @@ public class ServiceBusComponent extends DefaultComponent { // Find exactly one from the registry or create one if (tokenCredentialFromRegistry.size() == 1) { configuration.setTokenCredential(tokenCredentialFromRegistry.stream().findFirst().get()); - } else { - configuration.setTokenCredential(new DefaultAzureCredentialBuilder().build()); } } } diff --git a/components/camel-azure/camel-azure-servicebus/src/main/java/org/apache/camel/component/azure/servicebus/ServiceBusConfiguration.java b/components/camel-azure/camel-azure-servicebus/src/main/java/org/apache/camel/component/azure/servicebus/ServiceBusConfiguration.java index ad77caeec0e..4350cd83c4b 100644 --- a/components/camel-azure/camel-azure-servicebus/src/main/java/org/apache/camel/component/azure/servicebus/ServiceBusConfiguration.java +++ b/components/camel-azure/camel-azure-servicebus/src/main/java/org/apache/camel/component/azure/servicebus/ServiceBusConfiguration.java @@ -90,7 +90,7 @@ public class ServiceBusConfiguration implements Cloneable { @UriParam(label = "producer", defaultValue = "false") private boolean binary; @UriParam(label = "security", enums = "AZURE_IDENTITY,CONNECTION_STRING,TOKEN_CREDENTIAL", - defaultValue = "CONNECTION_STRING") + defaultValue = "CONNECTION_STRING") private CredentialType credentialType = CONNECTION_STRING; /** @@ -358,7 +358,6 @@ public class ServiceBusConfiguration implements Cloneable { this.binary = binary; } - public CredentialType getCredentialType() { return credentialType; } diff --git a/components/camel-azure/camel-azure-servicebus/src/test/java/org/apache/camel/component/azure/servicebus/ServiceBusEndpointTest.java b/components/camel-azure/camel-azure-servicebus/src/test/java/org/apache/camel/component/azure/servicebus/ServiceBusEndpointTest.java index f3a4831a5d9..58efbd71c03 100644 --- a/components/camel-azure/camel-azure-servicebus/src/test/java/org/apache/camel/component/azure/servicebus/ServiceBusEndpointTest.java +++ b/components/camel-azure/camel-azure-servicebus/src/test/java/org/apache/camel/component/azure/servicebus/ServiceBusEndpointTest.java @@ -26,7 +26,7 @@ import org.apache.camel.test.junit5.CamelTestSupport; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; class ServiceBusEndpointTest extends CamelTestSupport { @@ -83,7 +83,7 @@ class ServiceBusEndpointTest extends CamelTestSupport { assertEquals("testTopicOrQueue", endpoint.getConfiguration().getTopicOrQueueName()); assertEquals(10, endpoint.getConfiguration().getPrefetchCount()); assertEquals(fullyQualifiedNamespace, endpoint.getConfiguration().getFullyQualifiedNamespace()); - assertNotNull(endpoint.getConfiguration().getTokenCredential()); + assertNull(endpoint.getConfiguration().getTokenCredential()); } @Test @@ -131,4 +131,27 @@ class ServiceBusEndpointTest extends CamelTestSupport { assertEquals(fullyQualifiedNamespace, endpoint.getConfiguration().getFullyQualifiedNamespace()); assertEquals(credential, endpoint.getConfiguration().getTokenCredential()); } + + @Test + void testCreateEndpointWithAzureIdentity() throws Exception { + final String uri = "azure-servicebus://testTopicOrQueue"; + final String remaining = "testTopicOrQueue"; + final String fullyQualifiedNamespace = "namespace.servicebus.windows.net"; + final TokenCredential credential = new DefaultAzureCredentialBuilder().build(); + final Map<String, Object> params = new HashMap<>(); + params.put("serviceBusType", ServiceBusType.topic); + params.put("prefetchCount", 10); + params.put("fullyQualifiedNamespace", fullyQualifiedNamespace); + params.put("credentialType", CredentialType.AZURE_IDENTITY); + + final ServiceBusEndpoint endpoint + = (ServiceBusEndpoint) context.getComponent("azure-servicebus", ServiceBusComponent.class) + .createEndpoint(uri, remaining, params); + + assertEquals(ServiceBusType.topic, endpoint.getConfiguration().getServiceBusType()); + assertEquals("testTopicOrQueue", endpoint.getConfiguration().getTopicOrQueueName()); + assertEquals(10, endpoint.getConfiguration().getPrefetchCount()); + assertEquals(fullyQualifiedNamespace, endpoint.getConfiguration().getFullyQualifiedNamespace()); + assertNull(endpoint.getConfiguration().getTokenCredential()); + } }