sunishvk | f7c5655 | 2016-07-18 16:02:39 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.ospf.controller.impl; |
| 17 | |
| 18 | import com.fasterxml.jackson.databind.JsonNode; |
| 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 20 | import org.junit.After; |
| 21 | import org.junit.Before; |
| 22 | import org.junit.Test; |
| 23 | import org.onosproject.ospf.controller.OspfProcess; |
| 24 | |
| 25 | import java.util.ArrayList; |
| 26 | import java.util.List; |
| 27 | |
| 28 | import static org.hamcrest.CoreMatchers.is; |
| 29 | import static org.hamcrest.CoreMatchers.notNullValue; |
| 30 | import static org.hamcrest.MatcherAssert.assertThat; |
| 31 | |
| 32 | /** |
| 33 | * Unit test class for OspfJsonParsingUtilTest. |
| 34 | */ |
| 35 | public class OspfConfigUtilTest { |
| 36 | private ObjectMapper mapper; |
| 37 | private JsonNode jsonNode; |
| 38 | private List<OspfProcess> ospfProcessList = new ArrayList<>(); |
| 39 | private String jsonString = "{\n" + |
| 40 | "\t\"processes\": {\n" + |
| 41 | "\t\t\"areas\": [{\n" + |
| 42 | "\t\t\t\"interface\": [{\n" + |
| 43 | "\t\t\t\t\"interfaceIndex\": \"2\",\n" + |
| 44 | "\n" + |
| 45 | "\t\t\t\t\"helloIntervalTime\": \"10\",\n" + |
| 46 | "\n" + |
| 47 | "\t\t\t\t\"routerDeadIntervalTime\": \"40\",\n" + |
| 48 | "\n" + |
| 49 | "\t\t\t\t\"interfaceType\": \"2\",\n" + |
| 50 | "\n" + |
| 51 | "\t\t\t\t\"reTransmitInterval\": \"5\"\n" + |
| 52 | "\t\t\t}],\n" + |
| 53 | "\t\t\t\"areaId\": \"5.5.5.5\",\n" + |
| 54 | "\n" + |
| 55 | "\t\t\t\"routerId\": \"7.7.7.7\",\n" + |
| 56 | "\n" + |
| 57 | "\t\t\t\"isOpaqueEnable\": \"false\",\n" + |
| 58 | "\n" + |
| 59 | "\t\t\t\"externalRoutingCapability\": \"true\"\n" + |
| 60 | "\t\t}]\n" + |
| 61 | "\t}\n" + |
| 62 | "}"; |
| 63 | |
| 64 | @Before |
| 65 | public void setUp() throws Exception { |
| 66 | mapper = new ObjectMapper(); |
| 67 | jsonNode = mapper.readTree(jsonString); |
| 68 | mapper = new ObjectMapper(); |
| 69 | } |
| 70 | |
| 71 | @After |
| 72 | public void tearDown() throws Exception { |
| 73 | |
| 74 | } |
| 75 | |
| 76 | @Test |
| 77 | public void testProcesses() throws Exception { |
| 78 | jsonNode.path("areas"); |
| 79 | ospfProcessList = OspfConfigUtil.processes(jsonNode); |
| 80 | assertThat(ospfProcessList, is(notNullValue())); |
| 81 | } |
| 82 | } |