Open Kilda Java Documentation
TeTopologyParserTest.java
Go to the documentation of this file.
1 package org.openkilda.topo.builders;
2 
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertTrue;
5 import static org.junit.Assert.fail;
6 
7 import org.junit.Test;
8 import org.openkilda.topo.Link;
11 
12 public class TeTopologyParserTest {
13 
14  @Test
15  public void shouldParseJson() {
17  + "{\"name\":\"sw1\", \"outgoing_relationships\": [\"sw2\"]}, "
18  + "{\"name\":\"sw2\", \"outgoing_relationships\": []}"
19  + "]}");
20 
21  assertEquals("Expected 2 switches to be parsed", 2, result.getSwitches().size());
22  assertEquals("Expected 1 link to be parsed", 1, result.getLinks().size());
23  assertTrue("Expected 'sw1' switch to be parsed", result.getSwitches().containsKey("SW1"));
24  assertTrue("Expected 'sw2' switch to be parsed", result.getSwitches().containsKey("SW2"));
25  Link link = result.getLinks().values().iterator().next();
26  assertEquals("Expected a link from sw1 to be parsed", "SW1", link.getSrc().getTopoSwitch().getId());
27  assertEquals("Expected a link to sw2 to be parsed", "SW2", link.getDst().getTopoSwitch().getId());
28  }
29 
30  @Test
33  + "{\"name\":\"sw1\"}, "
34  + "{\"name\":\"sw2\"}"
35  + "]}");
36 
37  assertEquals("Expected 2 switches to be parsed", 2, result.getSwitches().size());
38  assertEquals("Expected 0 link to be parsed", 0, result.getLinks().size());
39  }
40 
41  @Test(expected = TopologyProcessingException.class)
42  public void shouldFailIfNodeHasNoName() {
44  + "{\"outgoing_relationships\": [\"sw2\"]}, "
45  + "{\"name\":\"sw2\", \"outgoing_relationships\": []}"
46  + "]}");
47 
48  fail();
49  }
50 
51  @Test(expected = TopologyProcessingException.class)
54  + "{\"name\":\"\", \"outgoing_relationships\": [\"sw2\"]}, "
55  + "{\"name\":\"sw2\", \"outgoing_relationships\": []}"
56  + "]}");
57 
58  fail();
59  }
60 }
list result
Definition: plan-d.py:72
static Topology parseTopologyEngineJson(String json)