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