Pier Luigi Ventre | d1173a1 | 2016-03-30 15:51:03 +0200 | [diff] [blame] | 1 | /* |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Pier Luigi Ventre | d1173a1 | 2016-03-30 15:51:03 +0200 | [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.sdxl2; |
| 18 | |
| 19 | import org.junit.After; |
| 20 | import org.junit.Before; |
| 21 | import org.junit.Rule; |
| 22 | import org.junit.Test; |
| 23 | import org.junit.rules.ExpectedException; |
| 24 | import org.onlab.packet.VlanId; |
| 25 | |
| 26 | import java.util.ArrayList; |
| 27 | import java.util.List; |
| 28 | |
| 29 | import static org.junit.Assert.assertEquals; |
| 30 | import static org.junit.Assert.assertNotEquals; |
| 31 | |
| 32 | /** |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame] | 33 | * Tests SdxL2ConnectionPoint functionality. |
Pier Luigi Ventre | d1173a1 | 2016-03-30 15:51:03 +0200 | [diff] [blame] | 34 | */ |
| 35 | public class SdxL2ConnectionPointTest { |
| 36 | |
| 37 | @Before |
| 38 | public void setUp() { |
| 39 | |
| 40 | } |
| 41 | |
| 42 | @After |
| 43 | public void tearDown() { |
| 44 | |
| 45 | } |
| 46 | |
| 47 | public static final String CP1 = "of:00000000000001/1"; |
| 48 | public static final String CP2 = "of:00000000000002/1"; |
| 49 | public static final String CP3 = "of:00000000000003/1"; |
| 50 | public static final String CP4 = "of:00000000000003/2"; |
| 51 | public static final String CP5 = "-1"; |
| 52 | public static final String CP6 = "of:00000000000004/2"; |
| 53 | public static final String CP7 = "of:00000000000004/1"; |
| 54 | |
| 55 | public static final String VLANS1 = "1,2,3,4"; |
| 56 | public static final String VLANS2 = "-1"; |
| 57 | public static final String VLANS3 = "1,2,3"; |
| 58 | public static final String VLANS4 = "2,2,2"; |
| 59 | public static final String VLANS5 = "2"; |
| 60 | public static final String VLANS6 = "-1"; |
| 61 | public static final String VLANS7 = "5"; |
| 62 | public static final String VLANS8 = "3,2,1"; |
| 63 | public static final String VLANS10 = "a"; |
| 64 | public static final String VLANS11 = "5196"; |
| 65 | public static final String VLANS12 = "2,-1,6"; |
| 66 | |
| 67 | public static final String CEMAC1 = "52:40:00:12:44:01"; |
| 68 | public static final String CEMAC2 = "-1"; |
| 69 | public static final String CEMAC3 = "-1"; |
| 70 | public static final String CEMAC4 = "-1"; |
| 71 | public static final String CEMAC5 = "52:40:00:12:44:01"; |
| 72 | public static final String CEMAC6 = "52:40:00:12:44:01"; |
| 73 | public static final String CEMAC7 = "-1"; |
| 74 | |
| 75 | @Test |
| 76 | public void testSdxL2ConnectionPoint1() { |
| 77 | SdxL2ConnectionPoint scp1 = SdxL2ConnectionPoint.sdxl2ConnectionPoint("RO1", CP1, VLANS1, CEMAC1); |
| 78 | } |
| 79 | |
| 80 | @Test |
| 81 | public void testSdxL2ConnectionPoint2() { |
| 82 | SdxL2ConnectionPoint scp2 = SdxL2ConnectionPoint.sdxl2ConnectionPoint("RO2", CP2, VLANS2); |
| 83 | } |
| 84 | |
| 85 | @Test |
| 86 | public void testSdxL2ConnectionPoint3() { |
| 87 | SdxL2ConnectionPoint scp3 = SdxL2ConnectionPoint.sdxl2ConnectionPoint("MI1", CP3, VLANS3); |
| 88 | } |
| 89 | |
| 90 | @Test |
| 91 | public void testSdxL2ConnectionPoint4() { |
| 92 | SdxL2ConnectionPoint scp4 = SdxL2ConnectionPoint.sdxl2ConnectionPoint("RO3", CP4, VLANS4); |
| 93 | } |
| 94 | |
| 95 | @Rule |
| 96 | public ExpectedException exceptionconnectionpoint = ExpectedException.none(); |
| 97 | |
| 98 | @Test |
| 99 | public void testSdxL2ConnectionPoint5() { |
| 100 | exceptionconnectionpoint.expect(IllegalArgumentException.class); |
| 101 | exceptionconnectionpoint.expectMessage("Connect point must be in \"deviceUri/portNumber\" format"); |
| 102 | SdxL2ConnectionPoint scp5 = SdxL2ConnectionPoint.sdxl2ConnectionPoint("MI2", CP5, VLANS5, CEMAC5); |
| 103 | } |
| 104 | |
| 105 | @Test |
| 106 | public void testSdxL2ConnectionPoint6() { |
| 107 | SdxL2ConnectionPoint scp6 = SdxL2ConnectionPoint.sdxl2ConnectionPoint("MI3", CP6, VLANS6, CEMAC6); |
| 108 | |
| 109 | } |
| 110 | |
| 111 | @Rule |
| 112 | public ExpectedException exceptionmac = ExpectedException.none(); |
| 113 | |
| 114 | @Test |
| 115 | public void testSdxL2ConnectionPoint7() { |
| 116 | exceptionmac.expect(IllegalArgumentException.class); |
| 117 | exceptionmac.expectMessage("Specified MAC Address must contain"); |
| 118 | SdxL2ConnectionPoint scp7 = SdxL2ConnectionPoint.sdxl2ConnectionPoint("RO4", CP7, VLANS7, CEMAC7); |
| 119 | } |
| 120 | |
| 121 | @Test |
| 122 | public void testSdxL2ConnectionPoint8() { |
| 123 | SdxL2ConnectionPoint scp8 = SdxL2ConnectionPoint.sdxl2ConnectionPoint("", CP4, VLANS2, CEMAC6); |
| 124 | } |
| 125 | |
| 126 | @Rule |
| 127 | public ExpectedException exceptionname = ExpectedException.none(); |
| 128 | |
| 129 | @Test |
| 130 | public void testSdxL2ConnectionPoint9() { |
| 131 | exceptionname.expect(IllegalStateException.class); |
| 132 | exceptionname.expectMessage("Names cannot contain some special characters"); |
| 133 | SdxL2ConnectionPoint scp9a = SdxL2ConnectionPoint.sdxl2ConnectionPoint("NA,1", CP1, VLANS1, CEMAC1); |
| 134 | SdxL2ConnectionPoint scp9b = SdxL2ConnectionPoint.sdxl2ConnectionPoint("{NA2}", CP2, VLANS2, CEMAC2); |
| 135 | SdxL2ConnectionPoint scp9c = SdxL2ConnectionPoint.sdxl2ConnectionPoint("NA3,elementId=50", CP3, VLANS3, CEMAC3); |
| 136 | } |
| 137 | |
| 138 | @Rule |
| 139 | public ExpectedException exceptionvlans = ExpectedException.none(); |
| 140 | |
| 141 | @Test |
| 142 | public void testSdxL2ConnectionPoint10() { |
| 143 | exceptionvlans.expect(NumberFormatException.class); |
| 144 | SdxL2ConnectionPoint scp10 = SdxL2ConnectionPoint.sdxl2ConnectionPoint("VE1", CP1, VLANS10, CEMAC7); |
| 145 | } |
| 146 | |
| 147 | @Test |
| 148 | public void testSdxL2ConnectionPoint11() { |
| 149 | exceptionvlans.expect(IllegalArgumentException.class); |
| 150 | exceptionvlans.expectMessage("value exceeds allowed maximum VLAN ID value (4095)"); |
| 151 | SdxL2ConnectionPoint scp11 = SdxL2ConnectionPoint.sdxl2ConnectionPoint("VE2", CP2, VLANS11, CEMAC6); |
| 152 | } |
| 153 | |
| 154 | @Test |
| 155 | public void testSdxL2ConnectionPoint12() { |
| 156 | SdxL2ConnectionPoint scp12 = SdxL2ConnectionPoint.sdxl2ConnectionPoint("AQ1", CP1, VLANS12, CEMAC5); |
| 157 | List<VlanId> vlanIdList = new ArrayList<>(); |
| 158 | vlanIdList.add(VlanId.vlanId(Short.parseShort("2"))); |
| 159 | vlanIdList.add(VlanId.vlanId(Short.parseShort("6"))); |
| 160 | assertEquals(vlanIdList, scp12.vlanIds()); |
| 161 | } |
| 162 | |
| 163 | @Test |
| 164 | public void testSdxL2ConnectionPointEquality() { |
| 165 | SdxL2ConnectionPoint scp1 = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI1", CP1, VLANS1, CEMAC1); |
| 166 | SdxL2ConnectionPoint scp2 = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI1", CP1, VLANS1, CEMAC6); |
| 167 | assertEquals(scp1, scp2); |
| 168 | SdxL2ConnectionPoint scp3 = SdxL2ConnectionPoint.sdxl2ConnectionPoint("GE4", CP2, VLANS3, CEMAC6); |
| 169 | assertNotEquals(scp1, scp3); |
| 170 | SdxL2ConnectionPoint scp4 = SdxL2ConnectionPoint.sdxl2ConnectionPoint("GE4", CP2, VLANS8, CEMAC6); |
| 171 | assertNotEquals(scp3, scp4); |
| 172 | } |
| 173 | |
| 174 | } |