blob: 68716dd622ef058ad022baf8381785c73be4a964 [file] [log] [blame]
Sean Condon0e89bda2017-03-21 14:23:19 +00001/*
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 */
16package org.onosproject.incubator.net.l2monitoring.cfm;
17
18import static org.junit.Assert.assertEquals;
19import static org.junit.Assert.assertFalse;
20import static org.junit.Assert.assertNotNull;
21import static org.junit.Assert.assertTrue;
22
23import java.util.ArrayList;
24import java.util.Collection;
25
26import org.junit.Before;
27import org.junit.Test;
28import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation.CcmInterval;
29import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaId2Octet;
30import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdCharStr;
31import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdPrimaryVid;
32import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdRfc2685VpnId;
33import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
34import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
35
36public class MaintenanceAssociationTest {
37
38 MaintenanceAssociation ma1;
39 MaintenanceAssociation ma2;
40 MaintenanceAssociation ma3;
41 MaintenanceAssociation ma4;
42 MaintenanceAssociation ma5;
43
44 @Before
45 public void setUp() throws Exception {
46 try {
47 ma1 = DefaultMaintenanceAssociation.builder(MaIdCharStr.asMaId("ma-1"), 10)
48 .ccmInterval(CcmInterval.INTERVAL_1MIN)
49 .maNumericId((short) 1)
50 .build();
51
52 ma2 = DefaultMaintenanceAssociation.builder(MaIdPrimaryVid.asMaId("1024"), 10)
53 .build();
54
55 ma3 = DefaultMaintenanceAssociation.builder(MaId2Octet.asMaId("33333"), 10)
56 .build();
57
58 ma4 = DefaultMaintenanceAssociation.builder(MaIdRfc2685VpnId
59 .asMaIdHex("0A:0B:0C:0D:0E:0F:00"), 10).build();
60
61 } catch (CfmConfigException e) {
62 throw new Exception(e);
63 }
64 }
65
66 @Test
67 public void testMaName() {
68 assertEquals("ma-1", ma1.maId().maName());
69
70 assertEquals("1024", ma2.maId().maName());
71
72 assertEquals("33333", ma3.maId().maName());
73
74 assertEquals("0A:0B:0C:0D:0E:0F:00".toLowerCase(), ma4.maId().maName());
75 }
76
77 @Test
78 public void testCcmInterval() {
79 assertEquals(CcmInterval.INTERVAL_1MIN, ma1.ccmInterval());
80 }
81
82 @Test
83 public void testComponentList() {
84 assertNotNull(ma1.componentList());
85 }
86
87 @Test
88 public void testWithComponentList() {
89 Collection<Component> componentList2 = new ArrayList<>();
90 MaintenanceAssociation ma2 = ma1.withComponentList(componentList2);
91 assertNotNull(ma2.componentList());
92 }
93
94 @Test
95 public void testRemoteMepIdList() {
96 assertNotNull(ma1.remoteMepIdList());
97 }
98
99 @Test
100 public void testWithRemoteMepIdList() throws CfmConfigException {
101 Collection<MepId> remoteMepIdList2 = new ArrayList<>();
102 remoteMepIdList2.add(MepId.valueOf((short) 450));
103 remoteMepIdList2.add(MepId.valueOf((short) 451));
104 remoteMepIdList2.add(MepId.valueOf((short) 452));
105 MaintenanceAssociation ma2 = ma1.withRemoteMepIdList(remoteMepIdList2);
106 assertEquals(3, ma2.remoteMepIdList().size());
107 }
108
109 @Test
110 public void testMaNumericId() {
111 assertEquals(1, ma1.maNumericId());
112 }
113
114 @Test
115 public void testCopyThroughBuilder() throws CfmConfigException {
116 MaintenanceAssociation maCopy =
117 DefaultMaintenanceAssociation.builder(ma3).build();
118 assertEquals(ma3, maCopy);
119 }
120
121 @Test
122 public void testEquals() {
123 //For char string
124 assertFalse(ma1.equals(null));
125 assertFalse(ma1.equals(new String("test")));
126
127 assertTrue(ma1.equals(ma1));
128 assertFalse(ma1.equals(ma2));
129 }
130
131 @Test
132 public void testHashCode() {
133 assertEquals(ma1.hashCode(), ma1.hashCode());
134 }
135
136}