package org.batfish.datamodel.bgp;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

import com.google.common.testing.EqualsTester;
import org.apache.commons.lang3.SerializationUtils;
import org.batfish.common.util.BatfishObjectMapper;
import org.batfish.datamodel.bgp.community.ExtendedCommunity;
import org.junit.Test;

/** Tests of {@link Layer2VniConfig} */
public class Layer2VniConfigTest {
  @Test
  public void testEquals() {

    Layer2VniConfig.Builder builder =
        Layer2VniConfig.builder()
            .setVni(1)
            .setVrf("v")
            .setRouteDistinguisher(RouteDistinguisher.from(65555L, 1))
            .setRouteTarget(ExtendedCommunity.of(0, 1, 1));
    Layer2VniConfig vni = builder.build();
    new EqualsTester()
        .addEqualityGroup(vni, vni, builder.build())
        .addEqualityGroup(builder.setVrf("v2").build())
        .addEqualityGroup(builder.setRouteDistinguisher(RouteDistinguisher.from(65555L, 2)).build())
        .addEqualityGroup(builder.setRouteTarget(ExtendedCommunity.of(0, 2, 2)).build())
        .addEqualityGroup(builder.setImportRouteTarget("^1:1$").build())
        .addEqualityGroup(new Object())
        .testEquals();
  }

  @Test
  public void testJavaSerialization() {
    Layer2VniConfig vni =
        Layer2VniConfig.builder()
            .setVni(1)
            .setVrf("v")
            .setRouteDistinguisher(RouteDistinguisher.from(65555L, 1))
            .setRouteTarget(ExtendedCommunity.of(0, 1, 1))
            .build();
    assertThat(SerializationUtils.clone(vni), equalTo(vni));
  }

  @Test
  public void testJsonSerialization() {
    Layer2VniConfig vni =
        Layer2VniConfig.builder()
            .setVni(1)
            .setVrf("v")
            .setRouteDistinguisher(RouteDistinguisher.from(65555L, 1))
            .setRouteTarget(ExtendedCommunity.of(0, 1, 1))
            .build();
    assertThat(BatfishObjectMapper.clone(vni, Layer2VniConfig.class), equalTo(vni));
  }
}

@@ -157,28 +157,175 @@
 mon.
-testing.EqualsTester
+collect.ImmutableList;%0Aimport com.google.common.collect.Lists;%0Aimport com.google.common.testing.EqualsTester;%0Aimport java.util.List;%0Aimport java.util.stream.Collectors
 ;%0Aim
@@ -624,17 +624,16 @@
 als() %7B%0A
-%0A
     Laye
@@ -873,16 +873,59 @@
 , 1, 1))
+%0A            .setImportRouteTarget(%22%5E1:1$%22)
 ;%0A    La
@@ -1340,19 +1340,19 @@
 arget(%22%5E
-1:1
+2:2
 $%22).buil
@@ -1702,32 +1702,76 @@
 ty.of(0, 1, 1))%0A
+            .setImportRouteTarget(%22import%22)%0A
             .bui
@@ -2142,32 +2142,32 @@
       .build();%0A
-
     assertThat(B
@@ -2238,11 +2238,883 @@
 i));%0A  %7D
+%0A%0A  @Test%0A  public void testSort() %7B%0A    Layer2VniConfig.Builder vni =%0A        Layer2VniConfig.builder()%0A            .setVni(1)%0A            .setVrf(%22v%22)%0A            .setRouteDistinguisher(RouteDistinguisher.from(65555L, 1))%0A            .setImportRouteTarget(%22import%22)%0A            .setRouteTarget(ExtendedCommunity.of(0, 1, 1));%0A    List%3CLayer2VniConfig%3E configs =%0A        ImmutableList.of(%0A            vni.build(),%0A            vni.setVni(2).build(),%0A            vni.setVrf(%22v2%22).build(),%0A            vni.setRouteDistinguisher(RouteDistinguisher.from(65555L, 2)).build(),%0A            vni.setImportRouteTarget(%22import2%22).build(),%0A            vni.setRouteTarget(ExtendedCommunity.of(0, 1, 2)).build());%0A    assertThat(%0A        configs.stream().sorted().collect(Collectors.toList()),%0A        equalTo(Lists.reverse(configs).stream().sorted().collect(Collectors.toList())));%0A  %7D
 %0A%7D%0A

improve unit test coverage (#7620)