1 package org.opendaylight.alto.commons.types.converter;
3 import org.opendaylight.alto.commons.types.model150404.ModelJSONMapper;
4 import org.opendaylight.alto.commons.types.rfc7285.RFC7285CostMap;
5 import com.fasterxml.jackson.databind.JsonNode;
6 import com.fasterxml.jackson.databind.ObjectMapper;
7 import org.junit.Assert;
8 import org.junit.Before;
11 public class YANGJSON2RFCCostMapConverterTest {
13 YANGJSON2RFCCostMapConverter converter;
15 ModelJSONMapper model2Json;
16 String yangModelString;
20 yangModelString = "{\"key\":{\"resourceId\":{\"value\":\"my-default-network-map-routingcost-numerical\"}},\"map\":[{\"key\":{\"src\":{\"value\":\"PID3\"}},\"implementedInterface\":\"org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.cost.map.Map\",\"dstCosts\":[{\"dst\":{\"value\":\"PID2\"},\"cost\":\"15\"},{\"dst\":{\"value\":\"PID1\"},\"cost\":\"20\"}],\"src\":{\"value\":\"PID3\"}},{\"key\":{\"src\":{\"value\":\"PID2\"}},\"implementedInterface\":\"org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.cost.map.Map\",\"dstCosts\":[{\"dst\":{\"value\":\"PID2\"},\"cost\":\"1\"},{\"dst\":{\"value\":\"PID1\"},\"cost\":\"5\"},{\"dst\":{\"value\":\"PID3\"},\"cost\":\"15\"}],\"src\":{\"value\":\"PID2\"}},{\"key\":{\"src\":{\"value\":\"PID1\"}},\"implementedInterface\":\"org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.cost.map.Map\",\"dstCosts\":[{\"dst\":{\"value\":\"PID2\"},\"cost\":\"5\"},{\"dst\":{\"value\":\"PID1\"},\"cost\":\"1\"},{\"dst\":{\"value\":\"PID3\"},\"cost\":\"10\"}],\"src\":{\"value\":\"PID1\"}}],\"tag\":{\"value\":\"da65eca2eb7a10ce8b059740b0b2e3f8eb1d4786\"},\"implementedInterface\":\"org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.resources.cost.maps.CostMap\",\"resourceId\":{\"value\":\"my-default-network-map-routingcost-numerical\"},\"meta\":{\"implementedInterface\":\"org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.cost.map.Meta\",\"costType\":{\"description\":null,\"implementedInterface\":\"org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.cost.map.meta.CostType\",\"costMetric\":{\"value\":\"routingcost\",\"enumeration\":null,\"string\":\"routingcost\"},\"costMode\":\"Numerical\"},\"dependentVtags\":[{\"key\":{\"resourceId\":{\"value\":\"my-default-network-map\"}},\"tag\":{\"value\":\"3ee2cb7e8d63d9fab71b9b34cbf764436315542e\"},\"implementedInterface\":\"org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.dependent.vtags.DependentVtags\",\"resourceId\":{\"value\":\"my-default-network-map\"}}]}}";
21 converter = new YANGJSON2RFCCostMapConverter();
22 mapper = new ObjectMapper();
23 model2Json = new ModelJSONMapper();
24 costMapJson = "{\"meta\":{\"dependent-vtags\":[{\"resource-id\":\"my-default-network-map\",\"tag\":\"3ee2cb7e8d63d9fab71b9b34cbf764436315542e\"}],\"cost-type\":{\"cost-mode\":\"numerical\",\"cost-metric\":\"routingcost\"}},\"cost-map\":{\"PID3\":{\"PID2\":15.0,\"PID1\":20.0},\"PID2\":{\"PID2\":1.0,\"PID1\":5.0,\"PID3\":15.0},\"PID1\":{\"PID2\":5.0,\"PID1\":1.0,\"PID3\":10.0}}}";
28 public void onYANGJSON2RFC() throws Exception {
29 JsonNode node = mapper.readTree(yangModelString);
30 RFC7285CostMap costMap = converter.convert(node);
31 String resultJson = model2Json.asJSON(costMap);
32 Assert.assertEquals(resultJson, this.costMapJson);