Ethan Tai | 8c18eb7 | 2017-06-26 16:44:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015-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.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; |
| 27 | import static org.junit.Assert.*; |
| 28 | |
| 29 | /** |
| 30 | * Unit tests for DefaultBridgeDescription. |
| 31 | */ |
| 32 | |
| 33 | public class DefaultBridgeDescriptionTest { |
| 34 | private final BridgeDescription.Builder build = DefaultBridgeDescription.builder(); |
| 35 | private final String name = "expected"; |
| 36 | private final IpAddress ip = IpAddress.valueOf("0.0.0.0"); |
| 37 | private final IpAddress ip2 = IpAddress.valueOf("0.0.0.1"); |
| 38 | private final IpAddress ip3 = IpAddress.valueOf("0.0.0.2"); |
| 39 | private final ControllerInfo controller1 = new ControllerInfo(ip, 6653, "test"); |
| 40 | private final ControllerInfo controller2 = new ControllerInfo(ip2, 6654, "test"); |
| 41 | private final ControllerInfo controller3 = new ControllerInfo(ip3, 6655, "test"); |
| 42 | private final List<ControllerInfo> controllers = Lists.newArrayList(controller1, |
| 43 | controller2, |
| 44 | controller3); |
| 45 | private final BridgeDescription.FailMode mode = BridgeDescription.FailMode.SECURE; |
| 46 | private final String id = "foo"; |
| 47 | private final String type = "bar"; |
| 48 | |
| 49 | /** |
| 50 | * Tests all the getter methods in DefaultBridgeDescription. |
| 51 | */ |
| 52 | @Test |
| 53 | public void testGet() { |
| 54 | |
| 55 | build.name(name); |
| 56 | build.controllers(controllers); |
| 57 | build.datapathId(id); |
| 58 | build.datapathType(type); |
| 59 | build.failMode(mode); |
| 60 | build.disableInBand(); |
| 61 | build.enableLocalController(); |
| 62 | BridgeDescription test; |
| 63 | test = build.build(); |
| 64 | |
| 65 | assertThat(test.name(), is("expected")); |
| 66 | assertThat(test.controllers(), is(controllers)); |
| 67 | assertThat(test.datapathId().get(), is(id)); |
| 68 | assertThat(test.datapathType().get(), is(type)); |
| 69 | assertThat(test.failMode().get(), is(mode)); |
| 70 | assertThat(test.disableInBand().get(), is(true)); |
| 71 | assertNull(test.annotations()); |
| 72 | assertTrue(test.enableLocalController()); |
| 73 | assertThat(test.deviceId().get(), is(DeviceId.deviceId("of:" + id))); |
| 74 | } |
| 75 | } |
| 76 | |