use of com.alibaba.nacos.naming.core.v2.service.ClientOperationService in project nacos by alibaba.
the class InstanceOperatorClientImplTest method testListInstance.
@Test
public void testListInstance() {
Mockito.when(pushService.canEnablePush(Mockito.anyString())).thenReturn(true);
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setGroupName("DEFAULT_GROUP");
serviceInfo.setName("B");
Mockito.when(serviceStorage.getData(Mockito.any())).thenReturn(serviceInfo);
ServiceMetadata metadata = new ServiceMetadata();
Mockito.when(metadataManager.getServiceMetadata(Mockito.any())).thenReturn(Optional.of(metadata));
Subscriber subscriber = new Subscriber("2.2.2.2", "", "app", "1.1.1.1", "A", "B", 8848);
instanceOperatorClient.listInstance("A", "B", subscriber, "C", true);
Mockito.verify(clientOperationService).subscribeService(Mockito.any(), Mockito.any(), Mockito.anyString());
}
use of com.alibaba.nacos.naming.core.v2.service.ClientOperationService in project nacos by alibaba.
the class SubscribeServiceRequestHandlerTest method testHandle.
@Test
public void testHandle() throws NacosException {
Instance instance = new Instance();
instance.setIp("1.1.1.1");
List<Instance> instances = Arrays.asList(instance);
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setGroupName("A");
serviceInfo.setGroupName("B");
serviceInfo.setName("C");
serviceInfo.setHosts(instances);
Mockito.when(serviceStorage.getData(Mockito.any())).thenReturn(serviceInfo);
ServiceMetadata serviceMetadata = new ServiceMetadata();
Mockito.when(metadataManager.getServiceMetadata(Mockito.any())).thenReturn(Optional.of(serviceMetadata));
SubscribeServiceRequest subscribeServiceRequest = new SubscribeServiceRequest();
subscribeServiceRequest.setNamespace("A");
subscribeServiceRequest.setGroupName("B");
subscribeServiceRequest.setServiceName("C");
subscribeServiceRequest.setSubscribe(true);
SubscribeServiceResponse subscribeServiceResponse = subscribeServiceRequestHandler.handle(subscribeServiceRequest, new RequestMeta());
Assert.assertEquals(subscribeServiceResponse.getServiceInfo().getName(), "C");
Mockito.verify(clientOperationService).subscribeService(Mockito.any(), Mockito.any(), Mockito.anyString());
subscribeServiceRequest.setSubscribe(false);
subscribeServiceResponse = subscribeServiceRequestHandler.handle(subscribeServiceRequest, new RequestMeta());
Assert.assertEquals(subscribeServiceResponse.getServiceInfo().getName(), "C");
Mockito.verify(clientOperationService).subscribeService(Mockito.any(), Mockito.any(), Mockito.anyString());
}
Aggregations