Committed by
Gerrit Code Review
Extract test json to separate files
Change-Id: Ica815b7c5ff0a77f411e621bbb6cfc8b78fcd012
Showing
5 changed files
with
54 additions
and
36 deletions
| ... | @@ -30,6 +30,7 @@ import org.onosproject.net.config.Config; | ... | @@ -30,6 +30,7 @@ import org.onosproject.net.config.Config; |
| 30 | import org.onosproject.net.config.ConfigApplyDelegate; | 30 | import org.onosproject.net.config.ConfigApplyDelegate; |
| 31 | import org.onosproject.segmentrouting.SegmentRoutingManager; | 31 | import org.onosproject.segmentrouting.SegmentRoutingManager; |
| 32 | 32 | ||
| 33 | +import java.io.InputStream; | ||
| 33 | import java.util.Optional; | 34 | import java.util.Optional; |
| 34 | import java.util.Set; | 35 | import java.util.Set; |
| 35 | 36 | ||
| ... | @@ -45,29 +46,7 @@ public class SegmentRoutingAppConfigTest { | ... | @@ -45,29 +46,7 @@ public class SegmentRoutingAppConfigTest { |
| 45 | 46 | ||
| 46 | private SegmentRoutingAppConfig config; | 47 | private SegmentRoutingAppConfig config; |
| 47 | private SegmentRoutingAppConfig invalidConfig; | 48 | private SegmentRoutingAppConfig invalidConfig; |
| 48 | - private static final String JSON_STRING = "{" + | 49 | + |
| 49 | - "\"vRouterMacs\" : [" + | ||
| 50 | - " \"00:00:00:00:00:01\"," + | ||
| 51 | - " \"00:00:00:00:00:02\"" + | ||
| 52 | - "]," + | ||
| 53 | - "\"vRouterId\" : \"of:1\"," + | ||
| 54 | - "\"suppressSubnet\" : [" + | ||
| 55 | - " \"of:1/1\"," + | ||
| 56 | - " \"of:1/2\"" + | ||
| 57 | - "]," + | ||
| 58 | - "\"suppressHost\" : [" + | ||
| 59 | - " \"of:1/1\"," + | ||
| 60 | - " \"of:1/2\"" + | ||
| 61 | - "]}"; | ||
| 62 | - private static final String INVALID_JSON_STRING = "{" + | ||
| 63 | - "\"vRouterMacs\" : [" + | ||
| 64 | - " \"00:00:00:00:00:01\"," + | ||
| 65 | - " \"00:00:00:00:00:02\"" + | ||
| 66 | - "]," + | ||
| 67 | - "\"suppressSubnet\" : [" + | ||
| 68 | - " \"of:1/1\"," + | ||
| 69 | - " \"wrongport\"" + | ||
| 70 | - "]}"; | ||
| 71 | private static final MacAddress ROUTER_MAC_1 = MacAddress.valueOf("00:00:00:00:00:01"); | 50 | private static final MacAddress ROUTER_MAC_1 = MacAddress.valueOf("00:00:00:00:00:01"); |
| 72 | private static final MacAddress ROUTER_MAC_2 = MacAddress.valueOf("00:00:00:00:00:02"); | 51 | private static final MacAddress ROUTER_MAC_2 = MacAddress.valueOf("00:00:00:00:00:02"); |
| 73 | private static final MacAddress ROUTER_MAC_3 = MacAddress.valueOf("00:00:00:00:00:03"); | 52 | private static final MacAddress ROUTER_MAC_3 = MacAddress.valueOf("00:00:00:00:00:03"); |
| ... | @@ -84,11 +63,16 @@ public class SegmentRoutingAppConfigTest { | ... | @@ -84,11 +63,16 @@ public class SegmentRoutingAppConfigTest { |
| 84 | */ | 63 | */ |
| 85 | @Before | 64 | @Before |
| 86 | public void setUp() throws Exception { | 65 | public void setUp() throws Exception { |
| 66 | + InputStream jsonStream = SegmentRoutingAppConfigTest.class | ||
| 67 | + .getResourceAsStream("/sr-app-config.json"); | ||
| 68 | + InputStream invalidJsonStream = SegmentRoutingAppConfigTest.class | ||
| 69 | + .getResourceAsStream("/sr-app-config-invalid.json"); | ||
| 70 | + | ||
| 87 | ApplicationId subject = APP_ID; | 71 | ApplicationId subject = APP_ID; |
| 88 | String key = SegmentRoutingManager.SR_APP_ID; | 72 | String key = SegmentRoutingManager.SR_APP_ID; |
| 89 | ObjectMapper mapper = new ObjectMapper(); | 73 | ObjectMapper mapper = new ObjectMapper(); |
| 90 | - JsonNode jsonNode = mapper.readTree(JSON_STRING); | 74 | + JsonNode jsonNode = mapper.readTree(jsonStream); |
| 91 | - JsonNode invalidJsonNode = mapper.readTree(INVALID_JSON_STRING); | 75 | + JsonNode invalidJsonNode = mapper.readTree(invalidJsonStream); |
| 92 | ConfigApplyDelegate delegate = new MockDelegate(); | 76 | ConfigApplyDelegate delegate = new MockDelegate(); |
| 93 | 77 | ||
| 94 | config = new SegmentRoutingAppConfig(); | 78 | config = new SegmentRoutingAppConfig(); | ... | ... |
| ... | @@ -26,6 +26,7 @@ import org.onosproject.net.DeviceId; | ... | @@ -26,6 +26,7 @@ import org.onosproject.net.DeviceId; |
| 26 | import org.onosproject.net.config.Config; | 26 | import org.onosproject.net.config.Config; |
| 27 | import org.onosproject.net.config.ConfigApplyDelegate; | 27 | import org.onosproject.net.config.ConfigApplyDelegate; |
| 28 | 28 | ||
| 29 | +import java.io.InputStream; | ||
| 29 | import java.util.HashMap; | 30 | import java.util.HashMap; |
| 30 | import java.util.HashSet; | 31 | import java.util.HashSet; |
| 31 | import java.util.Map; | 32 | import java.util.Map; |
| ... | @@ -45,16 +46,8 @@ public class SegmentRoutingDeviceConfigTest { | ... | @@ -45,16 +46,8 @@ public class SegmentRoutingDeviceConfigTest { |
| 45 | 46 | ||
| 46 | @Before | 47 | @Before |
| 47 | public void setUp() throws Exception { | 48 | public void setUp() throws Exception { |
| 48 | - String jsonString = "{" + | 49 | + InputStream jsonStream = SegmentRoutingDeviceConfigTest.class |
| 49 | - "\"name\" : \"Leaf-R1\"," + | 50 | + .getResourceAsStream("/sr-device-config.json"); |
| 50 | - "\"nodeSid\" : 101," + | ||
| 51 | - "\"routerIp\" : \"10.0.1.254\"," + | ||
| 52 | - "\"routerMac\" : \"00:00:00:00:01:80\"," + | ||
| 53 | - "\"isEdgeRouter\" : true," + | ||
| 54 | - "\"adjacencySids\" : [" + | ||
| 55 | - " { \"adjSid\" : 100, \"ports\" : [2, 3] }," + | ||
| 56 | - " { \"adjSid\" : 200, \"ports\" : [4, 5] }" + | ||
| 57 | - "]}"; | ||
| 58 | 51 | ||
| 59 | adjacencySids1 = new HashMap<>(); | 52 | adjacencySids1 = new HashMap<>(); |
| 60 | Set<Integer> ports1 = new HashSet<>(); | 53 | Set<Integer> ports1 = new HashSet<>(); |
| ... | @@ -74,7 +67,7 @@ public class SegmentRoutingDeviceConfigTest { | ... | @@ -74,7 +67,7 @@ public class SegmentRoutingDeviceConfigTest { |
| 74 | DeviceId subject = DeviceId.deviceId("of:0000000000000001"); | 67 | DeviceId subject = DeviceId.deviceId("of:0000000000000001"); |
| 75 | String key = "segmentrouting"; | 68 | String key = "segmentrouting"; |
| 76 | ObjectMapper mapper = new ObjectMapper(); | 69 | ObjectMapper mapper = new ObjectMapper(); |
| 77 | - JsonNode jsonNode = mapper.readTree(jsonString); | 70 | + JsonNode jsonNode = mapper.readTree(jsonStream); |
| 78 | ConfigApplyDelegate delegate = new MockDelegate(); | 71 | ConfigApplyDelegate delegate = new MockDelegate(); |
| 79 | 72 | ||
| 80 | config = new SegmentRoutingDeviceConfig(); | 73 | config = new SegmentRoutingDeviceConfig(); | ... | ... |
| 1 | +{ | ||
| 2 | + "name" : "Leaf-R1", | ||
| 3 | + "nodeSid" : 101, | ||
| 4 | + "routerIp" : "10.0.1.254", | ||
| 5 | + "routerMac" : "00:00:00:00:01:80", | ||
| 6 | + "isEdgeRouter" : true, | ||
| 7 | + "adjacencySids" : [ | ||
| 8 | + { "adjSid" : 100, "ports" : [2, 3] }, | ||
| 9 | + { "adjSid" : 200, "ports" : [4, 5] } | ||
| 10 | + ] | ||
| 11 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment