Hyunsun Moon | f4ba44f | 2017-03-14 03:25:52 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Laboratory |
| 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.ofagent.impl; |
| 17 | |
| 18 | import com.google.common.collect.Sets; |
| 19 | import com.google.common.testing.EqualsTester; |
| 20 | import org.junit.Test; |
| 21 | import org.onlab.packet.IpAddress; |
| 22 | import org.onlab.packet.TpPort; |
| 23 | import org.onosproject.incubator.net.virtual.NetworkId; |
| 24 | import org.onosproject.ofagent.api.OFAgent; |
| 25 | import org.onosproject.ofagent.api.OFController; |
| 26 | |
| 27 | import java.util.Set; |
| 28 | |
| 29 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 30 | import static org.onosproject.ofagent.api.OFAgent.State.STARTED; |
| 31 | import static org.onosproject.ofagent.api.OFAgent.State.STOPPED; |
| 32 | |
| 33 | /** |
| 34 | * Unit test of DefaultOFAgent model entity. |
| 35 | */ |
| 36 | public class DefaultOFAgentTest { |
| 37 | |
| 38 | private static final Set<OFController> CONTROLLER_1 = Sets.newHashSet( |
| 39 | DefaultOFController.of( |
| 40 | IpAddress.valueOf("192.168.0.3"), |
| 41 | TpPort.tpPort(6653))); |
| 42 | |
| 43 | private static final Set<OFController> CONTROLLER_2 = Sets.newHashSet( |
| 44 | DefaultOFController.of( |
| 45 | IpAddress.valueOf("192.168.0.3"), |
| 46 | TpPort.tpPort(6653)), |
| 47 | DefaultOFController.of( |
| 48 | IpAddress.valueOf("192.168.0.4"), |
| 49 | TpPort.tpPort(6653))); |
| 50 | |
| 51 | private static final NetworkId NETWORK_1 = NetworkId.networkId(1); |
| 52 | private static final NetworkId NETWORK_2 = NetworkId.networkId(2); |
| 53 | |
| 54 | private static final OFAgent OFAGENT = DefaultOFAgent.builder() |
| 55 | .networkId(NETWORK_1) |
| 56 | .controllers(CONTROLLER_1) |
| 57 | .state(STOPPED) |
| 58 | .build(); |
| 59 | |
| 60 | private static final OFAgent SAME_AS_OFAGENT_1 = DefaultOFAgent.builder() |
| 61 | .networkId(NETWORK_1) |
| 62 | .controllers(CONTROLLER_2) |
| 63 | .state(STOPPED) |
| 64 | .build(); |
| 65 | |
| 66 | private static final OFAgent SAME_AS_OFAGENT_2 = DefaultOFAgent.builder() |
| 67 | .networkId(NETWORK_1) |
| 68 | .controllers(CONTROLLER_1) |
| 69 | .state(STARTED) |
| 70 | .build(); |
| 71 | |
| 72 | private static final OFAgent ANOTHER_OFAGENT = DefaultOFAgent.builder() |
| 73 | .networkId(NETWORK_2) |
| 74 | .controllers(CONTROLLER_1) |
| 75 | .state(STOPPED) |
| 76 | .build(); |
| 77 | |
| 78 | @Test |
| 79 | public void testImmutability() { |
| 80 | assertThatClassIsImmutable(DefaultOFAgent.class); |
| 81 | } |
| 82 | |
| 83 | @Test |
| 84 | public void testEquality() { |
| 85 | new EqualsTester() |
| 86 | .addEqualityGroup(OFAGENT, SAME_AS_OFAGENT_1, SAME_AS_OFAGENT_2) |
| 87 | .addEqualityGroup(ANOTHER_OFAGENT) |
| 88 | .testEquals(); |
| 89 | } |
| 90 | } |