use of com.alibaba.nacos.api.selector.AbstractSelector in project nacos by alibaba.
the class NamingGrpcClientProxyTest method testUpdateService.
@Test
public void testUpdateService() throws NacosException {
// TODO thrown.expect(UnsupportedOperationException.class);
Service service = new Service();
AbstractSelector selector = new NoneSelector();
client.updateService(service, selector);
}
use of com.alibaba.nacos.api.selector.AbstractSelector in project nacos by alibaba.
the class NacosNamingMaintainServiceTest method testCreateService4.
@Test
public void testCreateService4() throws NacosException {
// given
Service service = new Service();
AbstractSelector selector = new NoneSelector();
// when
nacosNamingMaintainService.createService(service, selector);
// then
verify(serverProxy, times(1)).createService(service, selector);
}
use of com.alibaba.nacos.api.selector.AbstractSelector in project nacos by alibaba.
the class NacosNamingServiceTest method testGetServicesOfServer4.
@Test
public void testGetServicesOfServer4() throws NacosException {
// given
int pageNo = 1;
int pageSize = 10;
String groupName = "group1";
AbstractSelector selector = new AbstractSelector("aaa") {
@Override
public String getType() {
return super.getType();
}
};
// when
client.getServicesOfServer(pageNo, pageSize, groupName, selector);
// then
verify(proxy, times(1)).getServiceList(pageNo, pageSize, groupName, selector);
}
use of com.alibaba.nacos.api.selector.AbstractSelector in project nacos by alibaba.
the class AbstractNamingClientProxyTest method testGetSecurityHeaders.
@Test
public void testGetSecurityHeaders() {
SecurityProxy sc = Mockito.mock(SecurityProxy.class);
Properties props = new Properties();
AbstractNamingClientProxy proxy = new AbstractNamingClientProxy(sc, props) {
@Override
public void onEvent(ServerListChangedEvent event) {
}
@Override
public Class<? extends Event> subscribeType() {
return ServerListChangedEvent.class;
}
@Override
public void registerService(String serviceName, String groupName, Instance instance) throws NacosException {
}
@Override
public void deregisterService(String serviceName, String groupName, Instance instance) throws NacosException {
}
@Override
public void updateInstance(String serviceName, String groupName, Instance instance) throws NacosException {
}
@Override
public ServiceInfo queryInstancesOfService(String serviceName, String groupName, String clusters, int udpPort, boolean healthyOnly) throws NacosException {
return null;
}
@Override
public Service queryService(String serviceName, String groupName) throws NacosException {
return null;
}
@Override
public void createService(Service service, AbstractSelector selector) throws NacosException {
}
@Override
public boolean deleteService(String serviceName, String groupName) throws NacosException {
return false;
}
@Override
public void updateService(Service service, AbstractSelector selector) throws NacosException {
}
@Override
public ListView<String> getServiceList(int pageNo, int pageSize, String groupName, AbstractSelector selector) throws NacosException {
return null;
}
@Override
public ServiceInfo subscribe(String serviceName, String groupName, String clusters) throws NacosException {
return null;
}
@Override
public void unsubscribe(String serviceName, String groupName, String clusters) throws NacosException {
}
@Override
public boolean isSubscribed(String serviceName, String groupName, String clusters) throws NacosException {
return false;
}
@Override
public void updateBeatInfo(Set<Instance> modifiedInstances) {
}
@Override
public boolean serverHealthy() {
return false;
}
@Override
public void shutdown() throws NacosException {
}
};
String token = "aa";
Mockito.when(sc.getAccessToken()).thenReturn(token);
Map<String, String> securityHeaders = proxy.getSecurityHeaders();
Assert.assertEquals(1, securityHeaders.size());
Assert.assertEquals(token, securityHeaders.get(Constants.ACCESS_TOKEN));
}
use of com.alibaba.nacos.api.selector.AbstractSelector in project nacos by alibaba.
the class AbstractNamingClientProxyTest method testGetSpasHeaders.
@Test
public void testGetSpasHeaders() throws Exception {
SecurityProxy sc = Mockito.mock(SecurityProxy.class);
Properties props = new Properties();
String ak = "aa";
String sk = "bb";
props.put(PropertyKeyConst.ACCESS_KEY, ak);
props.put(PropertyKeyConst.SECRET_KEY, sk);
AbstractNamingClientProxy proxy = new AbstractNamingClientProxy(sc, props) {
@Override
public void onEvent(ServerListChangedEvent event) {
}
@Override
public Class<? extends Event> subscribeType() {
return ServerListChangedEvent.class;
}
@Override
public void registerService(String serviceName, String groupName, Instance instance) throws NacosException {
}
@Override
public void deregisterService(String serviceName, String groupName, Instance instance) throws NacosException {
}
@Override
public void updateInstance(String serviceName, String groupName, Instance instance) throws NacosException {
}
@Override
public ServiceInfo queryInstancesOfService(String serviceName, String groupName, String clusters, int udpPort, boolean healthyOnly) throws NacosException {
return null;
}
@Override
public Service queryService(String serviceName, String groupName) throws NacosException {
return null;
}
@Override
public void createService(Service service, AbstractSelector selector) throws NacosException {
}
@Override
public boolean deleteService(String serviceName, String groupName) throws NacosException {
return false;
}
@Override
public void updateService(Service service, AbstractSelector selector) throws NacosException {
}
@Override
public ListView<String> getServiceList(int pageNo, int pageSize, String groupName, AbstractSelector selector) throws NacosException {
return null;
}
@Override
public ServiceInfo subscribe(String serviceName, String groupName, String clusters) throws NacosException {
return null;
}
@Override
public void unsubscribe(String serviceName, String groupName, String clusters) throws NacosException {
}
@Override
public boolean isSubscribed(String serviceName, String groupName, String clusters) throws NacosException {
return false;
}
@Override
public void updateBeatInfo(Set<Instance> modifiedInstances) {
}
@Override
public boolean serverHealthy() {
return false;
}
@Override
public void shutdown() throws NacosException {
}
};
String serviceName = "aaa";
Map<String, String> spasHeaders = proxy.getSpasHeaders(serviceName);
Assert.assertEquals(4, spasHeaders.size());
Assert.assertEquals(AppNameUtils.getAppName(), spasHeaders.get("app"));
Assert.assertEquals(ak, spasHeaders.get("ak"));
Assert.assertTrue(spasHeaders.get("data").endsWith("@@" + serviceName));
String expectSign = SignUtil.sign(spasHeaders.get("data"), sk);
Assert.assertEquals(expectSign, spasHeaders.get("signature"));
}
Aggregations