// Path: server/src/main/java/io/pne/veth/server/handlers/dao/INetworkDao.java
// public interface INetworkDao {
// 
//     void addNetwork(TNetwork aNetwork);
// 
//     TNetwork findNetwork(String aNetworkId);
// 
//     void removeNetwork(String aNetworkId);
// }
// 
// Path: server/src/main/java/io/pne/veth/server/handlers/dao/NetworkDaoImpl.java
// public class NetworkDaoImpl implements INetworkDao {
// 
//     private static final Logger LOG = LoggerFactory.getLogger(NetworkDaoImpl.class);
// 
//     private final Map<String, TNetwork> map = new ConcurrentHashMap<>();
// 
//     @Override
//     public void addNetwork(TNetwork aNetwork) {
//         LOG.info("Adding network {} ...", aNetwork);
//         TNetwork previous = map.put(aNetwork.id, aNetwork);
//         if(previous != null) {
//             LOG.warn("The previous network war replaced by new [previous={}, new={}]", previous, aNetwork);
//         }
//     }
// 
//     @Override
//     public TNetwork findNetwork(String aNetworkId) {
//         TNetwork network = map.get(aNetworkId);
//         if(network == null) {
//             LOG.warn("No network {} in {}", aNetworkId, map);
//         }
//         return network;
//     }
// 
//     @Override
//     public void removeNetwork(String aNetworkId) {
//         TNetwork network = map.remove(aNetworkId);
//         if(network == null) {
//             LOG.warn("No network {}", aNetworkId);
//         } else {
//             LOG.info("Network was removed: {}", network);
//         }
//     }
// }
// 
// Path: server/src/main/java/io/pne/veth/server/handlers/location/networkdriver/CreateNetworkHandler.java
// public class CreateNetworkHandler implements IJsonHandler<CreateNetworkRequest, SuccessResponse> {
// 
//     private static final Logger LOG = LoggerFactory.getLogger(CreateNetworkHandler.class);
// 
//     private final INetworkDao networkDao;
// 
//     public CreateNetworkHandler(INetworkDao networkDao) {
//         this.networkDao = networkDao;
//     }
// 
//     @Override
//     public SuccessResponse handle(CreateNetworkRequest aRequest) {
//         networkDao.addNetwork(new TNetwork(
//                   aRequest.networkID
//                 , aRequest.ipv4Data[0].Gateway
//                 , aRequest.ipv4Data[0].Pool
//                 , getInterfaceSuffix(aRequest.options)
//         ));
// 
//         return SuccessResponse.SUCCESS;
//     }
// 
//     private String getInterfaceSuffix(Map<String, Object> aOptions) {
//         if(aOptions == null) {
//             return createRandomName("No options");
//         }
// 
//         Map<String, Object> generic = (Map<String, Object>) aOptions.get("com.docker.network.generic");
//         if(generic == null) {
//             return createRandomName("No com.docker.network.generic, creating");
//         }
// 
//         Object prefix = generic.get("ip.pne.veth.interface.prefix");
//         if(prefix == null) {
//             return createRandomName("No ip.pne.veth.interface.prefix");
//         }
//         return prefix.toString();
//     }
// 
//     private String createRandomName(String aMessage) {
//         String prefix = "veth-" + System.currentTimeMillis();
//         LOG.warn("{}, creating random interface prefix: {}", aMessage, prefix);
//         return prefix;
//     }
// 
//     @Override
//     public Class<CreateNetworkRequest> getRequestClass() {
//         return CreateNetworkRequest.class;
//     }
// }


import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.pne.veth.server.handlers.dao.INetworkDao;
import io.pne.veth.server.handlers.dao.NetworkDaoImpl;
import io.pne.veth.server.handlers.location.networkdriver.CreateNetworkHandler;
import org.junit.Test;
package io.pne.veth.server.handlers;


public class JsonHandlerTest {

    @Test
    public void test() {
        Gson gson        = new GsonBuilder().setPrettyPrinting().create();
        INetworkDao networkDao  = new NetworkDaoImpl();

        JsonHandler handler = new JsonHandler(gson, new CreateNetworkHandler(networkDao));
        String json = "{\"NetworkID\":\"9f55eb121867c859bf6bdac33127f79aed641976263138d99e34637edf0cc3fe\",\"Options\":{\"com.docker.network.enable_ipv6\":false,\"com.docker.network.generic\":{}},\"IPv4Data\":[{\"AddressSpace\":\"LocalDefault\",\"Gateway\":\"172.18.0.1/16\",\"Pool\":\"172.18.0.0/16\"}],\"IPv6Data\":[]}";
// Path: server/src/main/java/io/pne/veth/server/handlers/dao/INetworkDao.java
// public interface INetworkDao {
// 
//     void addNetwork(TNetwork aNetwork);
// 
//     TNetwork findNetwork(String aNetworkId);
// 
//     void removeNetwork(String aNetworkId);
// }
// 
// Path: server/src/main/java/io/pne/veth/server/handlers/dao/NetworkDaoImpl.java
// public class NetworkDaoImpl implements INetworkDao {
// 
//     private static final Logger LOG = LoggerFactory.getLogger(NetworkDaoImpl.class);
// 
//     private final Map<String, TNetwork> map = new ConcurrentHashMap<>();
// 
//     @Override
//     public void addNetwork(TNetwork aNetwork) {
//         LOG.info("Adding network {} ...", aNetwork);
//         TNetwork previous = map.put(aNetwork.id, aNetwork);
//         if(previous != null) {
//             LOG.warn("The previous network war replaced by new [previous={}, new={}]", previous, aNetwork);
//         }
//     }
// 
//     @Override
//     public TNetwork findNetwork(String aNetworkId) {
//         TNetwork network = map.get(aNetworkId);
//         if(network == null) {
//             LOG.warn("No network {} in {}", aNetworkId, map);
//         }
//         return network;
//     }
// 
//     @Override
//     public void removeNetwork(String aNetworkId) {
//         TNetwork network = map.remove(aNetworkId);
//         if(network == null) {
//             LOG.warn("No network {}", aNetworkId);
//         } else {
//             LOG.info("Network was removed: {}", network);
//         }
//     }
// }
// 
// Path: server/src/main/java/io/pne/veth/server/handlers/location/networkdriver/CreateNetworkHandler.java
// public class CreateNetworkHandler implements IJsonHandler<CreateNetworkRequest, SuccessResponse> {
// 
//     private static final Logger LOG = LoggerFactory.getLogger(CreateNetworkHandler.class);
// 
//     private final INetworkDao networkDao;
// 
//     public CreateNetworkHandler(INetworkDao networkDao) {
//         this.networkDao = networkDao;
//     }
// 
//     @Override
//     public SuccessResponse handle(CreateNetworkRequest aRequest) {
//         networkDao.addNetwork(new TNetwork(
//                   aRequest.networkID
//                 , aRequest.ipv4Data[0].Gateway
//                 , aRequest.ipv4Data[0].Pool
//                 , getInterfaceSuffix(aRequest.options)
//         ));
// 
//         return SuccessResponse.SUCCESS;
//     }
// 
//     private String getInterfaceSuffix(Map<String, Object> aOptions) {
//         if(aOptions == null) {
//             return createRandomName("No options");
//         }
// 
//         Map<String, Object> generic = (Map<String, Object>) aOptions.get("com.docker.network.generic");
//         if(generic == null) {
//             return createRandomName("No com.docker.network.generic, creating");
//         }
// 
//         Object prefix = generic.get("ip.pne.veth.interface.prefix");
//         if(prefix == null) {
//             return createRandomName("No ip.pne.veth.interface.prefix");
//         }
//         return prefix.toString();
//     }
// 
//     private String createRandomName(String aMessage) {
//         String prefix = "veth-" + System.currentTimeMillis();
//         LOG.warn("{}, creating random interface prefix: {}", aMessage, prefix);
//         return prefix;
//     }
// 
//     @Override
//     public Class<CreateNetworkRequest> getRequestClass() {
//         return CreateNetworkRequest.class;
//     }
// }


// Path: server/src/test/java/io/pne/veth/server/handlers/JsonHandlerTest.java
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.pne.veth.server.handlers.dao.INetworkDao;
import io.pne.veth.server.handlers.dao.NetworkDaoImpl;
import io.pne.veth.server.handlers.location.networkdriver.CreateNetworkHandler;
import org.junit.Test;

package io.pne.veth.server.handlers;


public class JsonHandlerTest {

    @Test
    public void test() {
        Gson gson        = new GsonBuilder().setPrettyPrinting().create();
        INetworkDao networkDao  = new NetworkDaoImpl();

        JsonHandler handler = new JsonHandler(gson, new CreateNetworkHandler(networkDao));
        String json = "{\"NetworkID\":\"9f55eb121867c859bf6bdac33127f79aed641976263138d99e34637edf0cc3fe\",\"Options\":{\"com.docker.network.enable_ipv6\":false,\"com.docker.network.generic\":{}},\"IPv4Data\":[{\"AddressSpace\":\"LocalDefault\",\"Gateway\":\"172.18.0.1/16\",\"Pool\":\"172.18.0.0/16\"}],\"IPv6Data\":[]}";
        final Object o = handler.parseRequest("/test", json);