DcRouteMetaComparator extends AbstractMetaComparator<RouteMeta, RouteChange> { @Override public void compare() { Triple<Set<RouteMeta>, Set<RouteMeta>, Set<RouteMeta>> result = getDiff(Sets.newHashSet(current.getRoutes()), Sets.newHashSet(future.getRoutes())); Set<RouteMeta> intersectionRouteMetas = filterTag(result.getMiddle()); added = filterTag(result.getFirst()); removed = filterTag(result.getLast()); for(RouteMeta routeMeta : intersectionRouteMetas) { RouteMeta currentRouteMeta = getRouteMeta(current, routeMeta.getId()); RouteMeta futureRouteMeta = getRouteMeta(future, routeMeta.getId()); if(currentRouteMeta == null || futureRouteMeta == null) { modified.add(new RouteMetaComparator(currentRouteMeta, futureRouteMeta)); continue; } if(!currentRouteMeta.getRouteInfo().equalsIgnoreCase(futureRouteMeta.getRouteInfo())) { modified.add(new RouteMetaComparator(currentRouteMeta, futureRouteMeta)); } } } DcRouteMetaComparator(DcMeta current, DcMeta future, String routeTagFilter);  DcRouteMetaComparator(DcMeta current, DcMeta future); @Override void compare(); @Override String idDesc();  }
@Test public void testCompareWithNoChanges() { comparator = new DcRouteMetaComparator(current, future); comparator.compare(); Assert.assertTrue(comparator.getAdded().isEmpty()); Assert.assertTrue(comparator.getRemoved().isEmpty()); Assert.assertTrue(comparator.getMofified().isEmpty()); }
@Test public void testCompareWithRouteAdd() { future.addRoute(new RouteMeta(1000).setRouteInfo("PROXYTCP: comparator = new DcRouteMetaComparator(current, future); comparator.compare(); Assert.assertTrue(comparator.getAdded().isEmpty()); Assert.assertTrue(comparator.getRemoved().isEmpty()); Assert.assertTrue(comparator.getMofified().isEmpty()); future.addRoute(new RouteMeta(2000).setTag(Route.TAG_META)); comparator = new DcRouteMetaComparator(current, future); comparator.compare(); Assert.assertFalse(comparator.getAdded().isEmpty()); Assert.assertTrue(comparator.getRemoved().isEmpty()); Assert.assertTrue(comparator.getMofified().isEmpty()); }
@Test public void testCompareWithRouteDeleted() { future.getRoutes().remove(0); comparator = new DcRouteMetaComparator(current, future); comparator.compare(); Assert.assertTrue(comparator.getAdded().isEmpty()); Assert.assertFalse(comparator.getRemoved().isEmpty()); Assert.assertTrue(comparator.getMofified().isEmpty()); }
@Test public void testCompareWithModified() { future.getRoutes().get(0).setRouteInfo("PROXYTCP: comparator = new DcRouteMetaComparator(current, future); comparator.compare(); Assert.assertTrue(comparator.getAdded().isEmpty()); Assert.assertTrue(comparator.getRemoved().isEmpty()); Assert.assertFalse(comparator.getMofified().isEmpty()); Assert.assertEquals(1, comparator.getMofified().size()); }