@Test void givenOneServiceWithMultipleRoutes_whenLocateRoutes_thenTwoRoutesLocatedWithBothPathFormats() { Map<String, String> metadata = new HashMap<>(); metadata.put(ROUTES + ".api-v1." + ROUTES_GATEWAY_URL, "api/v1"); metadata.put(ROUTES + ".api-v1." + ROUTES_SERVICE_URL, "/"); ZuulProperties.ZuulRoute expectedRoute = new ZuulProperties.ZuulRoute(); expectedRoute.setId("api/v1/service"); expectedRoute.setPath("/api/v1/service/**"); expectedRoute.setServiceId("service"); LinkedHashMap<String, ZuulProperties.ZuulRoute> expectedRoutesMap = new LinkedHashMap<>(); expectedRoutesMap.put("/api/v1/service/**", expectedRoute); expectedRoute = new ZuulProperties.ZuulRoute(); expectedRoute.setId("service/api/v1"); expectedRoute.setPath("/service/api/v1/**"); expectedRoute.setServiceId("service"); expectedRoutesMap.put("/service/api/v1/**", expectedRoute); metadata.put(ROUTES + ".ws-v1." + ROUTES_GATEWAY_URL, "ws/v1"); metadata.put(ROUTES + ".ws-v1." + ROUTES_SERVICE_URL, "/"); expectedRoute = new ZuulProperties.ZuulRoute(); expectedRoute.setId("ws/v1/service"); expectedRoute.setPath("/ws/v1/service/**"); expectedRoute.setServiceId("service"); expectedRoutesMap.put("/ws/v1/service/**", expectedRoute); expectedRoute = new ZuulProperties.ZuulRoute(); expectedRoute.setId("service/ws/v1"); expectedRoute.setPath("/service/ws/v1/**"); expectedRoute.setServiceId("service"); expectedRoutesMap.put("/service/ws/v1/**", expectedRoute); when(eurekaDiscoveryClient.getServices()).thenReturn(Collections.singletonList("service")); when(eurekaDiscoveryClient.getInstances("service")).thenReturn( Collections.singletonList(new DefaultServiceInstance("service", "localhost", 80, false, metadata))); Map<String, ZuulProperties.ZuulRoute> zuulRouteMap = underTest.locateRoutes(); assertEquals(expectedRoutesMap, zuulRouteMap); }
@Override @VisibleForTesting protected LinkedHashMap<String, ZuulProperties.ZuulRoute> locateRoutes() { log.debug("Locating routes from Discovery client"); LinkedHashMap<String, ZuulProperties.ZuulRoute> routesMap = new LinkedHashMap<>(); discoveryClient.getServices().forEach( serviceId -> routesMap.putAll(createServiceRoutes(serviceId)) ); routedServicesNotifier.notifyAndFlush(); return routesMap; }
NewApimlRouteLocator extends DiscoveryClientRouteLocator { @Override @VisibleForTesting protected LinkedHashMap<String, ZuulProperties.ZuulRoute> locateRoutes() { log.debug("Locating routes from Discovery client"); LinkedHashMap<String, ZuulProperties.ZuulRoute> routesMap = new LinkedHashMap<>(); discoveryClient.getServices().forEach( serviceId -> routesMap.putAll(createServiceRoutes(serviceId)) ); routedServicesNotifier.notifyAndFlush(); return routesMap; } }
NewApimlRouteLocator extends DiscoveryClientRouteLocator { @Override @VisibleForTesting protected LinkedHashMap<String, ZuulProperties.ZuulRoute> locateRoutes() { log.debug("Locating routes from Discovery client"); LinkedHashMap<String, ZuulProperties.ZuulRoute> routesMap = new LinkedHashMap<>(); discoveryClient.getServices().forEach( serviceId -> routesMap.putAll(createServiceRoutes(serviceId)) ); routedServicesNotifier.notifyAndFlush(); return routesMap; } NewApimlRouteLocator(String servletPath, ZuulProperties properties, DiscoveryClient discoveryClient, RoutedServicesNotifier notifier); }
NewApimlRouteLocator extends DiscoveryClientRouteLocator { @Override @VisibleForTesting protected LinkedHashMap<String, ZuulProperties.ZuulRoute> locateRoutes() { log.debug("Locating routes from Discovery client"); LinkedHashMap<String, ZuulProperties.ZuulRoute> routesMap = new LinkedHashMap<>(); discoveryClient.getServices().forEach( serviceId -> routesMap.putAll(createServiceRoutes(serviceId)) ); routedServicesNotifier.notifyAndFlush(); return routesMap; } NewApimlRouteLocator(String servletPath, ZuulProperties properties, DiscoveryClient discoveryClient, RoutedServicesNotifier notifier);  }
NewApimlRouteLocator extends DiscoveryClientRouteLocator { @Override @VisibleForTesting protected LinkedHashMap<String, ZuulProperties.ZuulRoute> locateRoutes() { log.debug("Locating routes from Discovery client"); LinkedHashMap<String, ZuulProperties.ZuulRoute> routesMap = new LinkedHashMap<>(); discoveryClient.getServices().forEach( serviceId -> routesMap.putAll(createServiceRoutes(serviceId)) ); routedServicesNotifier.notifyAndFlush(); return routesMap; } NewApimlRouteLocator(String servletPath, ZuulProperties properties, DiscoveryClient discoveryClient, RoutedServicesNotifier notifier);   }