Hyunsun Moon | f4ba44f | 2017-03-14 03:25:52 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Hyunsun Moon | f4ba44f | 2017-03-14 03:25:52 +0900 | [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.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; |
Thomas Vachuska | 52f2cd1 | 2018-11-08 21:20:04 -0800 | [diff] [blame^] | 24 | import org.onosproject.net.TenantId; |
Hyunsun Moon | f4ba44f | 2017-03-14 03:25:52 +0900 | [diff] [blame] | 25 | import org.onosproject.ofagent.api.OFAgent; |
| 26 | import org.onosproject.ofagent.api.OFController; |
| 27 | |
| 28 | import java.util.Set; |
| 29 | |
| 30 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 31 | import static org.onosproject.ofagent.api.OFAgent.State.STARTED; |
| 32 | import static org.onosproject.ofagent.api.OFAgent.State.STOPPED; |
| 33 | |
| 34 | /** |
| 35 | * Unit test of DefaultOFAgent model entity. |
| 36 | */ |
| 37 | public class DefaultOFAgentTest { |
| 38 | |
| 39 | private static final Set<OFController> CONTROLLER_1 = Sets.newHashSet( |
| 40 | DefaultOFController.of( |
| 41 | IpAddress.valueOf("192.168.0.3"), |
| 42 | TpPort.tpPort(6653))); |
| 43 | |
| 44 | private static final Set<OFController> CONTROLLER_2 = Sets.newHashSet( |
| 45 | DefaultOFController.of( |
| 46 | IpAddress.valueOf("192.168.0.3"), |
| 47 | TpPort.tpPort(6653)), |
| 48 | DefaultOFController.of( |
| 49 | IpAddress.valueOf("192.168.0.4"), |
| 50 | TpPort.tpPort(6653))); |
| 51 | |
| 52 | private static final NetworkId NETWORK_1 = NetworkId.networkId(1); |
| 53 | private static final NetworkId NETWORK_2 = NetworkId.networkId(2); |
| 54 | |
Jovana Vuleta | c884b69 | 2017-11-28 16:52:35 +0100 | [diff] [blame] | 55 | private static final TenantId TENANT_1 = TenantId.tenantId("Tenant_1"); |
| 56 | private static final TenantId TENANT_2 = TenantId.tenantId("Tenant_2"); |
| 57 | |
Hyunsun Moon | f4ba44f | 2017-03-14 03:25:52 +0900 | [diff] [blame] | 58 | private static final OFAgent OFAGENT = DefaultOFAgent.builder() |
| 59 | .networkId(NETWORK_1) |
Jovana Vuleta | c884b69 | 2017-11-28 16:52:35 +0100 | [diff] [blame] | 60 | .tenantId(TENANT_1) |
Hyunsun Moon | f4ba44f | 2017-03-14 03:25:52 +0900 | [diff] [blame] | 61 | .controllers(CONTROLLER_1) |
| 62 | .state(STOPPED) |
| 63 | .build(); |
| 64 | |
| 65 | private static final OFAgent SAME_AS_OFAGENT_1 = DefaultOFAgent.builder() |
| 66 | .networkId(NETWORK_1) |
Jovana Vuleta | c884b69 | 2017-11-28 16:52:35 +0100 | [diff] [blame] | 67 | .tenantId(TENANT_1) |
Hyunsun Moon | f4ba44f | 2017-03-14 03:25:52 +0900 | [diff] [blame] | 68 | .controllers(CONTROLLER_2) |
| 69 | .state(STOPPED) |
| 70 | .build(); |
| 71 | |
| 72 | private static final OFAgent SAME_AS_OFAGENT_2 = DefaultOFAgent.builder() |
| 73 | .networkId(NETWORK_1) |
Jovana Vuleta | c884b69 | 2017-11-28 16:52:35 +0100 | [diff] [blame] | 74 | .tenantId(TENANT_1) |
Hyunsun Moon | f4ba44f | 2017-03-14 03:25:52 +0900 | [diff] [blame] | 75 | .controllers(CONTROLLER_1) |
| 76 | .state(STARTED) |
| 77 | .build(); |
| 78 | |
| 79 | private static final OFAgent ANOTHER_OFAGENT = DefaultOFAgent.builder() |
| 80 | .networkId(NETWORK_2) |
Jovana Vuleta | c884b69 | 2017-11-28 16:52:35 +0100 | [diff] [blame] | 81 | .tenantId(TENANT_2) |
Hyunsun Moon | f4ba44f | 2017-03-14 03:25:52 +0900 | [diff] [blame] | 82 | .controllers(CONTROLLER_1) |
| 83 | .state(STOPPED) |
| 84 | .build(); |
| 85 | |
| 86 | @Test |
| 87 | public void testImmutability() { |
| 88 | assertThatClassIsImmutable(DefaultOFAgent.class); |
| 89 | } |
| 90 | |
| 91 | @Test |
| 92 | public void testEquality() { |
| 93 | new EqualsTester() |
| 94 | .addEqualityGroup(OFAGENT, SAME_AS_OFAGENT_1, SAME_AS_OFAGENT_2) |
| 95 | .addEqualityGroup(ANOTHER_OFAGENT) |
| 96 | .testEquals(); |
| 97 | } |
| 98 | } |