Skip to content
Snippets Groups Projects
Commit 183cd1fc authored by Nikhil Singh[MicroSoft]'s avatar Nikhil Singh[MicroSoft]
Browse files

Commit 19 Contents:

1-UT Cosmos
parent ac8efa38
No related branches found
No related tags found
2 merge requests!102Locking down maven central,!97Service Bus Create and Delete Support for Subscriptions
Pipeline #55106 failed
// Copyright © Microsoft Corporation
//
// Licensed 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.opengroup.osdu.register.provider.azure.subscriber;
import com.microsoft.azure.servicebus.management.ManagementClient;
import com.microsoft.azure.servicebus.management.SubscriptionDescription;
import com.microsoft.azure.servicebus.primitives.MessagingEntityNotFoundException;
import com.microsoft.azure.servicebus.primitives.ServiceBusException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.register.provider.azure.subscriber.messageBus.IManagementClientFactory;
import org.opengroup.osdu.register.provider.azure.subscriber.pubsub.PullSubscription;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
public class PullSubscriptionTest {
private static final String subscriptionId = "subscription-id";
private static final String topicName = "topic-name";
private static final String errorMessage = "some error message";
private static final String RESOURCE_PROVISIONING_ERROR_MESSAGE = "Resource cannot be updated during provisioning";
private static final String MANAGEMENT_CLIENT_ERROR_MESSAGE = "Unable to create management client";
private static final String SERVICE_BUS_ERROR_MESSAGE = "Server can not be reached";
@Mock
private IManagementClientFactory factory;
@Mock
private JaxRsDpsLog logger;
@Mock
private ManagementClient serviceBusManager;
@InjectMocks
private PullSubscription pullSubscription;
@Test
public void shouldCreatePullSubscription() throws Exception {
lenient().when(factory.getManager()).thenReturn(serviceBusManager);
SubscriptionDescription subscriptionDescription = new SubscriptionDescription(topicName, subscriptionId);
lenient().when(serviceBusManager.createSubscription(topicName, subscriptionId)).thenReturn(subscriptionDescription);
pullSubscription.createSubscription(subscriptionId, topicName);
verify(factory, times(1)).getManager();
verify(serviceBusManager, times(1)).createSubscription(topicName, subscriptionId);
verify(logger, times(1)).debug(String.format("Pull Subscription with id %s created successfully", subscriptionId));
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment