Ray Milkey | 9098b42 | 2017-08-22 09:23:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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 | |
Ray Milkey | 3f038c4 | 2017-09-26 11:31:54 -0700 | [diff] [blame] | 19 | import com.google.common.testing.EqualsTester; |
Ray Milkey | 9098b42 | 2017-08-22 09:23:49 -0700 | [diff] [blame] | 20 | import org.junit.Test; |
| 21 | import org.onosproject.net.DefaultAnnotations; |
| 22 | import org.onosproject.net.SparseAnnotations; |
| 23 | |
Ray Milkey | 3f038c4 | 2017-09-26 11:31:54 -0700 | [diff] [blame] | 24 | import static com.spotify.hamcrest.optional.OptionalMatchers.optionalWithValue; |
Ray Milkey | 9098b42 | 2017-08-22 09:23:49 -0700 | [diff] [blame] | 25 | import static org.hamcrest.Matchers.is; |
| 26 | import static org.junit.Assert.assertThat; |
Ray Milkey | 9098b42 | 2017-08-22 09:23:49 -0700 | [diff] [blame] | 27 | |
| 28 | |
| 29 | public class DefaultTunnelDescriptionTest { |
| 30 | |
| 31 | private static final String DID_1 = "device1"; |
| 32 | private static final String IFACE_NAME_1 = "eth1"; |
| 33 | private static final TunnelKey<Long> KEY_1 = new TunnelKey<>(1L); |
| 34 | private static final TunnelEndPoint<Long> LOCAL_1 = |
| 35 | new TunnelEndPoint<>(11L); |
| 36 | private static final TunnelEndPoint<Long> REMOTE_1 = |
| 37 | new TunnelEndPoint<>(12L); |
| 38 | private static final SparseAnnotations ANNOTATIONS_1 = |
| 39 | DefaultAnnotations.builder() |
| 40 | .set("AAA", "AAA") |
| 41 | .build(); |
| 42 | |
| 43 | private TunnelDescription tunnelDescription1 = |
| 44 | DefaultTunnelDescription.builder() |
| 45 | .deviceId(DID_1) |
| 46 | .ifaceName(IFACE_NAME_1) |
| 47 | .key(KEY_1) |
| 48 | .type(TunnelDescription.Type.GRE) |
| 49 | .local(LOCAL_1) |
| 50 | .remote(REMOTE_1) |
| 51 | .otherConfigs(ANNOTATIONS_1) |
| 52 | .build(); |
| 53 | |
| 54 | private TunnelDescription tunnelDescription2 = |
| 55 | DefaultTunnelDescription.builder() |
| 56 | .deviceId(DID_1) |
| 57 | .ifaceName(IFACE_NAME_1) |
| 58 | .key(KEY_1) |
| 59 | .type(TunnelDescription.Type.GRE) |
| 60 | .remote(LOCAL_1) |
| 61 | .local(REMOTE_1) |
| 62 | .build(); |
| 63 | |
| 64 | @Test |
| 65 | public void testConstruction() { |
Ray Milkey | 3f038c4 | 2017-09-26 11:31:54 -0700 | [diff] [blame] | 66 | assertThat(tunnelDescription1.deviceId(), optionalWithValue(is(DID_1))); |
Ray Milkey | 9098b42 | 2017-08-22 09:23:49 -0700 | [diff] [blame] | 67 | assertThat(tunnelDescription1.ifaceName(), is(IFACE_NAME_1)); |
Ray Milkey | 3f038c4 | 2017-09-26 11:31:54 -0700 | [diff] [blame] | 68 | assertThat(tunnelDescription1.key(), optionalWithValue(is(KEY_1))); |
Ray Milkey | 9098b42 | 2017-08-22 09:23:49 -0700 | [diff] [blame] | 69 | assertThat(tunnelDescription1.type(), is(TunnelDescription.Type.GRE)); |
Ray Milkey | 3f038c4 | 2017-09-26 11:31:54 -0700 | [diff] [blame] | 70 | assertThat(tunnelDescription1.local(), optionalWithValue(is(LOCAL_1))); |
| 71 | assertThat(tunnelDescription1.remote(), optionalWithValue(is(REMOTE_1))); |
Ray Milkey | 9098b42 | 2017-08-22 09:23:49 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | @Test |
| 75 | public void testEquals() { |
| 76 | new EqualsTester() |
| 77 | .addEqualityGroup(tunnelDescription1) |
| 78 | .addEqualityGroup(tunnelDescription2) |
| 79 | .testEquals(); |
| 80 | } |
| 81 | } |