Ray Milkey | f19b715 | 2014-11-21 10:56:52 -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 | */ |
| 16 | package org.onlab.onos.net.flow; |
| 17 | |
| 18 | import java.util.LinkedList; |
| 19 | import java.util.List; |
| 20 | |
| 21 | import org.junit.Test; |
| 22 | import org.onlab.onos.net.intent.IntentTestsMocks; |
| 23 | |
| 24 | import static org.hamcrest.MatcherAssert.assertThat; |
| 25 | import static org.hamcrest.Matchers.hasSize; |
| 26 | import static org.hamcrest.Matchers.is; |
| 27 | |
| 28 | /** |
| 29 | * Unit tests for the FlowRuleBatchRequest class. |
| 30 | */ |
| 31 | public class FlowRuleBatchRequestTest { |
| 32 | |
| 33 | /** |
| 34 | * Tests that construction of FlowRuleBatchRequest objects returns the |
| 35 | * correct objects. |
| 36 | */ |
| 37 | @Test |
| 38 | public void testConstruction() { |
| 39 | final FlowRule rule1 = new IntentTestsMocks.MockFlowRule(1); |
| 40 | final FlowRule rule2 = new IntentTestsMocks.MockFlowRule(2); |
| 41 | final List<FlowRule> toAdd = new LinkedList<>(); |
| 42 | toAdd.add(rule1); |
| 43 | final List<FlowRule> toRemove = new LinkedList<>(); |
| 44 | toRemove.add(rule2); |
| 45 | |
| 46 | |
| 47 | final FlowRuleBatchRequest request = |
| 48 | new FlowRuleBatchRequest(1, toAdd, toRemove); |
| 49 | |
| 50 | assertThat(request.toAdd(), hasSize(1)); |
| 51 | assertThat(request.toAdd().get(0), is(rule1)); |
| 52 | assertThat(request.toRemove(), hasSize(1)); |
| 53 | assertThat(request.toRemove().get(0), is(rule2)); |
| 54 | assertThat(request.batchId(), is(1)); |
| 55 | |
| 56 | final FlowRuleBatchOperation op = request.asBatchOperation(); |
| 57 | assertThat(op.size(), is(2)); |
| 58 | |
| 59 | final List<FlowRuleBatchEntry> ops = op.getOperations(); |
| 60 | assertThat(ops, hasSize(2)); |
| 61 | } |
| 62 | |
| 63 | } |