kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 52f2cd1 | 2018-11-08 21:20:04 -0800 | [diff] [blame] | 2 | * Copyright 2018-present Open Networking Foundation |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [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 | * |
Thomas Vachuska | 52f2cd1 | 2018-11-08 21:20:04 -0800 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 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 | */ |
Thomas Vachuska | 52f2cd1 | 2018-11-08 21:20:04 -0800 | [diff] [blame] | 16 | package org.onosproject.alarm; |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 17 | |
| 18 | import com.google.common.testing.EqualsTester; |
| 19 | import static org.junit.Assert.assertEquals; |
| 20 | import org.junit.Test; |
| 21 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
Thomas Vachuska | 52f2cd1 | 2018-11-08 21:20:04 -0800 | [diff] [blame] | 22 | import static org.onosproject.alarm.AlarmEntityId.alarmEntityId; |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * Test of the alarm source identifier. |
| 26 | * |
| 27 | */ |
| 28 | public class AlarmEntityIdTest { |
| 29 | |
| 30 | /** |
| 31 | * Checks that the class is immutable. |
| 32 | */ |
| 33 | @Test |
| 34 | public void testImmutability() { |
| 35 | assertThatClassIsImmutable(AlarmEntityId.class); |
| 36 | } |
| 37 | |
| 38 | @Test |
| 39 | public void string() { |
| 40 | assertEquals("och:foo", |
| 41 | alarmEntityId("och:foo").toString()); |
| 42 | } |
| 43 | |
| 44 | @Test |
| 45 | public void basics() { |
| 46 | new EqualsTester() |
| 47 | .addEqualityGroup( |
| 48 | alarmEntityId("och:foo"), |
| 49 | alarmEntityId("och:foo")) |
| 50 | .addEqualityGroup(alarmEntityId("och:bar")) |
| 51 | .testEquals(); |
| 52 | |
| 53 | } |
| 54 | |
| 55 | @Test |
| 56 | public void validSchemaPermitted() { |
| 57 | alarmEntityId("none:foo"); |
| 58 | alarmEntityId("port:foo"); |
| 59 | alarmEntityId("och:foo"); |
| 60 | alarmEntityId("other:foo"); |
| 61 | |
| 62 | } |
| 63 | |
| 64 | @Test(expected = IllegalArgumentException.class) |
| 65 | public void verifyUnexpectedSchemaRejected() { |
| 66 | alarmEntityId("junk:foo"); |
| 67 | } |
| 68 | |
| 69 | @Test(expected = IllegalArgumentException.class) |
| 70 | public void verifyCorruptSchemaRejected() { |
| 71 | alarmEntityId("other:"); |
| 72 | } |
| 73 | |
| 74 | } |