Unit test for converters in alto-commons.
[alto.git] / alto-commons / src / test / java / org / opendaylight / alto / commons / types / converter / YANGJSON2RFCCostMapConverterTest.java
1 package org.opendaylight.alto.commons.types.converter;
2
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;
9 import org.junit.Test;
10
11 public class YANGJSON2RFCCostMapConverterTest {
12     String costMapJson;
13     YANGJSON2RFCCostMapConverter converter;
14     ObjectMapper mapper;
15     ModelJSONMapper model2Json;
16     String yangModelString;
17
18     @Before
19     public void init() {
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}}}";
25     }
26
27     @Test
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);
33     }
34 }