Ray Milkey | 3f9820f | 2014-11-13 10:45:45 -0800 | [diff] [blame] | 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.flow; |
Ray Milkey | 3f9820f | 2014-11-13 10:45:45 -0800 | [diff] [blame] | 17 | |
Ray Milkey | f19b715 | 2014-11-21 10:56:52 -0800 | [diff] [blame] | 18 | import java.util.concurrent.TimeUnit; |
| 19 | |
Ray Milkey | 3f9820f | 2014-11-13 10:45:45 -0800 | [diff] [blame] | 20 | import org.junit.Test; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 21 | import org.onosproject.event.AbstractEventTest; |
| 22 | import org.onosproject.net.intent.IntentTestsMocks; |
Ray Milkey | 3f9820f | 2014-11-13 10:45:45 -0800 | [diff] [blame] | 23 | |
| 24 | import com.google.common.testing.EqualsTester; |
| 25 | |
| 26 | /** |
| 27 | * Unit Tests for the FlowRuleEvent class. |
| 28 | */ |
| 29 | public 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 Milkey | f19b715 | 2014-11-21 10:56:52 -0800 | [diff] [blame] | 73 | new FlowRuleEvent(FlowRuleEvent.Type.RULE_UPDATED, flowRule); |
| 74 | validateEvent(event, FlowRuleEvent.Type.RULE_UPDATED, flowRule, time, |
| 75 | time + TimeUnit.SECONDS.toMillis(30)); |
Ray Milkey | 3f9820f | 2014-11-13 10:45:45 -0800 | [diff] [blame] | 76 | } |
| 77 | } |