Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016 Open Networking Foundation |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [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 | package org.onosproject.tetopology.manager.api; |
| 17 | |
| 18 | import org.junit.Before; |
| 19 | import org.junit.Test; |
| 20 | import org.onosproject.tetopology.management.api.TeTopologyId; |
| 21 | import org.onosproject.tetopology.management.api.TeTopologyKey; |
| 22 | |
| 23 | import static org.junit.Assert.assertFalse; |
| 24 | import static org.junit.Assert.assertTrue; |
| 25 | |
| 26 | |
| 27 | /** |
| 28 | * Unit tests for TE topology APIs. |
| 29 | */ |
| 30 | public class TeNetworkApiTest { |
| 31 | private static final long DEFAULT_PROVIDER_ID = 1234; |
| 32 | private static final long DEFAULT_CLIENT_ID = 5678; |
| 33 | private static final long DEFAULT_TOPOLOGY_ID = 9876; |
| 34 | private static final String DEFAULT_TOPOLOGY_ID_STRING = |
| 35 | "default-topology-123"; |
| 36 | |
| 37 | private long providerId; |
| 38 | private long clientId; |
| 39 | private long topologyId; |
| 40 | private String topologyIdString; |
| 41 | |
| 42 | @Before |
| 43 | public void setUp() { |
| 44 | providerId = DEFAULT_PROVIDER_ID; |
| 45 | clientId = DEFAULT_CLIENT_ID; |
| 46 | topologyId = DEFAULT_TOPOLOGY_ID; |
| 47 | topologyIdString = DEFAULT_TOPOLOGY_ID_STRING; |
| 48 | } |
| 49 | |
| 50 | @Test |
| 51 | public void topologyIdEqualOperatorTest() { |
| 52 | TeTopologyId id1 = new TeTopologyId(providerId, clientId, |
| 53 | topologyIdString); |
| 54 | TeTopologyId id2 = new TeTopologyId(providerId, clientId, |
| 55 | topologyIdString); |
| 56 | TeTopologyId id3 = new TeTopologyId(providerId + 1, clientId, |
| 57 | topologyIdString); |
| 58 | TeTopologyId id4 = new TeTopologyId(providerId, clientId + 1, |
| 59 | topologyIdString); |
| 60 | TeTopologyId id5 = new TeTopologyId(providerId, clientId, |
| 61 | topologyIdString + "abc"); |
| 62 | |
| 63 | assertTrue("Two topology ids must be equal", id1.equals(id2)); |
| 64 | |
| 65 | assertFalse("Two topology ids must be unequal", id1.equals(id3)); |
| 66 | assertFalse("Two topology ids must be unequal", id3.equals(id1)); |
| 67 | |
| 68 | assertFalse("Two topology ids must be unequal", id1.equals(id4)); |
| 69 | assertFalse("Two topology ids must be unequal", id4.equals(id1)); |
| 70 | |
| 71 | assertFalse("Two topology ids must be unequal", id1.equals(id5)); |
| 72 | assertFalse("Two topology ids must be unequal", id5.equals(id1)); |
| 73 | } |
| 74 | |
| 75 | @Test |
| 76 | public void topologyKeyEqualOperatorTest() { |
| 77 | TeTopologyKey key1 = new TeTopologyKey(providerId, clientId, |
| 78 | topologyId); |
| 79 | TeTopologyKey key2 = new TeTopologyKey(providerId, clientId, |
| 80 | topologyId); |
| 81 | TeTopologyKey key3 = new TeTopologyKey(providerId + 1, clientId, |
| 82 | topologyId); |
| 83 | TeTopologyKey key4 = new TeTopologyKey(providerId, clientId + 1, |
| 84 | topologyId); |
| 85 | TeTopologyKey key5 = new TeTopologyKey(providerId, clientId, |
| 86 | topologyId + 1); |
| 87 | |
| 88 | assertTrue("Two topology keys must be equal", key1.equals(key2)); |
| 89 | |
| 90 | assertFalse("Two topology keys must be unequal", key1.equals(key3)); |
| 91 | assertFalse("Two topology keys must be unequal", key3.equals(key1)); |
| 92 | |
| 93 | assertFalse("Two topology keys must be unequal", key1.equals(key4)); |
| 94 | assertFalse("Two topology keys must be unequal", key4.equals(key1)); |
| 95 | |
| 96 | assertFalse("Two topology keys must be unequal", key1.equals(key5)); |
| 97 | assertFalse("Two topology keys must be unequal", key5.equals(key1)); |
| 98 | } |
| 99 | } |