Ray Milkey | c916699 | 2017-05-08 12:02:26 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Ray Milkey | c916699 | 2017-05-08 12:02:26 -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.protection; |
| 18 | |
| 19 | import java.util.List; |
| 20 | |
| 21 | import org.junit.Test; |
| 22 | import org.onosproject.net.DeviceId; |
| 23 | import org.onosproject.net.FilteredConnectPoint; |
| 24 | import org.onosproject.net.NetTestTools; |
| 25 | |
| 26 | import com.google.common.collect.ImmutableList; |
| 27 | |
| 28 | import static org.hamcrest.Matchers.contains; |
| 29 | import static org.hamcrest.Matchers.is; |
| 30 | import static org.hamcrest.Matchers.notNullValue; |
| 31 | import static org.junit.Assert.assertThat; |
| 32 | |
| 33 | /** |
| 34 | * Unit tests for protected transport endpoint state. |
| 35 | */ |
| 36 | public class ProtectedTransportEndpointStateTest { |
| 37 | |
| 38 | private List<TransportEndpointDescription> paths = ImmutableList.of(); |
| 39 | private DeviceId peer = NetTestTools.did("d1"); |
| 40 | private String fingerprint = "aaa"; |
| 41 | |
| 42 | private TransportEndpointDescription description = |
| 43 | TransportEndpointDescription |
| 44 | .builder() |
| 45 | .withEnabled(true) |
| 46 | .withOutput(new FilteredConnectPoint(NetTestTools.connectPoint("xxx", 1))) |
| 47 | .build(); |
| 48 | |
| 49 | private ProtectedTransportEndpointDescription protectedDescription = |
| 50 | ProtectedTransportEndpointDescription.buildDescription(paths, peer, |
| 51 | fingerprint); |
| 52 | private TransportEndpointState state1 = |
| 53 | TransportEndpointState |
| 54 | .builder() |
| 55 | .withId(TransportEndpointId.of("1")) |
| 56 | .withDescription(description) |
| 57 | .withLive(true) |
| 58 | .build(); |
| 59 | private List<TransportEndpointState> pathStates = ImmutableList.of(state1); |
| 60 | |
| 61 | |
| 62 | @Test |
| 63 | public void testConstruction() { |
| 64 | |
| 65 | ProtectedTransportEndpointState state = |
| 66 | ProtectedTransportEndpointState |
| 67 | .builder() |
| 68 | .withActivePathIndex(0) |
| 69 | .withDescription(protectedDescription) |
| 70 | .withPathStates(pathStates) |
| 71 | .build(); |
| 72 | |
| 73 | assertThat(state, notNullValue()); |
| 74 | assertThat(state.description(), is(protectedDescription)); |
| 75 | assertThat(state.pathStates(), contains(state1)); |
| 76 | assertThat(state.workingPathIndex(), is(0)); |
| 77 | } |
| 78 | |
| 79 | @Test |
| 80 | public void testToString() { |
| 81 | ProtectedTransportEndpointState state1 = |
| 82 | ProtectedTransportEndpointState |
| 83 | .builder() |
| 84 | .withActivePathIndex(0) |
| 85 | .withDescription(protectedDescription) |
| 86 | .withPathStates(pathStates) |
| 87 | .build(); |
| 88 | ProtectedTransportEndpointState state2 = |
| 89 | ProtectedTransportEndpointState |
| 90 | .builder() |
| 91 | .copyFrom(state1) |
| 92 | .build(); |
| 93 | assertThat(state1.toString(), is(state2.toString())); |
| 94 | } |
| 95 | } |