Ethan Tai | 8c18eb7 | 2017-06-26 16:44:25 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Ethan Tai | 8c18eb7 | 2017-06-26 16:44:25 -0700 | [diff] [blame] | 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.net.behaviour; |
| 18 | |
| 19 | import com.google.common.collect.Lists; |
| 20 | import org.junit.Test; |
| 21 | import org.onlab.packet.IpAddress; |
| 22 | import org.onosproject.net.DeviceId; |
| 23 | |
| 24 | import java.util.List; |
| 25 | |
| 26 | import static org.hamcrest.Matchers.is; |
Jian Li | 0aed0e6 | 2020-12-12 03:54:54 +0900 | [diff] [blame^] | 27 | import static org.junit.Assert.assertNull; |
| 28 | import static org.junit.Assert.assertThat; |
| 29 | import static org.junit.Assert.assertTrue; |
Ethan Tai | 8c18eb7 | 2017-06-26 16:44:25 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Unit tests for DefaultBridgeDescription. |
| 33 | */ |
| 34 | |
| 35 | public class DefaultBridgeDescriptionTest { |
| 36 | private final BridgeDescription.Builder build = DefaultBridgeDescription.builder(); |
| 37 | private final String name = "expected"; |
| 38 | private final IpAddress ip = IpAddress.valueOf("0.0.0.0"); |
| 39 | private final IpAddress ip2 = IpAddress.valueOf("0.0.0.1"); |
| 40 | private final IpAddress ip3 = IpAddress.valueOf("0.0.0.2"); |
| 41 | private final ControllerInfo controller1 = new ControllerInfo(ip, 6653, "test"); |
| 42 | private final ControllerInfo controller2 = new ControllerInfo(ip2, 6654, "test"); |
| 43 | private final ControllerInfo controller3 = new ControllerInfo(ip3, 6655, "test"); |
| 44 | private final List<ControllerInfo> controllers = Lists.newArrayList(controller1, |
| 45 | controller2, |
| 46 | controller3); |
| 47 | private final BridgeDescription.FailMode mode = BridgeDescription.FailMode.SECURE; |
| 48 | private final String id = "foo"; |
| 49 | private final String type = "bar"; |
| 50 | |
| 51 | /** |
| 52 | * Tests all the getter methods in DefaultBridgeDescription. |
| 53 | */ |
| 54 | @Test |
| 55 | public void testGet() { |
| 56 | |
| 57 | build.name(name); |
| 58 | build.controllers(controllers); |
| 59 | build.datapathId(id); |
| 60 | build.datapathType(type); |
| 61 | build.failMode(mode); |
| 62 | build.disableInBand(); |
Jian Li | 0aed0e6 | 2020-12-12 03:54:54 +0900 | [diff] [blame^] | 63 | build.mcastSnoopingEnable(); |
Ethan Tai | 8c18eb7 | 2017-06-26 16:44:25 -0700 | [diff] [blame] | 64 | build.enableLocalController(); |
| 65 | BridgeDescription test; |
| 66 | test = build.build(); |
| 67 | |
| 68 | assertThat(test.name(), is("expected")); |
| 69 | assertThat(test.controllers(), is(controllers)); |
| 70 | assertThat(test.datapathId().get(), is(id)); |
| 71 | assertThat(test.datapathType().get(), is(type)); |
| 72 | assertThat(test.failMode().get(), is(mode)); |
| 73 | assertThat(test.disableInBand().get(), is(true)); |
Jian Li | 0aed0e6 | 2020-12-12 03:54:54 +0900 | [diff] [blame^] | 74 | assertThat(test.mcastSnoopingEnable().get(), is(true)); |
Ethan Tai | 8c18eb7 | 2017-06-26 16:44:25 -0700 | [diff] [blame] | 75 | assertNull(test.annotations()); |
| 76 | assertTrue(test.enableLocalController()); |
| 77 | assertThat(test.deviceId().get(), is(DeviceId.deviceId("of:" + id))); |
| 78 | } |
| 79 | } |
| 80 | |