Phaneendra Manda | c612054 | 2016-04-18 13:57:16 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Phaneendra Manda | c612054 | 2016-04-18 13:57:16 +0530 | [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.vtnrsc; |
| 17 | |
| 18 | import static org.hamcrest.MatcherAssert.assertThat; |
| 19 | import static org.hamcrest.Matchers.is; |
| 20 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 21 | |
| 22 | import java.util.Map; |
| 23 | import java.util.concurrent.ConcurrentHashMap; |
| 24 | |
| 25 | import org.junit.Test; |
| 26 | |
| 27 | import com.google.common.testing.EqualsTester; |
| 28 | |
| 29 | /** |
| 30 | * Unit tests for ServiceFunctionGroup class. |
| 31 | */ |
| 32 | public class ServiceFunctionGroupTest { |
| 33 | |
| 34 | /** |
| 35 | * Checks that the ServiceFunctionGroup class is immutable. |
| 36 | */ |
| 37 | @Test |
| 38 | public void testImmutability() { |
| 39 | assertThatClassIsImmutable(ServiceFunctionGroup.class); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Checks the operation of equals() methods. |
| 44 | */ |
| 45 | @Test |
| 46 | public void testEquals() { |
| 47 | String name1 = "Firewall"; |
| 48 | String description1 = "Firewall service function"; |
| 49 | Map<PortPairId, Integer> portPairLoadMap1 = new ConcurrentHashMap<>(); |
| 50 | PortPairId portPairId1 = PortPairId.of("a4444444-4a56-2a6e-cd3a-9dee4e2ec345"); |
| 51 | portPairLoadMap1.put(portPairId1, Integer.valueOf(2)); |
| 52 | ServiceFunctionGroup sfg1 = new ServiceFunctionGroup(name1, description1, portPairLoadMap1); |
| 53 | ServiceFunctionGroup sameAsSfg1 = new ServiceFunctionGroup(name1, description1, portPairLoadMap1); |
| 54 | |
| 55 | String name2 = "Dpi"; |
| 56 | String description2 = "Dpi service function"; |
| 57 | Map<PortPairId, Integer> portPairLoadMap2 = new ConcurrentHashMap<>(); |
| 58 | PortPairId portPairId2 = PortPairId.of("b6666666-4a56-2a6e-cd3a-9dee4e2ec345"); |
| 59 | portPairLoadMap2.put(portPairId2, Integer.valueOf(3)); |
| 60 | ServiceFunctionGroup sfg2 = new ServiceFunctionGroup(name2, description2, portPairLoadMap2); |
| 61 | |
| 62 | new EqualsTester().addEqualityGroup(sfg1, sameAsSfg1).addEqualityGroup(sfg2).testEquals(); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Checks the construction of a ServiceFunctionGroup object. |
| 67 | */ |
| 68 | @Test |
| 69 | public void testConstruction() { |
| 70 | |
| 71 | String name = "Firewall"; |
| 72 | String description = "Firewall service function"; |
| 73 | Map<PortPairId, Integer> portPairLoadMap = new ConcurrentHashMap<>(); |
| 74 | PortPairId portPairId = PortPairId.of("a4444444-4a56-2a6e-cd3a-9dee4e2ec345"); |
| 75 | portPairLoadMap.put(portPairId, Integer.valueOf(2)); |
| 76 | ServiceFunctionGroup sfg = new ServiceFunctionGroup(name, description, portPairLoadMap); |
| 77 | |
| 78 | assertThat(name, is(sfg.name())); |
| 79 | assertThat(description, is(sfg.description())); |
| 80 | assertThat(2, is(sfg.portPairLoadMap().get(portPairId))); |
| 81 | } |
| 82 | } |