Ray Milkey | f19b715 | 2014-11-21 10:56:52 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Ray Milkey | f19b715 | 2014-11-21 10:56:52 -0800 | [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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.flow; |
Ray Milkey | f19b715 | 2014-11-21 10:56:52 -0800 | [diff] [blame] | 17 | |
Ray Milkey | f19b715 | 2014-11-21 10:56:52 -0800 | [diff] [blame] | 18 | import org.junit.Test; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 19 | import org.onosproject.net.intent.IntentTestsMocks; |
Ray Milkey | f19b715 | 2014-11-21 10:56:52 -0800 | [diff] [blame] | 20 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 21 | import java.util.HashSet; |
| 22 | import java.util.List; |
| 23 | import java.util.Set; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 24 | |
Ray Milkey | f19b715 | 2014-11-21 10:56:52 -0800 | [diff] [blame] | 25 | import static org.hamcrest.MatcherAssert.assertThat; |
| 26 | import static org.hamcrest.Matchers.hasSize; |
| 27 | import static org.hamcrest.Matchers.is; |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 28 | import static org.onosproject.net.flow.FlowRuleBatchEntry.FlowRuleOperation.ADD; |
| 29 | import static org.onosproject.net.flow.FlowRuleBatchEntry.FlowRuleOperation.REMOVE; |
Ray Milkey | f19b715 | 2014-11-21 10:56:52 -0800 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Unit tests for the FlowRuleBatchRequest class. |
| 33 | */ |
| 34 | public class FlowRuleBatchRequestTest { |
| 35 | |
| 36 | /** |
| 37 | * Tests that construction of FlowRuleBatchRequest objects returns the |
| 38 | * correct objects. |
| 39 | */ |
| 40 | @Test |
| 41 | public void testConstruction() { |
| 42 | final FlowRule rule1 = new IntentTestsMocks.MockFlowRule(1); |
| 43 | final FlowRule rule2 = new IntentTestsMocks.MockFlowRule(2); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 44 | final Set<FlowRuleBatchEntry> batch = new HashSet<>(); |
| 45 | batch.add(new FlowRuleBatchEntry(ADD, rule1)); |
| 46 | |
| 47 | batch.add(new FlowRuleBatchEntry(REMOVE, rule2)); |
Ray Milkey | f19b715 | 2014-11-21 10:56:52 -0800 | [diff] [blame] | 48 | |
| 49 | |
| 50 | final FlowRuleBatchRequest request = |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 51 | new FlowRuleBatchRequest(1, batch); |
Ray Milkey | f19b715 | 2014-11-21 10:56:52 -0800 | [diff] [blame] | 52 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 53 | assertThat(request.ops(), hasSize(2)); |
| 54 | assertThat(request.batchId(), is(1L)); |
Ray Milkey | f19b715 | 2014-11-21 10:56:52 -0800 | [diff] [blame] | 55 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 56 | final FlowRuleBatchOperation op = request.asBatchOperation(rule1.deviceId()); |
Ray Milkey | f19b715 | 2014-11-21 10:56:52 -0800 | [diff] [blame] | 57 | assertThat(op.size(), is(2)); |
| 58 | |
| 59 | final List<FlowRuleBatchEntry> ops = op.getOperations(); |
| 60 | assertThat(ops, hasSize(2)); |
| 61 | } |
| 62 | |
| 63 | } |