blob: 2fc1ff8cb266ba22b758c097100568ba0ab81b90 [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
Ray Milkeyf19b7152014-11-21 10:56:52 -080018import java.util.concurrent.TimeUnit;
19
Ray Milkey3f9820f2014-11-13 10:45:45 -080020import org.junit.Test;
21import org.onlab.onos.event.AbstractEventTest;
22import org.onlab.onos.net.intent.IntentTestsMocks;
23
24import com.google.common.testing.EqualsTester;
25
26/**
27 * Unit Tests for the FlowRuleEvent class.
28 */
29public class FlowRuleEventTest extends AbstractEventTest {
30
31 @Test
32 public void testEquals() {
33 final FlowRule flowRule1 = new IntentTestsMocks.MockFlowRule(1);
34 final FlowRule flowRule2 = new IntentTestsMocks.MockFlowRule(2);
35 final long time = 123L;
36 final FlowRuleEvent event1 =
37 new FlowRuleEvent(FlowRuleEvent.Type.RULE_ADDED, flowRule1, time);
38 final FlowRuleEvent sameAsEvent1 =
39 new FlowRuleEvent(FlowRuleEvent.Type.RULE_ADDED, flowRule1, time);
40 final FlowRuleEvent event2 =
41 new FlowRuleEvent(FlowRuleEvent.Type.RULE_ADD_REQUESTED,
42 flowRule2, time);
43
44 // Equality for events is based on Object, these should all compare
45 // as different.
46 new EqualsTester()
47 .addEqualityGroup(event1)
48 .addEqualityGroup(sameAsEvent1)
49 .addEqualityGroup(event2)
50 .testEquals();
51 }
52
53 /**
54 * Tests the constructor where a time is passed in.
55 */
56 @Test
57 public void testTimeConstructor() {
58 final long time = 123L;
59 final FlowRule flowRule = new IntentTestsMocks.MockFlowRule(1);
60 final FlowRuleEvent event =
61 new FlowRuleEvent(FlowRuleEvent.Type.RULE_REMOVE_REQUESTED, flowRule, time);
62 validateEvent(event, FlowRuleEvent.Type.RULE_REMOVE_REQUESTED, flowRule, time);
63 }
64
65 /**
66 * Tests the constructor with the default time value.
67 */
68 @Test
69 public void testConstructor() {
70 final long time = System.currentTimeMillis();
71 final FlowRule flowRule = new IntentTestsMocks.MockFlowRule(1);
72 final FlowRuleEvent event =
Ray Milkeyf19b7152014-11-21 10:56:52 -080073 new FlowRuleEvent(FlowRuleEvent.Type.RULE_UPDATED, flowRule);
74 validateEvent(event, FlowRuleEvent.Type.RULE_UPDATED, flowRule, time,
75 time + TimeUnit.SECONDS.toMillis(30));
Ray Milkey3f9820f2014-11-13 10:45:45 -080076 }
77}