blob: 90cd0c08af0a7a7b25c60ef2f0f1c2f7a45493f3 [file] [log] [blame]
Ray Milkey3f9820f2014-11-13 10:45:45 -08001/*
2 * Copyright 2014 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 */
16package org.onlab.onos.net.flow;
17
18import org.junit.Test;
19import org.onlab.onos.event.AbstractEventTest;
20import org.onlab.onos.net.intent.IntentTestsMocks;
21
22import com.google.common.testing.EqualsTester;
23
24/**
25 * Unit Tests for the FlowRuleEvent class.
26 */
27public class FlowRuleEventTest extends AbstractEventTest {
28
29 @Test
30 public void testEquals() {
31 final FlowRule flowRule1 = new IntentTestsMocks.MockFlowRule(1);
32 final FlowRule flowRule2 = new IntentTestsMocks.MockFlowRule(2);
33 final long time = 123L;
34 final FlowRuleEvent event1 =
35 new FlowRuleEvent(FlowRuleEvent.Type.RULE_ADDED, flowRule1, time);
36 final FlowRuleEvent sameAsEvent1 =
37 new FlowRuleEvent(FlowRuleEvent.Type.RULE_ADDED, flowRule1, time);
38 final FlowRuleEvent event2 =
39 new FlowRuleEvent(FlowRuleEvent.Type.RULE_ADD_REQUESTED,
40 flowRule2, time);
41
42 // Equality for events is based on Object, these should all compare
43 // as different.
44 new EqualsTester()
45 .addEqualityGroup(event1)
46 .addEqualityGroup(sameAsEvent1)
47 .addEqualityGroup(event2)
48 .testEquals();
49 }
50
51 /**
52 * Tests the constructor where a time is passed in.
53 */
54 @Test
55 public void testTimeConstructor() {
56 final long time = 123L;
57 final FlowRule flowRule = new IntentTestsMocks.MockFlowRule(1);
58 final FlowRuleEvent event =
59 new FlowRuleEvent(FlowRuleEvent.Type.RULE_REMOVE_REQUESTED, flowRule, time);
60 validateEvent(event, FlowRuleEvent.Type.RULE_REMOVE_REQUESTED, flowRule, time);
61 }
62
63 /**
64 * Tests the constructor with the default time value.
65 */
66 @Test
67 public void testConstructor() {
68 final long time = System.currentTimeMillis();
69 final FlowRule flowRule = new IntentTestsMocks.MockFlowRule(1);
70 final FlowRuleEvent event =
Yuta HIGUCHI6b38ee32014-11-14 02:02:59 -080071 new FlowRuleEvent(FlowRuleEvent.Type.RULE_UPDATED, flowRule, time);
Ray Milkey3f9820f2014-11-13 10:45:45 -080072 validateEvent(event, FlowRuleEvent.Type.RULE_UPDATED, flowRule, time);
73 }
74}