blob: a06e84a2c3d2c528eaff8ee054acdcf1cba0ba03 [file] [log] [blame]
Ray Milkeyf19b7152014-11-21 10:56:52 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
Ray Milkeyf19b7152014-11-21 10:56:52 -08003 *
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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.flow;
Ray Milkeyf19b7152014-11-21 10:56:52 -080017
Ray Milkeyf19b7152014-11-21 10:56:52 -080018import org.junit.Test;
Brian O'Connorabafb502014-12-02 22:26:20 -080019import org.onosproject.net.intent.IntentTestsMocks;
Ray Milkeyf19b7152014-11-21 10:56:52 -080020
Brian O'Connor72cb19a2015-01-16 16:14:41 -080021import java.util.HashSet;
22import java.util.List;
23import java.util.Set;
Brian O'Connor427a1762014-11-19 18:40:32 -080024
Ray Milkeyf19b7152014-11-21 10:56:52 -080025import static org.hamcrest.MatcherAssert.assertThat;
26import static org.hamcrest.Matchers.hasSize;
27import static org.hamcrest.Matchers.is;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080028import static org.onosproject.net.flow.FlowRuleBatchEntry.FlowRuleOperation.ADD;
29import static org.onosproject.net.flow.FlowRuleBatchEntry.FlowRuleOperation.REMOVE;
Ray Milkeyf19b7152014-11-21 10:56:52 -080030
31/**
32 * Unit tests for the FlowRuleBatchRequest class.
33 */
34public 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'Connor72cb19a2015-01-16 16:14:41 -080044 final Set<FlowRuleBatchEntry> batch = new HashSet<>();
45 batch.add(new FlowRuleBatchEntry(ADD, rule1));
46
47 batch.add(new FlowRuleBatchEntry(REMOVE, rule2));
Ray Milkeyf19b7152014-11-21 10:56:52 -080048
49
50 final FlowRuleBatchRequest request =
Brian O'Connor72cb19a2015-01-16 16:14:41 -080051 new FlowRuleBatchRequest(1, batch);
Ray Milkeyf19b7152014-11-21 10:56:52 -080052
Brian O'Connor72cb19a2015-01-16 16:14:41 -080053 assertThat(request.ops(), hasSize(2));
54 assertThat(request.batchId(), is(1L));
Ray Milkeyf19b7152014-11-21 10:56:52 -080055
Brian O'Connor72cb19a2015-01-16 16:14:41 -080056 final FlowRuleBatchOperation op = request.asBatchOperation(rule1.deviceId());
Ray Milkeyf19b7152014-11-21 10:56:52 -080057 assertThat(op.size(), is(2));
58
59 final List<FlowRuleBatchEntry> ops = op.getOperations();
60 assertThat(ops, hasSize(2));
61 }
62
63}