blob: eb0d66a8bf4a4d7df4715a5cf4437a828f0bab16 [file] [log] [blame]
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +09001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +09003 *
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 */
16package org.onosproject.ofagent.impl;
17
18import com.google.common.collect.Sets;
19import com.google.common.testing.EqualsTester;
20import org.junit.Test;
21import org.onlab.packet.IpAddress;
22import org.onlab.packet.TpPort;
23import org.onosproject.incubator.net.virtual.NetworkId;
Thomas Vachuska52f2cd12018-11-08 21:20:04 -080024import org.onosproject.net.TenantId;
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090025import org.onosproject.ofagent.api.OFAgent;
26import org.onosproject.ofagent.api.OFController;
27
28import java.util.Set;
29
30import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
31import static org.onosproject.ofagent.api.OFAgent.State.STARTED;
32import static org.onosproject.ofagent.api.OFAgent.State.STOPPED;
33
34/**
35 * Unit test of DefaultOFAgent model entity.
36 */
37public 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 Vuletac884b692017-11-28 16:52:35 +010055 private static final TenantId TENANT_1 = TenantId.tenantId("Tenant_1");
56 private static final TenantId TENANT_2 = TenantId.tenantId("Tenant_2");
57
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090058 private static final OFAgent OFAGENT = DefaultOFAgent.builder()
59 .networkId(NETWORK_1)
Jovana Vuletac884b692017-11-28 16:52:35 +010060 .tenantId(TENANT_1)
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090061 .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 Vuletac884b692017-11-28 16:52:35 +010067 .tenantId(TENANT_1)
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090068 .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 Vuletac884b692017-11-28 16:52:35 +010074 .tenantId(TENANT_1)
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090075 .controllers(CONTROLLER_1)
76 .state(STARTED)
77 .build();
78
79 private static final OFAgent ANOTHER_OFAGENT = DefaultOFAgent.builder()
80 .networkId(NETWORK_2)
Jovana Vuletac884b692017-11-28 16:52:35 +010081 .tenantId(TENANT_2)
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090082 .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}