}
}
@Test
public void test_previewRoute() throws Exception {
Route route = new Route();
route.setId(1L);
route.setService("hello.HelloService");
route.setMatchRule("consumer.host=1.1.2.2,2.2.2.3");
route.setFilterRule("provider.host=3.3.4.4&provider.application=morgan");
{
// no methods
Map<String, String> preview = RouteUtils.previewRoute("hello.HelloService", "1.1.2.2:20880", "application=morgan", serviceUrls, route, clusters, null);
Map<String, String> expected = new HashMap<String, String>();
expected.put("dubbo://3.3.4.4:20880/hello.HelloService", "dubbo=2.0.0&version=1.0.0&revision=1.1.1&methods=*&application=morgan");
assertEquals(expected, preview);
// 2 methods
preview = RouteUtils.previewRoute("hello.HelloService", "1.1.2.2", "application=morgan&methods=getPort,say", serviceUrls, route, clusters, null);
expected = new HashMap<String, String>();
expected.put("dubbo://3.3.4.4:20880/hello.HelloService", "dubbo=2.0.0&version=1.0.0&revision=1.1.1&methods=getPort,say&application=morgan");
assertEquals(expected, preview);
// ghost methods
preview = RouteUtils.previewRoute("hello.HelloService", "1.1.2.2", "application=morgan&methods=getPort,say,ghostMethod", serviceUrls, route, clusters, null);
expected = new HashMap<String, String>();
expected.put("dubbo://3.3.4.4:20880/hello.HelloService", "dubbo=2.0.0&version=1.0.0&revision=1.1.1&methods=getPort,say,ghostMethod&application=morgan");
assertEquals(expected, preview);
// no route
preview = RouteUtils.previewRoute("hello.HelloService", "1.2.3.4", "application=morgan", serviceUrls, route, clusters, null);
assertEquals(serviceUrls_starMethods, preview);
// no route, 2 methods
preview = RouteUtils.previewRoute("hello.HelloService", "1.2.3.4", "application=morgan&methods=getPort,say", serviceUrls, route, clusters, null);
assertEquals(serviceUrls, preview);
// no route, ghost methods
preview = RouteUtils.previewRoute("hello.HelloService", "1.2.3.4", "application=morgan&methods=getPort,say,ghostMethod", serviceUrls, route, clusters, null);
assertEquals(serviceUrls_ghostMethods, preview);
}
// with cluster
{
route.setMatchRule("consumer.cluster = cluster1");
// no method
Map<String, String> preview = RouteUtils.previewRoute("hello.HelloService", "7.7.7.7:20880", "application=morgan", serviceUrls, route, clusters, null);
Map<String, String> expected = new HashMap<String, String>();
expected.put("dubbo://3.3.4.4:20880/hello.HelloService", "dubbo=2.0.0&version=1.0.0&revision=1.1.1&methods=*&application=morgan");