Search in sources :

Example 1 with ModelConverter

use of org.btrplace.json.model.ModelConverter in project scheduler by btrplace.

the class NetworkConverterTest method switchesAndLinksTest.

@Test
public void switchesAndLinksTest() throws JSONConverterException {
    Model mo = new DefaultModel();
    Network net = new Network();
    Switch s = net.newSwitch(1000);
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    mo.getMapping().addOnlineNode(n1);
    mo.getMapping().addOnlineNode(n2);
    net.connect(1000, s, n1, n2);
    mo.attach(net);
    ModelConverter mc = new ModelConverter();
    JSONObject jo = mc.toJSON(mo);
    System.err.println(jo);
    Model mo2 = mc.fromJSON(jo);
    Network net2 = Network.get(mo2);
    Assert.assertTrue(net.getSwitches().equals(net2.getSwitches()));
    Assert.assertTrue(net.getLinks().equals(net2.getLinks()));
    Assert.assertTrue(net.getConnectedNodes().equals(net2.getConnectedNodes()));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Switch(org.btrplace.model.view.network.Switch) JSONObject(net.minidev.json.JSONObject) Network(org.btrplace.model.view.network.Network) Node(org.btrplace.model.Node) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) ModelConverter(org.btrplace.json.model.ModelConverter) Test(org.testng.annotations.Test)

Example 2 with ModelConverter

use of org.btrplace.json.model.ModelConverter in project scheduler by btrplace.

the class NetworkConverterTest method staticRoutingTest.

@Test
public void staticRoutingTest() throws JSONConverterException {
    Model mo = new DefaultModel();
    Network net = new Network(new StaticRouting());
    Switch s = net.newSwitch(1000);
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    mo.getMapping().addOnlineNode(n1);
    mo.getMapping().addOnlineNode(n2);
    net.connect(1000, s, n1, n2);
    Map<Link, Boolean> route = new LinkedHashMap<>();
    route.put(net.getConnectedLinks(n1).get(0), true);
    route.put(net.getConnectedLinks(n2).get(0), false);
    ((StaticRouting) net.getRouting()).setStaticRoute(new StaticRouting.NodesMap(n1, n2), route);
    mo.attach(net);
    ModelConverter mc = new ModelConverter();
    JSONObject jo = mc.toJSON(mo);
    System.err.println(jo);
    Model mo2 = mc.fromJSON(jo);
    Network net2 = Network.get(mo2);
    Assert.assertTrue(net.getSwitches().equals(net2.getSwitches()));
    Assert.assertTrue(net.getLinks().equals(net2.getLinks()));
    Assert.assertTrue(net.getConnectedNodes().equals(net2.getConnectedNodes()));
    Map<StaticRouting.NodesMap, Map<Link, Boolean>> routes = ((StaticRouting) net.getRouting()).getStaticRoutes();
    Map<StaticRouting.NodesMap, Map<Link, Boolean>> routes2 = ((StaticRouting) net2.getRouting()).getStaticRoutes();
    for (StaticRouting.NodesMap nm : routes.keySet()) {
        for (StaticRouting.NodesMap nm2 : routes2.keySet()) {
            Assert.assertTrue(nm.equals(nm2));
            Assert.assertTrue(routes.get(nm).equals(routes2.get(nm2)));
        }
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) StaticRouting(org.btrplace.model.view.network.StaticRouting) Node(org.btrplace.model.Node) ModelConverter(org.btrplace.json.model.ModelConverter) LinkedHashMap(java.util.LinkedHashMap) Switch(org.btrplace.model.view.network.Switch) JSONObject(net.minidev.json.JSONObject) Network(org.btrplace.model.view.network.Network) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Link(org.btrplace.model.view.network.Link) Test(org.testng.annotations.Test)

Example 3 with ModelConverter

use of org.btrplace.json.model.ModelConverter in project scheduler by btrplace.

the class ReconfigurationPlanConverterTest method testAccessors.

@Test
public void testAccessors() {
    ModelConverter mc = new ModelConverter();
    ReconfigurationPlanConverter rcp = new ReconfigurationPlanConverter(mc);
    Assert.assertEquals(rcp.getModelConverter(), mc);
}
Also used : ModelConverter(org.btrplace.json.model.ModelConverter) Test(org.testng.annotations.Test)

Aggregations

ModelConverter (org.btrplace.json.model.ModelConverter)3 Test (org.testng.annotations.Test)3 JSONObject (net.minidev.json.JSONObject)2 DefaultModel (org.btrplace.model.DefaultModel)2 Model (org.btrplace.model.Model)2 Node (org.btrplace.model.Node)2 Network (org.btrplace.model.view.network.Network)2 Switch (org.btrplace.model.view.network.Switch)2 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Link (org.btrplace.model.view.network.Link)1 StaticRouting (org.btrplace.model.view.network.StaticRouting)1