Charles Chan
Committed by Gerrit Code Review

Extract test json to separate files

Change-Id: Ica815b7c5ff0a77f411e621bbb6cfc8b78fcd012
......@@ -30,6 +30,7 @@ import org.onosproject.net.config.Config;
import org.onosproject.net.config.ConfigApplyDelegate;
import org.onosproject.segmentrouting.SegmentRoutingManager;
import java.io.InputStream;
import java.util.Optional;
import java.util.Set;
......@@ -45,29 +46,7 @@ public class SegmentRoutingAppConfigTest {
private SegmentRoutingAppConfig config;
private SegmentRoutingAppConfig invalidConfig;
private static final String JSON_STRING = "{" +
"\"vRouterMacs\" : [" +
" \"00:00:00:00:00:01\"," +
" \"00:00:00:00:00:02\"" +
"]," +
"\"vRouterId\" : \"of:1\"," +
"\"suppressSubnet\" : [" +
" \"of:1/1\"," +
" \"of:1/2\"" +
"]," +
"\"suppressHost\" : [" +
" \"of:1/1\"," +
" \"of:1/2\"" +
"]}";
private static final String INVALID_JSON_STRING = "{" +
"\"vRouterMacs\" : [" +
" \"00:00:00:00:00:01\"," +
" \"00:00:00:00:00:02\"" +
"]," +
"\"suppressSubnet\" : [" +
" \"of:1/1\"," +
" \"wrongport\"" +
"]}";
private static final MacAddress ROUTER_MAC_1 = MacAddress.valueOf("00:00:00:00:00:01");
private static final MacAddress ROUTER_MAC_2 = MacAddress.valueOf("00:00:00:00:00:02");
private static final MacAddress ROUTER_MAC_3 = MacAddress.valueOf("00:00:00:00:00:03");
......@@ -84,11 +63,16 @@ public class SegmentRoutingAppConfigTest {
*/
@Before
public void setUp() throws Exception {
InputStream jsonStream = SegmentRoutingAppConfigTest.class
.getResourceAsStream("/sr-app-config.json");
InputStream invalidJsonStream = SegmentRoutingAppConfigTest.class
.getResourceAsStream("/sr-app-config-invalid.json");
ApplicationId subject = APP_ID;
String key = SegmentRoutingManager.SR_APP_ID;
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(JSON_STRING);
JsonNode invalidJsonNode = mapper.readTree(INVALID_JSON_STRING);
JsonNode jsonNode = mapper.readTree(jsonStream);
JsonNode invalidJsonNode = mapper.readTree(invalidJsonStream);
ConfigApplyDelegate delegate = new MockDelegate();
config = new SegmentRoutingAppConfig();
......
......@@ -26,6 +26,7 @@ import org.onosproject.net.DeviceId;
import org.onosproject.net.config.Config;
import org.onosproject.net.config.ConfigApplyDelegate;
import java.io.InputStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
......@@ -45,16 +46,8 @@ public class SegmentRoutingDeviceConfigTest {
@Before
public void setUp() throws Exception {
String jsonString = "{" +
"\"name\" : \"Leaf-R1\"," +
"\"nodeSid\" : 101," +
"\"routerIp\" : \"10.0.1.254\"," +
"\"routerMac\" : \"00:00:00:00:01:80\"," +
"\"isEdgeRouter\" : true," +
"\"adjacencySids\" : [" +
" { \"adjSid\" : 100, \"ports\" : [2, 3] }," +
" { \"adjSid\" : 200, \"ports\" : [4, 5] }" +
"]}";
InputStream jsonStream = SegmentRoutingDeviceConfigTest.class
.getResourceAsStream("/sr-device-config.json");
adjacencySids1 = new HashMap<>();
Set<Integer> ports1 = new HashSet<>();
......@@ -74,7 +67,7 @@ public class SegmentRoutingDeviceConfigTest {
DeviceId subject = DeviceId.deviceId("of:0000000000000001");
String key = "segmentrouting";
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(jsonString);
JsonNode jsonNode = mapper.readTree(jsonStream);
ConfigApplyDelegate delegate = new MockDelegate();
config = new SegmentRoutingDeviceConfig();
......
{
"vRouterMacs" : [
"00:00:00:00:00:01",
"00:00:00:00:00:02"
],
"vRouterId" : "of:1",
"suppressSubnet" : [
"of:1/1",
"of:1/2"
],
"suppressHost" : [
"of:1/1",
"wrongPort"
]
}
{
"vRouterMacs" : [
"00:00:00:00:00:01",
"00:00:00:00:00:02"
],
"vRouterId" : "of:1",
"suppressSubnet" : [
"of:1/1",
"of:1/2"
],
"suppressHost" : [
"of:1/1",
"of:1/2"
]
}
{
"name" : "Leaf-R1",
"nodeSid" : 101,
"routerIp" : "10.0.1.254",
"routerMac" : "00:00:00:00:01:80",
"isEdgeRouter" : true,
"adjacencySids" : [
{ "adjSid" : 100, "ports" : [2, 3] },
{ "adjSid" : 200, "ports" : [4, 5] }
]
}
\ No newline at end of file