Simon Hunt | ce55af5 | 2017-10-24 16:57:30 -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 | package org.opencord.aaa.api; |
| 17 | |
| 18 | import org.junit.Test; |
| 19 | import org.onlab.packet.MacAddress; |
| 20 | import org.onlab.packet.VlanId; |
| 21 | import org.onosproject.net.ConnectPoint; |
| 22 | import org.opencord.aaa.PrintableTest; |
| 23 | import org.opencord.aaa.api.AaaEvent.Type; |
| 24 | |
| 25 | import static org.junit.Assert.assertEquals; |
| 26 | import static org.junit.Assert.assertNotEquals; |
| 27 | import static org.junit.Assert.assertNotSame; |
| 28 | import static org.onosproject.net.ConnectPoint.deviceConnectPoint; |
| 29 | |
| 30 | /** |
| 31 | * Unit tests for {@link AaaEvent}. |
| 32 | */ |
| 33 | public class AaaEventTest extends PrintableTest { |
| 34 | |
| 35 | private static final long TIME1 = 12345L; |
| 36 | private static final long TIME2 = 54321L; |
| 37 | private static final ConnectPoint CP1 = deviceConnectPoint("of:01/1"); |
| 38 | private static final ConnectPoint CP2 = deviceConnectPoint("of:02/2"); |
| 39 | private static final VlanId VLAN_32 = VlanId.vlanId((short) 32); |
| 40 | private static final VlanId VLAN_64 = VlanId.vlanId((short) 64); |
| 41 | private static final MacAddress MAC_A = MacAddress.valueOf(0xa); |
| 42 | private static final MacAddress MAC_B = MacAddress.valueOf(0xb); |
| 43 | |
| 44 | private static final AaaEvent AEV_1 = |
| 45 | new AaaEvent(Type.AUTH_START, CP1, TIME1); |
| 46 | private static final AaaEvent AEV_2 = |
| 47 | new AaaEvent(Type.AUTH_START, CP1, TIME1, VLAN_32, null); |
| 48 | private static final AaaEvent AEV_3 = |
| 49 | new AaaEvent(Type.AUTH_LOGOFF, CP1, TIME1); |
| 50 | private static final AaaEvent AEV_4 = |
| 51 | new AaaEvent(Type.AUTH_LOGOFF, CP1, TIME2); |
| 52 | private static final AaaEvent AEV_5 = |
| 53 | new AaaEvent(Type.AUTH_LOGOFF, CP2, TIME2); |
| 54 | private static final AaaEvent AEV_6 = |
| 55 | new AaaEvent(Type.AUTH_LOGOFF, CP2, VLAN_64, null); |
| 56 | private static final AaaEvent AEV_7 = |
| 57 | new AaaEvent(Type.AUTH_REQUEST_ACCESS, CP1, TIME1, VLAN_64, null); |
| 58 | private static final AaaEvent AEV_7_AGAIN = |
| 59 | new AaaEvent(Type.AUTH_REQUEST_ACCESS, CP1, TIME1, VLAN_64, null); |
| 60 | private static final AaaEvent AEV_8 = |
| 61 | new AaaEvent(Type.AUTH_REQUEST_ACCESS, CP1, TIME1, VLAN_64, MAC_A); |
| 62 | private static final AaaEvent AEV_9 = |
| 63 | new AaaEvent(Type.AUTH_REQUEST_ACCESS, CP1, TIME1, VLAN_64, MAC_B); |
| 64 | private static final AaaEvent AEV_10 = |
| 65 | new AaaEvent(Type.AUTH_REQUEST_ACCESS, CP1, TIME1, null, MAC_B); |
| 66 | |
| 67 | |
| 68 | private AaaEvent event; |
| 69 | |
| 70 | @Test |
| 71 | public void basic() { |
| 72 | event = new AaaEvent(Type.ACCESS_DENIED, CP1, TIME1); |
| 73 | print(event); |
| 74 | assertEquals(Type.ACCESS_DENIED, event.type()); |
| 75 | assertEquals(TIME1, event.time()); |
| 76 | assertEquals(CP1, event.subject()); |
| 77 | assertEquals(null, event.vlanId()); |
| 78 | } |
| 79 | |
| 80 | @Test |
| 81 | public void vlan32() { |
| 82 | event = new AaaEvent(Type.ACCESS_AUTHORIZED, CP1, VLAN_32, MAC_A); |
| 83 | print(event); |
| 84 | assertEquals(Type.ACCESS_AUTHORIZED, event.type()); |
| 85 | assertEquals(CP1, event.subject()); |
| 86 | assertEquals(VLAN_32, event.vlanId()); |
| 87 | assertEquals(MAC_A, event.macAddress()); |
| 88 | } |
| 89 | |
| 90 | @Test |
| 91 | public void checkEquivalence() { |
| 92 | assertNotEquals(AEV_1, AEV_2); |
| 93 | assertNotEquals(AEV_1, AEV_3); |
| 94 | assertNotEquals(AEV_3, AEV_4); |
| 95 | assertNotEquals(AEV_4, AEV_5); |
| 96 | assertNotEquals(AEV_5, AEV_6); |
| 97 | assertNotEquals(AEV_6, AEV_7); |
| 98 | assertNotSame(AEV_7, AEV_7_AGAIN); |
| 99 | assertEquals(AEV_7, AEV_7_AGAIN); |
| 100 | |
| 101 | assertNotEquals(AEV_7, AEV_8); |
| 102 | assertNotEquals(AEV_7, AEV_9); |
| 103 | assertNotEquals(AEV_7, AEV_10); |
| 104 | assertNotEquals(AEV_8, AEV_9); |
| 105 | assertNotEquals(AEV_8, AEV_10); |
| 106 | assertNotEquals(AEV_9, AEV_10); |
| 107 | } |
| 108 | } |