Committed by
Gerrit Code Review
FlowRule Event unit tests
Change-Id: I620e3f8d4a8bc7bd4f9af1b16403484edd43d9df
Showing
1 changed file
with
74 additions
and
0 deletions
1 | +/* | ||
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 | + */ | ||
16 | +package org.onlab.onos.net.flow; | ||
17 | + | ||
18 | +import org.junit.Test; | ||
19 | +import org.onlab.onos.event.AbstractEventTest; | ||
20 | +import org.onlab.onos.net.intent.IntentTestsMocks; | ||
21 | + | ||
22 | +import com.google.common.testing.EqualsTester; | ||
23 | + | ||
24 | +/** | ||
25 | + * Unit Tests for the FlowRuleEvent class. | ||
26 | + */ | ||
27 | +public 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 = | ||
71 | + new FlowRuleEvent(FlowRuleEvent.Type.RULE_UPDATED, flowRule); | ||
72 | + validateEvent(event, FlowRuleEvent.Type.RULE_UPDATED, flowRule, time); | ||
73 | + } | ||
74 | +} |
-
Please register or login to post a comment