Commit 8f36fe29 authored by Hema Vishnu Pola [Microsoft]'s avatar Hema Vishnu Pola [Microsoft]
Browse files

Merge branch 'users/komakkar/utServiceBus' into 'master'

Fixing UT for Service Bus Client

See merge request !68
parents d73ccbf2 3720baf1
Pipeline #21321 passed with stages
in 10 minutes and 28 seconds
......@@ -20,7 +20,7 @@
<groupId>org.opengroup.osdu</groupId>
<artifactId>core-lib-azure</artifactId>
<packaging>jar</packaging>
<version>0.0.56</version>
<version>0.0.57</version>
<name>core-lib-azure</name>
<properties>
......
......@@ -26,8 +26,8 @@ public class SubscriptionClientFactoryImpl implements ISubscriptionClientFactory
private SubscriptionClientCache clientCache;
/**
* @param dataPartitionId Data Partition Id
* @param topicName Service Bus Topic Name
* @param dataPartitionId Data Partition Id
* @param topicName Service Bus Topic Name
* @param subscriptionName Service Bus Subscription Name
* @return A client configured to communicate with a Service Bus Subscription
* @throws ServiceBusException Exception thrown by {@link SubscriptionClient}
......@@ -47,16 +47,25 @@ public class SubscriptionClientFactoryImpl implements ISubscriptionClientFactory
PartitionInfoAzure pi = this.partitionService.getPartition(dataPartitionId);
String serviceBusConnectionString = pi.getSbConnection();
ConnectionStringBuilder connectionStringBuilder = new ConnectionStringBuilder(
serviceBusConnectionString,
entityPath
);
SubscriptionClient subscriptionClient = new SubscriptionClient(connectionStringBuilder, ReceiveMode.PEEKLOCK);
SubscriptionClient subscriptionClient = getSubscriptionClient(entityPath, serviceBusConnectionString);
this.clientCache.put(cacheKey, subscriptionClient);
return subscriptionClient;
}
/***
* @param entityPath Service Bus entity path
* @param serviceBusConnectionString Service Bus Connection String
* @return SubscriptionClient object
* @throws InterruptedException Exception thrown by {@link SubscriptionClient}
* @throws ServiceBusException Exception thrown by {@link SubscriptionClient}
*/
SubscriptionClient getSubscriptionClient(final String entityPath, final String serviceBusConnectionString) throws InterruptedException, ServiceBusException {
ConnectionStringBuilder connectionStringBuilder = new ConnectionStringBuilder(
serviceBusConnectionString,
entityPath
);
return new SubscriptionClient(connectionStringBuilder, ReceiveMode.PEEKLOCK);
}
}
\ No newline at end of file
package org.opengroup.osdu.azure.servicebus;
import com.microsoft.azure.servicebus.SubscriptionClient;
import com.microsoft.azure.servicebus.primitives.ConnectionStringBuilder;
import com.microsoft.azure.servicebus.primitives.ServiceBusException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
......@@ -8,6 +9,7 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.opengroup.osdu.azure.cache.SubscriptionClientCache;
import org.opengroup.osdu.azure.partition.PartitionInfoAzure;
......@@ -34,6 +36,7 @@ public class SubscriptionClientFactoryImplTest {
private static final String SUBSCRIPTION_NAME = "testSubscription";
private static final String SB_ENTITY_PATH = "testTopic/subscriptions/testSubscription";
private static final String SB_CONNECTION_STRING = "Endpoint=sb://test-bus.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=testKey";
@BeforeEach
void init() {
initMocks(this);
......@@ -96,12 +99,15 @@ public class SubscriptionClientFactoryImplTest {
}
@Test
@Disabled
public void should_return_client_when_partition_valid() throws ServiceBusException, InterruptedException {
SubscriptionClient subscriptionClient = mock(SubscriptionClient.class);
SubscriptionClientFactoryImpl subscriptionClientFactorySpy = Mockito.spy(subscriptionClientFactory);
doReturn(subscriptionClient).when(subscriptionClientFactorySpy).getSubscriptionClient(anyString(), anyString());
when(this.partitionServiceClient.getPartition(PARTITION_ID)).thenReturn(
PartitionInfoAzure.builder().sbConnectionConfig(Property.builder().value(SB_CONNECTION_STRING).build())
.build());
assertNotNull(this.subscriptionClientFactory.getClient(PARTITION_ID, TOPIC_NAME, SUBSCRIPTION_NAME));
}
assertNotNull(subscriptionClientFactorySpy.getClient(PARTITION_ID, TOPIC_NAME, SUBSCRIPTION_NAME));
verify(this.clientCache, times(1)).put(any(), any());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment