InterVpnLinkLocator { public List<InterVpnLinkDataComposite> findInterVpnLinksSameGroup(InterVpnLink ivpnLinkToMatch, List<InterVpnLinkDataComposite> interVpnLinks) { List<String> vpnToMatch1IRTs = getIRTsByVpnName(ivpnLinkToMatch.getFirstEndpoint().getVpnUuid().getValue()); List<String> vpnToMatch2IRTs = getIRTsByVpnName(ivpnLinkToMatch.getSecondEndpoint().getVpnUuid().getValue()); Predicate<InterVpnLinkDataComposite> areSameGroup = (ivl) -> { if (ivl.getInterVpnLinkName().equals(ivpnLinkToMatch.getName())) { return false; } String vpn1Name = ivl.getFirstEndpointVpnUuid().orElse(null); String vpn2Name = ivl.getSecondEndpointVpnUuid().orElse(null); if (vpn1Name == null) { return false; } List<String> vpn1IRTs = getIRTsByVpnName(vpn1Name); List<String> vpn2IRTs = getIRTsByVpnName(vpn2Name); return haveSameIRTs(vpn1IRTs, vpnToMatch1IRTs) && haveSameIRTs(vpn2IRTs, vpnToMatch2IRTs) || haveSameIRTs(vpn1IRTs, vpnToMatch2IRTs) && haveSameIRTs(vpn2IRTs, vpnToMatch1IRTs); }; return interVpnLinks.stream().filter(areSameGroup).collect(Collectors.toList()); } @Inject  InterVpnLinkLocator(final DataBroker dataBroker, final InterVpnLinkCache interVpnLinkCache,
                               final VpnUtil vpnUtil); List<Uint64> selectSuitableDpns(InterVpnLink interVpnLink); List<InterVpnLinkDataComposite> findInterVpnLinksSameGroup(InterVpnLink ivpnLinkToMatch,
                                                                      List<InterVpnLinkDataComposite> interVpnLinks);  }
@Test public void testFindInterVpnLinksSameGroup() throws TransactionCommitFailedException { List<InterVpnLinkDataComposite> ivpnLinksSimilarTo12 = sut.findInterVpnLinksSameGroup(I_VPN_LINK_12.getInterVpnLinkConfig(), ALL_IVPN_LINKS); assertTrue(ivpnLinksSimilarTo12.size() == 1); assertEquals(ivpnLinksSimilarTo12.get(0), I_VPN_LINK_56); List<InterVpnLinkDataComposite> ivpnLinksSimilarTo34 = sut.findInterVpnLinksSameGroup(I_VPN_LINK_34.getInterVpnLinkConfig(), ALL_IVPN_LINKS); assertTrue(ivpnLinksSimilarTo34.isEmpty()); }