chidambar babu | 344dc81 | 2016-05-02 19:13:10 +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 | |
| 17 | package org.onosproject.isis.controller.impl; |
| 18 | |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 19 | import com.fasterxml.jackson.databind.JsonNode; |
| 20 | import com.fasterxml.jackson.databind.ObjectMapper; |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 21 | import org.junit.After; |
| 22 | import org.junit.Before; |
| 23 | import org.junit.Test; |
| 24 | |
| 25 | import static org.hamcrest.CoreMatchers.is; |
| 26 | import static org.hamcrest.CoreMatchers.notNullValue; |
| 27 | import static org.junit.Assert.assertThat; |
| 28 | |
| 29 | /** |
| 30 | * Unit test class for ControllerTest. |
| 31 | */ |
| 32 | public class ControllerTest { |
| 33 | |
| 34 | private Controller controller; |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 35 | private ObjectMapper mapper; |
| 36 | private JsonNode jsonNode; |
| 37 | private JsonNode jsonNode1; |
| 38 | private String jsonString = "{" + |
| 39 | " \"processes\": [{" + |
| 40 | " \"processId\": \"4.4.4.4\"," + |
| 41 | " \"interface\": [{" + |
| 42 | " \"interfaceIndex\": \"2\"," + |
| 43 | " \"macAddress\": \"08:00:27:b7:ab:bf\"," + |
| 44 | " \"interfaceIp\": \"192.168.56.101\"," + |
| 45 | " \"networkMask\": \"255.255.255.224\"," + |
| 46 | " \"intermediateSystemName\": \"ROUTERONE\"," + |
| 47 | " \"systemId\": \"2929.2929.2929\"," + |
| 48 | " \"lanId\": \"0000.0000.0000.00\"," + |
| 49 | " \"idLength\": \"0\"," + |
| 50 | " \"maxAreaAddresses\": \"3\"," + |
| 51 | " \"reservedPacketCircuitType\": \"1\"," + |
| 52 | " \"circuitId\": \"10\"," + |
| 53 | " \"networkType\": \"2\"," + |
| 54 | " \"areaAddress\": \"490000\"," + |
| 55 | " \"areaLength\": \"3\"," + |
| 56 | " \"lspId\": \"1313131313130000\"," + |
| 57 | " \"holdingTime\": \"50\"," + |
| 58 | " \"helloInterval\": \"10\"," + |
| 59 | " \"priority\": \"0\"" + |
| 60 | " }]" + |
| 61 | " }]" + |
| 62 | "}"; |
| 63 | private String jsonString1 = "{" + |
| 64 | " \"processes\": {" + |
| 65 | " \"interface\": [{" + |
| 66 | " \"interfaceIndex\": \"2\"," + |
| 67 | " \"interfaceIp\": \"100.100.100.100\"," + |
| 68 | " \"macAddress\": \"08:00:27:b7:ab:bf\"," + |
| 69 | " \"networkMask\": \"255.255.255.224\"," + |
| 70 | " \"intermediateSystemName\": \"ROUTERONE\"," + |
| 71 | " \"systemId\": \"2929.2929.2929\"," + |
| 72 | " \"lanId\": \"0000.0000.0000.00\"," + |
| 73 | " \"idLength\": \"0\"," + |
| 74 | " \"maxAreaAddresses\": \"3\"," + |
| 75 | " \"reservedPacketCircuitType\": \"1\"," + |
| 76 | " \"circuitId\": \"10\"," + |
| 77 | " \"networkType\": \"2\"," + |
| 78 | " \"areaAddress\": \"490000\"," + |
| 79 | " \"areaLength\": \"3\"," + |
| 80 | " \"lspId\": \"1313131313130000\"," + |
| 81 | " \"holdingTime\": \"50\"," + |
| 82 | " \"helloInterval\": \"10\"," + |
| 83 | " \"priority\": \"0\"" + |
| 84 | " }]" + |
| 85 | " }" + |
| 86 | "}"; |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 87 | |
| 88 | @Before |
| 89 | public void setUp() throws Exception { |
| 90 | controller = new Controller(); |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 91 | mapper = new ObjectMapper(); |
| 92 | jsonNode = mapper.readTree(jsonString); |
| 93 | jsonNode1 = mapper.readTree(jsonString1); |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | @After |
| 97 | public void tearDown() throws Exception { |
| 98 | controller = null; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Tests isisDeactivate() method. |
| 103 | */ |
| 104 | @Test(expected = Exception.class) |
| 105 | public void testIsisDeactivate() throws Exception { |
| 106 | controller.isisDeactivate(); |
| 107 | assertThat(controller, is(notNullValue())); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Tests getAllConfiguredProcesses() method. |
| 112 | */ |
| 113 | @Test |
| 114 | public void testGetAllConfiguredProcesses() throws Exception { |
| 115 | controller.getAllConfiguredProcesses(); |
| 116 | assertThat(controller, is(notNullValue())); |
| 117 | } |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 118 | |
| 119 | /** |
| 120 | * Tests updateConfig() method. |
| 121 | */ |
| 122 | @Test |
| 123 | public void testUpdateConfig() throws Exception { |
| 124 | jsonNode.path("interface"); |
| 125 | controller.updateConfig(jsonNode); |
| 126 | assertThat(controller, is(notNullValue())); |
| 127 | |
| 128 | controller.updateConfig(jsonNode1); |
| 129 | assertThat(controller, is(notNullValue())); |
| 130 | } |
| 131 | |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 132 | } |