package org.bitbucket.openkilda.tools.mininet;

import static org.junit.Assert.*;

import java.util.List;

import org.bitbucket.openkilda.tools.mininet.Mininet;
import org.bitbucket.openkilda.tools.mininet.MininetController;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.projectfloodlight.openflow.protocol.OFVersion;
import org.projectfloodlight.openflow.types.DatapathId;
import org.projectfloodlight.openflow.types.IPv4Address;
import org.projectfloodlight.openflow.types.TransportPort;

public class MininetTest {

  public static final String MININET_ADDRESS = "192.168.56.10";
  public static final int MININET_PORT = 38080;
  public static final int MAX_CONNECT_TIME = 5000;
  public static final int SLEEP_INTERVAL = 1000;
  
  @BeforeClass
  public static void setUpBeforeClass() throws Exception {
  }

  @AfterClass
  public static void tearDownAfterClass() throws Exception {
  }

  @Before
  public void setUp() throws Exception {
  }

  @After
  public void tearDown() throws Exception {
  }

  @Test
  public void testTDD() throws Exception {
    IPv4Address controllerAddress = IPv4Address.of("192.168.56.1");
    TransportPort controllerPort = TransportPort.of(6653);
    OFVersion ofVersion = OFVersion.OF_13;
    IMininetController controller = new MininetController()
        .setIP(controllerAddress)
        .setPort(controllerPort)
        .setVersion(ofVersion)
        .setName("floodlight")
        .build();
    
    IMininet mininet = new Mininet()
        .addMininetServer(MININET_ADDRESS, MININET_PORT)
        .clear()
        .addController(controller)
        .addSwitch("sw1", DatapathId.of(1))
        .addSwitch("sw2", DatapathId.of(2))
        .addLink("sw1", "sw2")
        .build();
    
    List<MininetSwitch> switches = mininet.switches().getSwitches();
    assertEquals("failure - should have exactly 2 switches", 2, switches.size());
    
    Thread.sleep(MAX_CONNECT_TIME);
    switches = mininet.switches().getSwitches();
    for(MininetSwitch sw: switches) {
      assertTrue(String.format("failure - %s should be connected", sw.getName()), sw.getConnected());
    }
    
    List<MininetLink> links = mininet.links().getLinks();
    for(MininetLink link: links) {
      assertTrue(String.format("failure - %s should be up", link.getName()), link.isUp());
    }
  }
}

@@ -656,28 +656,22 @@
 RESS = %22
-192.168.56.1
+0.0.0.
 0%22;%0A  pu
@@ -814,19 +814,17 @@
 = 1000;%0A
-  
 %0A
+
   @Befor
@@ -1195,20 +1195,15 @@
 of(%22
-192.168.56.1
+0.0.0.0
 %22);%0A
@@ -1507,29 +1507,25 @@
   .build();%0A
-    
 %0A
+
     IMininet
@@ -1795,21 +1795,17 @@
 uild();%0A
-    
 %0A
+
     List
@@ -1947,21 +1947,17 @@
 ize());%0A
-    
 %0A
+
     Thre
@@ -2179,20 +2179,16 @@
 ;%0A    %7D%0A
-    
 %0A    Lis

Replace discrete IP addresses in tests with 0.0.0.0