blob: 6e537b4afb637db5d9a96b4b9840308e4bb95a9e [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;
24import org.onosproject.ofagent.api.OFAgent;
25import org.onosproject.ofagent.api.OFController;
26
27import java.util.Set;
28
29import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
30import static org.onosproject.ofagent.api.OFAgent.State.STARTED;
31import static org.onosproject.ofagent.api.OFAgent.State.STOPPED;
32
33/**
34 * Unit test of DefaultOFAgent model entity.
35 */
36public 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}