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