-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase azure-eventhubs test coverage
Fixes #6367
- Loading branch information
1 parent
16ab2d8
commit 7e62303
Showing
10 changed files
with
976 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...in/java/org/apache/camel/quarkus/component/azure/eventhubs/it/AzureCredentialsHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.camel.quarkus.component.azure.eventhubs.it; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import com.azure.core.amqp.implementation.ConnectionStringProperties; | ||
import org.eclipse.microprofile.config.Config; | ||
import org.eclipse.microprofile.config.ConfigProvider; | ||
|
||
public final class AzureCredentialsHelper { | ||
private AzureCredentialsHelper() { | ||
// Utility class | ||
} | ||
|
||
public static boolean isMinimumConfigurationAvailable() { | ||
Config config = ConfigProvider.getConfig(); | ||
if (isMockBackEnd()) { | ||
return false; | ||
} | ||
Optional<String> storageAccountName = config.getOptionalValue("azure.storage.account-name", String.class); | ||
Optional<String> storageAccountKey = config.getOptionalValue("azure.storage.account-key", String.class); | ||
Optional<String> connectionString = config.getOptionalValue("azure.event.hubs.connection.string", String.class); | ||
return storageAccountName.isPresent() && storageAccountKey.isPresent() && connectionString.isPresent(); | ||
} | ||
|
||
public static boolean isAzureIdentityCredentialsAvailable() { | ||
Config config = ConfigProvider.getConfig(); | ||
if (isMockBackEnd()) { | ||
return false; | ||
} | ||
|
||
Optional<String> clientId = config.getOptionalValue("azure.client.id", String.class); | ||
Optional<String> tenantId = config.getOptionalValue("azure.tenant.id", String.class); | ||
Optional<String> username = config.getOptionalValue("azure.username", String.class); | ||
Optional<String> password = config.getOptionalValue("azure.password", String.class); | ||
Optional<String> clientSecret = config.getOptionalValue("azure.client.secret", String.class); | ||
Optional<String> clientCertificate = config.getOptionalValue("azure.client.certificate.path", String.class); | ||
Optional<String> clientCertificatePassword = config.getOptionalValue("azure.client.certificate.password", String.class); | ||
return (clientId.isPresent() && tenantId.isPresent() && | ||
(username.isPresent() || password.isPresent() || clientCertificate.isPresent() || clientSecret.isPresent() | ||
|| clientCertificatePassword.isPresent())); | ||
} | ||
|
||
public static boolean isSharedAccessKeyAvailable() { | ||
Config config = ConfigProvider.getConfig(); | ||
if (isMockBackEnd()) { | ||
return false; | ||
} | ||
return config.getOptionalValue("azure.event.hubs.shared.access.name", String.class).isPresent() | ||
&& config.getOptionalValue("azure.event.hubs.shared.access.key", String.class).isPresent(); | ||
} | ||
|
||
public static boolean isMockBackEnd() { | ||
Config config = ConfigProvider.getConfig(); | ||
return config.getOptionalValue("camel.quarkus.start.mock.backend", Boolean.class).orElse(true); | ||
} | ||
|
||
public static Map<String, String> parseConnectionString(String connectionString) { | ||
Map<String, String> properties = new HashMap<>(); | ||
ConnectionStringProperties stringProperties = new ConnectionStringProperties(connectionString); | ||
properties.put("Endpoint", stringProperties.getEndpoint().toString()); | ||
properties.put("EntityPath", stringProperties.getEntityPath()); | ||
properties.put("SharedAccessKey", stringProperties.getSharedAccessKeyName()); | ||
properties.put("SharedAccessKeyValue", stringProperties.getSharedAccessKey()); | ||
|
||
String host = stringProperties.getEndpoint().getHost(); | ||
properties.put("Namespace", host.substring(0, host.indexOf('.'))); | ||
|
||
return properties; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...n/java/org/apache/camel/quarkus/component/azure/eventhubs/it/AzureEventhubsProducers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.camel.quarkus.component.azure.eventhubs.it; | ||
|
||
import java.util.Optional; | ||
|
||
import com.azure.core.amqp.implementation.ConnectionStringProperties; | ||
import com.azure.core.credential.TokenCredential; | ||
import com.azure.messaging.eventhubs.EventHubClientBuilder; | ||
import com.azure.messaging.eventhubs.EventHubProducerAsyncClient; | ||
import com.azure.messaging.eventhubs.implementation.ClientConstants; | ||
import com.azure.messaging.eventhubs.implementation.EventHubSharedKeyCredential; | ||
import jakarta.inject.Named; | ||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
|
||
public class AzureEventhubsProducers { | ||
@ConfigProperty(name = "azure.event.hubs.connection.string") | ||
Optional<String> connectionString; | ||
|
||
@Named("connectionStringTokenCredential") | ||
TokenCredential tokenCredential() { | ||
if (connectionString.isPresent()) { | ||
ConnectionStringProperties properties = new ConnectionStringProperties(connectionString.get()); | ||
TokenCredential tokenCredential; | ||
if (properties.getSharedAccessSignature() == null) { | ||
tokenCredential = new EventHubSharedKeyCredential(properties.getSharedAccessKeyName(), | ||
properties.getSharedAccessKey(), ClientConstants.TOKEN_VALIDITY); | ||
} else { | ||
tokenCredential = new EventHubSharedKeyCredential(properties.getSharedAccessSignature()); | ||
} | ||
return tokenCredential; | ||
} | ||
return null; | ||
} | ||
|
||
@Named("eventHubClient") | ||
EventHubProducerAsyncClient eventHubClient() { | ||
return connectionString.map(connection -> new EventHubClientBuilder() | ||
.connectionString(connection) | ||
.buildAsyncProducerClient()) | ||
.orElse(null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.