Ray Milkey | 278e75b | 2017-04-05 14:11:06 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Ray Milkey | 278e75b | 2017-04-05 14:11:06 -0700 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.net.statistic; |
| 18 | |
| 19 | import org.junit.Test; |
| 20 | import org.onosproject.net.ConnectPoint; |
| 21 | import org.onosproject.net.NetTestTools; |
| 22 | import org.onosproject.net.flow.FlowEntry; |
| 23 | import org.onosproject.net.flow.StoredFlowEntry; |
| 24 | import org.onosproject.net.flow.StoredFlowEntryAdapter; |
| 25 | |
| 26 | import static org.hamcrest.MatcherAssert.assertThat; |
| 27 | import static org.hamcrest.Matchers.instanceOf; |
| 28 | import static org.hamcrest.Matchers.is; |
| 29 | |
| 30 | /** |
| 31 | * Unit tests for flow entry with load. |
| 32 | */ |
| 33 | public class FlowEntryWithLoadTest { |
| 34 | class MockFlowEntry extends StoredFlowEntryAdapter { |
| 35 | FlowLiveType liveType; |
| 36 | |
| 37 | public MockFlowEntry(FlowLiveType liveType) { |
| 38 | this.liveType = liveType; |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | public FlowLiveType liveType() { |
| 43 | return liveType; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | @Test |
| 48 | public void testConstructionCpFeLoad() { |
| 49 | ConnectPoint cp = NetTestTools.connectPoint("id1", 1); |
| 50 | StoredFlowEntry fe = new MockFlowEntry(FlowEntry.FlowLiveType.IMMEDIATE); |
| 51 | Load load = new DefaultLoad(); |
| 52 | FlowEntryWithLoad underTest = new FlowEntryWithLoad(cp, fe, load); |
| 53 | |
| 54 | assertThat(underTest.connectPoint(), is(cp)); |
| 55 | assertThat(underTest.load(), is(load)); |
| 56 | assertThat(underTest.storedFlowEntry(), is(fe)); |
| 57 | } |
| 58 | |
| 59 | @Test |
| 60 | public void testConstructionDEfaultLoad() { |
| 61 | ConnectPoint cp = NetTestTools.connectPoint("id1", 1); |
| 62 | StoredFlowEntry fe = new MockFlowEntry(FlowEntry.FlowLiveType.IMMEDIATE); |
| 63 | FlowEntryWithLoad underTest; |
| 64 | |
| 65 | fe = new MockFlowEntry(FlowEntry.FlowLiveType.IMMEDIATE); |
| 66 | underTest = new FlowEntryWithLoad(cp, fe); |
| 67 | assertThat(underTest.connectPoint(), is(cp)); |
| 68 | assertThat(underTest.load(), instanceOf(DefaultLoad.class)); |
| 69 | assertThat(underTest.storedFlowEntry(), is(fe)); |
| 70 | |
| 71 | fe = new MockFlowEntry(FlowEntry.FlowLiveType.LONG); |
| 72 | underTest = new FlowEntryWithLoad(cp, fe); |
| 73 | assertThat(underTest.connectPoint(), is(cp)); |
| 74 | assertThat(underTest.load(), instanceOf(DefaultLoad.class)); |
| 75 | |
| 76 | fe = new MockFlowEntry(FlowEntry.FlowLiveType.MID); |
| 77 | underTest = new FlowEntryWithLoad(cp, fe); |
| 78 | assertThat(underTest.connectPoint(), is(cp)); |
| 79 | assertThat(underTest.load(), instanceOf(DefaultLoad.class)); |
| 80 | |
| 81 | fe = new MockFlowEntry(FlowEntry.FlowLiveType.SHORT); |
| 82 | underTest = new FlowEntryWithLoad(cp, fe); |
| 83 | assertThat(underTest.connectPoint(), is(cp)); |
| 84 | assertThat(underTest.load(), instanceOf(DefaultLoad.class)); |
| 85 | |
| 86 | fe = new MockFlowEntry(FlowEntry.FlowLiveType.UNKNOWN); |
| 87 | underTest = new FlowEntryWithLoad(cp, fe); |
| 88 | assertThat(underTest.connectPoint(), is(cp)); |
| 89 | assertThat(underTest.load(), instanceOf(DefaultLoad.class)); |
| 90 | } |
| 91 | } |