blob: 3cbb66c57d8097150321c7ae5e7048d5b55ae998 [file] [log] [blame]
Ray Milkeyc9166992017-05-08 12:02:26 -07001/*
2 * Copyright 2017-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
17package org.onosproject.net.behaviour.protection;
18
19import java.util.List;
20
21import org.junit.Test;
22import org.onosproject.net.DeviceId;
23import org.onosproject.net.FilteredConnectPoint;
24import org.onosproject.net.NetTestTools;
25
26import com.google.common.collect.ImmutableList;
27
28import static org.hamcrest.Matchers.contains;
29import static org.hamcrest.Matchers.is;
30import static org.hamcrest.Matchers.notNullValue;
31import static org.junit.Assert.assertThat;
32
33/**
34 * Unit tests for protected transport endpoint state.
35 */
36public 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}